var section_intervalID = 0;
var combox_intervalID = 0;
if( typeof ActiveSection != "undefined" && ActiveSection == 0)
{
	function loadHomeBottom( paramLoad )
	{
		$("#HomeBottom").load(baseurl + "sections/home/home_bottom.php?ajax=true&listtype="+paramLoad+"&rnd="+(Math.random()*100), {}, function()
		{
			switch ( paramLoad )
			{
				case 1:
					$("#HomeBottom_1").attr("class", "OrderActive");
					$("#HomeBottom_2").attr("class", "Order");
					$("#HomeBottom_3").attr("class", "Order");
				break;
				case 2:
					$("#HomeBottom_1").attr("class", "Order");
					$("#HomeBottom_2").attr("class", "OrderActive");
					$("#HomeBottom_3").attr("class", "Order");
				break;
				case 3:
					$("#HomeBottom_1").attr("class", "Order");
					$("#HomeBottom_2").attr("class", "Order");
					$("#HomeBottom_3").attr("class", "OrderActive");
				break;
			}
			xec_overdivs();
		});
	}
	
	
	$ = jQuery;
	
	
	
	$(document).ready(function()
	{
		var LastVideosConteiner = new xec_slide("LastVideosConteiner");
		LastVideosConteiner.pager_links = 8;
		
		var LastPicturesConteiner = new xec_slide("LastPicturesConteiner");
		LastPicturesConteiner.pager_links = 8;
		
		
		$Changed = (navigator.appCodeName.search("Mozilla")!=-1)?true:false;
		if($Changed){
			//alert("aslkdfjaskl");
			LastPicturesConteiner.auto_slide_speed = 50;
			LastVideosConteiner.auto_slide_speed = 50;
		}else{
			LastVideosConteiner.auto_slide_speed = 100;	
			LastPicturesConteiner.auto_slide_speed = 100;
		}
		
		LastPicturesConteiner.init();
		LastVideosConteiner.init();
		
		
	});
	
	
	function PrevConteiner( paramConteiner, paramType )
	{
		if( paramType == 1 )
		{// pic
			if( PictureTrack > 1 )
			{
				NewPage = PictureTrack - 1;
				setNum = PictureTrack * 4 - 1;	
			}
			$("#"+paramConteiner+"_Page"+NewPage).click();
		}
		else if( paramType == 2)
		{// vid
			if( VideoTrack > 1 )
			{
				NewPage = VideoTrack - 1;
				setNum = VideoTrack * 4 - 1;	
			}
			$("#"+paramConteiner+"_Page"+NewPage).click();
		}
	}
	function NextConteiner( paramConteiner, paramType )
	{
		if( paramType == 1 )
		{// pic
			if( PictureTrack == 4 )
			{
				setNum = 0;
				NewPage = 1;
			}
			else
			{
				setNum = PictureTrack * 4 - 1;
				NewPage = PictureTrack + 1;
			}
			$("#"+paramConteiner+"_Page"+NewPage).click();
			//w("#"+paramConteiner+"_Page"+NewPage);
		}
		else if( paramType == 2)
		{// vid 
			if( VideoTrack == 4 )
			{
				setNum = 0;
				NewPage = 1;
			}
			else
			{
				setNum = VideoTrack * 4 - 1;
				NewPage = VideoTrack + 1;
			}
			$("#"+paramConteiner+"_Page"+NewPage).click();
		}
	}
	function w(what)
	{
		$("#console").html( $("#console").html() + "<br \>" + what );
	}
}


function init_combobox()
{
	if(typeof $('#CategoryDropdown').combobox != "function")
	{
		combox_intervalID = setTimeout("init_combobox()", 100);
	}
	else
	{
		video_top_right();
		
		var dropD = $('#CategoryDropdown').combobox(
		{
			comboboxContainerClass: "comboboxContainer",
			comboboxValueContainerClass: "comboboxValueContainer",
			comboboxValueContentClass: "comboboxValueContent",
			comboboxDropDownClass: "comboboxDropDownContainer",
			comboboxDropDownButtonClass: "comboboxDropDownButton",
			comboboxDropDownItemClass: "comboboxItem",
			comboboxDropDownItemHoverClass: "comboboxItemHover",
			comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader",
			comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer",
			animationType: "slide"
		});
		
		//var dropD = $('#CategoryDropdown').combobox();
		//dropD.combobox.updateSelection();
		
		clearInterval(combox_intervalID);
	}
}

function init_event_requred()
{
	if(typeof $('#rangeDatepicker').datepick != "function")
	{
		section_intervalID = setTimeout("init_event_requred()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		$('#rangeDatepicker').datepick($.extend({rangeSelect: true, 
			dateFormat: 'dd/mm/yy',
			onSelect: function(value, date) { document.SearchForm.submit(); }
			},
			$.datepick.regional['fr'])
		);	
	}
}

function init_event_level4()
{
	if(typeof $("#EventDate").date_input != "function")
	{
		section_intervalID = setTimeout("init_event_level4()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		$("#EventDate").date_input();
	}
}

function init_place_level4()
{
	if(typeof $("#EventDate").date_input != "function")
	{
		section_intervalID = setTimeout("init_place_level4()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		$("#EventDate").date_input();
	}
}

function init_drinks_level4()
{
	if(typeof $("#EventDate").date_input != "function")
	{
		section_intervalID = setTimeout("init_drinks_level4()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		$("#EventDate").date_input();
	}
}

function init_pictures_level3()
{
	if(typeof view_pictures_navigate_events != "function")
	{
		section_intervalID = setTimeout("init_pictures_level3()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		hasJSLink();
		convertLinksToAjax();
		view_pictures_navigate_events();
	}
}

function init_news_level3()
{
	/*
	if(typeof view_pictures_navigate_events != "function")
	{
		section_intervalID = setTimeout("init_news_level3()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
	}
	*/
	init_document_dimentions();
}

function init_news_level4()
{
	if(typeof $("#EventDate").date_input != "function")
	{
		section_intervalID = setTimeout("init_news_level4()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		$("#EventDate").date_input();
	}
}

function init_document_dimentions()
{
	if( typeof documentDimensions == "undefined")
	{
		section_intervalID = setTimeout("init_document_dimentions()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		documentDimensions();
	}
}

function new_panel_activate()
{
	if( typeof InitUpdateNews == "undefined" )
	{
		section_intervalID = setTimeout("new_panel_activate()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		if( NewsUpdatesCount > 0 )
		{
			$('#NewsUpdateLogoButton').css(
			{
			   "display" : "block"
			});
			if( PopWindow == true )
			{
				InitUpdateNews( PopPageID )	
			}
		}
	}
}

function init_members_level1()
{
	if( typeof ViewUserSwitchPanel == "undefined" || view_user_switch_panel_active == null )
	{
		section_intervalID = setTimeout("init_members_level1()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		ViewUserSwitchPanel();
	}
}

function init_video_level3()
{
	if( typeof embed_init == "undefined" )
	{
		section_intervalID = setTimeout("init_video_level3()", 100);
	}
	else
	{
		clearInterval(section_intervalID);
		embed_init();
	}
}

function openx_fit_background()
{
	var site_height = $("#SiteTable").height();
	var site_width = ( Math.abs($(document).width()) - 985 ) / 2;
	site_width-=2;
	if(browser_name=="Opera")
	{
		site_width-=1;
	}
	else if(browser_name=="IE")
	{
		site_width-=16;
	}
	else if( browser_name == "Firefox")
	{
		site_width-=1;
	}
	else if( browser_name == "Chrome")
	{
		site_width-=1;
	}
	//console.log("-> " + $("#site_left_block").html());
	if(null == $("#site_left_block a").html() )
	{// no ads
		$("#site_left_block").html('<img src="'+imgurl+'/transperant.png" alt="" border="0" style="width:'+site_width+'px; height:'+site_height+'px;" />');
		$("#site_left_block").clone().appendTo("#site_right_block");
		//console.log("vliza : "+site_width);
	}
	else
	{
		$("#site_left_block a").html('<img src="'+imgurl+'/transperant.png" alt="" border="0" style="width:'+site_width+'px; height:'+site_height+'px;" />');
		$("#site_left_block a").clone().appendTo("#site_right_block");	
	}
}

function footer_initial_load()
{
	//alert("Section : "+ActiveSection+ " | Sub : "+ActiveSubSections);
	
	openx_fit_background();
	
	if( ActiveSection == 0) { init_combobox(); } // home
	if( ActiveSection == 1 && ActiveSubSections == 3 ){ init_video_level3(); } // video
	if( ActiveSection == 4 && ( ActiveSubSections == 1 || ActiveSubSections == 2 )){ init_event_requred(); } // events
	if( ActiveSection == 4 && ActiveSubSections == 4 ){ init_event_level4(); } // events
	if( ActiveSection == 5 && ActiveSubSections == 4 ){ init_place_level4(); } // place
	if( ActiveSection == 6 && ActiveSubSections == 4 ){ init_drinks_level4(); } // drinks
	if( ActiveSection == 2 && ActiveSubSections == 3 ){ init_pictures_level3(); } // drinks
	if( ActiveSection == 9 && ActiveSubSections == 3 ){ init_news_level3(); } // news
	if( ActiveSection == 9 && ActiveSubSections == 4 ){ init_news_level4(); } // news
	if( ActiveSection == 7 && ActiveSubSections == 1 ){ init_members_level1(); } // community
	init_document_dimentions();
	xec_overdivs(); // overdiv INIT ALLWAYS
	xec_overgifs(); // over gifs for videos
	if( NewsUpdatesCount > 0 )
	{
		new_panel_activate();
	}
}
