// JavaScript Documentvar period = 800;
var selected_banner = "banner1";
var revertFlip;
var active_showcase = 1;
var number_showcase = 0;
var period = 700;
var auto_period = 10000;
var timer;
var timer2;
var current_timeline = 1;
var timeline_period = 1000;
var sliding_width = 999;

$(document).ready(function() {

//prevent form to be submitted with enter
 $(document).ready(function() {
         $("form").bind("keypress", function(e) {
             if (e.keyCode == 13) {
                 
                 return false;
            }
         });
     }); 
						   
	 //create a strip table
	 var counter = 1;
	$("table.strip_table tr").each(function(index) 
	{
		
		//var newstring = $(this).html().substring(0, 5);
		$(this).removeClass();
		if((counter % 2) == 1)
			$(this).addClass("light_gray");
		else
			$(this).addClass("gray");
	
		counter++;
   	
  	});
	 
	 // Top Nav
	 $(".nav_div").hover(
		function () {
			
			selected_id = ($(this).attr("id")).replace("_div","");
			$("#" + selected_id).css("background-position", "0 -21px");
			
			var ver = getInternetExplorerVersion();
		
			
			if (ver > -1) 
			{
		
				if (ver >= 8)// not using fadeIn effect on IE8
				{
					$("#" + selected_id + "_content").show();
				}
				
				if (ver == 7)// solve z-index bug in IE7
				{
					$(function() {
					   
						var zIndexNumber = 1000;
						$('div').each(function() {
							$(this).css('zIndex', zIndexNumber);
							zIndexNumber -= 10;
						});
					});
					$("#" + selected_id + "_content").show();
					
					$("#banner_nav_container").css('zIndex', 12000);
				} 
			}
			else
				$("#" + selected_id + "_content").fadeIn(300);
			
			
	  }, 
      	function () {	
		    selected_id = ($(this).attr("id")).replace("_div","");
			$("#" + selected_id).css("background-position", "0 0");
			$("#" + selected_id + "_content").hide();
			
      }
    );

	//video overlay functionality


	
	 
	 $(".video_overlay").hover(
		function () {
			$(this).css("background-position", "0 -140px");
	  }, 
      	function () {	
		    
			$(this).css("background-position", "0 0");
			
      }
    );
	 
	 $(".video_overlay").click(
		function () {
			window.location = $(this).siblings('a').attr('href');
			
	  }
    );
	 
	 
	
	
	
	//-------------------------------------main nav hover-------------------------------------------------
	
	$("#banner1_link").css("background-position", "0 -11px");
	
	timer = setInterval( "NextSlide()", auto_period );
	
	//banner effect
	$(".banner_link").click(
		function () {
			
			//pause the auto-slide
		   	clearInterval(timer);
			clearInterval(timer2);
					
			//restart
			timer2 = setInterval( "startSlide()", period + 500 );	
			
			selected_id = ($(this).attr("id")).replace("_link","");
		    if( selected_id != selected_banner)
			{
			$("#" + selected_banner + "_link").css("background-position", "0 0");
			selected_banner = selected_id;
			$("#" + selected_banner + "_link").css("background-position", "0 -11px");
			
				
				
					if(selected_id == "banner1")
					{	
						if ($.browser.msie && jQuery.browser.version >= 8.0)
						{
							$('#banners .banner_item img').animate({'opacity':'.4'},250);
							revertFlip = setInterval( "reverseOpacity()", period + 100);
						}
						$('#banners').animate({'opacity':'.4'},250).animate({'left':'0px'},period).animate({'opacity':'1'},250);
					}
					else if(selected_id == "banner2")
					{	
						if ($.browser.msie && jQuery.browser.version >= 8.0)
						{
							$('#banners .banner_item img').animate({'opacity':'.4'},250);
							revertFlip = setInterval( "reverseOpacity()", period + 100);
						}
						$('#banners').animate({'opacity':'.4'},250).animate({'left':'-977px'},period).animate({'opacity':'1'},250);
						
					}
					else if(selected_id == "banner3")
					{
						if ($.browser.msie && jQuery.browser.version >= 8.0)
						{
							$('#banners .banner_item img').animate({'opacity':'.4'},250);
							revertFlip = setInterval( "reverseOpacity()", period + 100);
						}
						$('#banners').animate({'opacity':'.4'},250).animate({'left':'-1954px'},period).animate({'opacity':'1'},250);
					}
					
				
		}
			
			

		}
		
    );
	
	//banner nav and tooltip
	$(".banner_link").hover(
		function () {
			selected_id = ($(this).attr("id")).replace("_link","");
			//$("#" + selected_id + "_tooltip").show();
			if( selected_id != selected_banner)
			{
				$("#" + selected_id + "_link").css("background-position", "0 -11px");
			}
			//$("#" + selected_id + "_content").slideDown(200);
			
	  }, 
      	function () {	
		    selected_id = ($(this).attr("id")).replace("_link","");
			//$("#" + selected_id + "_tooltip").hide();
			if( selected_id != selected_banner)
			{
				$("#" + selected_id + "_link").css("background-position", "0 0");
			}
			
      }
    );
	

	
	//remove time info on the event calendar pagelet
	$('.ip-calendarpagelet-eventtime').each(function(index) 
	{
		
		var newstring = $(this).html();
		var position = newstring.indexOf("-")
		newstring = newstring.substring(0, position)
		$(this).html(newstring);
		
		$(this).wrap('<div class="event_time_div">');
			
   	
  	});
	
	
	$('#calendar').find('br').each(function(index) 
	{
		$(this).remove();
  	});
	
	$('#ctl00_tblFeaturedEvents').hide();
	$('#ctl00_tblMain').hide();
	
    $('#timeline_left').hide();

	//Timeline sliding affect
	
	//by default the first one chosen
		$('#timeline_years ul li a').each(function(index) {
			if( $(this).attr("rel") == 1)
				$(this).attr("class", "selected");
		});
	
	$(".timeline_nav").click(
		function () {
			
			
			var direction = $(this).attr("id");
			
			if (direction == "timeline_left")
			{
				
				var pixel = (current_timeline - 2) * 999;
				pixel = "-" + pixel + "px"
				$('#timeline').animate({"left": pixel},timeline_period);
				
				current_timeline = parseInt(current_timeline) - 1 ;
				if(current_timeline == 1)
					$('#timeline_left').hide();
					
				if(current_timeline > 1)
					$('#timeline_right').show();
			}
			else//right
			{
				//alert(current_timeline);	
				var pixel = (current_timeline) * 999;
				pixel = "-" + pixel + "px"
				$('#timeline').animate({"left": pixel},timeline_period);
				current_timeline = parseInt(current_timeline) + 1 ;
				
				//alert(current_timeline);	
				
				//alert(current_timeline);
				if(current_timeline == ($(".timeline_column").size()/4))
					$('#timeline_right').hide();
					
				if(current_timeline > 1)
					$('#timeline_left').show();	
			
			}
			
			var found = 0
			
			
			$('#timeline_years ul li a').each(function(index) {
					if( $(this).attr("rel") == current_timeline)
						found = 1
			  });
			  
			if( found == 1)
			{
				$('#timeline_years ul li a').each(function(index) {
					if( $(this).attr("class") == "selected")
						$(this).removeClass();
			  	});
			
				$('#timeline_years ul li a').each(function(index) {
						if( $(this).attr("rel") == current_timeline)
							$(this).attr("class", "selected");
				  });
			}
			

		}
		
    );
	
	
	 $(".timeline_column").hover(
		function () {
			var yearid = $(this).attr("id");
			$("#" + yearid + " a h1").css("color","#be0005");
			$("#" + yearid + " a h2").css("color","#be0005");
	  }, 
      	function () {	
		    
			var yearid = $(this).attr("id");
			$("#" + yearid + " a h1").css("color","#474641");
			$("#" + yearid + " a h2").css("color","#474641");
			
      }
    );
	 
	  $("#timeline_years ul li a").click(
		function () {
			
			
			if(current_timeline != $(this).attr("rel"))
			{
				$("#timeline_years ul li a.selected").removeClass();
				
				$(this).attr("class", "selected");
				var pixel = ($(this).attr("rel") - 1) * 999;
				
				pixel = "-" + pixel + "px"
				$('#timeline').animate({"left": pixel},timeline_period);
					
				current_timeline = $(this).attr("rel") ;
				
				if(current_timeline > 1)
					$('#timeline_left').show();
				else
					$('#timeline_left').hide();
					
				if(current_timeline < ($(".timeline_column").size()/4))
					$('#timeline_right').show();
				else
					$('#timeline_right').hide();
			}
      }
    );
	 
	  
	 $(".timeline_column").click(
		function () {
			window.location = $(this).children('a').attr('href');
			
	  }
    );
	
	
	
	
});// end doc ready


function reverseOpacity()
{
	$('#banners .banner_item img').animate({'opacity':'1'},250);
	clearInterval(revertFlip);
}

function reverseOpacity()
{
	$('#banners .banner_item img').animate({'opacity':'1'},250);
	clearInterval(revertFlip);
}

function NextSlide() 
{
			if(selected_banner == "banner1")
				selected_id = "banner2";
		    else if(selected_banner == "banner2")
				selected_id = "banner3";
			else if(selected_banner == "banner3")
				selected_id = "banner1";
			
			
			//pause the auto-slide
		   clearInterval(timer);
					
			//restart
			timer2 = setInterval( "startSlide()", period + 500 );	
		
		   
		   if( selected_id != selected_banner)
			{
				$("#" + selected_banner + "_link").css("background-position", "0 0");
				selected_banner = selected_id;
				$("#" + selected_banner + "_link").css("background-position", "0 -11px");
				
				
				
					if(selected_id == "banner1")
					{	
						if ($.browser.msie && jQuery.browser.version >= 8.0)
						{
							$('#banners .banner_item img').animate({'opacity':'.4'},250);
							revertFlip = setInterval( "reverseOpacity()", period + 100);
						}
						$('#banners').animate({'opacity':'.4'},250).animate({'left':'0px'},period).animate({'opacity':'1'},250);
					}
					else if(selected_id == "banner2")
					{	
						if ($.browser.msie && jQuery.browser.version >= 8.0)
						{
							$('#banners .banner_item img').animate({'opacity':'.4'},250);
							revertFlip = setInterval( "reverseOpacity()", period + 100);
						}
						$('#banners').animate({'opacity':'.4'},250).animate({'left':'-977px'},period).animate({'opacity':'1'},250);
						
					}
					else if(selected_id == "banner3")
					{
						if ($.browser.msie && jQuery.browser.version >= 8.0)
						{
							$('#banners .banner_item img').animate({'opacity':'.4'},250);
							revertFlip = setInterval( "reverseOpacity()", period + 100);
						}
						$('#banners').animate({'opacity':'.4'},250).animate({'left':'-1954px'},period).animate({'opacity':'1'},250);
					}
					
					
		}
		
				
		   	

}

function startSlide()
{
	//pause the start-slide
	clearInterval(timer2);
	timer = setInterval( "NextSlide()", auto_period );
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	  {
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name)
		{
		return unescape(y);
		}
	  }
}

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
	var username=getCookie("browser");
	if (username!=null && username!="")
	{
		 
	}
	else
	{
	 	window.location.href = "http://www.lmu.edu/about/services/wnmd/Policies/Web_Browser_not_Supported.htm";	
	}
}

function getInternetExplorerVersion() {

    var rv = -1; // Return value assumes failure.

    if (navigator.appName == 'Microsoft Internet Explorer') {

        var ua = navigator.userAgent;

        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)

            rv = parseFloat(RegExp.$1);

    }

    return rv;

}

function checkVersion() {

    var msg = "You're not using Windows Internet Explorer.";

    var ver = getInternetExplorerVersion();

    if (ver > -1) {

        if (ver >= 8.0)

            msg = "You're using a recent copy of Windows Internet Explorer."

        else

            msg = "You should upgrade your copy of Windows Internet Explorer.";

    }

    //alert(msg);

}

// JavaScript Document

function addQuery()
{
   var hash = getUrlVars(); 
   old_src = document.getElementById('gsa_iframe').src;
   
 	
   if(hash['q'] != null && hash['as_sitesearch'] != null)
   		document.getElementById('gsa_iframe').src = old_src + "&q=" + hash['q'] + "&as_sitesearch=" + hash['as_sitesearch'];		
   else if(hash['q'] != null)
   		document.getElementById('gsa_iframe').src = old_src + "&q=" + hash['q'];
   
}


function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	
 

	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;

}

function SubmitCDSLogin()
                { 
//alert("called");               		
var cds_username = document.getElementById("username");
					var cds_password = document.getElementById("password");
					
					var thisform = document.getElementsByName("IronPointForm");
					var audience_select = document.getElementsByName("audience_select");
					
					myOption = -1;
					for (i=audience_select.length-1; i > -1; i--) 
					{
						if (audience_select[i].checked) 
						{
							myOption = i; i = -1;
						}
					}
					if (myOption == -1) 
					{
						alert("You must specify your group");
						return false;
					}
					
					
					if (cds_username.value.length < 1)
					{
						cds_username.focus();
						alert("User name is required")
						return false;
					}
					
					if (cds_password.value.length < 1)
					{
						cds_password.focus();
						alert("Password is required")
						return false;
					}
					

					if (cds_username.value.length > 1 && cds_password.value.length > 1 && myOption == 0)
					{
						document.forms.item('IronPointForm').action='https://lmu-csm.symplicity.com//students/';
						document.forms.item('IronPointForm').submit(); 
					}

					if (cds_username.value.length > 1 && cds_password.value.length > 1 && myOption == 1)
					{
						document.forms.item('IronPointForm').action='https://lmu-csm.symplicity.com//employers/';
						document.forms.item('IronPointForm').submit(); 
					}
					return false;
                }


