$(document).ready(function() {
	// put all your jQuery goodness in here.
});


function convert_to_time(secs)
{
    
    secs = parseInt(secs);    
    hh = secs / 3600;    
    hh = parseInt(hh);    
    mmt = secs - (hh * 3600);    
    mm = mmt / 60;    
    mm = parseInt(mm);    
    ss = mmt - (mm * 60);    
        
    if (hh > 23)    
    {    
       dd = hh / 24;    
       dd = parseInt(dd);    
       hh = hh - (dd * 24);    
    } else { dd = 0; }    
        
    if (ss < 10) { ss = "0"+ss; }    
    if (mm < 10) { mm = "0"+mm; }    
    if (hh < 10) { hh = "0"+hh; }    
    if (dd == 0) { return (hh+":"+mm+":"+ss); }    
    else {    
        if (dd > 1) { return (dd+" дней "+hh+":"+mm+":"+ss); }
        else { return (dd+" день "+hh+":"+mm+":"+ss); }
    }    
}

function updatedate(pr_id, diff){
    countdown = diff;
    countdown = countdown - 1;
    //alert(countdown);
    if (countdown < 0)    
    {     
         $('#'+pr_id).html("Завершен!");  
         $('#'+pr_id+'_button').css('display', 'none');

    }    
    else    
    {    
        $('#'+pr_id).html(convert_to_time(countdown));   
        setTimeout("updatedate('"+pr_id+"', "+countdown+")", 1000);
    }    
        
}
