// JavaScript Document

if (typeof console == "object") window.log = console.log;
else window.log = function() {};



$(document).ready(function(){
						   
	/* Keep Cufon from putting commented text (from DW templates) into output text */
	$("h1").each(function(){
		$(this).html($(this).text());
	});
						   
    $("body").addClass("js");    
	
	if ($.browser.safari){ 
		$("body").addClass("safari");
	}
	
	if ($.browser.msie){ 
		$("body").addClass("msie");
	}
	

/* Search box */
	/* Put text in the text box, and hide it when the user clicks it */
	
		var startingText = "Search OC Athletics";
		
		$("#box:input").attr("value", startingText).focus(function () {
			var currentText = $(this).attr("value");
			if (currentText == startingText){
				$(this).attr("value", '');
			}
	});
		
    $(".nav li").hover(
      function () {
		$(this).find("a:first").addClass("hover");
      },
	  
	  function () {
		$(this).find("a:first").removeClass("hover");
      }

    );
		
		
	$(".nav2 li ul a").hover(
      function () {
		$(this).parent().parent().parent().find("a:first").addClass("hover");
      },
	  
	  function () {
		$(this).parent().parent().parent().find("a:first").removeClass("hover");
      }

    );
		
	/* give class of "current" to top tab when current page is contained within that section */
	
	var currenturl = location.pathname.toLowerCase();

	
	/*** Top Menu ***/
	
	/* Check top level of top menu */
	$("#topmenu>ul>li:not('.ochomeli')>a").each(function(){
		thislink = $(this).attr("href");
		var splitaddress = thislink.split("/");
		var lastsection = splitaddress[splitaddress.length-1];
		if (currenturl.indexOf(lastsection) != -1) {
			$(this).addClass("current");
		}
	});
	
	/* Check submenu */
	
	var currentwholeurl = location.href.toLowerCase();
	$("#topmenu>ul>li:not('.ochomeli')>ul>li>a").each(function(){
		thislink = $(this).attr("href");
		var linkurl = thislink.toLowerCase();
		if (currentwholeurl.indexOf(linkurl) != -1) {
			$(this).parent().parent().parent().find("a").addClass("current");
		}
		
	});
	
	
	
	
	/*** Sport Menu ***/
	
	/* Check top level of sports menu */
	$("#sportsmenu>ul>li>a").each(function(){
		thislink = $(this).attr("href");
		var splitaddress = thislink.split("/");
		var lastsection = splitaddress[splitaddress.length-1];
		if (currenturl.indexOf(lastsection) != -1) {
			$(this).addClass("current");
		}
	});
	
	/* Check mens/womens submenu */
	$("#sportsmenu>ul>li>ul>li>a").each(function(){
		thislink = $(this).attr("href");
		var splitaddress = thislink.toLowerCase().split("/");
		var linkurl = "/" + splitaddress[3];
		
		if (currenturl.indexOf(linkurl) != -1) {
			$(this).parent().parent().parent().find("a").addClass("current");
		}
		
	});
		
	$(".localmenu a").each(function(){		
		thislink = $(this).attr("href");
		linkurl = "/" + thislink.toLowerCase();
		if (currenturl.indexOf(linkurl) != -1) {
			$(this).addClass("current");
		}

	});
	
	
	
	

	

	/******************************************** Carousel Code ********************************************/
	
	function fillTopImage (title, subtitle, caption, photourl, pageurl){
				
		/* Change the image*/
		$("#bigphoto img").attr("src",photourl);
		
		/* Change the title, then Cufon it */
		$("#bigphotocaption h2").text(title);
		
		/* Change the subtitle */
		$("#bigphotocaption p").text(subtitle);
		
		/*Thumb caption*/
		$("#caption").text(caption);
		
		/* Change the links to go to the correct place */
		$("#bigphotocaption a").attr("href",pageurl);

	}	
	
	$("#carmover").jCarouselLite({
        btnNext: "#photoboxdown",
        btnPrev: "#photoboxup",
		vertical:true
    });

	
	
	
	
	$("#carmover a").click(function(e){
		e.preventDefault();
		$this=$(this);
		$("#carmover .thumb").removeClass("current");
		$this.parent().addClass("current");
		
		/* Find the data divs under each image (currently hidden) and use them to fill the top image */
		function sendData (){
			var title = $this.parent().find(".title").text();
			var subtitle = $this.parent().find(".subtitle").text();
			var caption = $this.parent().find(".caption").text();
			var photourl = $this.parent().find(".photourl").text();
			var pageurl = $this.parent().find(".pageurl").text();
			
			fillTopImage (title, subtitle, caption, photourl, pageurl);
		}
		
		sendData();
		
	});
	
	
	/* Simulate a click on the first carousel image top populate the large image */
	$("#carmover a:eq(3)").click();
	
	


});






