/*
// "AJAX Vote" Plugin for Joomla! 1.0.x - Version 1.0
// License: http://www.gnu.org/copyleft/gpl.html
// Authors: George Chouliaras - Fotis Evangelou - Luca Scarpa
// Copyright (c) 2006 - 2007 JoomlaWorks.gr - http://www.joomlaworks.gr
// Project page at http://www.joomlaworks.gr - Demos at http://demo.joomlaworks.gr
// ***Last update: May 14th, 2007***
*/
var on_rating_icon=false;    

//$('body').bind("mousemove",function (e) {window.status="<span style='background:red;color:white'>".e.pageX."</span>";});

function jwAjaxVote(id,i,total,total_count,rating_type,user_id,user_rating,cookie,cookietime) {	
	on_rating_icon=false;  
	returnnd();
	var id_postfix = '_top';
	if(element_defined('jwajaxvote-star-user-rating'+id+id_postfix))
	{
		var update_postfix_elements=true;
	}
	else
	{
		var update_postfix_elements=false;	
	}
		
	//   display div to stop rating.
	//$('.abc').show();
	var media = 0;
	if(update_postfix_elements)
	{
		var div = document.getElementById('jwajaxvote'+id+id_postfix);
		// var tempInner_postfix=document.getElementById('jwajaxvote'+id+id_postfix).innerHTML;
		var old_innerHTML_postfix=document.getElementById('jwajaxvote-star-user-rating'+id+id_postfix).innerHTML;	
		document.getElementById('one-star' + id +id_postfix).style.display = 'none';
		document.getElementById('two-stars' + id+ id_postfix).style.display = 'none';
		document.getElementById('three-stars'+ id + id_postfix).style.display = 'none';
		document.getElementById('four-stars' + id+ id_postfix).style.display = 'none';
		document.getElementById('five-stars'+ id + id_postfix).style.display = 'none';
		$('#jwajaxvote-star-user-rating'+id+id_postfix).html('<img onmouseover="on_rating_icon=true" onmouseout="on_rating_icon=false;" src="'+live_site+'/mambots/mbox/mbox_plugin/images/loading.gif" border="0" style="width:110px; height:18px; border:none; padding-top:1px" />');
	}
	var div = document.getElementById('jwajaxvote'+id);
	//var tempInner=document.getElementById('jwajaxvote'+id).innerHTML;
	if(element_defined('jwajaxvote-star-user-rating'+id))
		var old_innerHTML=document.getElementById('jwajaxvote-star-user-rating'+id).innerHTML;	
	document.getElementById('one-star' + id ).style.display = 'none';
	document.getElementById('two-stars' + id ).style.display = 'none';
	document.getElementById('three-stars'+ id ).style.display = 'none';
	document.getElementById('four-stars' + id ).style.display = 'none';
	document.getElementById('five-stars'+ id ).style.display = 'none';
	$('#jwajaxvote-star-user-rating' + id ).html('<img onmouseover="on_rating_icon=true" onmouseout="on_rating_icon=false;return nd();" src="'+live_site+'/mambots/mbox/mbox_plugin/images/loading.gif" border="0" style="width:110px; height:18px; border:none; padding-top:1px" />');
		
	
	$.ajax({
		   type: "GET",
		   url:  live_site+"/mambots/mbox/mbox_plugin/ajax.php",
		   data: "task=vote&user_rating="+i+"&cid="+id+"&rating_type="+rating_type+"&user_id="+user_id+"&prev_rating="+user_rating,
		   success: function(response){
				try{
				
				var percentage;
				var newtotal_count;
				var newtotal;
			
				if(response==1) {//if user is rating for first time
					newtotal_count = total_count+1;
					newtotal = total + i;
					percentage = (((total - user_rating + i)/newtotal_count)*20);
					
					// hide div for enabling rating...
					//$('.abc').hide();
				} else if (response==2) {//if user is updating his own rating.
					newtotal_count = total_count;
					newtotal = total - user_rating + i;
					percentage = ((total - user_rating + i)/total_count)*20;
					// hide div for enabling rating...
					//$('.abc').hide();
				} else {
				}
								
				if(!!(window.attachEvent && !window.opera))
				{
					if(update_postfix_elements)
					{
						document.getElementById('jwajaxvote-star-user-rating'+id+id_postfix).innerHTML=old_innerHTML_postfix;
					}
					document.getElementById('jwajaxvote-star-user-rating'+id).innerHTML=old_innerHTML;
					var user_percentage = i*20;
					if(typeof(percentage) == "undefined")
					{
						percentage=user_percentage;
					}
					if(update_postfix_elements)
					{
					
						document.getElementById('user_rating'+id+id_postfix).style.width=user_percentage+ '%';
						document.getElementById('user_rating'+id+id_postfix).style.display='block';
						document.getElementById('rating'+id+id_postfix).style.width=percentage + '%';
						document.getElementById('rating'+id+id_postfix).style.display='block';
					}
					document.getElementById('user_rating'+id).style.width=user_percentage+ '%';
					document.getElementById('user_rating'+id).style.display='block';
					document.getElementById('rating'+id).style.width=percentage + '%';
					document.getElementById('rating'+id).style.display='block';
				}
				else 
				{
					var user_percentage = i*20;
					if(typeof(percentage) == "undefined")
					{
						percentage=user_percentage;
					}
					document.getElementById('jwajaxvote-star-user-rating'+id).innerHTML=old_innerHTML;
					document.getElementById('user_rating'+id).style.width=user_percentage+'%';
					document.getElementById('user_rating'+id).style.display='block';
					document.getElementById('rating'+id).style.display='block';
					document.getElementById('rating'+id).style.width=percentage+'%';
					if(update_postfix_elements)
					{
						document.getElementById('jwajaxvote-star-user-rating'+id+id_postfix).innerHTML=old_innerHTML_postfix;
						document.getElementById('user_rating'+id+id_postfix).style.width=user_percentage+'%';
						document.getElementById('user_rating'+id+id_postfix).style.display='block';
						document.getElementById('rating'+id+id_postfix).style.display='block';
						document.getElementById('rating'+id+id_postfix).style.width=percentage+'%';
					}
				}
				if(update_postfix_elements)
				{
					document.getElementById('one-star'+id+id_postfix).href ='javascript:jwAjaxVote('+id+',1,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('two-stars'+id+id_postfix).href = 'javascript:jwAjaxVote('+id+',2,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('three-stars'+id+id_postfix).href = 'javascript:jwAjaxVote('+id+',3,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('four-stars'+id+id_postfix).href = 'javascript:jwAjaxVote('+id+',4,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('five-stars'+id+id_postfix).href = 'javascript:jwAjaxVote('+id+',5,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';				
					$('#one-star'+id+id_postfix).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
					
					$('#two-stars'+id+id_postfix).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
					
					$('#three-stars'+id+id_postfix).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
					
					$('#four-stars'+id+id_postfix).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
					
					$('#five-stars'+id+id_postfix).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
				}
				
					document.getElementById('one-star'+id).href ='javascript:jwAjaxVote('+id+',1,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('two-stars'+id).href = 'javascript:jwAjaxVote('+id+',2,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('three-stars'+id).href = 'javascript:jwAjaxVote('+id+',3,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('four-stars'+id).href = 'javascript:jwAjaxVote('+id+',4,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
					document.getElementById('five-stars'+id).href = 'javascript:jwAjaxVote('+id+',5,'+newtotal+','+newtotal_count+',\''+rating_type+'\','+user_id+','+i+')';
				if(update_postfix_elements)
				{
					document.getElementById('one-star'+ id +id_postfix).style.display = "";
					document.getElementById('two-stars'+ id +id_postfix).style.display = "";
					document.getElementById('three-stars'+ id +id_postfix).style.display = "";
					document.getElementById('four-stars'+ id +id_postfix).style.display = "";
					document.getElementById('five-stars'+ id +id_postfix).style.display = "";
					document.getElementById('jwajaxvote'+id+id_postfix).innerHTML = '';
				}
				document.getElementById('one-star'+id).style.display = "";
				document.getElementById('two-stars'+id).style.display = "";
				document.getElementById('three-stars'+id).style.display = "";
				document.getElementById('four-stars'+id).style.display = "";
				document.getElementById('five-stars'+id).style.display = "";
				document.getElementById('jwajaxvote'+id).innerHTML = '';

			   $('#one-star'+id).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
			   
			   $('#two-stars'+id).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
			   
			   $('#three-stars'+id).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
			   
			   $('#four-stars'+id).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
			   
			   $('#five-stars'+id).unbind('mouseover').bind("mouseover",function () {getOverlibText(i)});
			   	
				/*if(on_rating_icon)
					getOverlibText(i);
				else
					return nd();*/
				}catch(ex)
				{
					alert(ex.message);
				}

			}
  	});	  	

}

function getOverlibText(userrating)
{
	if(readCookie("language"))					
		lang=readCookie("language");
	else
		lang="en-GB";
	if(lang=="en-GB")
	{
		myrating="My Rating";
		outof="out of";
	}
	else
	{
		myrating="بلدي التصنيف";
		outof="بعيدا عن";
	}
	return overlib( "<span style='font-size:12px !important;'>" + userrating + ' '+outof+' 5</span>',CAPTION,myrating);
}

function returnnd()
{
	return nd();	
}

