function load_video_dialog (trg_id, url, onload)
{
	var spiner = '<div class="preloader"><img src="'+strARECMSImagesPath+'dialog/preloader.gif" alt="" />'+strARECMSPreloaderCaption+'</div>';

	$('#'+trg_id).html(spiner);
	$('#'+trg_id).dialog('open');
	$('#'+trg_id).load(url, null, function(){
			var intVideoWidth = parseInt($('#'+trg_id).find('object').width()) + 2;
			$('#'+trg_id).dialog( "option" , "width" , intVideoWidth );										   
		});
}

/********************   ONLOAD   ********************/
$(document).ready(function()
{
	// Search Box
	if($('#search_button').size() && $('#search_box').size()) {

		$('#search_button').tooltip({ 
			offset: [30, -90],
			delay: 100,
			effect: 'slide',
			slideOffset: 30,
			position: 'bottom center',
			opacity: 1,
			predelay: 100,
			tip: '#search_box'
		});
	}

	// Collapsing panels (requires panel.js) 
	$('.cpanel').each( function(){pcpan_init( $(this) )} );
	
	// Textboxes and Textareas watermarks (requires watermark.js)
	if($('input.txtbox').size()) {
    	$('input.txtbox').simpleWaterMark('watermark');
	}
	if( $('textarea').size()) {
    	$('textarea').simpleWaterMark('watermark');
	}
	
	// Festival Cicle Images (requires jquery.cycle.all.min.js)
	/* Possible effects: 
	* blindX	    * blindY	    * blindZ
	* cover			* curtainX	    * curtainY
    * fade		    * fadeZoom		* growX
	* growY			* scrollUp	    * scrollDown
    * scrollLeft    * scrollRight	* scrollHorz
	* scrollVert	* shuffle	    * slideX
    * slideY	    * toss			* turnUp
	* turnDown		* turnLeft	    * turnRight
    * uncover	    * wipe			* zoom
	* all
	*/
	if( $('.festival .pics').size()) {
    	$('.festival .pics').cycle('fade');
	}
	
	// Dialog
	if ( $('#video_dialog').size() ) {
		$("#video_dialog").dialog({
			autoOpen: false,
			stack: false,
			modal: true,
			position: ['center', 75],
			width: 482,
			resizable: true
		});
		
		$(".video_link").click(function(){ load_video_dialog( 'video_dialog', $(this).attr('rel'), null );});
	}
	
	// Past scroller (requires past.scroll.js)
	if ( $('.archive ul').size() )
	{
		fnPastFestivalScrollerInit('div.archive');
	}
	
	// Archive navigation
	if ( $('.articles_archive').size() ) {
		$('.articles_archive h2 select').change(function(){
			window.location = $(this).val();
		});
	}
});
