var CentsCounter = CentsCounter != null ? CentsCounter:
{
	initVal:null,
	crtValue:null,
	cookieName:"roseCentsCounter",
	domElement:null,
	counterCreated:false,
	increment:40,
	
	init:function(initValue,domElemName)	{
		if(this.counterCreated) return;
		this.crtValue = parseInt(this.readCookie(this.cookieName));
		if(!this.crtValue){		
			this.createCookie(this.cookieName,initValue,60); //for 60 seconds; store the crt value of the coutner				
		}
		this.initVal = parseInt(initValue);
		this.crtValue=this.crtValue? this.crtValue : this.initVal;
		this.domElement = document.getElementById(domElemName);				
		if(this.domElement){
			this.domElement.innerHTML = this.getDollars(this.crtValue);
		}
		this.counterCreated = true;	
	},
	next:function(){
		if(this.crtValue===0 || this.crtValue){						
			this.crtValue+=this.increment;			
			this.createCookie(this.cookieName,this.crtValue,60);
			this.domElement.innerHTML = this.getDollars(this.crtValue);
		}
	},
	createCookie:function (name,value,seconds) {
		if (seconds) {
			var date = new Date();
			date.setTime(date.getTime()+(seconds*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	
	readCookie:function (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	eraseCookie:function(name) {
		createCookie(name,"",-1);
	},
	getDollars:function(cents){
		var c = cents%100;
		var dollars = Math.floor(cents/100);
		//return dollars+"."+c;
		var dollars = dollars+"";
		var result = "";
		for(var i=dollars.length-1,c=0; i >= 0; i--,c++){
			result =  dollars.charAt(i)+( c%3 == 0 && c != 0 ? "," : "" )+result; 
		}
		return result;
	},
	stop:function(){
		clearInterval(counterInterval);
	}
			
};



var counterInterval = null;
$(document).ready(function() {
	if(roseCounterValue===0  || roseCounterValue){
		CentsCounter.init(roseCounterValue,"roseCentCounterText");
		counterInterval = setInterval("CentsCounter.next()",1000);	
	} 
});	




