//ON DOM READY CALLS
jQuery(document).ready(function () {
	jQuery("#Login_ID").focus(function () {
		document.getElementById('Login_ID').style.background = '#ffffff';
		//console.log('Login_ID:focus');
	});
	
	jQuery("#loginUsername").focus(function () {
		document.getElementById('loginUsername').style.background = '#ffffff';
		//console.log('Login_ID:focus');
	});
	
	jQuery("#loginPass").focus(function () {
		document.getElementById('loginPass').style.background = '#ffffff';
		//console.log('loginPass:focus');
	});
	/*
	jQuery("#PremiumTabContainer .tab-button").click(function () { 
		PremiumTabs(this);
    	console.log('Click Premium Tab'); 
    });
	*/
	InitializePremiumTabs();
});

function InitializePremiumTabs()
{
	var activeNum=0;
	jQuery("td.tab-button").click(function ()
	{
 		jQuery("div.tab-content").hide();
// 		jQuery("div.tab-content").removeClass("active");
 		jQuery("td.tab-button").removeClass("activePremiumTab");	//remove active from tab-button

		jQuery(this).addClass("activePremiumTab");

		activeNum=jQuery(".activePremiumTab").attr("id").split("_");
//		alert(activeNum[1]);
		obj=jQuery("#PremiumContent_"+activeNum[1]);
//		jQuery(obj).addClass("active");
		jQuery(obj).fadeIn("slow");
  });
}


/*
function InitializePremiumTabs() {
	jQuery("td.tab-button").click(function () { 

		jQuery("div.tab-content").removeClass("active");
 		jQuery("div.tab-content").hide("slow");
 		jQuery("div.tab-content").removeClass("active");
 		jQuery("td.tab-button").removeClass("active");	//remove active from tab-button

		jQuery(this).addClass("tab-button active");
		for(i = 0; i < jQuery("td.tab-button").length; i++) 
		{
			if(jQuery("td.tab-button")[i].className=='active')
			{
				//jQuery(".arrow-box img").animate({"left": arrow_left[i]+"px"}, 1500);
				//jQuery("div.tab-content")[i].className='tab-content active';
				obj=jQuery("div.tab-content")[i];
				setTimeout('jQuery(obj).slideDown("750")',750);
			}
		}
   	});
}
*/

function PremiumTabs(obj_this) {
	jQuery("#PremiumTabContainer .tab-button").removeClass("active");
	jQuery("#PremiumTabContainer .tab-content").removeClass("active");
	
	for(i = 0; i < jQuery("td.tab-button").length; i++){
		if(jQuery("td.tab-button")[i]==obj_this){
			ActivatePremiumTabs(i+1);
		}
	}
}

function ActivatePremiumTabs(num) {
	for(i = 0; i < jQuery(".tab-button").length; i++)
	{
		jQuery("td.tab-button")[i].className=='tab-button';
		jQuery(".tab-content")[i].className = 'tab-content';
	}
	document.getElementById('PremiumButton_'+num).className = 'tab-button active';
	document.getElementById('PremiumContent_'+num).className = 'tab-content active';	
}

function PremiumTabContent() {
	for(i = 0; i < jQuery("td.tab-button").length; i++) 
	{
		if(jQuery("td.tab-button")[i].className=='tab-button active') 
		{
			jQuery("#PremiumTabContainer .tab-content")[i].className = 'tab-content active';
		}
	}
}
	
/**************************************************************************
START ROTATOR
**************************************************************************/
/*var rotate = true;*/
var rotate_current = 0;
var rotate_end = 4;

//ON DOM READY
jQuery(document).ready(function () {
	jQuery(".sub-story-box").click(function () { 
	    	selectSubImage(this)
	    });
});

function Rotate() {
	//console.log("Rotate()");
	if(rotate) {
		//console.log("go");
		rotateForward(false);
	}
	else {
		//console.log('stop');
	}
}

function rotateForward(button) {
	if(button)
		rotate = false;
	//console.log('Forward');
	if(rotate_current!=rotate_end)
		rotate_current ++;
	else
		rotate_current = 0;	
	changeArticle();
}

function selectSubImage(obj) {
	//console.log('this:'+obj);
	for(i = 0; i < jQuery(".sub-story-box").length; i++) {
		//console.log('sub-story-box:'+jQuery(".sub-story-box")[i]);
		if(jQuery(".sub-story-box")[i]==obj)
			rotate_current = i;
	}
	rotate = false;
	changeArticle();
}

function rotateBack() {
	//console.log('Back');
	if(rotate_current!=0)
		rotate_current --;
	else
		rotate_current = rotate_end;	
	changeArticle();
}

function changeArticle() {
	jQuery(".main-content").removeClass("active");
	jQuery(".main-content").hide();
	for(i = 0; i < jQuery(".main-content").length; i++)
	{
		if(i==rotate_current)
		{
			jQuery(".main-content")[i].className='main-content active';
			jQuery("#rotatorMainLimiter .active").hide();
			jQuery("#rotatorMainLimiter .active").fadeIn("slow");
//			alert(i);
		}
	}

	for(i = 0; i < jQuery(".sub-story-box").length; i++) 
	{
		if(i==rotate_current) 
		{
			jQuery(".sub-story-box")[i].className='sub-story-box inactive';
//			jQuery(".sub-story-box")[i].fadeOut();
		}
		else 
		{
			jQuery(".sub-story-box")[i].className=("sub-story-box active");
//			jQuery(".sub-story-box")[i].fadeOut();
		}
	}
}

function toggle() {
	//console.log('toggle');
	if(rotate) 
		rotate = false;
	else 
		rotate = true;
}

var r = setInterval('Rotate()',5000);	//call rotate every 5 seconds

/**************************************************************************
END ROTATOR
**************************************************************************/

function ActivateBottomTab(num) {
	jQuery(".bottom-control").hide();
	jQuery(".bottom-tab-content").hide();
	jQuery("#Control_"+num).show();
	jQuery("#Content_"+num).fadeIn("slow");
}