Current File : /home/aventura/public_html/js/countdown.js
function JBCountDown(settings) {
    var glob = settings;
   
    function deg(deg) {
			return (Math.PI/180)*deg - (Math.PI/180)*90
    }
   // Convertir el ahora en unix
		var d = new Date();
		//alert(d);
		var control=d.getDate()-2;
		var positivo = -(control);
		//alert(positivo);
		if (positivo>2)
		{
					//alert( d.getDate());
			var curr_date = d.getDate()-2;
		}else{
			//alert("aca tiene que entrar");
			var curr_date = d.getDate();
		}//alert(curr_date);
		var curr_month = d.getMonth() + 1; //Months are zero based
		//alert(curr_month);
		if (curr_date<10){curr_date="0"+ curr_date}
		if (curr_month<10){curr_month="0"+ curr_month}
		var curr_year = d.getFullYear();		
		var dateString = curr_year + "-" + curr_month + "-" + curr_date + " 23:59:59";
		dateString = dateString.split(' ').join('T');
		var date2 = new Date(dateString);
		//alert(date2);
		var ahora = date2.getTime() / 1000;
		

//
    glob.total   = Math.floor((glob.endDate - glob.startDate)/86400);
    glob.days    = Math.floor((glob.endDate - ahora ) / 86400);
    glob.hours   = 24 - Math.floor(((glob.endDate -  ahora) % 86400) / 3600);
    glob.minutes = 60 - Math.floor((((glob.endDate -  ahora) % 86400) % 3600) / 60) ;
    glob.seconds = 60 - Math.floor((glob.endDate -  ahora) % 86400 % 3600 % 60);
	//glob.seconds = 60 - Math.floor((glob.endDate -  ahora) % 86400 % 3600 % 60);
    
    if (ahora >= glob.endDate) {
        return;
    }
    
    var clock = {
        set: {
            days: function(){
                var cdays = $("#canvas_days").get(0);
                var ctx = cdays.getContext("2d");
                ctx.clearRect(0, 0, cdays.width, cdays.height);
                ctx.beginPath();
                ctx.strokeStyle = glob.daysColor;
                
                ctx.shadowBlur    = 10;
                ctx.shadowOffsetX = 0;
                ctx.shadowOffsetY = 0;
                ctx.shadowColor = glob.daysGlow;
                
                ctx.arc(35,40,30,  deg(0), deg((360/glob.total)*(glob.total - glob.days)));
                ctx.lineWidth = 9;
                ctx.stroke();
                $(".clock_days .val").text(glob.days);
            },
            
            hours: function(){
                var cHr = $("#canvas_hours").get(0);
                var ctx = cHr.getContext("2d");
                ctx.clearRect(0, 0, cHr.width, cHr.height);
                ctx.beginPath();
                ctx.strokeStyle = glob.hoursColor;
                
                ctx.shadowBlur    = 10;
                ctx.shadowOffsetX = 0;
                ctx.shadowOffsetY = 0;
                ctx.shadowColor = glob.hoursGlow;
                
                 ctx.arc(35,40,30,  deg(0), deg(15*glob.hours));
                ctx.lineWidth = 9;
                ctx.stroke();
                $(".clock_hours .val").text(24 - glob.hours);
            },
            
            minutes : function(){
                var cMin = $("#canvas_minutes").get(0);
                var ctx = cMin.getContext("2d");
                ctx.clearRect(0, 0, cMin.width, cMin.height);
                ctx.beginPath();
                ctx.strokeStyle = glob.minutesColor;
                
                ctx.shadowBlur    = 10;
                ctx.shadowOffsetX = 0;
                ctx.shadowOffsetY = 0;
                ctx.shadowColor = glob.minutesGlow;
                
                 ctx.arc(35,40,30,  deg(0), deg(6*glob.minutes));
                ctx.lineWidth = 9;
                ctx.stroke();
                $(".clock_minutes .val").text(60 - glob.minutes);
            },
            seconds: function(){
                var cSec = $("#canvas_seconds").get(0);
                var ctx = cSec.getContext("2d");
	            
                ctx.clearRect(0, 0, cSec.width, cSec.height);
                ctx.beginPath();
                ctx.strokeStyle = glob.secondsColor;
                
                ctx.shadowBlur    = 10;
                ctx.shadowOffsetX = 0;
                ctx.shadowOffsetY = 0;
                ctx.shadowColor = glob.secondsGlow;
                
                ctx.arc(35,40,30, deg(0), deg(6*glob.seconds));
                ctx.lineWidth = 9;
                ctx.stroke();
        
                $(".clock_seconds .val").text(60 - glob.seconds);
            }
        },
       
        start: function(){
            /* Seconds */
            var cdown = setInterval(function(){
                if ( glob.seconds > 59 ) {
                    if (60 - glob.minutes == 0 && 24 - glob.hours == 0 && glob.days == 0) {
                      // clearInterval(cdown);
                        
                        /* Countdown is complete */
                        
                        return;
                    }
                    glob.seconds = 1;
                    if (glob.minutes > 59) {
                        glob.minutes = 1;
                        clock.set.minutes();
                        if (glob.hours > 23) {
                            glob.hours = 1;
                            if (glob.days > 0) {
                                glob.days--;
                                clock.set.days();
                            }
                        } else {
                            glob.hours++;
                        }
                        clock.set.hours();
                    } else {
                        glob.minutes++;
                    }
                    clock.set.minutes();
                } else {
                    glob.seconds++;
                }
                clock.set.seconds();
            },1000);
        }
    }
    clock.set.seconds();
    clock.set.minutes();
    clock.set.hours();
    clock.set.days();
    clock.start();
}