$(function(){
	
	//setup top video slider
	var s = 3;
	$.jc = "";
	
	$('#mycarousel').css("visibility","visible")
		.jcarousel({
			start: 1,
			auto: 5,
			wrap: "both", //"circular",
			scroll: s,
			animation: 1500,
			initCallback: videoSliderCallback
	});
	
	var c = $("#widgetVideoSlider #mycarousel li").length;
	var n = 1;
	for(var i=0;i<Math.ceil(c/s);i++){
		var n = 1+(i*s);
		if(n>=c){
			n = c - (s-c%s);
		}		
		$("#widgetVideoSlider .videoSliderDots").append("<a href=\"#"+n+"\" id=\"videoSlider-"+(i+1)+"\"><img src=\"/images/global/Blank.gif\" width=\"9\" height=\"9\" /></a>");
	}
	
	$("#widgetVideoSlider .videoSliderDots a").click(function(){
		this.blur();
		var id = this.href.split("#");
		id = parseInt(id[1]);
		$.jc.startAuto(0);
		$.jc.scroll(id);
		return false;
	});
	
	
	//setup right rail video slider
	
	var sRR = 2;
	$.jcRR = "";
	$.jcRRprev = 1;
	
	$('#widgetVideoSliderRR #videoSlider').css("visibility","visible")
		.jcarousel({
			start: 1,
			auto: 5,
			scroll: sRR,
			wrap: "both",
			animation: 1500,
			buttonNextHTML: null,
			buttonPrevHTML: null,
			initCallback: videoSliderRRCallback,
			itemFirstInCallback: firstInCallBack
	});
	
	var cRR = $("#widgetVideoSliderRR #videoSlider li").length;
	var n = 1;
	for(var i=0;i<Math.ceil(cRR/sRR);i++){
		var n = 1+(i*sRR);
		if(n>=cRR){
			n = cRR - (sRR-c%sRR);
		}		
		$("#widgetVideoSliderRR .videoSliderDots").append("<a href=\"#"+n+"\" id=\"videoSlider-"+(i+1)+"\"><img src=\"/images/global/Blank.gif\" width=\"9\" height=\"9\" /></a>");
	}
	
	$("#widgetVideoSliderRR .videoSliderDots a").click(function(){
		this.blur();
		var id = this.href.split("#");
		id = parseInt(id[1]);
		$.jcRR.startAuto(0);
		$.jcRR.scroll(id);
		return false;
	});
	$("#widgetVideoSliderRR .videoSliderDots a:first").addClass("current");
	
	
});

function videoSliderCallback(e,s){
	$.jc = e;
	// Pause autoscrolling if the user moves with the cursor over the clip.
	e.clip.hover(function() {
		e.stopAuto();
	}, function() {
		e.startAuto();
	});
}
function videoSliderRRCallback(e,s){
	$.jcRR = e;
	// Pause autoscrolling if the user moves with the cursor over the clip.
	e.clip.hover(function() {
		e.stopAuto();
	}, function() {
		e.startAuto();
	});
}

function firstInCallBack(o,l,i,s){
	i /= 2;
	if($("#widgetVideoSliderRR .videoSliderDots a").eq($.jcRRprev).hasClass("current")){
		$("#widgetVideoSliderRR .videoSliderDots a").eq($.jcRRprev).removeClass("current");
	}
	$("#widgetVideoSliderRR .videoSliderDots a").eq(i).addClass("current");
	$.jcRRprev = i;
	
}







