var IE6playbuttonObj;
var playerRunning = false;
var rotate_current = 1;
var rotate_old = 1;
var rotate_total = 5;
var rotate_flag = true;
var rotate_time = 7000;
var rotate_timer = null;
var score_timer = null;
var easing = 'backin';


function rotate() {
	if (rotate_flag)
		rotate_timer = setTimeout("rotateForward()", rotate_time);
}

function rotateForward() {
		rotate_current++;
		if (rotate_current > rotate_total)
			rotate_current = 1;
			
		rotateTo(rotate_current);
}

function rotateBack() {
		rotate_current--;
		if (rotate_current < 1)
			rotate_current = rotate_total;
			
		rotateTo(rotate_current);
}

function rotateTo(num) {
	freeze();
	setTimeout('unfreeze()', 2015);
	rotate_current = num;
	if (rotate_timer)
		clearTimeout(rotate_timer);
	//moves the headline bar down
	//jQuery("#titleContainer"+rotate_old).animate({ top: 372 }, 500);

	//fades the old image out and the new one in
	jQuery("#rotatorImage"+rotate_old).fadeOut(500);
	jQuery("#rotatorTitle"+rotate_old).fadeOut(500);
	jQuery("#rotatorSub"+rotate_old).css('color', '#999');
	
	setTimeout('jQuery("#rotatorImage'+rotate_old+'").hide()',500);	
	setTimeout('jQuery("#rotatorTitle'+rotate_old+'").hide()',500);	
	
	setTimeout('jQuery("#rotatorImage'+num+'").fadeIn(500)',510);	
	setTimeout('jQuery("#rotatorTitle'+num+'").fadeIn(500)',510);	
	//moves the headline bar up
	//setTimeout('jQuery("#titleContainer'+num+'").animate({ top: 336 }, 500)', 1515);
	
	//slides over the sub slider
	slider_left = ((rotate_current-1)*131)+4;
	jQuery("#subSlider").animate({ left: slider_left }, {duration: 1515});
	setTimeout('jQuery("#rotatorSub'+num+'").css("color", "#E7CF30")',1520);	
	
	rotate_old = num;
	rotate();
}

function freeze() {
	jQuery("#subHide").show();
	jQuery("#subHideButtons").show();
}

function unfreeze() {
	jQuery("#subHide").hide();
	jQuery("#subHideButtons").hide();
}

function showNeuLionVid(vidid){
	rotate = true;
	//toggle();
	document.getElementById('NeulionVidContainer').style.display = 'block';
	jQuery("#rotatorImageContainer").hide();
	jQuery("#articleVideoContainer").css('height', '372px');
	neulionPlayer(vidid);

	playerRunning = true;
}

function hideNeuLionVid(){
	jQuery("#rotatorImageContainer").show();
	jQuery("#articleVideoContainer").css('height', '0px');
	if (document.getElementById('NeulionVidContainer').style.display != 'none'){
		document.getElementById('NeulionVidContainer').style.display = 'none';
		//document.getElementById('articleVideoAdContainer').style.display = 'none';
		if (document.getElementById('jtvshlembed') != null && document.getElementById('jtvshlembed').pauseVideo){
		document.getElementById('jtvshlembed').pauseVideo();
		
		}
		rotate = false;
		//toggle();
		playerRunning = false;
	}
}

function vidboxHover(imgid){
	//jQuery('#' + imgid).attr("src","/fls/<dbvar>DB_OEM_ID</dbvar>/site_graphics/play_overlay1t.png");
}

function vidboxUnHover(imgid){
	//jQuery('#' + imgid).attr("src","/fls/<dbvar>DB_OEM_ID</dbvar>/site_graphics/play_overlay1t.png");
}

function autoScroll() {
	var leftpos = parseInt(jQuery("#scoreboard .slider").css('left').replace('px', ''));
	
	if (leftpos > -(jQuery("#scoreboard .slider").width()-140)) {
		jQuery("#scoreboard .slider").animate({
			left: (leftpos - 140)
		}, 500);
	}
	else {
		jQuery("#scoreboard .slider").animate({
			left: 0
		}, 500);
	}
}

function scoreLeft() {
	var leftpos = parseInt(jQuery("#scoreboard .slider").css('left').replace('px', ''));
	
	if (leftpos < 0) {
		jQuery("#scoreboard .slider").animate({
			left: (leftpos + 140)
		}, 500);
		
		resetScoreAuto();
	}
}

function scoreRight() {
	var leftpos = parseInt(jQuery("#scoreboard .slider").css('left').replace('px', ''));
	if (leftpos > -(jQuery("#scoreboard .slider").width()-140)) {
		jQuery("#scoreboard .slider").animate({
			left: (leftpos - 140)
		}, 500);
		
		resetScoreAuto();	
	}
}

function scoreAuto() {
	score_timer = setInterval(function() {autoScroll();}, 4000);
}

function clearScoreAuto() {
	clearInterval(score_timer);
}

function resetScoreAuto() {
	clearScoreAuto();
	scoreAuto();	
}


jQuery(document).ready(function() {
    //jQuery("#titleContainer1").animate({ top: 336 }, 500);
    rotate();
    jQuery(".eventDiv").each( function() {
    	//console.log(jQuery("a:last", this));
    	jQuery("a:last", this).css('border', 'none');
    	//jQuery(".eventDiv a:last").css('border', 'none');
    });
    
    jQuery("#scoreboard .arrow:eq(0)").click(function() {
    	scoreLeft();
    });
     jQuery("#scoreboard .arrow:eq(1)").click(function() {
    	scoreRight();
    });
    jQuery("#scoreboard .slider").width(jQuery("#scoreboard .item").length * 140);
    jQuery("#scoreboard .item").each(function() {
    	jQuery(this).find(".bar:last").hide();
    });
    
    scoreAuto();
});
