$(function(){
	
	/******** STANDARD SYNCSHOW BLOCK **********/
	//INJECT THE DATE INTO THE FOOTER
	var d=new Date();
    $("#currentYear").html( d.getFullYear() );
    //NYROMODAL LIVE UPDATING FOR FUTURE DOM OBJECTS
    $('.nyroModal').live('mouseover',function(){ $(this).nyroModal(); });
    //USE "sstip" CLASS TO DISPLAY TOOL TIP OFF TITLE ATTR
    //$(".sstip").live('mouseover',function(){ $(".aToolTip").remove(); $(this).aToolTip().mouseover(); });
	/******** END SYNCSHOW BLOCK **********/
    
	//INVOKE TABBING 
	$('.tabs').tabs();
	$('.tabs a.tabsLink').click(function(e){
		e.preventDefault();
		selectedID = $(this).attr("href");
		$(this).parent().siblings().removeClass("ui-tabs-selected ui-state-active").addClass("ui-state-default");
		$(this).parent().removeClass("ui-state-default").addClass("ui-tabs-selected ui-state-active");
		$(selectedID).siblings(":not(.ui-tabs-nav)").addClass("ui-tabs-hide");
		$(selectedID).removeClass("ui-tabs-hide");
	});
	
	$(".helpCard").hover(function(){
        $(this).css("cursor","pointer");
        $(this).find("a").css("text-decoration","underline");
     },function(){
        $(this).css("cursor","default");
        $(this).find("a").css("text-decoration","none");
     }) 
     .click(function(){
        var href = $(this).find("a").attr("href");
        window.location=href;
     });
	
	//HOMEPAGE HELP ROTATION
	if( $('#Home-HelpRotation').is("div") ){
		$('#Home-HelpRotation').cycle({
			timeout: 7500
		});
	}	
    if( $('#InternalHelpRotation').is("div") ){
  	  $('#InternalHelpRotation').cycle({
  	    timeout: 7500
  	  });
    }
    
    $("#newsletterInput").keypress(function(event){
    	if(event.keyCode==13){
    		$("#newsletterLink").click();
    		return false;
    	}
    	return true;
    });
    $("#newsletterLink").click(function(e){
    	e.preventDefault();
    	var email = $("#newsletterInput").val();
    	email = (email.toLowerCase()=='enter your email') ? '' : email;
    	openAJAX('pagename=ajax_newsletter&fname=newsletter|&newsletter_email='+email+'&path=ajax_newsletter');
    });
	
	//this would adjust the homepage to show the full editor
	if( $(".syncshow").is("div") && $("#HomeContentLimited").is("div") ){
		$("#HomeContentLimited").css('overflow','visible');
	}
	///////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////
	//For HomePage Videos
	//Internet Explorer Specific Styles for homepage videos
	var $appName = navigator.appName;
	if ($appName == 'Microsoft Internet Explorer'){
		$('.homeVidPopup').css("letter-spacing","-1px");
	}
	
	//FOR PLAY AGAIN BUTTON
	//$('#introvid-playagain').click(function() {
		//$(this).fadeOut();
		//document.getElementById("homevideo-1").play();
		//$('#homevideo-1').attr('controls','controls');
	//});
	
	///////////////////////////////////////////////////////////////
	//FOR VIDEO BUTTONS HOVER ACTIONS
	var vidButtonName;
	var titleMovementAmt = 40;
	$('.vidnavbuttons').hover(
		function () {
			vidButtonID = $(this).attr('id');
			vidButtonID = vidButtonID.split('-');
			vidButtonName = vidButtonID[1];
			var $this = $(this);
			
			//For active, inactive state
			if ($('#vidnavbut-transfer').hasClass('transfer-active')) { $('#vidnavbut-transfer').removeClass('transfer-active'); $('#vidnavbut-transfer').addClass('transfer-inactive');}
			if ($('#vidnavbut-transport').hasClass('transport-active')) { $('#vidnavbut-transport').removeClass('transport-active'); $('#vidnavbut-transport').addClass('transport-inactive');}
			if ($('#vidnavbut-lift').hasClass('lift-active')) { $('#vidnavbut-lift').removeClass('lift-active'); $('#vidnavbut-lift').addClass('lift-inactive');}
			if ($this.hasClass(vidButtonName+'-inactive')) {
					$this.removeClass(vidButtonName+'-inactive');
					$this.addClass(vidButtonName+'-active');
			}
			
			//For Title Animation Slide Down
			if (!videoplayed) {
				$('#'+vidButtonName+'-title').stop();
				$('#'+vidButtonName+'-title').css('top','-'+titleMovementAmt+'px');
				$('#'+vidButtonName+'-title').animate({
					top: '+='+titleMovementAmt
				});
			}
			//For Popups
			$('#'+vidButtonName+'-popup').show();
		},
		function () {
			if (!videoplayed) {
				//For Title Animation Slide Up
				$('#'+vidButtonName+'-title').stop();
				$('#'+vidButtonName+'-title').css('top','0px');
				$('#'+vidButtonName+'-title').animate({
					top: '-='+titleMovementAmt
				});
			}
			//For Popups
			$('#'+vidButtonName+'-popup').hide();
		}
	);
	
	//////////////////////////////////////////////////////////////////
	//For playing a marketing video (by clicking one of the three tabs)
	var numberOfVideos = $("video").length;
	var videoplayed;
	//Videos are set to autoplay so when a user clicks on a tab they will start playing. HOWEVER they will play before a user clicks on it. This code stops that.
//	if ($appName != 'Microsoft Internet Explorer') {
//			for (n=2;n<=numberOfVideos;n++) {
//				document.getElementById('homevideo-'+n).pause();
//		}	
//	}
	
	//Change out links if its an Android Phone
	if (navigator.userAgent.match(/Android/i)) {
				//for navigation buttons
				$('.vidnavbuttons').each(function(index) {
					$this = $(this);
					var videoLinkID = $this.attr('rel');
					var videoLink = $('#homevideoandroid-'+videoLinkID).attr('href');
					$this.attr('href',videoLink);
				});
				//for green play button in video navigation area
				var playbuttonlink = $('#homepage-playbutton').attr('rel');
				var videoLink = $('#homevideoandroid-'+playbuttonlink).attr('href');
				$('#homepage-playbutton').attr('href',videoLink);
				vidButtonName = 'transfer';
				$('#vidnavbut-transfer').click();
	}
	$('.vidnavbuttons').click(function(){
		//For keeping the title bar showing
		videoplayed = true;
		$('.vidtitle').css('top','-'+titleMovementAmt+'px');
		$('#'+vidButtonName+'-title').css('top','0px');
		
		//Getting variables ready to play either HTML version or FLASH version of video, also executing some animations.
		var videoPlayerID = $(this).attr('rel');
		var flashVideoPlayerID = 'homeflashvideo-'+videoPlayerID;
		var flashVideoName = $('#'+flashVideoPlayerID).attr('alt');
		videoPlayerID = "homevideo-"+videoPlayerID;
		$('.homehtmlvideo, #introvid-playagain, .homeflashvideo, #homepage-playbutton, #homepage-vidcallout, .viddetails, .vidnavbox-TNwrapper').fadeOut();
		$('#'+videoPlayerID+', #'+flashVideoPlayerID+', #'+vidButtonName+'-details, #'+vidButtonName+'-TN').fadeIn();
		
		//Video toggles - DC
		var videocalled = $(this).attr('id');
		if(videocalled == "vidnavbut-transfer"){
			
			flashPlay('stop','video1');
			flashPlay('stop','video3');
			flashPlay('stop','video4');
			$("#video3,#video4,#video1").hide();
			$("#video2").show('normal',function(){
				//flashPlay('play','video2');
				setTimeout(function() {
					flashPlay('play','video2');
				 }, 1000 /* time to delay */ );
			});

		}
		else if(videocalled == "vidnavbut-transport"){
			
			flashPlay('stop','video1');
			flashPlay('stop','video2');
			flashPlay('stop','video4');
			$("#video1,#video2,#video4").hide();
			$("#video3").show('normal',function(){
				//flashPlay('play','video3');
				setTimeout(function() {
					flashPlay('play','video3');
				 }, 1000 /* time to delay */ );
			});
			
		}
		else if(videocalled == "vidnavbut-lift"){
			
			flashPlay('stop','video1');
			flashPlay('stop','video2');
			flashPlay('stop','video3');
			$("#video1,#video2,#video3").hide();
			$("#video4").show('normal',function(){
				//flashPlay('play','video4');
				setTimeout(function() {
					flashPlay('play','video4');
				 }, 1000 /* time to delay */ );
			});
			
		}
	});
	//////////////////////////////////////////////////////////////////
	
	//Stop these videos on the Homepage load
	flashPlay('play','video1');
	flashPlay('stop','video2');
	flashPlay('stop','video3');
	flashPlay('stop','video4');
	
	//Large play button in center of white area to the right of the video
	$('#homepage-playbutton').click(function(){
		vidButtonName = 'transfer';
		$('#vidnavbut-transfer').click();
	});
	
	
	
	
	
	

});

function homepageintrovid(domVideo) {
	var videoID = domVideo.id;
		if ( !(navigator.userAgent.match(/iPhone/i)) ) {
				$('#introvid-playagain').fadeIn();
		};
		$('#'+videoID).attr('controls','');
}

