var slider_milliseconds  = 4000;
var period  = 7000;
var image_period  = 3000;
var animate_period  = 1000;
var active_number = 1;
var active_type = 1; // 1 for cover, 2 for image
var max_image_banner = 10
var timer;		
	
		

$(document).ready(function() {
	

	
	
	//----------------------------------------Banner animation -----------------------------------------------------
	
	timer = setInterval( "runBanner()", period );
	
	$("#clickarea").click(
		
		function () 
		{
			if ($("#banner" + active_number).children().attr("href") != null)
				window.location = $("#banner" + active_number).children().attr("href");
        }
    );
	
	
	//----------------------------------------Banner animation Ends-----------------------------------------------------
	
	//&nbsp before event title
	$('.ip-calendar-eventdetailspanel').each(function(index) 
	{
		temp = $(this).html().replace("&nbsp;","");
		
		$(this).html(temp);
		
   	
  	});
	
	//remove time info on the event calendar pagelet
	$('.ip-calendarpagelet-eventtime').each(function(index) 
	{
		
		var newstring = $(this).html().substring(0, 7);
		$(this).html(newstring);
		
		$(this).wrap('<div class="event_time_div">');
			
   	
  	});
	
	
	
	var counter = 1;
	$('.ip-calendarpagelet-mainlist li ul li table tr').each(function(index) 
	{
		//var newstring = $(this).html().substring(0, 5);
		if((counter % 2) == 1)
		{
			$(this).addClass("even");
		}
		counter++;
   	
  	});
	
	
	
	//-------------------------------------main nav hover-------------------------------------------------
	
	var url = window.location.href;
	
	if(url.indexOf("http://soe.lmu.edu/home") != -1) //we are under admissions category
	{
		$("#pageid55593 div a").css("background", "url(/Sites/41/templates/v2-images/nav-home.png) 0 0 no-repeat");
	}
	else if(url.indexOf("http://soe.lmu.edu/admissions") != -1) //we are under admissions category
	{
		$("#pageid55492 div a").css("background", "url(/Sites/41/templates/v2-images/nav-admission.png) 0 0 no-repeat");
	}
	else if(url.indexOf("http://soe.lmu.edu/faculty") != -1) //we are under faculty category
	{
		$("#pageid55493 div a").css("background", "url(/Sites/41/templates/v2-images/nav-faculty.png) 0 0 no-repeat");
	}
	else if(url.indexOf("http://soe.lmu.edu/centers") != -1) //we are under centers category
	{
		$("#pageid55494 div a").css("background", "url(/Sites/41/templates/v2-images/nav-center.png) 0 0 no-repeat");
	}
	else if(url.indexOf("http://soe.lmu.edu/news") != -1) //we are under news category
	{
		$("#pageid57986 div a").css("background", "url(/Sites/41/templates/v2-images/nav-news.png) 0 0 no-repeat");
	}
	else if(url.indexOf("http://soe.lmu.edu/about") != -1) //we are under about category
	{
		$("#pageid60820 div a").css("background", "url(/Sites/41/templates/v2-images/nav-about.png) 0 0 no-repeat");
	}
	else // under home
	{
		$("#pageid55593 div a").css("background", "url(/Sites/41/templates/v2-images/nav-home.png) 0 0 no-repeat");
	}
	
	
	
	//first level
	$("#header_nav ul li").hover(
		function () {
			
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://soe.lmu.edu/admissions") == -1) //we are under Welcome category
			{	
				$("#" + id + " div a").addClass("selected");
			}
			
			$("#" + id + " ul").show();
	  }, 
      	function () {	
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://soe.lmu.edu/admissions") == -1) //we are under Welcome category
			{	
				$("#" + id + " div a").removeClass("selected");
			}
			
			$("#" + id + " ul").hide();
			
      }
    );
	
	
	//second level
	$("#header_nav ul li ul li").hover(
		function () {
			
			var url = window.location.href;
			
				if ( $(this).attr("class") == 'ipf-parent')
				    $(this).css("background", "url(images-V3/header-nav-level2-li-hover-special-bg.png)");
				else
					$(this).addClass("hover");
	  }, 
      	function () {	
			var url = window.location.href;
				
				
				if ( $(this).attr("class") == 'ipf-parent')
					$(this).css("background", "url(images-V3/header-nav-level2-li-bg.png) bottom");
				else
					$(this).removeClass("hover");
	  }
    );
	
	
		//remove 2nd level parent div
	$('#header_nav li ul li a').each(function(index) 
	{
		
		if($(this).parent().is('div'))
			$(this).unwrap();
			
   	
  	});
	
	
	//add rounded bottom
	$('.ipf-parent').each(function(index) 
	{
		//alert($(this).attr("level"));
		if( $(this).attr("level") == '1')
		{
			var  temp =  $(this).attr("id");
			//alert("do " + temp);
			$("#" + temp + " ul").append('<li class="bottom"></li>');
		}
   	
  });
	
	//when one of the header nav clicked
	$("#header_nav li ul li").click(
		
		function () 
		{
			if ($(this).children().attr("href") != null)
				window.location = $(this).children().attr("href");
       }
    );
	
	//when one of the header nav clicked
	$("#header_nav li ul li ul li").click(
		
		function () 
		{
			if ($(this).children().attr("href") != null)
				window.location = $(this).children().attr("href");
       }
    );
	
	
	
	
	//Three button quick links
	$(".quick_link").hover(
		function () {
			$(this).css("background-position", "0 -57px");
	  }, 
      	function () {	
			$(this).css("background-position", "0 0");
			
      }
    );
	
	//Three button quick links clicked
	$(".quick_link").click(
		function () {
			id = $(this).attr("id");
			if(id == "quick_link1")
				window.location = "http://www.lmu.edu";
			else if(id == "quick_link2")
				window.location = "http://www.lmu.edu/admin";
			else if(id == "quick_link3")
				window.location = "http://www.lmu.edu/give";	
	  }
    );
	
	$("#button_news").hover(
		function () {
			$(this).css("background-position", "0 -23px");
	  }, 
      	function () {	
			$(this).css("background-position", "0 0");
			
      }
    );
	
	

	
	//Add shadow to body images
	$('#subpage_content_wrapper .content_format img').each(function(index) 
	{
		
		$(this).wrap('<div class="shadowed">');
		
  });
	
});// end doc ready



//-------------------------------------------------------------------------------------------------video banner -------------------------------------------------------------------


function runBanner()
{
	//pause counter for now
	clearInterval(timer);			
	
	
	if(active_type == 1) //cover
	{
		active_type = 2;
		
		$("#banner_cover" + active_number  ).animate({"top": "-500px"}, animate_period );
		
		timer = setInterval( "runBanner()", image_period );
		
	}
	else if(active_type == 2) //image
	{
		active_type = 1;
		
		//$("#banner_cover" + active_number  ).animate({"opacity": "0.0"}, animate_period );
		$("#banner_cover" + active_number  ).hide();
		
		$("#banner" + active_number  ).animate({"opacity": "0.0"}, animate_period );
		
		if(active_number == max_image_banner) //restart
		{
			active_number = 1;
			$("#banner_cover" + active_number  ).show();
			$("#banner_cover" + active_number  ).animate({"top": "0"}, animate_period );
			$("#banner" + active_number  ).animate({"opacity": "100.0"}, animate_period );
			
			for(i = 2; i <=  max_image_banner; i++)
			{
				$("#banner_cover" + i  ).show();
				//$("#banner_cover" + i  ).css("opacity", "100.0");	
				$("#banner_cover" + i  ).css("top", "0");	
				$("#banner" + i  ).css("opacity", "100.0");	
			}
				
		}
		else
			active_number++;
			
		timer = setInterval( "runBanner()", period );	
	}
	
	
	
}
