(function($){

	$.glassSlidy = {
		themeDir : '',
		
		navjump  : function(li) {	
	        $('#descriptions li').fadeOut(100).eq(li).fadeIn(800);
	        if (li>id){
			    // move right
				shift =	li-x-3;
				
				if (shift>0){
					$.glassSlidy.shiftslider(shift)
					x=x+shift;
				}else{
					$.glassSlidy.normalslide();
				}
				id=li;	
			
			}else{
			   // go left
				shift = li-x;
			
				if (shift<0){
					$.glassSlidy.shiftslider(shift)
					x=x+shift;
				}else{
					$.glassSlidy.normalslide();
				}
					
				id=li;	
			}
		},
		
		shiftslider : function(shift) {
	
			if (shift<0){
				shift = -shift;
				operator = '+';
				$('.glass').animate({
				    left: 0
			    }, 300); 
				i=0;
				
			}else{
				operator = '-';
				$('.glass').animate({
				    	left: 675
				  }, 300); 
				i=3;
			}
			
			$('.test').animate({
				left: operator+'='+shift*225
			}, 300); 
		},
		
		normalslide : function() {

			var newi = i+li-id;
			i=newi;	
			$('.glass').animate(
			     {left: newi*225},
			     300
			); 	  
			newi=0;
		},

		slidy : function (direction) {
			operator = (direction=='right') ? '-' : '+'
				
			$('.glass').animate({
		    	left: operator+'=225'
		    }, 300); 
		},
		
		backslide : function (sliderdirection) {
			operator = (sliderdirection=='right') ? '+' : '-'
			$('.test').animate({
		    	left: operator+'=225'
		    }, 300); 
		},
		
		next : function (max) {
			if (id<max) {
			
				id++;
				$('#descriptions li').fadeOut(100).eq(id).fadeIn(800);
					
				if (i==3) {
					$.glassSlidy.backslide('left')
					x++
				} else {
					$.glassSlidy.slidy('left');
					i++
				} 
	
			 } else {
				$('.next').effect("bounce", { times:3 }, 200);
			 }	
		},
		
		previous : function() {

			if (id>0) {
			
				id--;
		
				$('#descriptions li').fadeOut(100).eq(id).fadeIn(800);
						
				if (i==0) {
					$.glassSlidy.backslide('right')
					x--;
				} else {
					$.glassSlidy.slidy('right');
					i--;
				}	
								   			
			}else{
				$('.previous').effect("bounce", { times:3 }, 200);
			}	
		
		 },
		 
		 buttons : function() {

			if (id==0){
				$('.previous').css("background-image", "url("+ $.glassSlidy.themeDir +"/images/left_arrow.png)"); 
			}else{	
				$('.previous').css("background-image", "url("+ $.glassSlidy.themeDir +"/images/left_arrow_bright.png)"); 
			}
			
			if (id==max){
				$('.next').css("background-image", "url("+ $.glassSlidy.themeDir +"/images/right_arrow.png)"); 
			}else{	
				$('.next').css("background-image", "url("+ $.glassSlidy.themeDir +"/images/right_arrow_bright.png)"); 
			}
		
		}

	}
})(jQuery);

