/*
+----------------------------------------------------------------+
|																							|
|	WordPress 2.0 Plugin: WP-PostRatings 1.04								|
|	Copyright (c) 2006 Lester "GaMerZ" Chan									|
|																							|
|	File Written By:																	|
|	- Lester "GaMerZ" Chan															|
|	- http://www.lesterchan.net													|
|																							|
|	File Information:																	|
|	- Post Ratings Javascript File													|
|	- wp-content/plugins/postratings/postratings-js.js						|
|																							|
+----------------------------------------------------------------+
*/


// Variables
var ratings = new sack(ajax_url);
var post_id = 0;
var post_rating = 0;
var post_show = 'normal';
var rate_fadein_opacity = 0;
var rate_fadeout_opacity = 100;
var is_ie = (navigator.userAgent.indexOf("Explorer") > -1);
var is_moz = (navigator.userAgent.indexOf("Firefox") > -1);
var is_opera = (navigator.userAgent.indexOf("Opera") > -1);
var is_being_rated = false;


// Post Ratings Fade In Text
function rade_fadein_text() {
	if(rate_fadein_opacity < 100) {
		rate_fadein_opacity += 10;
		if(is_opera)  {
			rate_fadein_opacity = 100;
		} else if(is_ie) {
			document.getElementById('post-ratings-' + post_id).filters.alpha.opacity = rate_fadein_opacity;
		} else if(is_moz) {
			//document.getElementById('post-ratings-' + post_id).style.MozOpacity = (rate_fadein_opacity/100);
			document.getElementById('post-ratings-' + post_id).style.MozOpacity = 1;
			rate_fadein_opacity = 100;
		}
		setTimeout("rade_fadein_text()", 100); 
	} else {
		rate_fadein_opacity = 100;
		rate_unloading_text();
		is_being_rated = false;
	}
}


// When User Mouse Over Ratings
function current_rating(id, rating) {
	if(!is_being_rated) {

		post_id = id;
		post_rating = rating;
		for(i = 1; i <= 5; i++) {
			if (i <= rating)
				document.getElementById('rating_' + post_id + '_' + i).className = 'rate rated';
			else
				document.getElementById('rating_' + post_id + '_' + i).className = 'rate non_rated';
		}
	}
}

// When User Mouse Out Ratings
function ratings_off(rating_score, ratings_max) {
	if(!is_being_rated) {
	 	
		for(i = 1; i <= ratings_max; i++) {
			if(i <= rating_score) {
				document.getElementById('rating_' + post_id + '_' + i).className = 'rate rated';
			} else {
				document.getElementById('rating_' + post_id + '_' + i).className = 'rate non_rated';
			}
		}
	}
}


// Post Ratings Loading Text
function rate_loading_text() {
	document.getElementById('post-ratings-' + post_id + '-loading').style.display = 'none';
}


// Post Ratings Finish Loading Text
function rate_unloading_text() {
	document.getElementById('post-ratings-' + post_id + '-loading').style.display = 'none';
}


// Process Post Ratings
function rate_post(show) {	
	if(!is_being_rated) {
		is_being_rated = true;
		rate_loading_text();
		post_show = show;
		rate_process();		
	} else {		
		alert('Please rate only 1 post at a time.');
	}
}


// Process Post Ratings
function rate_process() {
	if(rate_fadeout_opacity > 0) {
		rate_fadeout_opacity -= 10;
		if(is_opera) {
			rate_fadein_opacity = 0;
		} else if(is_ie) {
			document.getElementById('post-ratings-' + post_id).filters.alpha.opacity = rate_fadeout_opacity;
		} else if(is_moz) {
			document.getElementById('post-ratings-' + post_id).style.MozOpacity = (rate_fadeout_opacity/100);
		}
		setTimeout("rate_process()", 100); 
	} else {
		rate_fadeout_opacity = 0;		
		ratings.setVar("pid", post_id);
		ratings.setVar("rate", post_rating);
		ratings.setVar("show", post_show);
		ratings.method = 'GET';
		ratings.element = 'post-ratings-' + post_id;
		ratings.onCompletion = rade_fadein_text;
		ratings.runAJAX();
		rate_fadein_opacity = 0;
		rate_fadeout_opacity = 100;
	}
}