var qbText = new Array("Connect on Facebook","Follow on Twitter","Live Video","Live Stats","Photo Galleries","Shop Online");
var qbLink = new Array("http://www.facebook.com/pages/Spartanburg-SC/Southern-Conference/115952227317","http://twitter.com/SoConSports","/liveEvents/liveEvents.dbml?DB_OEM_ID=4000","/liveStats/liveStats.dbml?DB_OEM_ID=4000","PhotoAlbum_Archives.dbml?DB_OEM_ID=4000","http://www.socongear.com");
var sbLink = new Array("http://www.goasu.com/", "http://www.cofcsports.com/", "http://www.citadelsports.com/", "http://www.davidsonwildcats.com/", "http://www.elonphoenix.com/", "http://www.furmanpaladins.com/", "http://www.georgiasoutherneagles.com/", "http://www.uncgspartans.com/", "http://samfordsports.cstv.com/", "http://www.gomocs.com/", "http://www.catamountsports.com/", "http://athletics.wofford.edu/");
var sbCount = 0;
var rotatorTimer = null;
var rotate = true;

jQuery(document).ready(function () {
	jQuery("#quickbar .icon").each(function() {
		var qbi = jQuery("#quickbar .icon").index(this);
		
		jQuery(this).mouseenter(function() {
			jQuery(this).find(".on").animate({
				opacity: 1
			}, 500);
			
			jQuery("#quickbar .text").html(qbText[qbi]);
		});
		jQuery(this).mouseleave(function() {
			jQuery(this).find(".on").animate({
				opacity: 0
			}, 500);
			
			jQuery("#quickbar .text").html('');
		});
		jQuery(this).click(function() {
			if (qbi == 5)
				window.open(qbLink[qbi]);
			else
			location.href = qbLink[qbi];
		});
	});
	
	jQuery("#schools .icon").each(function() {
		var sbi = jQuery("#schools .icon").index(this);
		
		jQuery(this).mouseenter(function() {
			jQuery(this).find(".on").animate({
				opacity: 1
			}, 500);
			jQuery(this).animate({
				top: -5
			}, 500);
		});
		jQuery(this).mouseleave(function() {
			jQuery(this).find(".on").animate({
				opacity: 0
			}, 500);
			jQuery(this).animate({
				top: 0
			}, 500);
		});
		jQuery(this).click(function() {
			window.open(sbLink[sbi]);
		});
	});
	
	jQuery("#rotator .subs .item").each(function() {
		jQuery(this).click(function() {
			jumpto(jQuery(this).index());
		});
	});
	
	jQuery("#rotator .more").click(function() {
		moreHeadlines();
	});
	
	jQuery("#rotator .headlines .close").click(function() {
		moreHeadlines();
	});
	
	jQuery("#fronttabs .header .tab").each(function() {
		jQuery(this).click(function() {
			var tabid = jQuery("#fronttabs .header .tab.active");
			var contentid = jQuery("#fronttabs .content .tab.active");
			var tabindex = jQuery("#fronttabs .header .tab").index(this);
			var oldtabindex = jQuery("#fronttabs .header .tab.active").index();
			
			jQuery(this).find(".on").animate({
				opacity: 1
			}, 500);
			
			jQuery(tabid).find(".on").animate({
				opacity: 0
			}, 500);
			
			jQuery("#fronttabs .content .tab:eq("+tabindex+")").fadeIn(500);
			jQuery("#fronttabs .content .tab:eq("+oldtabindex+")").fadeOut(500);
			
			jQuery(tabid).removeClass('active');
			jQuery(this).addClass('active');
			jQuery("#fronttabs .content .tab:eq("+tabindex+")").addClass('active');
			jQuery("#fronttabs .content .tab:eq("+oldtabindex+")").removeClass('active');
			
			//ajax in the data if the data contains the loading image
			if (jQuery("#fronttabs .content .tab:eq("+tabindex+") img.loading").attr('tabname')) {
				var tabFilename = jQuery("#fronttabs .content .tab:eq("+tabindex+") img.loading").attr('tabname');
				var tabObject = jQuery("#fronttabs .content .tab:eq("+tabindex+") img.loading").parent();
				
				jQuery.ajax({
					type:"POST",
					url:getBaseUrl()+"/tabs/"+tabFilename+".dbml",
					data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&spid='+spid,
					success: function(data) {
						jQuery(tabObject).html(data);
					}
					,error: function(XMLHttpRequest, textStatus, errorThrown) {
						alert("errorThrown:"+errorThrown);
					}
				});
			}
		});
	});
	
	jQuery("#videotabs .header .tab").each(function() {
		jQuery(this).click(function() {
			var tabid = jQuery("#videotabs .header .tab.active");
			var contentid = jQuery("#videotabs .content .tab.active");
			var tabindex = jQuery("#videotabs .header .tab").index(this);
			var oldtabindex = jQuery("#videotabs .header .tab.active").index();
			
			jQuery(this).find(".on").animate({
				opacity: 1
			}, 500);
			
			jQuery(tabid).find(".on").animate({
				opacity: 0
			}, 500);
			
			
			jQuery("#videotabs .content .tab:eq("+tabindex+")").fadeIn(500);
			jQuery("#videotabs .content .tab:eq("+oldtabindex+")").fadeOut(500);
			
			jQuery(tabid).removeClass('active');
			jQuery(this).addClass('active');
			jQuery("#videotabs .content .tab:eq("+tabindex+")").addClass('active');
			jQuery("#videotabs .content .tab:eq("+oldtabindex+")").removeClass('active');
			
			//ajax in the data if the data contains the loading image
			if (jQuery("#videotabs .content .tab:eq("+tabindex+") img.loading").length > 0) {
				var tabChannelName = jQuery("#videotabs .content .tab:eq("+tabindex+") img.loading").attr('channel');
				var tabObject = jQuery("#videotabs .content .tab:eq("+tabindex+") img.loading").parent();
				
				jQuery.ajax({
					type:"POST",
					url:getBaseUrl()+"/tabs/video.dbml",
					data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&frm_channel_name='+tabChannelName+"&spid="+spid,
					success: function(data) {
						jQuery(tabObject).html(data);
					}
					,error: function(XMLHttpRequest, textStatus, errorThrown) {
						alert("errorThrown:"+errorThrown);
					}
				});
			}
			
		});
	});
	
	setTimeout('cycleSports();', 1000);
	rotator();
});

function cycleSports() {
	if (jQuery("#schools .icon:eq("+sbCount+")").length >= 0) {
		jQuery("#schools .icon:eq("+sbCount+")").trigger('mouseenter').delay(1000).trigger('mouseleave');
		sbCount++;
		setTimeout("cycleSports();", 300);
	}
}

function rotator() {
	stopRotate();
	rotatorTimer = setTimeout("rotateForward();", 7000);
}

function rotateForward() {
	var storyIndex = jQuery("#rotator .subs .item.active").index();
	var nextIndex = storyIndex+1;
	if(nextIndex >= 4)
		nextIndex = 0;
	jQuery("#rotator .main:eq("+storyIndex+")").fadeOut(500);
	jQuery("#rotator .main:eq("+nextIndex+")").fadeIn(500);
	jQuery("#rotator .subs .item:eq("+storyIndex+")").removeClass('active');
	jQuery("#rotator .subs .item:eq("+nextIndex+")").addClass('active');
	
	if (rotate)
		rotator();
}

function jumpto(num) {
	stopRotate();
	var storyIndex = jQuery("#rotator .subs .item.active").index();
	var nextIndex = num;
	jQuery("#rotator .main:eq("+storyIndex+")").fadeOut(500);
	jQuery("#rotator .main:eq("+nextIndex+")").fadeIn(500);
	jQuery("#rotator .subs .item:eq("+storyIndex+")").removeClass('active');
	jQuery("#rotator .subs .item:eq("+nextIndex+")").addClass('active');
}

function moreHeadlines() {
	stopRotate();
	
	if (jQuery("#rotator .headlines").hasClass('loading')) {
		jQuery.ajax({
			type:"POST",
			url:getBaseUrl()+"/sections/moreheadlines.dbml",
			data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&spid='+spid+'&headline_exclude_list='+excludeList,
			success: function(data) {
				jQuery("#rotator .headlines").append(data);
				jQuery("#rotator .headlines img.loading").remove();
				jQuery("#rotator .headlines").removeClass('loading');
			}
			,error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("errorThrown:"+errorThrown);
			}
		});
	}
	
	if (jQuery("#rotator .headlines").height() == 0) {
		jQuery("#rotator .headlines").animate({
			height: 402,
			top: 0
		}, 1000);	
	}
	else {
		jQuery("#rotator .headlines").animate({
			height: 0,
			top: 402
		}, 1000);	
		rotator();
	}	
}

function stopRotate() {
	if (rotatorTimer)
		clearTimeout(rotatorTimer);
}

function getBaseUrl() {
     urlTokens = window.location.href.split('/');
     url = urlTokens[0]+'//'+urlTokens[2];
     return url;
}

function scheduleSport(sportId, schoolId) {
	jQuery("#fronttabs .content .tab.active .info").fadeOut(500);
	
	if (schoolId == '') {
		jQuery.ajax({
			type:"POST",
			url:getBaseUrl()+"/share/schoollist.dbml",
			data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&tab_sport_id='+sportId,
			success: function(data) {
				jQuery("#fronttabs .schoolselect").html(data);
			}
			,error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("errorThrown:"+errorThrown);
			}
		});
	}	
	
	setTimeout("scheduleAjax('"+sportId+"', '"+schoolId+"');", 500);
}

function scheduleAjax(sportId, schoolId) {
	var sportText = jQuery("#fronttabs .sportselect option:selected").html();
	if (sportText == 'Select a Sport')
		sportText = 'All Sports';
	jQuery.ajax({
		type:"POST",
		url:getBaseUrl()+"/tabs/schedule.dbml",
		data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&spid='+sportId+'&tab_school_id='+schoolId+'&schedule_mode=info',
		success: function(data) {
			jQuery("#fronttabs .content .tab.active .info").html(data);
			jQuery("#fronttabs .content .tab.active .info").fadeIn(500);
			jQuery("#fronttabs .content .tab.active .showing").html('Now Showing: '+sportText);
		}
		,error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("errorThrown:"+errorThrown);
		}
	});	
}

function scoresSport(sportId, schoolId) {
	jQuery("#fronttabs .content .tab.active .info").fadeOut(500);
	
	if (schoolId == '') {
		jQuery.ajax({
			type:"POST",
			url:getBaseUrl()+"/share/schoollist.dbml",
			data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&tab_sport_id='+sportId,
			success: function(data) {
				jQuery("#fronttabs .schoolselect").html(data);
			}
			,error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("errorThrown:"+errorThrown);
			}
		});
	}	
	
	setTimeout("scoreAjax('"+sportId+"', '"+schoolId+"');", 500);
}

function scoreAjax(sportId, schoolId) {
	jQuery.ajax({
		type:"POST",
		url:getBaseUrl()+"/tabs/scores.dbml",
		data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&spid='+sportId+'&tab_school_id='+schoolId+'&score_mode=info',
		success: function(data) {
			jQuery("#fronttabs .content .tab.active .info").html(data);
			jQuery("#fronttabs .content .tab.active .info").fadeIn(500);
		}
		,error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("errorThrown:"+errorThrown);
		}
	});
}

function standingssport(sportId) {
	jQuery("#standings .content .info").fadeOut(500);
	setTimeout("standingAjax('"+sportId+"');", 500);
}

function standingAjax(sportId) {
	jQuery.ajax({
		type:"POST",
		url:getBaseUrl()+"/sections/standings.dbml",
		data: "DB_OEM_ID="+oemid+"&key="+key+'&is_home_page='+ishome+'&spid='+sportId+'&standings_mode=info',
		success: function(data) {
			jQuery("#standings .content .info").html(data);
			jQuery("#standings .sporttitle").html(jQuery("#sportname").html());
			jQuery("#standings .content .info").fadeIn(500);
			var standingsSpsid = jQuery.trim(jQuery("#extstandingsspsid").html());
			jQuery("#standings .footer .extstandings").attr('href', '/standings/Standings.dbml?DB_OEM_ID=4000&SPID='+sportId+'&SPSID='+standingsSpsid);
		}
		,error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert("errorThrown:"+errorThrown);
		}
	});
}

function slideLeft(slideId) {
	var sliderWidth = jQuery("#"+slideId+" .slider").width();
	var sliderSlide = jQuery("#"+slideId+" .slider").parent().width();
	var sliderLeft = jQuery("#"+slideId+" .slider").css('left').replace('px', '');
	var sliderTo = sliderLeft;
	
	jQuery("#"+slideId+" .slideLeft").removeAttr('onclick');
	jQuery("#"+slideId+" .slideRight").removeAttr('onclick');
	
	jQuery("#"+slideId+" .slideLeft").unbind('click');
	jQuery("#"+slideId+" .slideRight").unbind('click');
	
	if (sliderLeft < 0) {
		sliderTo = parseInt(sliderLeft)+parseInt(sliderSlide);
	}
	
	if (sliderTo == 0)
		pageon = 'one';
	else if (sliderTo == -parseInt(sliderSlide))
		pageon = 'two';
	else if (sliderTo == -(parseInt(sliderSlide)*2))
		pageon = 'three';
	
	jQuery("#"+slideId+" .slider").animate({
		left: sliderTo
	}, 500);
	
	jQuery("#"+slideId+" .pagebutton").attr('src', '/fls/4000/site_graphics/page_off.png');
	jQuery("#"+slideId+" .pagebutton."+pageon).attr('src', '/fls/4000/site_graphics/page_on.png');
	
	setTimeout("slideClick('"+slideId+"');", 500);
}

function slideRight(slideId) {
	var sliderWidth = jQuery("#"+slideId+" .slider").width();
	var sliderSlide = jQuery("#"+slideId+" .slider").parent().width();
	var sliderLeft = jQuery("#"+slideId+" .slider").css('left').replace('px', '');
	var sliderTo = sliderLeft;
	
	jQuery("#"+slideId+" .slideLeft").removeAttr('onclick');
	jQuery("#"+slideId+" .slideRight").removeAttr('onclick');

	jQuery("#"+slideId+" .slideLeft").unbind('click');
	jQuery("#"+slideId+" .slideRight").unbind('click');
	
	if (sliderLeft > -(sliderWidth - sliderSlide)) {
		sliderTo = sliderLeft - sliderSlide;
	}
	
	if (sliderTo == 0)
		pageon = 'one';
	else if (sliderTo == -parseInt(sliderSlide))
		pageon = 'two';
	else if (sliderTo == -(parseInt(sliderSlide)*2))
		pageon = 'three';

	jQuery("#"+slideId+" .slider").animate({
		left: sliderTo
	}, 500);
	
	jQuery("#"+slideId+" .pagebutton").attr('src', '/fls/4000/site_graphics/page_off.png');
	jQuery("#"+slideId+" .pagebutton."+pageon).attr('src', '/fls/4000/site_graphics/page_on.png');
	
	setTimeout("slideClick('"+slideId+"');", 500);
}

function slideClick(slideId) {
	jQuery("#"+slideId+" .slideLeft").click(function() {
		slideLeft(slideId);
	});
	jQuery("#"+slideId+" .slideRight").click(function() {
		slideRight(slideId);
	});	
}

function showNeuLionVid(vidid){
	stopRotate();
	jQuery("#NeulionVidContainer").show();
	neulionPlayer(vidid);
	rotate = true;
	playerRunning = true;
}

function hideNeuLionVid(){
	if (jQuery("#NeulionVidContainer").css('display') != 'none'){
		jQuery("#NeulionVidContainer").hide();
		slProxy("hide"); // handle Silverlight
		if (jQuery("#jtvshlembed") && document.getElementById('jtvshlembed').pauseVideo){
			document.getElementById('jtvshlembed').pauseVideo();
			playerRunning = false;
		}
		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;
		}
		rotator();
	}
}

function showLogin() {
	if (jQuery("#headerlogin").css('display') == 'block')
		jQuery("#headerlogin").fadeOut(500);
	else
		jQuery("#headerlogin").fadeIn(500);
}
