﻿var TIMER_SPEED = 7000; var InitConfig = function (timerSpeed) { TIMER_SPEED = timerSpeed; }; $(function () { var $active = {}, play = 0; $(".nav").show(); $(".nav li:first").addClass("active"); var imageReelWidth = function () { var _width = 0; var widthTab = $.map($(".image_reel img"), function (elem, index) { return $(elem).width() }); for (var i in widthTab) { _width += widthTab[i]; } if ($.browser.msie && $.browser.version < 9) { return _width * 2; } else { return _width; } }; var image_reelPosition = function () { var _width = 0; var widthTab = $.map($(".image_reel img:lt(" + $active.index() + ")"), function (elem, index) { return $(elem).width() }); for (var i in widthTab) { _width += widthTab[i]; } return _width; }; $(".image_reel").css({ 'width': imageReelWidth() }); var rotate = function () { $(".nav li.active").removeClass('active'); $active.addClass('active'); $(".image_reel").css({ 'width': imageReelWidth(), 'margin': 0, 'padding': 0 }).animate({ left: -image_reelPosition() }, 500); }; var rotateSwitch = function () { play = setInterval(function () { if ($("body").hasClass("ACTIVEWINDOW")) { $active = $('.nav li.active').next(); if ($active.length === 0) { $active = $('.nav li:first'); } rotate(); } }, TIMER_SPEED); }; rotateSwitch(); $(".image_reel a").hover(function () { clearInterval(play); }, function () { rotateSwitch(); }); $(".nav li").click(function (event) { event.preventDefault(); $active = $(this); clearInterval(play); rotate(); rotateSwitch(); }); var firstMove = function (event) { $("body").addClass("ACTIVEWINDOW"); $("body").unbind("mousemove", firstMove); }; $("body").bind("mousemove", firstMove); function onBlur() { $("body").removeClass("ACTIVEWINDOW"); }; function onFocus() { $("body").addClass("ACTIVEWINDOW"); }; if ($.browser.msie) { document.onfocusin = onFocus; document.onfocusout = onBlur; } else { window.onfocus = onFocus; window.onblur = onBlur; } });
