var REED = REED || {}; REED.carousel = function(scope, slides, pagination, prev, next, animation, delay) { var s = this; s.scope = $(scope); s.delay = delay || 4000; s.animateSlides = typeof animation == "function" ? animation : function(activeID, stagedObj, callback) { stagedObj.addClass('staged').css({ opacity: 0 }).show().animate({ opacity: 1 }, 250, 'swing', function() { if(typeof(callback) == "function") { callback(); } }); }; s.showSlide = function(id, dir) { var staged = getSlide(id); if(!dir) { dir = 1; } if(!staged.hasClass('active')) { setActivePage(id); s.animateSlides(s.active, staged, function() { setActiveSlide(id); }); } }; function getSlide(o) { if(typeof(o) === 'string' && o.indexOf('#') != 0) var o = '#'+o; return $(o, s.scope); } function getID(o) { return "#" + getSlide(o).attr('id'); } function getPage(o) { // might be faster // return $(pagination).find('a[href='+getID(o)+']').parent() return $(pagination).find('a').filter(function() { return $(this).attr('href') === getID(o); }).parent(); } function setActivePage(o) { getPage(o) .addClass('active') .removeClass('staged') .siblings('.active') .removeClass('active'); } function setActiveSlide(o) { getSlide(o) .addClass('active') .removeClass('staged') .siblings('.active') .removeClass('active'); s.active = getID(o); } function isImg(src) { return (/([^\s]+(?=\.(jpg|jpeg|gif|png|bmp))\.\2)/i).test(src); }; function paginate(dir) { var index = getSlide(s.active).prevAll().length + dir, highIndex = $(slides, scope).length - 1; if(index > highIndex) { index = 0; } else if(index < 0) { index = highIndex; } s.showSlide($(slides, scope).eq(index), dir); } s.start = function() { if(s.paused) { s.paused = false; s.interval = setInterval(function() { paginate(1); }, s.delay); } }; s.dontRestart = function(){ s.paused_forever = true; }; s.pause = function() { if(!s.paused) { s.paused = true; clearInterval(s.interval); } }; function init() { setActiveSlide(s.scope.find(slides).first()); setActivePage(s.scope.find(slides).first()); $(pagination).find('li').bind({ click: function(e) { s.pause(); s.dontRestart(); e.preventDefault(); s.showSlide($(this).find('a').attr('href')); } }); $(scope).hover(function() { s.pause(); }, function() { if(s.paused_forever !== true){ s.start(); } }); $(prev).bind({ click: function() { s.pause(); s.dontRestart(); paginate(-1); } }); $(next).bind({ click: function() { s.pause(); s.dontRestart(); paginate(1); } }); s.paused = true; s.start(); } init(); }; REED.common = { 'init': function() {} }; REED.home = { 'init': function() { function newsTickerAnimation(activeID, stagedObj, callback) { var activeObj = $(activeID); activeObj.animate({ left: '-=100px', opacity: 0 }, 250, function() { $(this).css({ display: 'none', left: 0, opacity: 1 }); stagedObj.animate({ left: '+=100px', opacity: 0 }, 0, function() { $(this).css({ display: 'block' }).animate({ left: 0, opacity: 1 }, 250, function() { $(this).attr('style', 'display: block'); if(typeof callback == "function") { callback(); } }); }); }); }; var newsTicker = new REED.carousel('.news-ticker', 'li', '', '.news-ticker .prev', '.news-ticker .next', newsTickerAnimation); //pagination animation function featureAnimation(activeID, stagedObj, callback) { var activeObj = $(activeID); stagedObj.addClass('staged').css({ opacity: 0 }).show(); activeObj.animate({ opacity: 0 }, 250, 'swing', function() { stagedObj.animate({ opacity: 1 }, 500, 'swing', function() { if(typeof(callback) == "function") { callback(); activeObj.attr('style', ''); } }); }); }; var feature = new REED.carousel('#feature', '.slides li', '.pagination ul', '#feature .prev', '#feature .next', featureAnimation, 6000); } }; REED.contactUs = { 'init': function() { $('form.required-form').simpleValidate({ errorElement: 'em' }); } }; UTIL = { exec: function( controller, action ) { var ns = REED, action = ( action === undefined ) ? "init" : action; if ( controller !== "" && ns[controller] && typeof( ns[controller][action] ) == "function" ) { ns[controller][action](); } }, init: function() { var body = document.body, controller = body.className; UTIL.exec( "common" ); UTIL.exec( controller ); $(document).trigger('finalized'); } }; $(document).ready( UTIL.init );