	var currentPosition = 0;
	var slideWidth = 858;
	var slides;
	var numberOfSlides;
	var arrive;
	var description_txt= new Array();
	$(document).ready(function() {
		 
		slides = $('.slide');
				
		numberOfSlides = slides.length;
		
		tool_tip= new Array();
		
		slides.each(function(index){
			
			tool_tip[index]=$(this).attr('title');
			
		});
		
		$("#slide_inner").css("width",slideWidth*numberOfSlides);
		slides.css("width",slideWidth);
		
		setTimeout(slideshow, 20000);
		
		//next
		$("#nav_next").click(function(){
							
			if(currentPosition==numberOfSlides-1)		
			{
				arrive=numberOfSlides-1;
				currentPosition=0
			}
			else
			{
				arrive=0;
				currentPosition++;
			}
			
			setup_tooltip();
			
			
			$("#slide_inner").animate({
			      'marginLeft' : slideWidth*(-currentPosition)
			});
			 
						
			return false;
		});
				
		//prev	
		$("#nav_prev").click(function(){
			
			
			//console.log("FIRST:"+currentPosition);
			if(currentPosition<=0)		
			{
				currentPosition=numberOfSlides-1;
			}
			else
			{
				currentPosition--;
			}

			
			setup_tooltip();
			
			//console.log("LAST:"+currentPosition);
			$("#slide_inner").animate({
			      'marginLeft' : slideWidth*(-currentPosition)
			});
			 
			
						
			return false;
		});
		
		
		
		/// TIP

		
		$("#nav_next").hover(function(){
			
					
			//this.title = "";
			var $tip = $('#right_tip');
			var $tipInner = $('#right_tip .tipMid');
			var $this = $(this);
			var tTitle = $this.attr("title");
			var offset = $(this).offset();
			var tLeft = offset.left;
			
			var tTop = offset.top;
			var tWidth = $this.width();
			var tHeight = $this.height();
			
			$tipInner.html(tTitle);
			
			var topOffset = $tip.height();
			var xTip = (tLeft-30)+"px";
			var yTip = (tTop-topOffset-60)+"px";
			$tip.css({'top' : yTip, 'left' : xTip});
			//$tip.fadeIn();
			$tip.animate({"top": "+=20px", "opacity": "toggle"}, 300);
			
			
		},function() {
			$('#right_tip').hide();
		});
		
		
		$("#nav_prev").hover(function(){
			
				var $tipInner = $('#left_tip .tipMid');
				var $this = $(this);
				
				var tTitle = $this.attr("title");
				var offset = $(this).offset();
				var tLeft = offset.left;
				
				var tTop = offset.top;
				var tWidth = $this.width();
				var tHeight = $this.height();
				
				$tipInner.html(tTitle);
				
				var topOffset = $('#left_tip').height();
				var xTip = (tLeft-30)+"px";
				var yTip = (tTop-topOffset-60)+"px";
				
				$('#left_tip').css({'top' : yTip, 'left' : xTip});
				
				$('#left_tip').animate({"top": "+=20px", "opacity": "toggle"}, 300);	
					
		},function() {
			$('#left_tip').hide();
		});
		
		
		$("#slide_open").click(function(){
			var slideshow=$("#slideshow").html();
			$("#slideshow").jqbox({
			html:slideshow,
			width:448,
			height:448	
			});
			$(".jqbox_close").attr("src", "<?=bloginfo('template_url')?>/images/fancy_closebox.png")
			return false;
		});
		
	});
	
	
	function slideshow()
		{
		
						
			if(currentPosition==numberOfSlides-1)		
			{
				currentPosition=0
			}
			else
			{
				currentPosition++;
			}
		
			
			//console.log(tool_tip[currentPosition]);
			
			setup_tooltip();
			
			$("#slide_inner").animate({
			      'marginLeft' : slideWidth*(-currentPosition)
			    });
			 
			
			setTimeout(slideshow, 20000); 
		}
	
	
	
	function setup_tooltip()
	{
		if(currentPosition==numberOfSlides-1)
		{
			$("#nav_next").attr("title", tool_tip[0]);
		}
		else
		{
			$("#nav_next").attr("title", tool_tip[currentPosition+1]);
			
		}

		if(currentPosition-1<0)
		{
			$("#nav_prev").attr("title", tool_tip[numberOfSlides-1]);
		}
		else
		{
			$("#nav_prev").attr("title", tool_tip[currentPosition-1]);
		}
		
		$('#right_tip .tipMid').html($("#nav_next").attr("title"));
		$('#left_tip .tipMid').html($("#nav_prev").attr("title"));
	}

