/*
+----------------------------------------------------------------+
|																							|
|	WordPress 2.0 Plugin: WP-PostRatings 1.05								|
|	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(ratings_ajax_url);
var post_id = 0;
var post_rating = 0;
var is_ie = (document.all && document.getElementById);
var is_moz = (!document.all && document.getElementById);
var is_opera = (navigator.userAgent.indexOf("Opera") > -1);
var is_being_rated = false;


// When User Mouse Over Ratings
function current_rating(id, rating, rating_text) {
	if(!is_being_rated) {
		post_id = id;
		post_rating = rating;
		for(i = 1; i <= rating; i++) {
			document.images['rating_' + post_id + '_' + i].src = eval("ratings_mouseover_image.src");
		}
	}
}


// When User Mouse Out Ratings
function ratings_off(rating_score, insert_half) {
	if(!is_being_rated) {
		for(i = 1; i <= ratings_max; i++) {
			if(i <= rating_score) {
				document.images['rating_' + post_id + '_' + i].src = site_url + '/design/img/' + ratings_image + '1.gif';
			} else if(i == insert_half) {
				document.images['rating_' + post_id + '_' + i].src = site_url + '/design/img/' + ratings_image + '2.gif';
			} else {
				document.images['rating_' + post_id + '_' + i].src = site_url + '/design/img/' + ratings_image + '3.gif';
			}
		}
	}
}

// Post Ratings Fade In Text
function rade_fadein_text() {
	splits = ratings.response.split("x");
	if (document.getElementById('post-ratings-' + post_id + '_rates'))
	{
		document.getElementById('post-ratings-' + post_id + '_rates').innerHTML = splits[0];
	}
	if (document.getElementById('post-ratings-' + post_id + '_votes'))
	{
		document.getElementById('post-ratings-' + post_id + '_votes').innerHTML = splits[1];
	}
}

// Process Post Ratings
function rate_post() {
	if(!is_being_rated) {
		is_being_rated = true;
		rate_process();
	} else {
		alert(ratings_text_wait);
	}
}

// Process Post Ratings
function rate_process() {
	ratings.setVar("pid", post_id);
	ratings.setVar("rate", post_rating);
	ratings.method = 'GET';
	ratings.element = 'post-ratings-' + post_id;
	ratings.onCompletion = rade_fadein_text;
	ratings.runAJAX();
}