function getOffset(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

jQuery(document).ready(function() {

	document.getElementById('ranking').savedWidth=document.getElementById('ranking').offsetWidth;

	document.getElementById('noter').onmouseover=
	document.getElementById('noter').onmousemove=
		function(e) {
			if(e) {
				event=e;
			}
			document.getElementById('ranking').style.display='block';

			var width=event.clientX-getOffset(document.getElementById('ranking'))[0];
			//console.log(width);
			var increment=parseInt(document.getElementById('noter').offsetWidth)/10

			var note=Math.ceil(10*width/parseInt(document.getElementById('noter').offsetWidth));

			width=note*increment+1;

			document.getElementById('ranking').style.width=width+'px';
		};

	document.getElementById('noter').onmouseout=function(event) {
		document.getElementById('ranking').style.width=document.getElementById('ranking').savedWidth;
	};


	document.getElementById('noter').onclick=function(e) {
		if(refreshDynamicBlocks) {
			refreshDynamicBlocks()
		}

		document.getElementById('noter').savedOnmouseout=document.getElementById('noter').onmouseout;
		document.getElementById('noter').onmouseout=function() {return false;}

		var note=Math.ceil(10*
			parseInt(document.getElementById('ranking').offsetWidth)
			/parseInt(document.getElementById('noter').offsetWidth))-1;


		var element=document.getElementById('noter').getAttribute('element');

		noter(note, element);
	}
});


function noter(note, element) {


	document.getElementById('noter').savedEvent=document.getElementById('noter').onclick;


	document.getElementById('noter').onclick=function() {return false};



	var handler=new GC_Ajax(function() {
		if(h.readyState==4) {

			jQuery('#noterConfirmation').show('drop');
			jQuery('#ranking').hide('drop');
			document.getElementById('noter').onmouseout=document.getElementById('noter').savedOnmouseout;

			setTimeout(function() {
				eval('var newNote=' + h.responseText + ';');
				var increment=parseInt(document.getElementById('noter').offsetWidth)/10
				var width=increment*newNote.average;
				document.getElementById('currentNote').style.width=width+1+'px';
				document.getElementById('noterLoader').style.display='none';
				document.getElementById('noter').onclick=document.getElementById('noter').savedEvent;
				document.getElementById('voix').innerHTML = '(' + newNote.number + ' voix)';
				jQuery('#noterConfirmation').hide('drop');
			},2000)

		}
	})

	var h=handler.init();

	handler.addData('note', note);
	handler.addData('element', element);


	document.getElementById('noterLoader').style.display='block';

	handler.sendQuery('http://www.cuisineetvinsdefrance.com/direct/community/noter');



}

