function ImageSlider() { var self = this; self.stopInterval = false; self.makeList = function(imageSlider) { var l = ''; var images = $('> div img', imageSlider); var divs = $('> div', imageSlider); for(var i=1; i<=images.length; i++) l += '
  • '+i+'
  • '; $(imageSlider).prepend($('')); if(!$('ul > li[class=clicked]', imageSlider)[0]) { for(var i=0; i<=divs.length; i++) if($(divs[i]).hasClass('active')) { $($('ul > li', imageSlider)[i]).addClass('clicked'); break; } else { $('ul > li:first', imageSlider).addClass('clicked'); break; } } $('ul > li', imageSlider).click(function() { self.stopInterval = true; if(!$(this).hasClass('clicked')) { $('.clicked', imageSlider).removeClass('clicked'); $(this).addClass('clicked'); self.singleAnimation(imageSlider, $(this).attr('name')); } }); }; self.triggerNextBtn = function(imageSlider) { var current = $('.clicked', imageSlider); var next = current.next(); if(!next[0]) next = $('ul li:first', imageSlider); current.removeClass('clicked'); next.addClass('clicked'); }; self.setAnimation = function(imageSlider) { if(self.stopInterval) return false; var active = $('> div[class*=active]', imageSlider); if(active[0]) { var next = active.next(); if(!next[0]) next = $('> div:first', imageSlider); next.show(); next.find('.text-container').hide(); $('.text-container', active).fadeOut('fast', function() { active.fadeOut(1000, function() { self.triggerNextBtn(imageSlider); next.find('.text-container').fadeIn(1000, function() { active.removeClass('active'); next.addClass('active'); }); setTimeout(function() {self.setAnimation(imageSlider);}, 6500); }); }); } else { var active = $('> div:first', imageSlider).addClass('active') $('.text-bg', imageSlider).opacity(0.4); $('.text-container', active).show(); } }; self.singleAnimation = function(imageSlider, ani) { var active = $('> div[class*=active]', imageSlider); var next = $($('> div', imageSlider)[ani-1]); $('> div, .text-container', imageSlider).stop(); $('> div', imageSlider).where(function() { return (!$(this).hasClass('active') && $(this).css('display') == 'block') }).hide(); if(!next.hasClass('active')) { next.show(); active.find('.text-container').hide(); if(!$.browser.msie) { next.find('.text-container').hide(); active.fadeOut('fast', function() { active.removeClass('active'); next.addClass('active'); setTimeout(function() {next.find('.text-container').fadeIn('slow');}, 250); }); } else { $('.text-container', next).show(); next.show(); active.fadeOut('fast', function() { active.removeClass('active'); next.addClass('active'); }); } } }; self.init = function (imageSlider) { self.makeList(imageSlider); setTimeout(function() {self.setAnimation(imageSlider);}, 6500); }; } $(document).ready(function() { var imageSlider = new ImageSlider(); $('.imageSlider' ).initClasses() .each(function(){ imageSlider.init(this); }); }); function buildLink(args) { var req_uri = location.pathname; if(typeof args == 'undefined' || !args) return req_uri; var url = ''; var temp = ''; req_uri = req_uri.split('/'); for (var key in req_uri) if(req_uri[key] && typeof(req_uri[key]) == 'string' && !req_uri[key].match('=')) url += '/'+req_uri[key]; for (var arg in args) if(args[arg]) url += '/'+arg+'='+args[arg]; return url; }