//------------------------------------------------------------------------------
// Tabs
//------------------------------------------------------------------------------

// ShowTab - Afisaza tab-ul selectat si le ascunde pe celelalte
function ShowTab(sender, element)
{
	if (sender !== null)
	{
		ResetTabsState();
		$(sender).addClass("selected");
	}

	if ($("#tab1").is(":visible"))
		$("#tab1").hide();
	if ($("#tab2").is(":visible"))
		$("#tab2").hide();
	if ($("#tab3").is(":visible"))
		$("#tab3").hide();
	if ($("#tab4").is(":visible"))
		$("#tab4").hide();
	if ($("#tab5").is(":visible"))
		$("#tab5").hide();

	$(element).fadeIn(300);
	SetHeight(element);

	if ($.toggle_right_tabs == true)
	{
		var right_tab = $(element + "-right");

		if (right_tab !== null)
			right_tab.show();
	}
}


function ResetTabsState(sender)
{
	if (sender == undefined)
	{
		$("li.tab1 a").removeClass("selected");
		$("li.tab2 a").removeClass("selected");
		$("li.tab3 a").removeClass("selected");
		$("li.tab4 a").removeClass("selected");
		$("li.tab5 a").removeClass("selected");
		
		if ($.toggle_right_tabs == true)
		{
			var right1 = $("#tab1-right");
			var right2 = $("#tab2-right");
			var right3 = $("#tab3-right");
			var right4 = $("#tab4-right");
			var right5 = $("#tab5-right");

			if (right1 !== null)
				right1.hide();

			if (right2 !== null)
				right2.hide();

			if (right3 !== null)
				right3.hide();
			
			if (right4 !== null)
				right4.hide();
			
			if (right5 !== null)
				right5.hide();
		}
	}
	else
	{
		$.ul = $(sender).parent().parent();

		$("#" + $.ul.get(0).id + " > li > a").each(function(){
			if ("#" + this.id !== sender)
				$("#" + this.id).removeClass("selected");
		});
	}
}


function SetHeight(tab)
{
	// - container (acelas height cu tab1, deoarece tab1 este afisat default)
	//		- slot-main
	//			- tabX (height fix)
	//		- slot right (height fix, deoarece fara mosteneste height 100% de la clasa)
	
	var a = parseInt($("div.container > div.slot-main > " + tab).height());
	var b = parseInt($("div.container > div.slot-right").height());
	var x = ( a >= b ? a : b );
	
	$("div.container").css("height", x.toString() + "px");
	$("div.container > div.slot-main > " + tab).css("height", x.toString() + "px");
}


//------------------------------------------------------------------------------
// Link direct cater un anumit tab
//------------------------------------------------------------------------------

function CheckAndSwitchTo()
{
	var tab_rx		= /\?tab=/i;
	var index_rx	= /index.html/;
	var where		= document.location.href;

	if (where.match(tab_rx))
	{
		var items		= where.split(tab_rx);
		var tab_name	= "#tab" + items[1];
		var tab_btn		= "#tab" + items[1] + "-btn";

		if (where.match(index_rx))
		{
			DisplayContent("#batchphoto-tab" + items[1] + "-btn", "#batchphoto-tab" + items[1], "#batchphoto");
		}
		else
		{
			try
			{
				ResetTabsState();
				ShowTab(tab_btn, tab_name);
			}
			catch (ex) { }
		}
	}
}
