// mimicks li:hover for IE, which doesn't support it
var hoverDebug = Array();
sfHover = function() {
	try
	{

		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
	catch(err)
	{
		hoverDebug[0] = err;
	}
}
//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";
		}
	}
}

function popupClose(a){
	var popup = a.parentNode.parentNode;
	var popupClass = popup.className;
	popup.className = popupClass.substring(0, popupClass.indexOf(" open"));
}

// 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();};
}

// search 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';}
		}
	};

// add event onload
addEventToObject(window,'onload',Searchbox.init);
