//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
// to select a course
	
	function getQueryKey(searchKey) {
	   var url = location.search;
	   var query = url.split("?");
	   if(query.length < 2)
		return "";
	   var pairs = query[1].split("&");

	   var split, key, val, found = false;

	   for ( var i = 0; i < pairs.length; i++ ){
		split = pairs[i].split("=");
		key = split[0];
		val = split[1];
	 
		if ( key == searchKey )
		{
		 found = val;
		 found = unescape(found);
		 found.replace(/\+/g, " ");
		 found.replace(/\%20/g, " ");
		 return found;
		}
	   }

	   if ( found == false ){
		return "";
	   }
	  };
	  
	  
// to set up the cookie
	function setCookie(c_name,value)
		{
		document.cookie=c_name+ "=" +escape(value);
		}

	function getCookie(c_name)
	{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
	}
		
	function loadBanner(){		
		var flashvars = {};
		var params = {
			allowfullscreen: "true",
			allowscriptaccess: "always",
			wmode: "transparent"
		};
		var attributes = {
			id: "VideoPlayback"
		};
		
		swfobject.embedSWF("cmsflash/banner.swf", "bannermovie", "900", "268", "9.0.0", "", flashvars, params, attributes);

		};

$(window).load(function() {
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		// this adds flyout support for IE 6
		$(".navtop > li li ").hover(function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").hover(function () {
			$(this).addClass("redraw");
		},
		function () {
			$(this).removeClass("redraw");
		});
	}	
	
	
	//embedd banner.swf if cookie not detected
	/*
	cookie = getCookie('bannerCookie');
	if((cookie == null || cookie == "")&& (typeof swfobject!= 'undefined'))
	{		
		loadBanner();
		setCookie('bannerCookie', 'true');
	}
	else
	{
		//delete_cookie('newsletterCookie');
	}
	*/
	

	
	// for image and text nav to hover at the same time in subnav	
	$('ul.text li a').hover(
		function(){
			var selector = 'ul.image li a[href=' + $(this).attr('href') +  ']';
			$(selector).addClass('selected');
		},
		function(){
			var selector = 'ul.image li a[href=' + $(this).attr('href') +  ']';
			$(selector).removeClass('selected');
		}
	);
	
	
	
	$('ul.image li a').hover(
		function(){
			var selector = 'ul.text li a[href=' + $(this).attr('href') +  ']';
			$(selector).parent().addClass('hover');
		},
		function(){
			var selector = 'ul.text li a[href=' + $(this).attr('href') +  ']';
			$(selector).parent().removeClass('hover');
		}
	);
	
	
	// for hover modals
	$('.m_button').hover(
		function(){
			$(this).next('div.modal').addClass('show');
		},
		function() {
			$(this).next('div.modal').removeClass('show');
		}	
	);
	
	// triangle graphic
	$('.o_title').hover(
		function(){
			$(this).next('li.o_description').addClass('show');
		},
		function() {
			$(this).next('li.o_description').removeClass('show');
		}	
	);
	
	
	$('#o_one').hover(
		function() {
			$('td.o_graphic').addClass('move_one');
		},
		function() {
			$('td.o_graphic').removeClass('move_one');
		}
	);
	
	$('#o_two').hover(
		function() {
			$('td.o_graphic').addClass('move_two');
		},
		function() {
			$('td.o_graphic').removeClass('move_two');
		}
	);
	
	$('#o_three').hover(
		function() {
			$('td.o_graphic').addClass('move_three');
		},
		function() {
			$('td.o_graphic').removeClass('move_three');
		}
	);
	
	$('#o_four').hover(
		function() {
			$('td.o_graphic').addClass('move_four');
		},
		function() {
			$('td.o_graphic').removeClass('move_four');
		}
	);
	
	$('#o_five').hover(
		function() {
			$('td.o_graphic').addClass('move_five');
		},
		function() {
			$('td.o_graphic').removeClass('move_five');
		}
	);
	
	
	// for click modals
	$('.mc_button').click(
		function(){
			$(this).next('div.cmodal').toggleClass('show');
		});
		
	$('.close_modal').click(
		function(){
			$(this).parent('div.cmodal').toggleClass('show');
		});
		
		
	

	  /*
         var courseKey = getQueryKey('course');
		 //parseInt(courseKey);
	$('select#courseSelect').val(courseKey);
	*/
	
	
	// Remove default form text on focus
	$(".emptytext").focus( function(){
		if ( $(this).val() == $(this)[0].defaultValue ) {
			$(this).val("");
		}
	});
	// Replace default form text on blur if input is empty
	$(".emptytext").blur( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this)[0].defaultValue );
		}
	});	
	
	
});
