//  @copyright	Copyright (C) 2008 IceTheme. All Rights Reserved
//  @license	Copyrighted Commercial Software 
//  @author     IceTheme (icetheme.com)

var Iceslideshow=new Class({Implements:Options,options:{speed:300,scroll:null,tips:false},initialize:function(e,b){this.setOptions(b);this.carousel=$(e);if(!this.carousel){return}this.stage=this.carousel.getElement(".iceslideshow_stage ");this.scroll=this.carousel.getElement(".iceslideshow_thumbnails");this.ul=this.scroll.getElement("ul");this.leftButton=this.carousel.getElement(".iceslideshow_arrow_l");this.rightButton=this.carousel.getElement(".iceslideshow_arrow_r");this.scroll.setStyle("overflow","hidden");this.stage.setStyle("overflow","hidden");this.scrollEffect=new Fx.Scroll(this.scroll,{transition:Fx.Transitions.Expo.easeOut,duration:2000,link:"cancel",wheelStops:false});this.carousel.addEvent("keypress",function(i){if(i.key=="left"&&this.currentIndex>0){var h=this.currentIndex-1;var g=this.thumbnails[h];this.highlight(g);this.show(h);this.scrollTo(g)}if(i.key=="right"&&this.currentIndex<this.items.length-1){var f=this.currentIndex+1;var j=this.thumbnails[f];this.highlight(j);this.show(f);this.scrollTo(j)}}.bindWithEvent(this));this.scroll.addEvent("mousewheel",function(f){f.preventDefault();this.position-=f.wheel*200;if(this.position<0){this.position=0}if(this.position>this.max){this.position=this.max}this.scrollTo(this.position)}.bindWithEvent(this));this.scrollWidth=this.scroll.getSize().x;this.max=this.ul.getSize().x-this.scroll.getSize().x;this.speed=this.options.speed;this.position=this.options.scroll||Math.round(this.max/2);this.scrollEffect.set(this.position);this.leftButton.addEvent("click",function(){this.position-=(this.position>0)?this.speed:0;this.scrollTo(this.position)}.bindWithEvent(this));this.rightButton.addEvent("click",function(){this.position+=(this.position<this.max)?this.speed:0;this.scrollTo(this.position)}.bindWithEvent(this));this.thumbnails=this.scroll.getElements("li");this.thumbnails.each(function(f){f.linkedIndex=this.thumbnails.indexOf(f);f.setStyle("opacity",0.3);f.set("tween",{duration:200});f.addEvents({mouseover:function(g){f.fade(1)},mouseout:function(g){if(!f.current){f.fade(0.3)}},click:function(h,g){this.highlight(f);this.scrollTo(f);if(this.currentIndex!=f.linkedIndex){this.show(f.linkedIndex)}return false}.bindWithEvent(this)});f.getElements("a").each(function(g){g.onclick=function(){return false}}.bind(this))}.bind(this));this.items=new Array();var a=this.stage.getElements("div.iceslideshow_item");var c=a.getRandom();this.currentIndex=a.indexOf(c);var d=this.thumbnails[this.currentIndex];d.fade(1);d.current=true;this.scrollTo(d);a.each(function(f){f.fadeOut=function(){this.get("tween").onComplete=this.dispose;this.fade("out")};f.fadeIn=function(){this.fade("hide");this.fade("in")};this.items.push(f);if(f!=c){f.dispose()}else{f.fadeIn()}},this);if(this.options.tips){new Tips(".hastip",{className:"tool-tip"})}},scrollTo:function(b){if($type(b)=="number"){this.scrollEffect.start(b)}else{if($type(b)=="element"){var a=b.getPosition(this.scroll).x;a-=(this.scrollWidth-b.getSize().x)/2;this.scrollEffect.start(a);this.position=a}}},show:function(c){var b=this.items[this.currentIndex];var a=this.items[c];a.inject(this.stage);b.setStyle("position","absolute");b.fadeOut();a.fadeIn();this.currentIndex=c},highlight:function(a){this.thumbnails.each(function(b){if(b==a){b.current=true;b.fireEvent("mouseover",{target:b})}else{b.current=false;b.fireEvent("mouseout",{target:b})}})}});
