/******************************************************************************
	START Rotator
******************************************************************************/
var rotObject = {
	current : 0,
	last : 0,
	total : 4,
	interval : 10000,
	rotate : true,
	playingVideo : false,
	next : 1,
	previous : 4,
	oemid : 5200
};

jQuery(document).ready(function(){
	if(jQuery("body").hasClass("sport")) 
		rotObject.rotate = false;	//don't rotate on sport pages
	if(jQuery("body").hasClass("article")) 
		rotObject.rotate = false;	//don't rotate on article pages
	if(jQuery("#rotator").length > 0) 
		buildRotator();	
	    jQuery("#rotator .main-image").mouseenter(function(){
    	jQuery(this).addClass("active");
    }).mouseleave(function(){
    	jQuery(this).removeClass("active");
    });
	/*jQuery("#rotator .play-button").click(function () {
		rotPlayVideo();
	});	
	jQuery("#rotator .video-close").click(function () {
		rotStopVideo();
	});*/	
}); 
function buildRotator() {
	jQuery("#rotator").animate({height:"360px",opacity:"1"},1000);	
	setTimeout("rotChangeOverlayHeadline()",1000);
	for(x=0;x<jQuery("#rotator .data").length;x++) {
		imageSrc = jQuery("#rotator .data .large-image:eq("+x+")").html();
		articleId = jQuery("#rotator .data:eq("+x+") .articleId").html();
		videoId = jQuery("#rotator .data:eq("+x+") .viewVideo").html();
		if(videoId > '') {			
			if (articleId.substring(0,7)=='http://') {
				jQuery("#rotator .main-image").append('<img id="main-'+x+'" class="rot-image" onclick="document.location.href=\''+articleId+'\'" src="'+imageSrc+'"/>')			
			}else{
				jQuery("#rotator .main-image").append('<img id="main-'+x+'" class="rot-image" onclick="document.location.href=\'/createarticle.php?ID='+articleId+'\'" src="'+imageSrc+'"/>')			
			}
			jQuery("#rotator .main-image").append('<div id="button-'+x+'" class="play-button" onclick="document.location.href=\'http://www.youtube.com/user/laurierathletics#p/u/0/'+videoId+'\'" />')			
		}else{			
			if (articleId.substring(0,7)=='http://') {
				jQuery("#rotator .main-image").append('<img id="main-'+x+'" class="rot-image" onclick="document.location.href=\''+articleId+'\'" src="'+imageSrc+'"/>')					
			}else{
				jQuery("#rotator .main-image").append('<img id="main-'+x+'" class="rot-image" onclick="document.location.href=\'/createarticle.php?ID='+articleId+'\'" src="'+imageSrc+'"/>')
			}
		}
		headline = jQuery("#rotator .data:eq("+x+") .headline").html();
		shortHeadline = jQuery("#rotator .data:eq("+x+") .short-headline").html();
		jQuery("#rotator .storys").append('<div onclick="rotSelect('+x+')" class="story"><div class="selected"></div><div class="text">'+shortHeadline+'</div></div>');
		if(x==0) {
			jQuery("#main-0").addClass("active");
			startVideoId=jQuery("#rotator .data:eq("+x+") .viewVideo").html();									
		}
	}
	if(startVideoId > '') {
		jQuery("#rotator .play-button").show();		
	}else{
		jQuery("#rotator .play-button").hide();
	}
	setInterval("rotAuto()",9000);
}

function rotSubStorySelect() {
	jQuery("#rotator .storys .story .selected").fadeOut(250);
	jQuery("#rotator .storys .story .text").css("color","#777777");	
	setTimeout("rotSubStoryActivate()",250);
}

function rotSubStoryActivate() {
	jQuery("#rotator .storys .story .selected:eq("+rotObject.current+")").fadeIn(250);
	jQuery("#rotator .storys .story .text:eq("+rotObject.current+")").css("color","#ffffff");	
}

function rotSlideUpHeadline() {
	jQuery("#rotator .overlay-headline").animate({height:"79px"	},500);
	//jQuery("#rotator .overlay-headline .headline")[0].style.removeAttribute('filter');

}

function rotSlideDownHeadline() {
	jQuery("#rotator .overlay-headline").animate({height:"0px"	},500);
	//jQuery("#rotator .overlay-headline .headline")[0].style.removeAttribute('filter');
}

function fixClearType(obj) {
	//element.style.removeAttribute('filter');
}

function rotAuto() {
	if(rotObject.rotate) 
		rotNext();	
}

function rotNext() {
	rotObject.last = rotObject.current;
	if(rotObject.current==rotObject.total) {
		rotObject.current = 0;
		rotSetupSubStory(rotObject.current);
	}
	else {
		rotObject.current ++;
		rotSetupSubStory(rotObject.current);
	}
}

function rotSelect(num) {
	rotObject.rotate = false;
	rotObject.last = rotObject.current;
	rotObject.current = num;	
	rotStopVideo();
	setTimeout("rotSetupSubStory()",100);
}

function rotSetupSubStory() {
	videoId = jQuery("#rotator .data:eq("+rotObject.current+") .viewVideo").html();
	if(videoId > '') 
		jQuery("#rotator .play-button").show();	
	else {
		jQuery("#rotator .play-button").hide();	
		//jQuery("#rotator .play-button").hide();
	}
	if(rotObject.current == rotObject.total)
		rotObject.next = 0;
	else
		rotObject.next = rotObject.current + 1;
	if(rotObject.current == 0)
		rotObject.previous = rotObject.total;
	else
		rotObject.previous = rotObject.current - 1;
	jQuery("#main-"+rotObject.current).addClass("next");
	rotSlideDownHeadline();
	setTimeout("rotChangeOverlayHeadline()",500);
	setTimeout("rotSelectSubStory()",10);
}

function rotChangeOverlayHeadline() {
	jContent = jQuery("#rotator .overlay-headline .content");
	jContent.html('');
	headline = jQuery("#rotator .data:eq("+rotObject.current+") .headline").html();
	articleId = jQuery("#rotator .data:eq("+rotObject.current+") .articleId").html();
	if(articleId>'') {
		if (articleId.substring(0,7)=='http://') {
			headline = '<a href="'+articleId+'">'+headline+'</a>';	
		}else{
			headline = '<a href="/createarticle.php?ID='+articleId+'">'+headline+'</a>';
		}
	}
	//shortHeadline = headline = jQuery("#rotator .data:eq("+rotObject.current+") .short-headline").html();
	jContent.prepend('<div class="headline">'+headline+'</div>');
	if (articleId.substring(0,7)=='http://') {
		jContent.prepend('<div class="links"><a class="overlay-link" href="'+articleId+'">Read Article <span>&#187</span></a></div>');
	}else{
		jContent.prepend('<div class="links"><a class="overlay-link" href="/createarticle.php?ID='+articleId+'">Read Article <span>&#187</span></a></div>');
	}
	buyPhoto = jQuery("#rotator .data:eq("+rotObject.current+") .buyPhoto").html();
	statsURL = jQuery("#rotator .data:eq("+rotObject.current+") .viewStats").html();
	videoId = jQuery("#rotator .data:eq("+rotObject.current+") .viewVideo").html();
	if(videoId>'') {		
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="http://www.youtube.com/user/laurierathletics#p/u/0/'+videoId+'">Video <span>&#187</span></a>');
	}
	if(buyPhoto>'') {		
		//Replay Photos
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="'+buyPhoto+'">Photo Gallary <span>&#187</span></a>');
		
	}
	if(statsURL>'') {		
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="'+statsURL+'">Stats <span>&#187</span></a>');
	}
	
	rotSlideUpHeadline();
	rotSubStorySelect();
}

function rotSelectSubStory() {
	//jQuery("#main-"+rotObject.last).animate({"opacity":"0"},500);	
	for(x=0;x<jQuery(".rot-image").length;x++) {
		if(x==rotObject.current) {
			jQuery(".rot-image:eq("+x+")").fadeIn(500);
		}
		else {
			jQuery(".rot-image:eq("+x+")").fadeOut(500);
		}	
	}
	setTimeout("rotSetActive()",600);
}

function rotSetActive() {
	//jQuery(".rot-image").css("opacity","1");
	jQuery(".rot-image").removeClass("active");
	jQuery("#main-"+rotObject.current).addClass("active");
	jQuery(".rot-image").removeClass("next");
}

function rotPlayVideo() {
	rotObject.rotate = false;
	rotObject.playingVideo = true;
	jQuery("#neulion-video").css("display","block");
	videoId = jQuery("#rotator .data:eq("+rotObject.current+") .viewVideo").html();
    neulionPlayer(videoId);
    jQuery("#rotator .video-close").show();
}
	
function rotStopVideo() {
	rotObject.playingVideo = false;
	if(jQuery("#jtvshlembed").length>0) {
		try {document.getElementById('jtvshlembed').pauseVideo();}
		catch(ex) {setTimeout("rotStopVideo()",1000);}
	}
	jQuery("#neulion-video").hide();
	jQuery("#jtvshlAdContainer").hide();
	jQuery("#rotator .video-close").hide();
}
/******************************************************************************
	END Rotator
******************************************************************************/


