var BvGlobalCounter=function(){};BvGlobalCounter.value=0;function bvGetMouseX(e){var tempX;if(document.all){tempX=e.clientX+document.body.scrollLeft;}else{tempX=e.pageX;}if(tempX<0){tempX=0;}return tempX;}







function BvRatingBar(ratedItem){ 



	var _prepend=ratedItem;



	var _BGWidth=15;



	var _BGHeight=14;



	var _specificity=1;



	var _maxRating=5;



	var _minRating=1;



	var _ratingType=lang_txt['stars'];



	var _ratingTypeSingular=lang_txt['star'];



	var _sparkleImage=baseURL+"catalog/template/beststoreitems/image/sparkle.gif?47903";



	var _rating;



	var _displayItemOverride="score_title";



	var _inputItemOverride="product_score";



	var _isMouseDown=false;



	var _hasValueSet=false;



	this.initializeValue=function(givenValue){



		_hasValueSet=true;



		var ratingValue=(Math.ceil(givenValue/_specificity)*100*_specificity)/100;



		if(ratingValue>_maxRating){ratingValue=_maxRating;}else if(ratingValue<_minRating){ratingValue=_minRating;}



		_rating=ratingValue;



		var tableWidth=ratingValue*_BGWidth;



		window.$("#"+ratedItem+"Filled").css({width:tableWidth});



		if(_inputItemOverride){var inputItemOverrideElement=$("#"+_inputItemOverride)[0];



		if(inputItemOverrideElement){inputItemOverrideElement.value=_rating;}}	



		if(_displayItemOverride){



			if($("#"+_displayItemOverride)[0]){



				if(_rating==1){



					if('ja' == langs){						



						$("#"+_displayItemOverride).html("星"+_rating+"つ");



					}else{						



					$("#"+_displayItemOverride).html(_rating+" "+_ratingTypeSingular);



					}



				}else{



					if('ja' == langs){



						$("#"+_displayItemOverride).html("星"+_rating+"つ");



					}else{



					$("#"+_displayItemOverride).html(_rating+" "+_ratingType);



				}



			}



		}



		}		



	};



	this.resizeTable=function(event,table){



		var ratingBarElement=$("#"+_prepend+'RatingBar')[0];



		var tableWidth=ratingBarElement.style.width;



		var scaleAmt=bvGetMouseX(event)-$(ratingBarElement).offset().left;



		var ratingValue=(Math.ceil(scaleAmt/_BGWidth/_specificity)*100*_specificity)/100;



		if(ratingValue>_maxRating){ratingValue=_maxRating;}else if(ratingValue<_minRating){ratingValue=_minRating;}



		tableWidth=ratingValue*_BGWidth;



		if(tableWidth<1){tableWidth=1;}



		$("#"+table).css({width:tableWidth});



		_rating=ratingValue;



	};



	this.setRating=function(event){



		this.updateRating(event,_prepend+'Filled');



		_hasValueSet=true;



	};



	this.updateRating=function(event,table,ignoreInput){	



		this.resizeTable(event,table);



		if(!ignoreInput){



			if(_inputItemOverride){



				var inputItemOverrideElement=$("#"+_inputItemOverride)[0];



				if(inputItemOverrideElement){



					inputItemOverrideElement.value=_rating;



				}



			}



		}



		if(_displayItemOverride){



			var displayItemOverrideElement=$("#"+_displayItemOverride)[0];



			if(displayItemOverrideElement){



				if('ja' == langs){					



					displayItemOverrideElement.innerHTML="星"+_rating+"つ";



				}else{



				if(_rating==1){



					//displayItemOverrideElement.innerHTML=_rating+" "+_ratingTypeSingular;



					displayItemOverrideElement.innerHTML=_rating+" "+_ratingType+" "+"<input type='hidden' name='rating' value='"+_rating+"'>";



				}else{					



					//displayItemOverrideElement.innerHTML=_rating+" "+_ratingType;							



					displayItemOverrideElement.innerHTML=_rating+" "+_ratingType+" "+"<input type='hidden' name='rating' value='"+_rating+"'>";



				}



			}



		}



		}



	};



	this.startSlide=function(){_isMouseDown=true;};



	this.stopSlide=function(){



		if(_isMouseDown){



			var backgroundPath=_sparkleImage+'?i='+BvGlobalCounter.value++;



			$("#"+_prepend+'Filled').css({background:"url("+backgroundPath+")"});



			_isMouseDown=false;



		}



	};



	this.doSlide=function(event){



		if(_isMouseDown){



			this.updateRating(event,_prepend+"Filled");



			_hasValueSet=true;



		}else if(!_hasValueSet){



			this.updateRating(event,_prepend+"Hover",true);



		}



	};



	this.resetHover=function(){



		



		$("#"+_prepend+"Hover").css({width:1});



		if(!_hasValueSet){



			if(_displayItemOverride){



				var displayItemOverrideElement=$("#"+_displayItemOverride)[0];



				if(displayItemOverrideElement){



					displayItemOverrideElement.innerHTML="";



				}



			}



		}



	}



}