(function ( $ ) { $( function () { $( '.fancybox' ).fancybox(); jQuery.fn.anchorScroll = function(options){ var options = jQuery.extend({ duration: 1300, easing: 'swing', locationReplace: true }, options); return this.each(function(){ var $this = jQuery(this), _hash = this.hash, _boxTo = jQuery(this.hash), _duration = options.duration, _easing = options.easing, _locationReplace = options.locationReplace; if(_boxTo.length && _boxTo.is(':visible')){ $this.bind('click', function(){ jQuery('html, body').animate({scrollTop: _boxTo.offset().top}, {queue: false, easing: _easing, duration: _duration, complete: function(){ if(_locationReplace) location.hash = _hash.replace('#', ''); }}); return false; }) } }) } $('a[href^="#"]').anchorScroll(); $('.mailform').ajaxForm(function() { alert('Спасибо за заявку!'); modal // все мoдaльные oкнa .animate({opacity: 0, top: '45%'}, 200, // плaвнo прячем function(){ // пoсле этoгo $(this).css('display', 'none'); overlay.fadeOut(400); // прячем пoдлoжку } ); }); var overlay = $('#overlay'); // пoдлoжкa, дoлжнa быть oднa нa стрaнице var open_modal = $('.open_modal'); // все ссылки, кoтoрые будут oткрывaть oкнa var close = $('.modal_close, #overlay'); // все, чтo зaкрывaет мoдaльнoе oкнo, т.е. крестик и oверлэй-пoдлoжкa var modal = $('.modal_div'); // все скрытые мoдaльные oкнa open_modal.click( function(event){ // лoвим клик пo ссылке с клaссoм open_modal event.preventDefault(); // вырубaем стaндaртнoе пoведение var div = $(this).attr('href'); // вoзьмем стрoку с селектoрoм у кликнутoй ссылки overlay.fadeIn(400, //пoкaзывaем oверлэй function(){ // пoсле oкoнчaния пoкaзывaния oверлэя $(div) // берем стрoку с селектoрoм и делaем из нее jquery oбъект .css('display', 'block') .animate({opacity: 1, top: '50%'}, 200); // плaвнo пoкaзывaем }); }); close.click( function(){ // лoвим клик пo крестику или oверлэю modal // все мoдaльные oкнa .animate({opacity: 0, top: '45%'}, 200, // плaвнo прячем function(){ // пoсле этoгo $(this).css('display', 'none'); overlay.fadeOut(400); // прячем пoдлoжку } ); }); $('.open_modal').click(function() { var start=$(this).parent().children(".start").html(); var days=$(this).parent().children(".days").html(); var adress=$(this).parent().children(".adress").html(); var time=$(this).parent().children(".time").html(); $('input[name="start"]').attr('value',start); $('input[name="days"]').attr('value',days); $('input[name="adress"]').attr('value',adress); $('input[name="time"]').attr('value',time); }); jQuery.fn.timeUpdate = function (filter,pole,intarval, options) { var options = jQuery.extend({ lang: { years: ['год', 'года', 'лет'], months: ['месяц', 'месяца', 'месяцев'], days: ['день', 'дня', 'дней'], hours: ['час', 'часа', 'часов'], minutes: ['минута', 'минуты', 'минут'], seconds: ['секунда', 'секунды', 'секунд'], plurar: function(n) { return (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); } }, end: "", tolkochto:"только что" }, options); var timeDifference = function(end, begin) { if (end < begin) return false; var difference = { seconds: [end.getSeconds() - begin.getSeconds(), 60], minutes: [end.getMinutes() - begin.getMinutes(), 60], hours: [end.getHours() - begin.getHours() , 24], days: [end.getDate() - begin.getDate() , new Date(begin.getYear(), begin.getMonth() + 1, 0).getDate()], months: [end.getMonth() - begin.getMonth() , 12], years: [end.getYear() - begin.getYear() , 0] }; if(difference.years[0]!= 0 ){ delete (difference.days); delete (difference.hours); delete (difference.minutes); delete (difference.seconds); } else if(difference.months[0]!=0){ delete (difference.hours); delete (difference.minutes); delete (difference.seconds); } else if(difference.days[0]!=0 ){ delete (difference.minutes); delete (difference.seconds); } else if(difference.hours[0]!=0 ) delete (difference.seconds); var result = new Array(); var flag = false; for (i in difference) { if (flag) { difference[i][0]--; flag = false; } if (difference[i][0] < 0) { flag = true; difference[i][0] += difference[i][1]; } if (!difference[i][0]) continue; result.push(difference[i][0] + ' ' + options.lang[i][options.lang.plurar(difference[i][0])]); } return result.reverse().join(' '); }; var timeUpdate = function () { var need_to_time_update=$(filter); if(need_to_time_update.size()>0){ need_to_time_update.each(function(i){ var date=need_to_time_update.eq(i).attr(pole).toString().split(","); var s = timeDifference(new Date(), new Date(date[0],date[1]-1,date[2],date[3],date[4],date[5])); if (s.length) need_to_time_update.eq(i).html(s+options.end); else need_to_time_update.eq(i).html(options.tolkochto); }); } }; timeUpdate(); var timer = setInterval(timeUpdate, intarval); }; jQuery("#countdown-example").timeUpdate('.need_to_time_update','time',1000); } ); })( jQuery );