var TopCounter=Class.create({
    initialize:function(top_date, top_id){
        this.start_date=new Date();
        tmp=$w(top_date.gsub('-',' '));
        year=tmp[0];
        month=tmp[1]-1;
        day=tmp[2];
        
        this.start_date.setFullYear(year,month, day);
        
        
        this.top_id=$(top_id);
        this.top_days=this.top_id.down('.days');
        this.top_hours=this.top_id.down('.hours');
        this.top_minutes=this.top_id.down('.minutes');
        this.top_seconds=this.top_id.down('.seconds');
        this.top_counter=null;
        
        this.start_counting();
        this.top_counter=new PeriodicalExecuter(this.start_counting.bind(this),1);
        
    },
    
    start_counting:function(){
        try{
            today_date=new Date();
            //alert(this.start_date);
            
            diff=Date.parse(this.start_date)-Date.parse(today_date);
            
            days=Math.floor(diff/(60*60*1000*24)*1);
            hours=Math.floor((diff%(60*60*1000*24))/(60*60*1000)*1);
            minutes=Math.floor(((diff%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
            seconds=Math.floor((((diff%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
            
            this.top_days.update(days);
            this.top_hours.update(hours);
            this.top_minutes.update(minutes);
            this.top_seconds.update(seconds);
            //alert(days+':'+hours+':'+minutes+':'+seconds)
           
        }
        catch(e){
            alert(e);
            
        }
    }
    
});

