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  ****** */

	}
})();


/* start of top nav js */

$.ajaxSetup({
'cache' : true
});

$(document).ready(function(){
MTV.init();
});

MTV = new function(){
this.initArray = new Array();

this.init = function(){

return true;
}
}


$(function()
{
MTV.Navigation=new MtvNavigation();
});

function MtvNavigation()
{
var self=this;
this.init=function()
{
self.meta = {

}

self.init_triggers();

}

this.init_triggers=function()
{
self.init_nav_interaction();
}


this.init_nav_interaction=function()
{
	
	/** uncomment to do dynamic logo change var href = window.location.href;
	var s = href.split("/");
	if(s[3]=="music"){
		$('div#nav.globalNav div#mtvLogo').css("background","url(images/topnav/site_wide2.png) no-repeat 0 -486px #262626"); 
	}*/
	
/* tooltip on logo*/
$('div#mtvLogo a, .navLogoToolTip').mouseover(function() {
$('.navLogoToolTip').show();
}).mouseout(function() {
$('.navLogoToolTip').hide();
});
/* mtvsites nav */
$('.globalNav ul#mtvSitesNav li.topLevel').hover( function() {
$(this).addClass('hover').children('ul').addClass('hover');
}, function() {
$(this).removeClass('hover').children('ul').removeClass('hover');
});

/* global Nav */
$('#navlist li.toplvl').hover( function() {
$(this).addClass('hover').children('ul.gridContainer').addClass('hover');
}, function() {
$(this).removeClass('hover').children('ul.gridContainer').removeClass('hover');
});

/* global Nav grid columns height matching */
$('ul#navlist li.toplvl').each( function(a) {
var maxHeight = 0;
var $columns = $( $('ul#navlist li.toplvl')[a] ).find('ul.gridContainer div.grid ul.gridMain, ul.gridContainer div.grid ul.centerCol');
$columns.each( function(e) {
if( $($columns[e]).height() > maxHeight ) maxHeight = $($columns[e]).height();
});
$columns.height( maxHeight );
});

}

self.init();
}
/* end of top nav js */

function opencontestbox(strurl)
{
  eval('$.fn.colorbox('+strurl+');');
}


