/*!
 * zoomSlider Library v0.1
 * http://codecanyon.net/user/Alexandra1710/portfolio
 *
 * Copyright 2011, Andrei Dinca
 *
 * Date: 14.02.2011
 */
(function($){$.fn.zoomSlider=function(options){var defaults={content:".sliderContent",children:"li",transition:"fadeZoom",zoomSize:10,animationSpeed:300,easing:'',autoplay:false,autoplaySpeed:3000,pauseOnHover:false,bullets:true,arrows:true,arrowsHide:true,keyBrowse:true,mouseWheel:true,preloadImages:true,itemSize:{width:960,height:468},prev:"prev",next:"next",bkcolor:{},running:false,animationStart:function(){},animationComplete:function(){}};var option=$.extend({},defaults,options);return this.each(function(){var $t=$(this),item=$t.children(option.content).children(option.children),item_img=item.find('img'),sliderContent=$t.find(option.content),l=item.length-1,w=item.width(),h=item.height(),allImage=[],step=0,play,front_item,front_item_img,next_item,next_item_img,bullets,arrows,z,on,bullet,evt;var slider={init:function(){if(option.preloadImages){$(".prealoadImages").remove();$t.append('<img src="images/ajax-loader.gif" class="prealoadImages" />');item_img.hide();item_img.each(function(i){allImage[i]=$(this).attr('src');});slider.preLoadImages(allImage,function(){item_img.show();$("img.prealoadImages").hide();slider.load_slider();});}else{slider.load_slider();}},load_slider:function(){slider.data();$t.css('background-color',"#"+option.bkcolor[0]);if(option.bullets===true){slider.bullets.create();}
if(option.arrows===true){slider.arrows.create();}
if(option.autoplay===true){slider.autoplay();}
slider.triggers();},data:function(){item.each(function(i){var $this=$(this);$this.css("z-index",-(i-l));$this.find('img').css("opacity",0);option.bkcolor[i]=$this.attr('title');$this.attr('title','');});if(option.transition==="fade"){item.eq(0).show().addClass('on').find('img').css("opacity",1);}
if(option.transition==="fadeZoom"){item.eq(0).addClass('on').find('img').css("opacity",1);}},zindex:{prev:function(){if(step===l){item.eq(0).css("z-index",l+3);}else{item.css("z-index",l+1);}
item.eq(step).css("z-index",l+4).next(item).css("z-index",l+2);},next:function(){item.css("z-index",l+1).eq(step).css("z-index",l+3).prev(item).css("z-index",l+2);},bullets:function(){item.css("z-index",l+1).eq(on).css("z-index",l+2);item.eq(step).css("z-index",l+3);},trigger:function(){if(z===1){slider.zindex.next();}else{if(z===-1){slider.zindex.prev();}else{if(z===0){slider.zindex.bullets();}}}}},preLoadImages:function(imageList,callback){var pic=[],i,total,loaded=0;if(typeof imageList!=='undefined'){if($.isArray(imageList)){total=imageList.length;for(i=0;i<total;i++){pic[i]=new Image();pic[i].onload=function(){loaded++;if(loaded===total){if($.isFunction(callback)){callback();}}}
pic[i].src=imageList[i];}}
else{pic[0]=new Image();pic[0].onload=function(){if($.isFunction(callback)){callback();}};pic[0].src=imageList;}}
pic=undefined;},slide:{fade:function(){option.animationStart.call(this);front_item=sliderContent.find('.on');front_item_img=front_item.find('img');next_item=item.eq(step);next_item_img=next_item.find('img');front_item.fadeOut(option.animationSpeed,function(){$t.css('background-color',"#"+option.bkcolor[step]);next_item_img.animate({opacity:1},option.animationSpeed/2,option.easing,function(){next_item.css('display','block').css('display','block');sliderContent.find('.on').removeClass('on');next_item.addClass('on');option.animationComplete.call(this);option.running=false;});});},fadeZoom:{backFront:function(){option.animationStart.call(this);front_item=item.eq(step-1);front_item_img=front_item.find('img');next_item=item.eq(step);next_item_img=next_item.find('img');front_item_img.animate({width:"+="+option.zoomSize+"px",marginBottom:"-="+parseInt(option.zoomSize/2,10)+"px",marginLeft:"-="+parseInt(option.zoomSize/2,10)+"px",opacity:0},option.animationSpeed/2,option.easing,function(){$t.css('background-color',"#"+option.bkcolor[step]);next_item.css('display','block');next_item_img.css({width:parseInt(option.itemSize.width-option.zoomSize,10)+"px",marginTop:"0px",marginLeft:"-"+parseInt(parseInt(option.itemSize.width-option.zoomSize,10)/2,10)+"px",opacity:0});next_item_img.animate({width:option.itemSize.width+"px",marginTop:"0px",marginLeft:"-"+parseInt(option.itemSize.width/2,10)+"px",opacity:1},option.animationSpeed/2,option.easing,function(){sliderContent.find('.on').removeClass('on');next_item.addClass('on');});slider.zindex.trigger();option.running=false;slider.bullets.update();option.animationComplete.call(this);});},frontBack:function(){option.animationStart.call(this);front_item=sliderContent.find('.on');front_item_img=front_item.find('img');next_item=item.eq(step);next_item_img=next_item.find('img');front_item_img.animate({width:parseInt(option.itemSize.width-option.zoomSize,10)+"px",marginTop:"0px",marginLeft:"-"+parseInt(parseInt(option.itemSize.width-option.zoomSize,10)/2,10)+"px",opacity:0},option.animationSpeed/2,option.easing,function(){$t.css('background-color',"#"+option.bkcolor[step]);next_item.css('display','block');next_item_img.css({width:parseInt(option.itemSize.width+option.zoomSize,10)+"px",marginTop:"0px",marginLeft:"-"+parseInt(parseInt(option.itemSize.width+option.zoomSize,10)/2,10)+"px",opacity:0});next_item_img.animate({width:option.itemSize.width+"px",marginTop:"0px",marginLeft:"-"+parseInt(option.itemSize.width/2,10)+"px",opacity:1},option.animationSpeed/2,option.easing,function(){sliderContent.find('.on').removeClass('on');next_item.addClass('on');});option.running=false;slider.zindex.trigger();option.animationComplete.call(this);});}}},animation:{previous:function(){if(step===0){step=l;}else{step--;}
z=-1;switch(option.transition){case"fade":slider.slide.fade();break;case"fadeZoom":slider.slide.fadeZoom.frontBack();break;}},next_item:function(){if(step===l){step=0;}else{step++;}
z=1;switch(option.transition){case"fade":slider.slide.fade();break;case"fadeZoom":slider.slide.fadeZoom.backFront();break;}}},keyBrowse:function(){$(document).keyup(function(e){if(option.running){return false;}
option.running=true;if(e.keyCode===37){slider.animation.previous();if(option.bullets===true){slider.bullets.update();}}
if(e.keyCode===39){slider.animation.next_item();if(option.bullets===true){slider.bullets.update();}}
return false;});},mouseWheel:function(){$t.mousewheel(function(event,delta){if(option.running){return false;}
option.running=true;var dir=delta>0?'up':'down',vel=Math.abs(delta);if(dir==='down'){slider.animation.next_item();if(option.bullets===true){slider.bullets.update();}}else{slider.animation.previous();if(option.bullets===true){slider.bullets.update();}}
return false;});},autoplay:function(){if(option.autoplay===true){play=setInterval(function(){slider.animation.next_item();if(option.bullets===true){setTimeout(function(){slider.bullets.update();},option.animationSpeed+200);}},option.autoplaySpeed);}},pause:function(){clearInterval(play);},bullets:{create:function(){$(".sliderBullets").remove();$t.append($("<div />").addClass("sliderBullets"));bullets=$t.find(".sliderBullets");for(i=0;i<=l;i++){bullets.append($("<a />").attr({href:"#",rel:i}).text(i));}},trigger:function(){bullet=bullets.find("a");bullet.eq(0).addClass("on");bullet.click(function(){var b=$(this),rel=b.attr("rel");on=bullet.filter(".on").attr("rel");step=rel;sign=rel>on?"+":"-";z=0;if(!b.hasClass("on")){switch(option.transition){case"fade":slider.slide.fade();break;case"fadeZoom":if(sign==="+"){slider.slide.fadeZoom.backFront();}else{slider.slide.fadeZoom.frontBack();}
break;}}
bullet.removeClass("on");b.addClass("on");return false;});},update:function(){bullet.removeClass("on").eq(step).addClass("on");}},arrows:{create:function(){$(".nextBackControllers").remove();$t.append($("<div />").addClass("nextBackControllers"));arrows=$t.find(".nextBackControllers");arrows.append($("<a />").attr("href","#").addClass(option.prev).text("Previous"));arrows.append($("<a />").attr("href","#").addClass(option.next).text("Next"));},trigger:function(){arrows.find("."+option.prev).click(function(){if(option.running){return false;}
option.running=true;slider.animation.previous();if(option.bullets===true){slider.bullets.update();}
return false;});arrows.find("."+option.next).click(function(){if(option.running){return false;}
option.running=true;slider.animation.next_item();if(option.bullets===true){slider.bullets.update();}
return false;});if(option.arrowsHide===true){arrows.find('a').hide();$t.hover(function(){$t.mousemove(function(e){var offset=$(this).offset();var x=e.pageX-(offset.left);if(x<w/2){arrows.find("."+option.next).hide();arrows.find("."+option.prev).fadeIn(150);}else{arrows.find("."+option.prev).hide();arrows.find("."+option.next).fadeIn(150);}});},function(){arrows.find('a').hide();});}}},triggers:function(){if(option.arrows===true){slider.arrows.trigger();}
if(option.bullets===true){slider.bullets.trigger();}
if(option.mouseWheel===true){slider.mouseWheel();}
if(option.keyBrowse===true){slider.keyBrowse();}
if(option.pauseOnHover===true){$t.hover(function(){slider.pause();},function(){slider.autoplay();});}}};slider.init();});};}(jQuery));(function($){var types=['DOMMouseScroll','mousewheel'];$.event.special.mousewheel={setup:function(){var i;if(this.addEventListener){for(i=types.length;i;){this.addEventListener(types[--i],handler,false);}}else{this.onmousewheel=handler;}},teardown:function(){var i;if(this.removeEventListener){for(i=types.length;i;){this.removeEventListener(types[--i],handler,false);}}else{this.onmousewheel=null;}}};$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel");},unmousewheel:function(fn){return this.unbind("mousewheel",fn);}});function handler(event){var args=[].slice.call(arguments,1),delta=0,returnValue=true;event=$.event.fix(event||window.event);event.type="mousewheel";if(event.wheelDelta){delta=event.wheelDelta/120;}
if(event.detail){delta=-event.detail/3;}
args.unshift(event,delta);return $.event.handle.apply(this,args);}}(jQuery));
