function $(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $T(i,v) { return((typeof(i)=='string'?$(i):(i?i:document)).getElementsByTagName(v)); }
function switchID(w,n) { if($(w)) $(w).id=''; if(n) n.id=w; }
function $S(o) { return((typeof(o)=='object'?o:$(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }
function createRequestObject() { var request_o; var browser = navigator.appName; if (browser == "Microsoft Internet Explorer") { request_o = new ActiveXObject("Microsoft.XMLHTTP"); }  else { request_o = new XMLHttpRequest(); } return request_o; }
function trim(s) { return(s.replace(/^\s+|\s+$/g, '')); }

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();

/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

var http = createRequestObject();
star={};
var width = 99;
var height = 20;

star.mouse=function(e,o) { if(star.stop || isNaN(star.stop)) { star.stop=0;
	document.onmousemove=function(e) { var n=star.num;
		var p=abPos($('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);
		if(oX<1 || oX>width || oY<0 || oY>height) { star.stop=1; star.revert(); $('starCur'+n).className = 'curr'; }
		else {
			$('starCur'+n).className = 'over';
			$S('starCur'+n).width=(Math.ceil(oX/height)*height)+'px';
			$('starUser'+n).innerHTML=Math.ceil((oX/width*100)/20)*20;
		}
	};
} };


star.update=function(e,o,songid,artist) { var n=star.num, v=parseInt($('starUser'+n).innerHTML);
	n=o.id.substr(4); $('starCur'+n).title=v;
	$('star0').className += ' wait';
	http.open('get', '/inc_vx2/AJAX_Star_Vote.php?vote='+(v/100)+'&songid='+songid+'&artist='+artist);
	http.onreadystatechange = display;
	http.send(null);
};

star.revert=function() { var n=star.num, v=parseInt($('starCur'+n).title);
	$S('starCur'+n).width=Math.round(v*width/100)+'px';
	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
	$('starUser'+n).style.color='#888';
	
	document.onmousemove='';

};

star.num=0;

function display() {
	if (http.readyState == 4) {
	/*	if( http.responseText == 'error-db' ) */
		if(http.responseText && isNaN(http.responseText)) window.alert(http.responseText);
		else if(!isNaN(http.responseText)) updateRateCount(http.responseText);
		$('star0').className = trim($('star0').className.replace('wait',''));
		$('confirm').innerHTML = 'Thanks!';
		$('confirm').className = 'green';
	}
}

function updateRateCount(count) {
	$('ratecount').innerHTML = '[ '+count+' ]';
}
