/* Author: Red 5 Interactive

*/
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("main-navigation");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;

//Count Down Timer
/*var before="The big game"
var current="Today is the big game"
var montharray=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

function countdown(yr,m,d,message){
	
	function IsInteger(x) {
		var temp = parseInt(x);
		if (temp == x) {
			return true;
		}
		return false;
	}
	
	if(IsInteger(yr) || IsInteger(m) || IsInteger(d)) {

    theyear=yr;themonth=m;theday=d;
    var today=new Date()
    var todayy=today.getYear()
        if (todayy < 1000) {todayy+=1900;}
    var todaym=today.getMonth(),
        todayd=today.getDate(),
        todayh=today.getHours(),
        todaymin=today.getMinutes(),
        todaysec=today.getSeconds();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
futurestring=montharray[m-1]+" "+d+", "+yr;
dd=Date.parse(futurestring)-Date.parse(todaystring);
dday=Math.floor(dd/(60*60*1000*24)*1);
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
function addZero(x) {(x <= '9') ? a = '0' + x : a = x ; return a};
function addZeros(x) {
	if(x <= 10){a='00' + x} else if(x <= 100) {a='0' + x} else {a=x}
	return a;
};
    if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1){
        //document.forms.count.count2.value=current
        $('#cd-timer').html('<span>'+ message +'</span>');
        return
    } else {
        //document.forms.count.count2.value=dday+ " : "+dhour+" : "+dmin+" : "+dsec
        $('#cd-timer').html(addZeros(dday)+ ":"+addZero(dhour)+":"+addZero(dmin)+":"+addZero(dsec));
        setTimeout("countdown(theyear,themonth,theday)",1000)
    }
}
}*/  

$(document).ready(function() {


//
//RSS Feed
if($('.hp-countdown').length != 0){
	var before="Count down to"
	var current="Today is the big game"
	//var uri;
	//Football
	//var uri="http://www.cyclones.com/rss.dbml?db_oem_id=10700&RSS_SPORT_ID=4653&media=schedules";
	//Basketball (M)
	//var uri="http://www.cyclones.com/rss.dbml?db_oem_id=10700&RSS_SPORT_ID=4252&media=schedules";
	if(uri){	
		$.jGFeed(encodeURIComponent(uri),
		function(feeds){
		  // Check for errors
		  if(!feeds){
		    // there was an error
		    return false;
		  }
		  // do whatever you want with feeds here
			$('#headline').html(feeds.title.replace("Schedules",""))
			if(feeds.entries.length <= 0){				
				$('#breakout .subhead').html('Waiting until next season');
				} else {
					var str = "Iowa State " + feeds.entries[0].title.slice((feeds.entries[0].title.indexOf(":") + 1));
					var title = str.substring(0,(str.indexOf("(")));
					var date = str.substring((str.indexOf("(") + 1),(str.indexOf(")")));
					var strSnip = feeds.entries[0].contentSnippet;
					var time = strSnip.substring(0,(strSnip.lastIndexOf("-")));
				    var formatDate = date.split("/");
					$('#breakout .subhead').html(title + ' <br /> ' + date + ', ' + time);					
					//console.log(date);
				    countdown(formatDate[2],formatDate[0],formatDate[1], current);
				}
			}, 10);	
	}
};


//
//Fancybox
$("a.example1").fancybox();

//
//Tabs
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

//
//column-sort
		if($('div #breakout').length >= '1') { 
			var adjHeight = ($('#breakout').height() - 120) +'px';
			$('#column-sort').css('padding-top',adjHeight);
		 }

//		 
//Home Page Slider
		//Show the paging and activate its first link
		$(".paging").show();
		$(".paging a:first").addClass("active");
		
		//Get size of the image, how many images there are, then determin the size of the image reel.
		var imageWidth = $(".window").width();
		var imageSum = $(".image_reel img").size();
		var imageReelWidth = imageWidth * imageSum;
		
		//Adjust the image reel to its new size
		$(".image_reel").css({'width' : imageReelWidth});
		
		//Paging  and Slider Function
		rotate = function(){
		    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
		
		    $(".paging a").removeClass('active'); //Remove all active class
		    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		    //Slider Animation
		    $(".image_reel").animate({
		        left: -image_reelPosition
		    }, 500 );
		
		}; 

//		
		//Rotation  and Timing Event
		rotateSwitch = function(){
		    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
		        $active = $('.paging a.active').next(); //Move to the next paging
		        if ( $active.length === 0) { //If paging reaches the end...
		            $active = $('.paging a:first'); //go back to first
		        }
		        rotate(); //Trigger the paging and slider function
		    }, 7000); //Timer speed in milliseconds (7 seconds)
		};
		
		rotateSwitch(); //Run function on launch
		
		//On Hover
		/*$(".image_reel div").hover(function() {
		    clearInterval(play); //Stop the rotation
		}, function() {
		    rotateSwitch(); //Resume rotation timer
		});*/
		
		//On Click
		$(".paging a").click(function() {
		    $active = $(this); //Activate the clicked paging
		    //Reset Timer
		    clearInterval(play); //Stop the rotation
		    rotate(); //Trigger rotation immediately
		    rotateSwitch(); // Resume rotation timer
		    return false; //Prevent browser jump to link anchor
		});
//End Home Page Slider
	
	
});//end jquery on page load
