GNav = {
		
		getPosition : function(e){
			//TPOINT('getPosition');
			var left = 0;
			var top  = 0;
		
			while (e.offsetParent){
				left += e.offsetLeft;
				top  += e.offsetTop;
				e     = e.offsetParent; 
			}
		
			left += e.offsetLeft;
			top  += e.offsetTop;
		
			return {x:left, y:top};
		},
		
		
		report : function(aObj){
		
			// aObj is the link obj
			var linkurl = aObj.href;
			var linkname = aObj.name;
			var strReport = '';
			strReport = "GlobalNav : " + linkname + " : " + linkurl;
			// getting error on blog
			// test for the reporting function before calling
			if(typeof(sendLinkCall)=='function')
				sendLinkCall(strReport);
		
		},
		
		init : function() {
			this.findMatch(this.path);
	
		} // END init function
		
	
		
	}; // end GNav Object





// mimicks li:hover for IE, which doesn't support it
var hoverDebug = Array();
sfHover = function() {
	//System.out.println('sfHover');
	try{
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				//System.out.println('mouseover');
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				//System.out.println('mouseout');
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	catch(e){
		hoverDebug[0] = e;
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

// for thumbnail view toggling
function vidExpand() {
	if(document.getElementById && document.createTextNode) {
		if(document.getElementById('vidclips')) {
			document.getElementById('vidclips').className='full';
			document.getElementById('linkExpand').className='hide';
			document.getElementById('linkCollapse').className='';
			document.getElementById('vid-toggle-bottom').className='vid-toggle';
			if (typeof tooltip.deactivate == "function") tooltip.deactivate(document.getElementById("vidclips"));
		}
	}
}

function vidCollapse() {
	if(document.getElementById && document.createTextNode) {
		if(document.getElementById('vidclips')) {
			document.getElementById('vidclips').className='simple';
			document.getElementById('linkCollapse').className='hide';
			document.getElementById('linkExpand').className='';
			document.getElementById('vid-toggle-bottom').className='hide';
			if (typeof tooltip.activate == "function") tooltip.activate(document.getElementById("vidclips"));
		}
	}
}


// for popups
function popupOpen(a){
	// close all popups first - so two cant be open at the same time
	var all = a.parentNode.parentNode.getElementsByTagName("div");
	for (var i=0; i<all.length; i++){
		if (all[i].className.indexOf(" open") > 0){
			all[i].className = all[i].className.substring(0, all[i].className.indexOf(" open"));
		}
	}
	
	var siblingDivs = a.parentNode.getElementsByTagName("div");
	for (var i=0; i<siblingDivs.length; i++){
		if (siblingDivs[i].className == "popup"){
			siblingDivs[i].className = siblingDivs[i].className + " open";
		}
	}
	//arcade iframe hazzard
	if (document.getElementById("game")) document.getElementById("game").className = document.getElementById("game").className + " hide";
}

function popupClose(a){
	var popup = a.parentNode.parentNode;
	var popupClass = popup.className;
	popup.className = popupClass.substring(0, popupClass.indexOf(" open"));
	//arcade iframe hazzard
	if (document.getElementById("game")) document.getElementById("game").className = document.getElementById("game").className.substring(0, document.getElementById("game").className.indexOf('hide'));
}

// for sidebar nav
function toggleSn(snid){
	if(document.getElementById(snid).className == 'active'){
		document.getElementById(snid).className = '';
	} else{
		document.getElementById(snid).className = 'active';
	}
}





// default search text

// event handler
function addEventToObject(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}

// lyrics box stuff
var Searchbox = {
	init : function()
		{
		var sBox = document.getElementById('search-lyrics');
		if (sBox)
			{
			addEventToObject(sBox,'onclick',Searchbox.click);
			addEventToObject(sBox,'onblur',Searchbox.blur);
			}	
		},
	click : function()
		{
		var sBox = document.getElementById('search-lyrics');
		if (sBox.value == 'Enter lyric, artist name or song title')
			{
			sBox.value = '';
			sBox.style.color = 'black';
			}
	  	},
	blur : function()
		{
		var sBox = document.getElementById('search-lyrics');
		if (sBox.value == '' || sBox.value == ' ') {sBox.value = 'Enter lyric, artist name or song title'; sBox.style.color = '#999999';}
		}
	};

// search box stuff
var Searchbar = {
	init : function()
		{
		var sBar = document.getElementById('searchmtv-text');
		if (sBar)
			{
			addEventToObject(sBar,'onclick',Searchbar.click);
			addEventToObject(sBar,'onblur',Searchbar.blur);
			}	
		},
	click : function()
		{
		var sBar = document.getElementById('searchmtv-text');
		if (sBar.value == 'Search all MTV.com')
			{
			sBar.value = '';
			}
	  	},
	blur : function()
		{
		var sBar = document.getElementById('searchmtv-text');
		if (sBar.value == '' || sBar.value == ' ') {sBar.value = 'Search all MTV.com';}
		}
	};

// add event onload
addEventToObject(window,'onload',Searchbox.init);
addEventToObject(window,'onload',Searchbar.init);
