var rotObject = {
	last : 0,
	current : 0,
	total : 4,
	interval : 8000,
	rotate : true,
	playingVideo : false,
	oemid : 1700
};

jQuery(document).ready(function(){
	rotator = jQuery("#rotator");
	if(rotator.length>0)
		setInterval("rotAutoRotate()",rotObject.interval);
		
	jQuery("#rotator .video-close").click(function () {
		rotStopVideo();
	});	
	jQuery("#controls .backward").click(function() {
		rotObject.rotate = false;
		rotPrevious();
	});
	jQuery("#controls .stop").click(function() {
		rotObject.rotate = false;
	});
	jQuery("#controls .forward").click(function() {
		rotObject.rotate = false;
		rotNext();
	});
});

function rotAutoRotate() {	
	if(rotObject.rotate) {
		rotNext();
	}
	else {
		//do nothing
	}
}

function rotPlayVideo(videoId) {
	rotObject.rotate = false;
	rotObject.playingVideo = true;
	jQuery("#neulion-video").css("display","block");
    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();
}

function rotNext() {
	if(rotObject.current==(rotObject.total-1)) {
		rotObject.current = 0;
	}
	else {
		rotObject.current ++;
	}
	rotSelectStory();
}

function rotPrevious() {
	if(rotObject.current==0) {
		rotObject.current = (rotObject.total-1);
	}
	else {
		rotObject.current --;
	}
	rotSelectStory();
}

function rotSelectStoryClick(story) {
	rotStopVideo();
	rotObject.rotate = false;
	rotObject.current = story;
	rotSelectStory();
}

function rotSelectStory() {
	jQuery(".main-image",rotator).removeClass("active");
	jQuery(".overlay-headline",rotator).removeClass("active");
	jQuery(".teaser",rotator).removeClass("active");
	jQuery(".story",rotator).removeClass("active");
	
	jQuery(".main-image:eq("+rotObject.current+")",rotator).addClass("active");
	jQuery(".overlay-headline:eq("+rotObject.current+")",rotator).addClass("active");
	jQuery(".teaser:eq("+rotObject.current+")",rotator).addClass("active");
	jQuery(".story:eq("+rotObject.current+")",rotator).addClass("active");
}
