// JavaScript Document

function submitForm()	{
	document.login.submit();
}


function highlightMainNav(selector){
	$(selector).addClass("current");
	$(selector).children(".btnOver").show();
	$(selector).children(".btn").hide();
}

$(document).ready(function(){
	
	$(".hover-btn").hover(function () {
			if($(this).hasClass("current")){
			}else{
				$(this).children(".btnOver").show();
				$(this).children(".btn").hide();
			}
		}, function () {
			if($(this).hasClass("current")){
			}else{
				$(this).children(".btn").show();
				$(this).children(".btnOver").hide();
			}
	});
	
	// all popup close buttons
	$('.close-popup-button').click(function() {
	  closePopup();
	});
	
	$("#loginLink, .loginLink").click(function() { popup($('#loginPopup')); } );
	
	
	//demo: http://www.malsup.com/jquery/cycle/int2.html
	$('#rotating-divs') 
	.cycle({ 
		//speed:  'fast', 
		timeout: 7000, 
		//delay:2000,
		timeoutFn: calculateTimeout,
		next:   '#aboutRightArrow', 
    	prev:   '#aboutLeftArrow',
		pager:  '#rotation-tabs' 
	});
	function calculateTimeout(currElement, nextElement, opts, isForward) { 
		var index = opts.currSlide;
		if (index == 0){ return 9000;}
		else {return 7000;}
		//return index = 1 ? 14000 : 7000; 
	}
	$("#rotation-pause").click(function(){
		if($('#rotation-pause').hasClass('pause')){
			$('#rotating-divs').cycle('pause');
			$('#rotation-pause').removeClass('pause');
			$('#rotation-pause').addClass('play');
		} else{
			$('#rotating-divs').cycle('resume');
			$('#rotation-pause').removeClass('play');
			$('#rotation-pause').addClass('pause');
		}
		
	});
	
	//LINKS
	$('#toPanel2').click(function() { 
		$('#rotating-divs').cycle(1); 
		return false; 
	});
	$('#toPanel3').click(function() { 
		$('#rotating-divs').cycle(2); 
		return false; 
	});
	$('#toPanel4').click(function() { 
		$('#rotating-divs').cycle(3); 
		return false; 
	});
	$('#toPanel5').click(function() { 
		$('#rotating-divs').cycle(4); 
		return false; 
	});
	$('#toPanel6').click(function() { 
		$('#rotating-divs').cycle(5); 
		return false; 
	});
	$('#toPanel7').click(function() { 
		$('#rotating-divs').cycle(6); 
		return false; 
	});
	$('#toPanel8').click(function() { 
		$('#rotating-divs').cycle(7); 
		return false; 
	});
	$('#toPanel9').click(function() { 
		$('#rotating-divs').cycle(8); 
		return false; 
	});
	$('#toPanel10').click(function() { 
		$('#rotating-divs').cycle(9); 
		return false; 
	});
	$('#toPanel11').click(function() { 
		$('#rotating-divs').cycle(10); 
		return false; 
	});
	
	
	
	
	
});



//************************ POPUPS ***********************************/

var currPopup;

function popup(popupElement) {
    
	// Keeping track of popup for resize function and use in supporting functions
    currPopup = $(popupElement);
    
	sizeUnderlay();
	$("#popup-underlay").show();
	
	positionPopup();
	
	//Scroll to window top because top position of popup is based on window rather than height of popup
    $(window).scrollTop(0);
    
	$(currPopup).fadeIn();
}
function closePopup() {
    $(currPopup).fadeOut();
	$("#popup-underlay").hide();
}
function positionPopup() {
	var numForOffset = 45;
    $(currPopup).css("left", parseInt(($(window).width() / 2) - (($(currPopup).width()-numForOffset) / 2)).toString() + "px");
    $(currPopup).css("top", parseInt($(window).height() * 0.15).toString() + "px");
}
function sizeUnderlay(){
	$("#popup-underlay").css("width", $(document).width() + "px");
   	$("#popup-underlay").css("height", $(document).height() + "px");  	
}
$(window).resize(function() {
  	sizeUnderlay();
	positionPopup();
});
