/*
 * 	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.mySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			continuous: 		false,
			brows: 		'Firefox'
			
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = "700"; 
			var h = $("li", obj).height(); 
			obj.width($(window).width()); 
			obj.height("365"); 
			obj.css("overflow","hidden");
            //all pictures
			var ts = s-1;
            //current picture
			var i = 0;
            
            //initialize
            $(".right_container", obj).css('margin-left',($(window).width()-300));
            //$(".goright", obj).css('margin-left',($(window).width()-300));
			$("ul", obj).css('width',s*w);			
			$("li", obj).css('float','left');
            $("li", obj).fadeTo(1,0.2);
            
            
            //set the first to active
            $("li:eq(0)", obj).addClass('active');
            $("li.active", obj).fadeTo(1,1);
            
			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);
			};				
			
			 
            //goleft, goright mouseover/out if browser not IE, if IE show the  arrows
			/*if(options.brows!="Internet Explorer"){

                 $('.left_container').mouseover(function(){
    			 $('.goleft').fadeIn(200);
    			});
                
                $('.goleft').mouseout(function(){
    			 $('.goleft').fadeOut(200);
    			});
                
                $('.right_container').mouseover(function(){
    			 $('.goright').fadeIn(200);
    			});
                
                $('.goright').mouseout(function(){
    			 $('.goright').fadeOut(200);
    			});
                 
			}else{
			 
             $('.goleft,.goright').show();
             
			}*/
            
            
            //Left navigation
            $('.goleft').click(function(){
                
               if(i > 0)
                {
                    
                    //alert(i);
                 var current = $('li.active',obj);
                 var next    = $('li:eq('+(i-1)+')',obj);
                 current.fadeTo(1,0.2);
                 //remove active class and set the next to the inaktive
                 current.removeClass('active');   
                 next.addClass('active').fadeTo(1,1.0);
                 
                 i--;
                 //alert(i);
                 $("ul",obj).animate({"margin-left" : (i*w*-1)},500); 
                 
                 
                }else{
                
                 var current = $('li:eq(0)',obj);
                 var next    = $('li:last',obj);
                    
                 current.fadeTo(1,0.2);
                 //remove active class and set the next to the inaktive
                 current.removeClass('active');   
                 next.addClass('active').fadeTo(1,1.0);
                    
                 i=ts;
                 
                 $("ul",obj).animate({"margin-left" : (i*w*-1)},500);   
                  
                    
                }
                
            });
            
            //Left navigation
            $('.goright').click(function(){
                
                
                
                if(i < ts)
                {
                 var current = $('li.active',obj);
                 var next    = $('li.active',obj).next();
                 current.fadeTo(1,0.2);
                 //remove active class and set the next to the inaktive
                 current.removeClass('active');
                 i++;  
                 next.addClass('active').fadeTo(1,1.0);
                 $("ul",obj).animate({"margin-left" : (i*w*-1)},"slow");
                 
                 
                 
                }else{
                
                 var current = $('li.active',obj);
                 var next    = $('li:eq(0)',obj);
                    
                 current.fadeTo(1,0.2);
                 //remove active class and set the next to the inaktive
                 current.removeClass('active');   
                 next.addClass('active').fadeTo(1,1.0);
                    
                 i=0;
                 
                 $("ul",obj).animate({"margin-left" : (i*w*-1)},500);   
                  
                    
                }
               //alert("right"); 
            });
			
			$(window).resize(function(){         
              $(".right_container").css({'margin-left' : ($(window).width()-300)});
              obj.width($(window).width());
            });
			
							
			
		});
	  
	};

})(jQuery);




