var tabloc = 10;
var oldtab = 'rotator';
var quickurls = new Array('http://www.gobison.com/liveEvents/liveEvents.dbml?DB_OEM_ID=2400', 'http://www.gobison.com/liveStats/liveStats.dbml?DB_OEM_ID=2400', 'http://www.gobison.com/PhotoStore.dbml?&DB_OEM_ID=2400', 'http://www.ndsubookstore.com ', 'http://www.gobison.com/tickets/TicketHome.dbml?DB_OEM_ID=2400', 'https://www.ndsualumni.com/NetCommunity/SSLPage.aspx?pid=743 ');
var rotatorIndex = 0;
var rotatorTotal = 4;
var rotatorTime = 5000;
var rotatorTimer = null;

jQuery(document).ready(function () {
	tabsetbind();
	
	jQuery("#header .quick .item").mouseover(function() {
		jQuery(this).removeClass('off');
		jQuery(this).addClass('on');
	}).mouseout(function() {
		jQuery(this).removeClass('on');
		jQuery(this).addClass('off');
	}).click(function() {
		var qbindex = jQuery("#header .quick .item").index(this);
		if (jQuery(this).index() == 3 || jQuery(this).index() == 5 || jQuery(this).index() == 6)
			window.open(quickurls[qbindex],'_blank');
		else
			location.href = quickurls[qbindex];
	});
	
	jQuery("#subimages .subitem").bind('click', function() {
		jumpTo(jQuery(this).index());
	});
	
	jQuery("#featuredphotos .leftarrow").click(function() {
		photoSlide('left');
	});
	
	jQuery("#featuredphotos .rightarrow").click(function() {
		photoSlide('right');
	});
	
	jQuery("#features .leftarrow").click(function() {
		featSlide('left');
	});
	
	jQuery("#features .rightarrow").click(function() {
		featSlide('right');
	});
	
	jQuery("#hometabs .content .info").fadeOut(0);
	jQuery("#hometabs .content .info.active").fadeIn(0);
	
	setTimeout('rotate();', rotatorTime);
	
	if (jQuery("#contentLeft").length > 0) {
		if (jQuery("#contentRight").length > 0) {
			leftheight = jQuery("#contentLeft").height();
			rightheight = jQuery("#contentRight").height();
			
			if (leftheight > rightheight)
				jQuery("#contentRight").css('height', leftheight+'px');
			else if (rightheight > leftheight)
				jQuery("#contentLeft").css('height', rightheight+'px');
			
		}
	}
});

function tabsetbind() {
	jQuery("#hometabs .tabs .tab").bind('click', function() {
		var tabclasses = jQuery(this).attr('class');
		tabclasses = tabclasses.replace('tab', '');
		tabclasses = tabclasses.replace('left', '');
		tabclasses = tabclasses.replace('active', '');
		tabclasses = jQuery.trim(tabclasses);
		
		tabslide(tabclasses, jQuery(this).index());
	});
}

function tabslide(tabclass, tabindex) {
	jQuery("#hometabs .tabs .tab").unbind('click');
	
	var newtableft = (tabindex*164)+10;
	
	jQuery("#hometabs .tabs .highlight").animate({
		left: newtableft
	}, 500);
	
	jQuery("#hometabs .tabs ."+oldtab).removeClass('active');
	setTimeout('jQuery("#hometabs .tabs .'+tabclass+'").addClass("active");', 500);
	
	
	jQuery("#hometabs .content .active").fadeOut(250);
	setTimeout('jQuery("#hometabs .content .'+oldtab+'").removeClass("active");', 250);
	setTimeout('jQuery("#hometabs .content .'+tabclass+'").addClass("active");', 250);
	setTimeout('jQuery("#hometabs .content .active").fadeIn(250);', 250);
	
	setTimeout('tabsetbind();', 500);
	oldtab = tabclass;
}

function rotate() {
	rotatorTimer = setTimeout("rotateForward()", rotatorTime);
}

function rotateForward() {
	jQuery("#subimages .subitem").unbind('click');	
	//before increment
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeOut(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: .4
	}, 1000);
	
	rotatorIndex++;
	if (rotatorIndex == rotatorTotal) 
		rotatorIndex = 0;
	
	//after increment
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeIn(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: 0
	}, 1000);
	
	clearTimeout(rotatorTimer);
	rotatorTimer = setTimeout("rotate()", rotatorTime);
	setTimeout('jQuery("#subimages .subitem").bind("click", function() {jumpTo(jQuery(this).index());});', 1000);
}

function jumpTo(itemNum) {
	jQuery("#subimages .subitem").unbind('click');	
	//before increment
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeOut(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: .4
	}, 1000);
	
	rotatorIndex = itemNum;
		
	//after increment
	jQuery("#mainimage .mainstory:eq("+itemNum+")").fadeIn(1000);
	jQuery("#subimages .subitem:eq("+itemNum+") .overlay").animate({
		opacity: 0
	}, 1000);
	
	clearTimeout(rotatorTimer);
	
	setTimeout('jQuery("#subimages .subitem").bind("click", function() {jumpTo(jQuery(this).index());});', 1000);
}

function rotatorStop() {
	clearTimeout(rotatorTimer);	
}

function showNeuLionVid(vidid){ 
	rotatorStop();
	jQuery("#NeulionVidContainer").show(); 
	neulionPlayer(vidid); 
	//rotate = true;
	playerRunning = true;
	jQuery("#mainimage").hide();
	jQuery("#subrotator").hide();
	jQuery("#hometabs .content").css('background', '#000');
}

function hideNeuLionVid(){
	jQuery("#mainimage").show();
	jQuery("#subrotator").show();
	jQuery("#hometabs .content").css('background', 'url(/fls/2400/site_graphics/hometabbg.png) repeat-x');
	
	if (jQuery("#NeulionVidContainer").css('display') != 'none'){
		jQuery("#NeulionVidContainer").hide();
		if (jQuery("#jtvshlembed") && document.getElementById('jtvshlembed').pauseVideo){
			document.getElementById('jtvshlembed').pauseVideo();
			playerRunning = false;
			slProxy("hide");
		}
		rotate();
	}
}

function showNeuLionVidArticle(vidid){
	jQuery("#articleVideoContainer").show();
	jQuery("#NeulionVidContainer").show();
	neulionPlayer(vidid);
	playerRunning = true;
}

function hideNeuLionVidArticle(){
	if (jQuery("#NeulionVidContainer").css('display') != 'none'){
		jQuery("#articleVideoContainer").hide();
		jQuery("#NeulionVidContainer").hide();
		if (jQuery("#jtvshlembed") && document.getElementById('jtvshlembed').pauseVideo){
			document.getElementById('jtvshlembed').pauseVideo();
			playerRunning = false;
		}
		rotate();
	}
}

function photoSlide(dir) {
	var slideleft = jQuery("#featuredphotos .slider").position().left;
	
	if (dir == 'left') {
		if (slideleft < 0)
			slideleft = slideleft + 201;
	}
	else if (dir == 'right') {
		if (slideleft > -(jQuery("#featuredphotos .slider").width() - 201) )
			slideleft = slideleft - 201;
	}
	
	jQuery("#featuredphotos .slider").animate({
		left: slideleft
	}, 500);
}

function featSlide(dir) {
	var slideleft = jQuery("#features .slider").position().left;
	
	if (dir == 'left') {
		if (slideleft < 0)
			slideleft = slideleft + 756;
	}
	else if (dir == 'right') {
		if (slideleft > -(jQuery("#features .slider").width() - 756) )
			slideleft = slideleft - 756;
	}
	
	jQuery("#features .slider").animate({
		left: slideleft
	}, 500);
}
