/*
 * 	Easy Slider - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
 *
 *	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
 *
 */
 
(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevImg:		'',
			prevAltText:    '',
			nextId: 		'nextBtn',	
			nextImg:        '',
			nextAltText:    '',
			orientation:	'', //  'vertical' is optional;
			speed: 			800			
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 				
			var s = $("li", obj).length;
			var w = 125;  // 500px --> #slider
			var h = obj.height(); 
			var ts = s-4;
			var t = 0;
			var vertical = (options.orientation == 'vertical');
			$("ul", obj).css('width',s*w);			
			if(!vertical) $("li", obj).css('float','left');
			$(obj).before('<div id="'+ options.prevId +'"><a href=\"javascript:void(0);\"><img src="'+ options.prevImg +'" width="35" height="120" alt="' + options.prevAltText + '" title="' + options.prevAltText + '"/></a></div>');
			$(obj).after('<div id="'+ options.nextId +'"><a href=\"javascript:void(0);\"><img src="'+ options.nextImg +'"width="35" height="120" alt="' + options.nextAltText + '" title="' + options.nextAltText + '"/></a></div>');		
			$("a","#"+options.prevId).hide();
			$("a","#"+options.nextId).hide();
			$("a","#"+options.nextId).click(function(){		
				animate("next");
				if (t>=ts) $(this).fadeOut();
				$("a","#"+options.prevId).fadeIn();
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev");
				if (t<=0) $(this).fadeOut();
				$("a","#"+options.nextId).fadeIn();
			});	
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;	
				} else {
					t = (t<=0) ? 0 : t-1;
				};								
				if(!vertical) {
					p = (t*w*-1);
					$("#ulpicanimate").animate(
						{ marginLeft: p }, 
						options.speed
					);				
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						options.speed
					);					
				}
			};
			if(s>4) $("a","#"+options.nextId).fadeIn();	
		});
	  
	};

})(jQuery);

(function($) {

	$.fn.easySliderBig = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtnBig',
			prevImg:		'',
			prevAltText:    '',
			nextId: 		'nextBtnBig',	
			nextImg:        '',
			nextAltText:    '',
			speed: 			800,	
			picpostion:		''	
		}; 
		
		var options = $.extend(defaults, options);  
		return this.each(function() {  
			obj = $(this); 				
			var s = $("li", obj).length;
			var w = 500;  // 500px --> #slider
			var h = obj.height(); 
			var ts = s-1;
			var t = options.picpostion;
			$("ul", obj).css('width',s*w);			
			$("li", obj).css('float','left');
			$(obj).before('<div id="'+ options.prevId +'"><a href=\"javascript:void(0);\"><img src="'+ options.prevImg +'" width="15" height="50" alt="' + options.prevAltText + '" title="' + options.prevAltText + '"/></a></div>');
			$(obj).after('<div id="'+ options.nextId +'"><a href=\"javascript:void(0);\"><img src="'+ options.nextImg +'"width="15" height="50" alt="' + options.nextAltText + '" title="' + options.nextAltText + '"/></a></div>');		
			$("a","#"+options.prevId).hide();
			$("a","#"+options.nextId).hide();
			//alert("picpostion (t) " + t);
			start = (t*w*-1);
			$("#ulpicbiganimate").animate(
				{ marginLeft: start }, 
				options.speed
			);
			
			/* TODO:Bei jedem Aufruf muss t für next und prev resetted werden. */

			$("a","#"+options.nextId).click(function(){
				//alert("t onclick: " + t + " prevId:" + options.prevId);
				animate("next");
				if (t>=ts) $(this).fadeOut();
				$("a","#"+options.prevId).fadeIn();
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev");
				if (t<=0) $(this).fadeOut();
				$("a","#"+options.nextId).fadeIn();
			});	

			function gotoPosition(position) {
				t = position;
				p = (t*w*-1);
				//alert("p: " + t + " * " + w);
				$("#ulpicbiganimate").animate(
					{ marginLeft: p }, 
					options.speed
				);
				showHideArrows();
			}
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;
				} else {
					t = (t<=0) ? 0 : t-1;
				};								
				p = (t*w*-1);
				//alert("p: " + t + " * " + w);
				$("#ulpicbiganimate").animate(
					{ marginLeft: p }, 
					options.speed
				);				
			};
			obj.bind("goto", function(event, position) { gotoPosition(position);});
			function showHideArrows() {
				if(t==0) {
					/* erstes Bild */
					$("a","#"+options.prevId).hide();
				} else {
					$("a","#"+options.prevId).show();
				}
				if(t==ts) {
					/* letztes Bild */
					$("a","#"+options.nextId).hide();
				} else {
					$("a","#"+options.nextId).show();
				}
			}
			showHideArrows();
		});
	  
	};

})(jQuery);