(function($){ var timeOpt = { 'dateCount' : new Date(), 'start' : parseInt(1432027557.7195), 'elapsed' : 0, 'seconds' : 0, 'minutes' : 0, 'hours' : 0, 'days' : 0, 'timer' : null, 'timerDay' : null, 'timerMinute' : null, 'timerHour' : null, 'timerSecond' : null, 'enddate' : 0 }; var timeCount = { init : function(option){ timeOpt.start = new Date(); //timeOpt.dateCount = new Date(2013, 4, 6, 0, 0, 0); //Trenutno vrijeme koje je proteklo timeOpt.elapsed = timeOpt.dateCount.getTime() - timeOpt.start; timeOpt.elapsed = (timeOpt.elapsed - timeOpt.elapsed % 1000) / 1000; timeOpt.seconds = timeOpt.elapsed % 60; timeOpt.minutes = (( timeOpt.elapsed - timeOpt.seconds ) / 60 ) % 60; timeOpt.hours = (((( timeOpt.elapsed - timeOpt.seconds ) / 60 ) - timeOpt.minutes) / 60 ) % 24; timeOpt.days = ((((( timeOpt.elapsed - timeOpt.seconds ) / 60 ) - timeOpt.minutes) / 60 ) - timeOpt.hours ) / 24; timeCount.get(); }, count : function(){ timeOpt.start = new Date(); timeOpt.elapsed = timeOpt.dateCount.getTime() - timeOpt.start; timeOpt.elapsed = (timeOpt.elapsed - timeOpt.elapsed % 1000) / 1000; timeOpt.seconds = timeOpt.elapsed % 60; timeOpt.minutes = (( timeOpt.elapsed - timeOpt.seconds ) / 60 ) % 60; timeOpt.hours = (((( timeOpt.elapsed - timeOpt.seconds ) / 60 ) - timeOpt.minutes) / 60 ) % 24; timeOpt.days = ((((( timeOpt.elapsed - timeOpt.seconds ) / 60 ) - timeOpt.minutes) / 60 ) - timeOpt.hours ) / 24; timeCount.set(); }, get : function(){ timeOpt.timer = jQuery('.timer'); timeOpt.timerDay = timeOpt.timer.find('.timer-circle').eq(0); timeOpt.timerHour = timeOpt.timer.find('.timer-circle').eq(1); timeOpt.timerMinute = timeOpt.timer.find('.timer-circle').eq(2); timeOpt.timerSecond = timeOpt.timer.find('.timer-circle').eq(3); }, set : function(){ timeOpt.timerDay.find('h1').html(timeOpt.days); timeOpt.timerHour.find('h1').html(timeOpt.hours); timeOpt.timerMinute.find('h1').html(timeOpt.minutes); timeOpt.timerSecond.find('h1').html(timeOpt.seconds); //Set changes if time - seconds, minutes, hours, days is 0,1 timeOpt.timerDay.find('p').html((timeOpt.days == 1 || timeOpt.days == 0 ?'Day' : 'Days')); timeOpt.timerHour.find('p').html((timeOpt.hours == 1 || timeOpt.hours == 0 ?'Hour' : 'Hours')); timeOpt.timerMinute.find('p').html((timeOpt.minutes == 1 || timeOpt.minutes == 0 ?'Minute' : 'Minutes')); timeOpt.timerSecond.find('p').html((timeOpt.seconds == 1 || timeOpt.seconds == 0 ?'Second' : 'Seconds')); } }; $.fn.countdownNow = function(options){ var settings = $.extend( { 'year' : 0, 'month' : 0, 'day' : 0, 'minutes' : 0, 'hours' : 0, 'timer' : this }, options); timeOpt.dateCount = new Date(settings.year, (settings.month == 0 ? settings.month : settings.month-1), settings.day, (settings.hours == 0 ? settings.hours : settings.hours-1), settings.minutes, 0); timeCount.init(settings.year); timeCount.set(); //setTimeout(function(){timeCount.count()}, 500); setInterval(timeCount.count, 1000); }; })(jQuery);