function resetCarousel(){
    window.location.href = window.location.href
}
//window.onresize = resetCarousel;

// jQuery primer
$(document).ready(function(){
	
	
	if(!$("#homecalendar")) return;
	
		//BG randomiser //////////////////////////
		var randBG = Math.ceil(Math.random()*5);
		var bgClass = "bg_"+randBG;
		if ($("#home").length>0){
			$("#home").addClass(bgClass);
		};
		if ($("#calendar").length>0){
			$("#calendar").addClass(bgClass);
		};
	
	
	
	// Home page/////////////////////////////
	if ($("#homecalendar").length>0){
	var ctrPos = $("ol#homecalendar").width();	
	
	//delay carousel reset on window resize...
	var resizeTimer;
	$(window).resize(function() {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(resetCarousel, 100); 
	});
			   
	// Initialise carousel
	$("#homecalendar").CloudCarousel(		
		{			
			xPos: ctrPos/2,
			yPos: 80,
			mouseWheel:true,
			buttonLeft: $("#left-but"),
			buttonRight: $("#right-but"),
			xRadius: 1200,
			yRadius:130,
			//bringToFront:true,
			//altBox: $("#alt-text"),
			//titleBox: $("#title-text")
			altBox: null,
			titleBox: null
		}
		
		
	);
	
	
// custom tooltip fade function
$.tools.tooltip.addEffect("newFade",

	// show function
	function(done) {
		// 'this' variable is a reference to the tooltip API
		var tip = this.getTip(), trigger = this.getTrigger();
		var w = trigger.prop("width"), ratio=(w/250), size=100*ratio;
		//set tw manually
		var tw = 336;
		var ctr = ((336-size)/2)+15;
		//vtop uses CSS padding/margins
		var vtop = 8+130+(size/2);
		if (w<=218){
			vtop = -36-(size/2);
		}
		tip.find('.playbutton').width(size).height(size).css({top: vtop, left: ctr}).show();

		tip.fadeIn('slow', function()  {
			// reposition tip & play icon after fade
			
			tip.find('.playbutton').width(size).height(size).css({top: vtop, left: ctr}).show();
			var tleft = trigger.offset();
			tleft = tleft.left;
			tleft += w/2;
			tleft -= tw/2;
			tleft -= 14;
			tip.css({left:tleft+"px"});
			//debug
			//$('#homecontent .col1').html('width: '+w+' ratio:'+ratio+' vtop:'+vtop+' tleft:'+tleft+' tw:'+tw+' tip:'+tip);
			done.call();
		})
	},

	// hide function
	function(done) {
	// peform your effect. for example:
	this.getTip().hide();
	done.call();
	}
);

	
	$(".cloudcarousel").tooltip({
		onBeforeHide: function() {
			//stop(clear queue , end animation)
			this.getTip().stop(true, true);
		},
		onBeforeShow: function() {
		var lvl = this.getTrigger().prop("width");
		if (lvl<=218){
			//alert(lvl)
			this.getTip().addClass("tipdown");
		} else {
			this.getTip().removeClass("tipdown");
			}
	},
		position: 'center center',
		effect:'newFade'	
	});
	};
	
});
////////////////
