/* global.js */


$(function(){

	
	
	/** 
	 * Gets omniture vars based on string matching for any link that strats with http...
	 **/
	$('a[@href^="http://"]').bind("click" ,function(e){
		
		
		
		var href = $(this).attr("href");
		var linkText = $(this).text().toLowerCase();
		
		if(href.indexOf("www.todaysmilitary.com") < 0)//ensure the tm.com links are not tracked (google searchH)
		{
			
			s.linkTrackVars="eVar1,eVar2,prop2,prop3,events";
			s.linkTrackEvents="event2";
			s.events = "event2";
			
			
			
			//set the value for eVar1 
			if(linkText.indexOf("army") > -1){
				s.eVar1 = "Army";
				if(linkText.indexOf("reserve") > -1)
					s.eVar1 += " Reserves";
			}
			if(!s.eVar1 && (linkText.indexOf("goguard") > -1 || linkText.indexOf("ngb") > -1)){
				s.eVar1 = "Army National Guard";
			}
			if(!s.eVar1 && linkText.indexOf("marine") > -1){
				
				s.eVar1 = "Marines";
				if(href.indexOf("Reserves.jsp") > -1)
					s.eVar1 += " Reserve";
			}
		
			if(!s.eVar1 && linkText.indexOf("navy") > -1){
				s.eVar1 = "Navy";
				if(linkText.indexOf("reserve") > -1)
					s.eVar1 += " Reserve";
				}
			if(!s.eVar1 && linkText.indexOf("force") > -1){
				s.eVar1 = "Air Force";
				if(linkText.indexOf("reserve") > -1 || linkText.indexOf("afreserve") > -1)
				 s.eVar1 += " Reserve";
				}
				if(!s.eVar1 && href.indexOf("ang") > -1){
					s.eVar1 = "Air Guard";
				}
				if(!s.eVar1 && (linkText.indexOf("coast") > -1 || linkText.indexOf("uscg") > -1)){
					s.eVar1 = "Coast Guard";
					if(linkText.indexOf("reserve") > -1){
						s.eVar1 += " Reserve";
					}
				}
				if(!s.eVar1)
				{
					s.eVar1 = "General Government";
				}
		
				//set eVar 2 and corresponding sprop's.
				if(s.eVar1)
				{
					if(linkText.indexOf("parent") > -1 || linkText.indexOf("mom") > -1){
						s.eVar2 = s.eVar1+" | Parents";
					}
					if(linkText.indexOf("tuition") > -1){
						s.eVar2 = s.eVar1+" | Tuition Informaion";
					}
					if(linkText.indexOf("recruit") > -1){
						s.eVar2 = s.eVar1+" | Recruiter Informaion";
					}
					if(linkText.indexOf("news") > -1){
						s.eVar2 = s.eVar1+" | News";
					}
					if(!s.eVar2)
					{
						s.eVar2 = s.eVar1+" | General";
					}
			
			
					s.eVar2 +=" "+href; //append url to eVar2
					
					//set the corresponding sprop's
					s.prop2 = s.eVar1
					s.prop3 = s.eVar2;
					
				}
				//send vals.
				s.tl(this,'e','link_'+s.eVar1+'_'+href.replace(/^https?:\/\//i,""));
				window.open(href);
				
				//reset the eVars to clean them;
				s.eVar1 = "";
				s.eVar2 = "";
				
				return false;
		}//end tm.com if
	});// end 

	/**
	 * Gets branch interests upon form submission
	 **/
	$("#btnSubmit").click(function(){
		
		var selectedBranches = ""; 
		
		//if the corrext form, loop through and get selected vals.
		if($("#fieldsetMIBranches").size() >  0)
		{
			$(".chkBranchInterest").each(function(){
				if(this.checked)
				{
					selectedBranches += this.value+",";
				}
				
			});
			//set the omniture var
			if(selectedBranches != "")
			{
				s.linkTrackVars="eVar3";
				s.eVar3 = selectedBranches; 
				s.tl(this,'o','"Interested" Form Submissions');
			}
		}
	});//end
	
	/**
	 * Track PDF Downloads
	 */
	$('a[@href$=".pdf"]').bind("click" ,function(e){
		
		
		var href = $(this).attr("href");
		s.tl(this, 'd', href.replace("/pdf/", ""));
		window.open(href);
		return false;
	});

	
	
});

function playerLoaded(){
   if(($("#divVidModuleContainer").length < 1) && ($("#videoPlayer").length >= 1)){
      window.setTimeout("document.getElementById(\"videoPlayer\").selectClip(0);", 100);
   }
}
