var MTVNI = {};

MTVNI.Global = (function(){

	var _hatTotal = 0;

/* Public Properties and Methods */
   return {
		/* ****** random hats  ****** */
	   hatTrick : function(hatNumber, subset) {
			// var total = 66; // now set in MtvniOnScenic.xml, then in local xml configs per region. DA
			//var total = 0;

			if (localHatTotal && localHatTotal>0){_hatTotal = localHatTotal};
			if (_hatTotal != 0){
				var bodyTag = document.getElementsByTagName('body')[0];
				var classList = bodyTag.className;
				if (classList.indexOf("hat") > -1) {
					var tempClasses = new Array();
					var classes = classList.split(" ");
					var j = 0;
					for(i = 0; i < classes.length; i++) {
						if(classes[i].substr(0,3) != "hat") tempClasses[j++] = classes[i];
					}
					classList = tempClasses.join(" ");
				}
				if (!hatNumber) hatNumber = Math.floor(_hatTotal*Math.random());
				var newHat = " hat" + hatNumber;

			// allow for static overrides from ISIS in HatOverride
			// if no manual override in ISIS - go with random hats
			if(typeof(staticOverrideFlag) == "undefined"){	
					bodyTag.className = classList + newHat + "";
				}
			else {
				if(staticOverrideFlag == "on"){
					var overrideClass = staticOverrideClass;
					bodyTag.className = classList + " " + overrideClass + "";
					}
				}
			}
		} /* ****** end of random hats  ****** */

	}
})();

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.titlelink").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.titlelink").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});



