/*
 * 	Easy Slider 1.7 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#slider").easySlider();
 *	
 * 	<div id="slider">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'&nbsp;',
			nextId: 		'nextBtn',	
			nextText: 		'&nbsp;',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			
			if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};				
			
			if(!options.vertical) $("li", obj).css('float','left');
								
			if(options.controlsShow){
				var html = options.controlsBefore;				
				if(options.numeric){
					html += '<ol id="'+ options.numericId +'"></ol>';
				} else {
					if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
					html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
					html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
					if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';				
				};
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
			
			if(options.numeric){									
				for(var i=0;i<s;i++){						
					$(document.createElement("li"))
						.attr('id',options.numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ options.numericId))
						.click(function(){							
							animate($("a",$(this)).attr('rel'),true);
						}); 												
				};							
			} else {
				$("a","#"+options.nextId).click(function(){		
					animate("next",true);
				});
				$("a","#"+options.prevId).click(function(){		
					animate("prev",true);				
				});	
				$("a","#"+options.firstId).click(function(){		
					animate("first",true);
				});				
				$("a","#"+options.lastId).click(function(){		
					animate("last",true);				
				});				
			};
			
			function setCurrent(i){
				i = parseInt(i)+1;
				$("li", "#" + options.numericId).removeClass("current");
				$("li#" + options.numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				if(!options.vertical) {
					$("ul",obj).css("margin-left",(t*w*-1));
				} else {
					$("ul",obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;						
					if(!options.vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);					
					};
					
					if(!options.continuous && options.controlsFade){					
						if(t==ts){
							$("a","#"+options.nextId).hide();
							$("a","#"+options.lastId).hide();
						} else {
							$("a","#"+options.nextId).show();
							$("a","#"+options.lastId).show();					
						};
						if(t==0){
							$("a","#"+options.prevId).hide();
							$("a","#"+options.firstId).hide();
						} else {
							$("a","#"+options.prevId).show();
							$("a","#"+options.firstId).show();
						};					
					};				
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
			
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);


/*
 * CrossSlide jQuery plugin v0.4
 *
 * Copyright 2007-2010 by Tobia Conforto <tobia.conforto@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
jQuery.fn.crossSlide=function(c,f){var a=this,e=this.width(),b=this.height();function d(j){for(var h=1;h<arguments.length;h++){j=j.replace(new RegExp("\\{"+(h-1)+"}","g"),arguments[h])}return j}function g(){arguments[0]="CrossSlide: "+arguments[0];throw new Error(d.apply(null,arguments))}(function(j){var h=0;function i(l,k){k.onload=function(m){h++;f[l].width=k.width;f[l].height=k.height;if(h==f.length){j()}};k.src=f[l].src;if(l+1<f.length){i(l+1,new Image())}}i(0,new Image())})(function(){function u(y){var i=1;var p=y.replace(/^\s*|\s*$/g,"").split(/\s+/);if(p.length>3){throw new Error()}if(p[0]=="center"){if(p.length==1){p=["center","center"]}else{if(p.length==2&&p[1].match(/^[\d.]+x$/i)){p=["center","center",p[1]]}}}if(p.length==3){i=parseFloat(p[2].match(/^([\d.]+)x$/i)[1])}var z=p[0]+" "+p[1];if(z=="left top"||z=="top left"){return{xrel:0,yrel:0,zoom:i}}if(z=="left center"||z=="center left"){return{xrel:0,yrel:0.5,zoom:i}}if(z=="left bottom"||z=="bottom left"){return{xrel:0,yrel:1,zoom:i}}if(z=="center top"||z=="top center"){return{xrel:0.5,yrel:0,zoom:i}}if(z=="center center"){return{xrel:0.5,yrel:0.5,zoom:i}}if(z=="center bottom"||z=="bottom center"){return{xrel:0.5,yrel:1,zoom:i}}if(z=="right top"||z=="top right"){return{xrel:1,yrel:0,zoom:i}}if(z=="right center"||z=="center right"){return{xrel:1,yrel:0.5,zoom:i}}if(z=="right bottom"||z=="bottom right"){return{xrel:1,yrel:1,zoom:i}}return{xrel:parseInt(p[0].match(/^(\d+)%$/)[1])/100,yrel:parseInt(p[1].match(/^(\d+)%$/)[1])/100,zoom:i}}function j(y,i){switch(i){case 1:var z=0;break;case 2:var z=w/(y.time_ms+2*w);break;case 3:var z=1-w/(y.time_ms+2*w);break;case 4:var z=1;break}return{left:Math.round(y.from.left+z*(y.to.left-y.from.left)),top:Math.round(y.from.top+z*(y.to.top-y.from.top)),width:Math.round(y.from.width+z*(y.to.width-y.from.width)),height:Math.round(y.from.height+z*(y.to.height-y.from.height))}}if(!c.fade){g("missing fade parameter.")}if(c.speed&&c.sleep){g("you cannot set both speed and sleep at the same time.")}var w=Math.round(c.fade*1000);if(c.sleep){var v=Math.round(c.sleep*1000)}if(c.speed){var k=c.speed/1000,q=Math.round(w*k)}a.empty().css({overflow:"hidden",padding:0});if(!/^(absolute|relative|fixed)$/.test(a.css("position"))){a.css({position:"relative"})}if(!a.width()||!a.height()){g("container element does not have its own width and height")}if(c.shuffle){f.sort(function(){return Math.random()-0.5})}for(var n=0;n<f.length;++n){var h=f[n];if(!h.src){g("missing src parameter in picture {0}.",n+1)}if(k){switch(h.dir){case"up":h.from={xrel:0.5,yrel:0,zoom:1};h.to={xrel:0.5,yrel:1,zoom:1};var s=h.height-b-2*q;break;case"down":h.from={xrel:0.5,yrel:1,zoom:1};h.to={xrel:0.5,yrel:0,zoom:1};var s=h.height-b-2*q;break;case"left":h.from={xrel:0,yrel:0.5,zoom:1};h.to={xrel:1,yrel:0.5,zoom:1};var s=h.width-e-2*q;break;case"right":h.from={xrel:1,yrel:0.5,zoom:1};h.to={xrel:0,yrel:0.5,zoom:1};var s=h.width-e-2*q;break;default:g("missing or malformed dir parameter in picture {0}.",n+1)}if(s<=0){g("picture {0} is too small for the desired fade duration.",n+1)}h.time_ms=Math.round(s/k)}else{if(!v){if(!h.from||!h.to||!h.time){g("missing either speed/sleep option, or from/to/time params in picture {0}.",n+1)}try{h.from=u(h.from)}catch(r){g('malformed "from" parameter in picture {0}.',n+1)}try{h.to=u(h.to)}catch(r){g('malformed "to" parameter in picture {0}.',n+1)}if(!h.time){g('missing "time" parameter in picture {0}.',n+1)}h.time_ms=Math.round(h.time*1000)}}if(h.from){jQuery.each([h.from,h.to],function(y,p){p.width=Math.round(h.width*p.zoom);p.height=Math.round(h.height*p.zoom);p.left=Math.round((e-p.width)*p.xrel);p.top=Math.round((b-p.height)*p.yrel)})}var t;if(h.href){t=jQuery(d('<a href="{0}"><img src="{1}"/></a>',h.href,h.src))}else{t=jQuery(d('<img src="{0}"/>',h.src))}if(h.onclick){t.click(h.onclick)}if(h.alt){t.find("img").attr("alt",h.alt)}t.appendTo(a)}k=undefined;var o=a.find("img").css({position:"absolute",visibility:"hidden",top:0,left:0,border:0});o.eq(0).css({visibility:"visible"});if(!v){o.eq(0).css(j(f[0],2))}var x=c.loop;function l(K,p){if(K%2==0){if(v){var A=K/2,O=(A-1+f.length)%f.length,L=o.eq(A),I=o.eq(O);var H=function(){I.css("visibility","hidden");setTimeout(p,v)}}else{var D=K/2,O=(D-1+f.length)%f.length,N=o.eq(D),I=o.eq(O),B=f[D].time_ms,J=j(f[D],3);var H=function(){I.css("visibility","hidden");N.animate(J,B,"linear",p)}}}else{if(v){var z=Math.floor(K/2),C=Math.ceil(K/2)%f.length,M=o.eq(z),y=o.eq(C),P={},G={visibility:"visible"},F={};if(C>z){G.opacity=0;F.opacity=1;if(c.doubleFade){P.opacity=0}}else{P.opacity=0;if(c.doubleFade){G.opacity=0;F.opacity=1}}var H=function(){y.css(G);if(P.opacity!=undefined){if(c.doubleFade){y.animate(F,w,"linear")}M.animate(P,w,"linear",p)}else{if(c.doubleFade){M.animate(P,w,"linear")}y.animate(F,w,"linear",p)}}}else{var z=Math.floor(K/2),C=Math.ceil(K/2)%f.length,M=o.eq(z),y=o.eq(C),P=j(f[z],4),G=j(f[C],1),F=j(f[C],2);if(C>z){G.opacity=0;F.opacity=1}else{P.opacity=0}G.visibility="visible";var H=function(){M.animate(P,w,"linear");y.css(G);y.animate(F,w,"linear",p)}}}if(c.loop&&K==f.length*2-2){var E=H;H=function(){if(--x){E()}}}if(K>0){return l(K-1,H)}else{return H}}var m=l(f.length*2-1,function(){return m()});m()});return a};


