$(document).ready(function(){
	assignRollover();
	prepareVideoLinks();
	startTransitions();
});

var oInterval = "";
var iHeaderCounter = 0;
function startTransitions(){
   oInterval = setInterval(fnDoHeaderTransition,5000);
}

function restartTransitions(){
	if(iHeaderCounter==-1){			
		iHeaderCounter=0;
	}
}

function fnDoHeaderTransition(){
    switch (iHeaderCounter){
		case 0:
			$('#hero').fadeOut();
			$('#hero0').fadeIn(1500);
			$('#hero1').fadeOut();
			$('#hero2').fadeOut();
			$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange_over.png') no-repeat top left");
			$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
			$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
			iHeaderCounter = 1;
			break;
		case 1:
			$('#hero').fadeOut();
			$('#hero0').fadeOut();
			$('#hero1').fadeIn(1500);
			$('#hero2').fadeOut();
			$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
			$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue_over.png') no-repeat top left");
			$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
			iHeaderCounter = 2;
			break;
		case 2:
			$('#hero').fadeOut();
			$('#hero0').fadeOut();
			$('#hero1').fadeOut();
			$('#hero2').fadeIn(1500);
			$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
			$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
			$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray_over.png') no-repeat top left");
			iHeaderCounter = 3;
			break;
		case 3:
			$('#hero').fadeIn(1500);
			$('#hero0').fadeOut();
			$('#hero1').fadeOut();
			$('#hero2').fadeOut();
			$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
			$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
			$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
			iHeaderCounter = 0
			break;
		default:
   }
}

function assignRollover(){
	$('#hero0').hide();
	$('#hero1').hide();
	$('#hero2').hide();
	
	/* assign events for right top nav image links*/
	$('#questions #heroLink0').mouseover(function(){
	    $('#hero0').fadeIn();
		$('#hero').fadeOut();
		$('#hero1').fadeOut();
		$('#hero2').fadeOut();
		
		$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange_over.png') no-repeat top left");
		$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
		$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
				
		iHeaderCounter=-1;//transitions off
		
	});
	$('#questions #heroLink1').mouseover(function(){
	    $('#hero').fadeOut();
		$('#hero0').fadeOut();
		$('#hero2').fadeOut();
		$('#hero1').fadeIn();
		$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
		$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue_over.png') no-repeat top left");
		$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
		iHeaderCounter=-1;//transitions off
	});
	$('#questions #heroLink2').mouseover(function(){
	    $('#hero').fadeOut();
		$('#hero0').fadeOut();
		$('#hero1').fadeOut();
		$('#hero2').fadeIn();
		$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
		$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
		$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray_over.png') no-repeat top left");
		iHeaderCounter=-1;//transitions off
	});
	
	
	$('#toplinks').mouseover(function(){
	    if(iHeaderCounter==-1){
			$('#hero0').fadeOut();
			$('#hero1').fadeOut();
			$('#hero2').fadeOut();
			$('#hero').fadeIn();
			$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
			$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
			$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
			restartTransitions();
		}
	});
	
	$('#block-megamenu-0').mouseover(function(){
		if(iHeaderCounter==-1){
			$('#hero0').fadeOut();
			$('#hero1').fadeOut();
			$('#hero2').fadeOut();
			$('#hero').fadeIn();
			$('#heroLink0').css("background","url('/sites/all/themes/moonstone/images/bg_orange.png') no-repeat top left");
			$('#heroLink1').css("background","url('/sites/all/themes/moonstone/images/bg_blue.png') no-repeat top left");
			$('#heroLink2').css("background","url('/sites/all/themes/moonstone/images/bg_gray.png') no-repeat top left");
			restartTransitions();
		}
	});
	
	
}

function xxassignRollover(){
	/* assign events for right top nav image links*/
	$('#questions a').mouseover(function(){
		var bannerID = $(this).attr('rel');
		$('.hero').hide();
		$('#'+bannerID).show();	
	});
	/*
	$('#questions a').mouseout(function(){
		var bannerID = $(this).attr('rel');
		$('.hero').show();
		$('#'+bannerID).hide();	
	});
	*/
	
	
	$('#toplinks').mouseover(function(){
		var bannerID = $(this).attr('rel');
		$('.hero').show();
		$('#'+bannerID).hide();	
	});
	
	$('#block-megamenu-0').mouseover(function(){
		var bannerID = $(this).attr('rel');
		$('.hero').show();
		$('#'+bannerID).hide();	
	});
	
	
}
	
function resetZindex(elements){
	for (var i=0; i<elements.length; i++){
		elements[i].style.zIndex = 0;
	}
}

function prepareVideoLinks(){
	if(!getElementsByClassName(document, 'a', 'openFlashVideo')) return;
	var links = getElementsByClassName(document, 'a', 'openFlashVideo');
	for (var i=0; i<links.length; i++){
		links[i].onclick = function(){
			playRtmpVideo(this.getAttribute('rel'), "videoLink", true);
			return false;
		}
	}
}
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}


