if (typeof baseurl== 'undefined') {
	baseurl=".";
}
var voteurl = baseurl+"/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 = baseurl+"themes/default/media/images/img_rating";
	var imgEnd = ".gif";
	var imgBego = baseurl+"themes/default/media/images/img_rating";
	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=page + '&rate=' + rt;
}

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 style="padding:0px;margin:0px;float:left;" name="i' + what + '">');
		if (mode == 0) {
			document.write('<area shape=rect coords="0,0,12,17" href="#" alt="1" onMouseOver="imgOn(\'' + what + '\', 1)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 1, \'' + type1 + '\', \'' + page + '\'); return false">');
			document.write('<area shape=rect coords="16,0,32,17" href="#" alt="2" onMouseOver="imgOn(\'' + what + '\', 2)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 2, \'' + type1 + '\', \'' + page + '\'); return false">');
			document.write('<area shape=rect coords="30,0,45,17" href="#" alt="3" onMouseOver="imgOn(\'' + what + '\', 3)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 3, \'' + type1 + '\', \'' + page + '\'); return false">');
			document.write('<area shape=rect coords="45,0,61,17" href="#" alt="4" onMouseOver="imgOn(\'' + what + '\', 4)" onMouseOut="imgOff(\'' + what + '\')" onClick="vote(\'' + what + '\', 4, \'' + type1 + '\', \'' + page + '\'); return false">');
			document.write('<area shape=rect coords="63,0,80,17" href="#" alt="5" 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" href="#" alt="1" 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" href="#" alt="2" 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" href="#" alt="3" 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" href="#" alt="4" 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" href="#" alt="5" 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('align="absmiddle" border=0 name="' + what + '"' + (va[what] ? ' alt="' + ma[-2] + '"' : ' ismap usemap="#i' + what) + '">');
	document.write("</b>");
	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;
}

