// JavaScript Document

function init() {
	if (-1 < location.href.indexOf("artist.asp")) showBioTab();
	if (-1 < top.location.href.indexOf("graysoncapps")) top.location.href="http://www.singersongwritermusic.nl/artist.asp?strArtistId=2";
}

// MOUSE POS
function getMousePos(e) {
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}


///////////// COMMENT KUDOS /////////////

// wordt aangeroepen vanuit asp om box te sluiten
function closeKudoDiv() {
	if (document.getElementById("kudoDiv")) {
		varobjBox = document.getElementById("kudoDiv");
		varobjBox.style.visibility = 'visible';
		window.setTimeout("varobjBox.removeNode(this)", 2000);
	}
}

// wordt aangeroepen vanuit asp om visueel direct een punt op te tellen
function addPoint(intComment, intAmount) {
	var elNumber;
	var newValue;
	if (document.getElementById("kudos_comment_" + intComment)) {
		elNumber = document.getElementById("kudos_comment_" + intComment);
		newValue = parseInt(elNumber.innerHTML) +  parseInt(intAmount);
		elNumber.innerHTML = newValue + "";
		if (0 < parseInt(newValue)) {
			elNumber.className = 'kudosPlus';
		} else if (parseInt(newValue) < 0) {
			elNumber.className = 'kudosMin';	
		} else {
			elNumber.className = 'kudosZero';	
		}
	}
}


// wordt aangeroepen vanuit html (onclick) om box te openen met asp-iframe die de kudos afhandelt
function doKudos(intCommentId, intAmount, userip) {
	var errorMsg = "";
	
	getMousePos();
	
	// create html elements
	var kudoDiv = document.createElement("DIV");
	var kudoIframe = document.createElement("IFRAME");
	kudoDiv.className = "kudoDiv";
	kudoDiv.id = "kudoDiv";
	kudoIframe.className = "kudoIframe";
	kudoDiv.Iframe = "kudoIframe";
	kudoIframe.setAttribute("src", "/_asp/doKudo.asp?intCommentId=" + intCommentId + "&intAmount=" + intAmount + "&userip=" + userip + "");
	kudoIframe.setAttribute("width", "100%");
	kudoIframe.setAttribute("height", "80%");
	
	//get Body
	var pageBody
	var arrBody = document.getElementsByTagName("body");
	if (arrBody.length == 1) {
		for(var i=0;i<arrBody.length;i++) {
			if(arrBody[i] && i == 0) {
				pageBody = arrBody[i];
			}
		}
	} else {
		errorMsg = errorMsg + "more or less then 1 body tag \n";	
	}
	
	//check if Div is already created
	if (document.getElementById("kudoDiv")) errorMsg += "kudo box already created";
	
	//append Div & Iframe to body
	if (errorMsg == "") {
		pageBody.appendChild(kudoDiv);
		kudoDiv.appendChild(kudoIframe);
		document.getElementById("kudoDiv").style.top = (posy - 75) + "px";
	} else {
		//alert(errorMsg);
		var strNull = null;
	}
}
/////////////////////////////////////////


///////////// SELECT TABLIST ////////////
function selectTab(selectedHref) {
	var tabToSelect = selectedHref.firstChild.nodeValue;
	var tablist = document.getElementById("tablist");
	var tabs = tablist.getElementsByTagName("li");
	for (var i=0;i<tabs.length;i++) {
		tabs[i].className = "none";	
	}
	selectedHref.parentNode.className = "current";
	if (-1 < tabToSelect.indexOf("Songs")) {
		showSongsTab();	
	} else if (-1 < tabToSelect.indexOf("Bio")) {
		showBioTab();	
	} else if (-1 < tabToSelect.indexOf("Disco")) {
		showDiscoTab();	
	} else if (-1 < tabToSelect.indexOf("Links")) {
		showLinksTab();	
	} else {
		alert("Tab niet gevonden!");	
	}
	window.focus();
}
function showSongsTab() {
	if (document.getElementById("songs")) document.getElementById("songs").style.display = "block";
	if (document.getElementById("bio")) document.getElementById("bio").style.display = "none";
	if (document.getElementById("disco")) document.getElementById("disco").style.display = "none";
	if (document.getElementById("links")) document.getElementById("links").style.display = "none";
}
function showBioTab() {
	if (document.getElementById("songs")) document.getElementById("songs").style.display = "none";
	if (document.getElementById("bio")) document.getElementById("bio").style.display = "block";
	if (document.getElementById("disco")) document.getElementById("disco").style.display = "none";
	if (document.getElementById("links")) document.getElementById("links").style.display = "none";
}
function showDiscoTab() {
	if (document.getElementById("songs")) document.getElementById("songs").style.display = "none";
	if (document.getElementById("bio")) document.getElementById("bio").style.display = "none";
	if (document.getElementById("disco")) document.getElementById("disco").style.display = "block";
	if (document.getElementById("links")) document.getElementById("links").style.display = "none";
}
function showLinksTab() {
	if (document.getElementById("songs")) document.getElementById("songs").style.display = "none";
	if (document.getElementById("bio")) document.getElementById("bio").style.display = "none";
	if (document.getElementById("disco")) document.getElementById("disco").style.display = "none";
	if (document.getElementById("links")) document.getElementById("links").style.display = "block";
}
/////////////////////////////////////////
