var timer;
var revertFlip;
var photo = new Array();
for(i=0; i <= 9; i++)
	photo[i] = 0;


var period = 6000;
var flip_period = 500;

var active_quote  = 0;

$(document).ready(function() {
	
//-------------------------------------Photo flip effect-------------------------------------------------

				//Only when a user clicks
				$(".photo_col").click(function () {
					var id = $(this).attr("id");
					//alert(id);
					var id_number = id.substr(5);
					
					if(id_number != 2 && id_number != 4 && id_number != 8 && id_number != 9 )  
					{
						if(photo[id_number] == 0)
						{
							photo[id_number] = 1;
							var message = $("#photo_content" + id_number).html();
							$("#photo" + id_number).flip({
								direction: 'lr',
								color: '#CCCCCC',
								speed: flip_period,
								content: message
							});
							//pause the auto-flip
							clearInterval(timer);
							
						}
						else 
						{
							photo[id_number] = 0;
							$("#photo" + id_number).revertFlip({
							
							});	
							//reactivate auto-flip if none is open
							var allclose = 1;
							for(i=0; i <= 9; i++)
							{	
								if(photo[i] == 1) // at least one is open
									allclose = 0;
							}
							if(allclose == 1)
							{
								//period += flip_period;
								timer = setInterval( "randomFlip()", period );
							}
						}
					}
				});
				
				timer = setInterval( "randomFlip()", period );
				
		
	
	
	
	//-------------------------------------main nav hover-------------------------------------------------
	
	var url = window.location.href;
	
	if(url.indexOf("http://bellarmine.lmu.edu/iama") != -1) //we are under I am category
	{
		$("#pageid66954 div a").addClass("selected");
	}
	else if(url.indexOf("http://bellarmine.lmu.edu/academics") != -1) //we are under academics category
	{
		$("#pageid66755 div a").addClass("selected");
	}
	else if(url.indexOf("http://bellarmine.lmu.edu/newsroom") != -1) //we are under newsroom category
	{
		$("#pageid66962 div a").addClass("selected");
	}
	else if(url.indexOf("http://bellarmine.lmu.edu/about") != -1) //we are under about category
	{
		$("#pageid66784 div a").addClass("selected");
	}
	
	//I am... Category
	$("#pageid66954").hover(
		function () {
			
			var url = window.location.href;
			id = $(this).attr("id");
			//alert(url.indexOf("http://bellarmine.lmu.edu/iama"));
			if(parseInt(url.indexOf("http://bellarmine.lmu.edu/iama")) == -1) //we are under iama category
			{	
				$("#" + id + " div a").addClass("selected");
			}
			
			$("#pageid66954 ul").show();
			
	  }, 
      	function () {	
			var url = window.location.href;
			id = $(this).attr("id");
			if(parseInt(url.indexOf("http://bellarmine.lmu.edu/iama")) == -1) //we are under iama category
			{	
				$("#" + id + " div a").removeClass("selected");
			}
			
			$("#pageid66954 ul").hide();
			
      }
    );
	
	//Academics Category
	$("#pageid66755").hover(
		function () {
			
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://bellarmine.lmu.edu/academics") == -1) //we are under academics category
			{	
				$("#" + id + " div a").addClass("selected");
			}
			
			$("#pageid66755 ul").show();
	  }, 
      	function () {	
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://bellarmine.lmu.edu/academics") == -1) //we are under academics category
			{	
				$("#" + id + " div a").removeClass("selected");
			}
			
			$("#pageid66755 ul").hide();
			
      }
    );
	
	//newsroom Category
	$("#pageid66962").hover(
		function () {
			
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://bellarmine.lmu.edu/newsroom") == -1) //we are under newsroom category
			{	
				$("#" + id + " div a").addClass("selected");
			}
			
			$("#pageid66962 ul").show();
	  }, 
      	function () {	
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://bellarmine.lmu.edu/newsroom") == -1) //we are under newsroom category
			{	
				$("#" + id + " div a").removeClass("selected");
			}
			
			$("#pageid66962 ul").hide();
			
      }
    );
	
	//About Category
	$("#pageid66784").hover(
		function () {
			
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://bellarmine.lmu.edu/about") == -1) //we are under about category
			{	
				$("#" + id + " div a").addClass("selected");
			}
			
			$("#pageid66784 ul").show();
	  }, 
      	function () {	
			var url = window.location.href;
			id = $(this).attr("id");
			if(url.indexOf("http://bellarmine.lmu.edu/about") == -1) //we are under about category
			{	
				$("#" + id + " div a").removeClass("selected");
			}
			
			$("#pageid66784 ul").hide();
			
      }
    );
	
	
	
	//second level
	$("#header_nav ul li ul li").hover(
		function () {
			
			var url = window.location.href;
			
			if(url.indexOf("http://soe.lmu.edu/admissions") == -1) //we are under Welcome category
			{	
				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(url.indexOf("http://soe.lmu.edu/admissions") == -1) //we are under Welcome category
			{	
				
				
				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
/*	$('#header_nav li ul li.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>');
		}
   	
  });
	*/
	
/*	$('#pageid66753').each(function(index) 
	{
		var  temp =  $(this).attr("id");
		$("#" + temp + " ul").append('<li class="bottom"></li>');
		
  });
*/	
	$('#pageid66954').each(function(index) 
	{
		var  temp =  $(this).attr("id");
		$("#" + temp + " ul").append('<li class="bottom"></li>');
		
  });
	
	$('#pageid66755').each(function(index) 
	{
		var  temp =  $(this).attr("id");
		$("#" + temp + " ul").append('<li class="bottom"></li>');
		
  });
	
	$('#pageid66962').each(function(index) 
	{
		var  temp =  $(this).attr("id");
		$("#" + temp + " ul").append('<li class="bottom"></li>');
		
  });
	
	$('#pageid66784').each(function(index) 
	{
		var  temp =  $(this).attr("id");
		$("#" + 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://bellarmine.lmu.edu/page66789.aspx";
			else if(id == "quick_link2")
				window.location = "http://bellarmine.lmu.edu/thebellarmineforum.htm";
			else if(id == "quick_link3")
				window.location = "http://admission.lmu.edu";	
	  }
    );
	
	$("#button_news").hover(
		function () {
			$(this).css("background-position", "0 -23px");
	  }, 
      	function () {	
			$(this).css("background-position", "0 0");
			
      }
    );
	
	//-----------------------------------------------------------------------------------Did you know blobs-----------------------------------------------------------------------------------
	var randomnumber=Math.floor(Math.random()*7) // to 7 blobs
	
	active_quote = randomnumber + 1;
	
	$("#blob" + active_quote).fadeIn();
	$("#blob_nav" + active_quote).css("background-position", "0 0");
	
	
	$("#blob_nav ul li a").hover(
		function () {
			var temp = $(this).attr("id");
			if(active_quote != temp.substr(8))
				$(this).css("background-position", "0 0");
	  }, 
      	function () {	
			var temp = $(this).attr("id");
			if(active_quote != temp.substr(8))
				$(this).css("background-position", "0 -7px");
			
      }
    );
	
	
	$("#blob_nav ul li a").click(
		function () 
		{
			$("#blob" + active_quote).hide();
			$("#blob_nav" + active_quote).css("background-position", "0 -7px");
			
			var temp = $(this).attr("id");
			active_quote = temp.substr(8);
			
			$("#blob_nav" + active_quote).css("background-position", "0px 0px");
	
			$("#blob" + active_quote).fadeIn();
	    }
    );
	
	
	$("#button_news").click(
		function () 
		{
			window.location = "http://bellarmine.lmu.edu/newsroom/releases.htm";
	    }
    );
	
	

	
	//Add shadow to body images
	$('#subpage_content_middle .content_format img').each(function(index) 
	{
		
		$(this).wrap('<div class="shadowed">');
		
  });
	
});// end doc ready

function randomFlip(id_number)
{
				var randomnumber=Math.floor(Math.random()*9) // to 3 spolights
				id_number = randomnumber + 1;
				
				while(id_number == 2 || id_number == 4 || id_number == 8 || id_number == 9 )
				{
					randomnumber=Math.floor(Math.random()*9) // to 3 spolights
					id_number = randomnumber + 1;
				}
				
				//alert(id_number);
				
				//if it has not been flipped, then flip
				if(photo[id_number] == 0)
				{
					photo[id_number] = 1;
					var message = $("#photo_content" + id_number).html();
					$("#photo" + id_number).flip({
						direction: 'lr',
						color: '#CCCCCC',
						speed: flip_period,
						content: message
					});
					
					//pause the auto-flip
					clearInterval(timer);
					
					//revert back 3 seconds later
					revertFlip = setInterval( "backFlip("+ id_number +")", 4000 );
				}
}
			
function backFlip(id_number)
{
	photo[id_number] = 0;
	$("#photo" + id_number).revertFlip({
				
	});
	clearInterval(revertFlip);
	
	timer = setInterval( "randomFlip()", period );

}
			
			
