if (typeof baseurl== 'undefined') {

	baseurl=".";

}

var voteurl = "http://www.musicmaza.com/onvote.php";

var ma = new Array(); // message array



if (typeof mode != 'undefined' && mode == 1) {

	var min = 99999999;

	var imgBeg = baseurl+"/tstar";

	var imgEnd = ".gif";

	var imgBego = baseurl+"/tstar";

	var imgEndo = ".gif";

	ma[-2] = 'You already voted!';

	ma[-1] = '';

	ma[0] = '';

	ma[1] = '';

	ma[2] = '';

	ma[3] = '';

	ma[4] = '';

	ma[5] = '';

} else {

	mode = 0;

	var min = 0;

	var imgBeg = "/images/star";

	var imgEnd = ".gif";

	var imgBego = "/images/star";

	var imgEndo = ".gif";

	ma[-2] = 'You already voted!';

	ma[-1] = '';

	ma[0] = '';

	ma[1] = '';

	ma[2] = '';

	ma[3] = '';

	ma[4] = 'Pretty good';

	ma[5] = 'Excellent!';

}



var da = new Array(); // old array

var va = new Array(); // vote array



var votes = getCookie("votes");

if(votes != null) {

	var temp = votes.split(".");

	for(i = 0; i < temp.length; i++) {

		va[temp[i]] = -1;

	}

}



// check browser versions

var ie4 = (document.all) ? true : false;

var ns4 = (document.layers) ? true : false;

var ns6 = (document.getElementById && !document.all) ? true : false;



// preload the images

var ia = new Array(); // item array

if (document.images) { // let's precache the images

	for(i = 0; i <= 5; i++) {

		ia[i] = new Image();

		ia[i].src = imgBeg + i + imgEnd;

	}

	for(i = 6; i <= 10; i++) {

		ia[i] = new Image();

		ia[i].src = imgBego + (i-5) + imgEndo;

	}

}



function imgOn(imgName, imgNum) {

	if (!va[imgName]) {

		count = 0;

		if (document.images) {

			for(i in document.images) { if (i == imgName) document.images[count-1].src = ia[imgNum].src; count++; }

			document[imgName].src = ia[imgNum].src;



			

		}

		//ts(imgName + 't', ma[imgNum]);

	}

}



function imgOff(imgName) {

	if (!va[imgName]) {

		count = 0;

		if (document.images) {

			for(i in document.images) { if (i == imgName) document.images[count-1].src = ia[da[imgName]].src; count++; }

			document[imgName].src = ia[da[imgName]].src;

		}

		//ts(imgName + 't', ma[0]);

	}

}



function vote(imgName, val, type1,page) {	

	var id=imgName;

	var rt=val;

	var cat=type1;

	window.location="http://www.musicmaza2.com/onvote.php?cat="+cat+"&itemcat="+id+"&rt="+rt+"&page="+page;

	/*if (!va[imgName]) {

		count = 0;

		if (document.images) {

			for(i in document.images) { if (i == imgName) document.images[count-1].src = ia[val+5].src; count++; }

			//document[imgName].src = ia[val+5].src;

		}

		ts(imgName + 't', ma[-1] + '<img src="' + voteurl + '?id=' + imgName + '&rate=' + val + '&type=' + type1 + '" width="1" height="1">');

		myUC(imgName);

		va[imgName] = -1;

	}*/	

}



function ts(where,txt) { // text swap

	if (ie4) {

		document.all[where].innerHTML = txt;

	}

	if (ns4) {

		document[where].document.write(txt);

		document[where].document.close();

	}

	if (ns6) {

		over = document.getElementById([where]);

		range = document.createRange();

		range.setStartBefore(over);

		domfrag = range.createContextualFragment(txt);

		while (over.hasChildNodes()) {

			over.removeChild(over.lastChild);

		}

		over.appendChild(domfrag);

	}	

}



function ms(what, type1, initial,page) { // make selector

	var argv = ms.arguments;

	var argc = ms.arguments.length;

	var avg = (argc > 3) ? argv[3] : null;

	var num = (argc > 4) ? argv[4] : null;

	var who = (argc > 5) ? argv[5] : null;

	// unfortunately the only method compatable with all browsers

	da[what] = initial;

	if (!va[what]) {

		document.write('<map name="i' + what + '">');

		if (mode == 0) {

			document.write('<area shape=rect coords="0,0,22,17" title="give it up!" href="#" alt="give it up!" onMouseOver="imgOn(\'' + what + '\', 1)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 1, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="16,0,42,17" title="needs work!" href="#" alt="needs work!" onMouseOver="imgOn(\'' + what + '\', 2)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 2, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="30,0,65,17" title="better than average" href="#" alt="better than average" onMouseOver="imgOn(\'' + what + '\', 3)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 3, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="45,0,95,17" title="pretty good!" href="#" alt="pretty good!" onMouseOver="imgOn(\'' + what + '\', 4)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 4, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="63,0,110,17" title="superstar!!!" href="#" alt="superstar!!!" onMouseOver="imgOn(\'' + what + '\', 5)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 5, \'' + type1 + '\', \'' + page + '\'); return false">');

		} else {

			document.write('<area shape=rect coords="0,0,12,15" title="give it up!" href="#" alt="give it up!" onMouseOver="imgOn(\'' + what + '\', 1)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 1, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="11,0,24,15" title="needs work!" href="#" alt="needs work!" onMouseOver="imgOn(\'' + what + '\', 2)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 2, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="23,0,34,15" title="better than average" href="#" alt="better than average" onMouseOver="imgOn(\'' + what + '\', 3)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 3, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="33,0,47,15" title="pretty good!" href="#" alt="pretty good!" onMouseOver="imgOn(\'' + what + '\', 4)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 4, \'' + type1 + '\', \'' + page + '\'); return false">');

			document.write('<area shape=rect coords="46,0,59,15" title="superstar!!!" href="#" alt="superstar!!!" onMouseOver="imgOn(\'' + what + '\', 5)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 5, \'' + type1 + '\', \'' + page + '\'); return false">');



		}

		document.write('</map>');

		document.write('<img src="' + imgBeg + initial + imgEnd + '" ');

	} else {

		document.write('<img src="' + imgBego + initial + imgEndo + '" ');

	}

	document.write('border=0 name="' + what + '"' + (va[what] ? ' alt="' + ma[-2] + '"' : ' ismap usemap="#i' + what) + '">');

	document.write(va[what] ? '<span id="' + what + 't">' + ma[-1] + '</span>' : 

			'<span id="' + what + 't">' + ma[0] + '</span>');

	//if ((avg || num && num > min) || who) document.write('<div class=content id="' + what + 'd"><b>');

	//if (avg && num > min) document.write("Avg: " + fn(avg,2) + " ");

	//if (num && num > min) document.write("Votes: " + fn(num,0) + " ");

	//if (who) document.write("Submitted by: " + who + " ");

	document.write("</b></div>");

	document.close();

}



function fn(what,round) { // format number -- add commas and round number

	var f = what, s = 0;

	if (round == 0) what = f = Math.round(what);

	else {

		what = "" + Math.round(100*what); 

		var dp = what.length - round;

		f = Math.round(what.substring(0, dp));

		s = what.substring(dp, what.length);

	}

	f = f.toString();

	var cycles = Math.floor(f.length/3);

	for (var i = 0; i < cycles; i++)

		f = f.substring(0,f.length-(4*i+3))+','+

			f.substring(f.length-(4*i+3));



	return f + (round == 0 ? "" : "." + s);

}



function myUC(what) {

	if (!va[what]) {

		if (votes != null && votes != '')

			votes = what + "." + votes;

		else

			votes = what;

		votes = votes.substr(0,4000);

		var expdate = new Date();

		// keep the cookie for one year -- WE TRACK WHAT YOU VOTED FOR ONLY

		// TO MAKE IT MORE DIFFICULT TO VOTE MULTIPLE TIMES. THAT'S ALL! :)

		expdate.setTime(expdate.getTime() + (365 * 24 * 60 * 60 * 1000));

		setCookie("votes", votes, expdate, "/");

		va[what] = -1;

	}

}



function setCookie(name, value) {

	var argv = setCookie.arguments;

	var argc = setCookie.arguments.length;

	var expires = (argc > 2) ? argv[2] : null;

	var path = (argc > 3) ? argv[3] : null;

	var domain = (argc > 4) ? argv[4] : null;

	var secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +

		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

		((path == null) ? "" : ("; path=" + path)) +

		((domain == null) ? "" : ("; domain=" + domain)) +

		((secure == true) ? "; secure" : "");

}



function getCookieVal(offset) {

	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1) endstr = document.cookie.length;

	return unescape (document.cookie.substring(offset, endstr));

}



function getCookie(name) {

	var arg = name+"=";

	var alen = arg.length;

	var clen = document.cookie.length;

	var i = 0;

	while (i < clen) {

		var j = i + alen;

		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break;

	}

	return null;

}




