var play=0;
var counter=1;

jQuery().ready(function(){

			$(".left_menu_green_slide").next("div").hide();
			
			$(".inside_slideshow").attr('style', 'visibility:visible;')
			$(".inside_slideshow").hide();
			
			
			$(".left_menu_green_slide").mouseenter(function(){
				$(this).next("div").slideDown();
				$(this).find("img").attr('src', './images/button-up.png');
			});
			
			$("#left").mouseleave(function(){
					$(".left_menu_green_slide").next("div").slideUp();
					$(".left_menu_green_slide").find("img").attr('src', './images/button-down.png');
				});
			
			
			
			for (i=1; i<=8; i++)
			{
				$("#cat"+i).fadeIn(i*300);
			}
			
			$(".category").mouseenter(function(){
				$(this).fadeTo("normal", 0.7);
			});
			
			$(".category").mouseleave(function(){
				$(this).fadeTo("normal", 1);
			});
			
			
			
			$(".inside_slideshow_active").mouseenter(function(){
				$(this).find("div").animate({
					height: 310,
				}, 1000, function(){$(".down-arrow").show(); $(".up-arrow").show();});
			});
			
			$(".inside_slideshow_active").mouseleave(function(){
				$(".down-arrow").hide();
				$(".up-arrow").hide();
				$(".description_text").scrollTo(0,800);
				$(this).find("div").animate({
					height: 80
				}, 1000);
			});
			
			$(".inside_slideshow").mouseenter(function(){
				$(this).find("div").animate({
					height: 310,
				}, 1000, function(){$(".down-arrow").show(); $(".up-arrow").show();});
			});
			
			$(".inside_slideshow").mouseleave(function(){
				$(".down-arrow").hide();
				$(".up-arrow").hide();
				$(".description_text").scrollTo(0,800);
				$(this).find("div").animate({
					height: 80
				}, 1000);
			});
			
			
			
			
			$(".down-arrow").click(function(){
				$(".description_text").scrollTo({top:'+=100px', left:'+=0px'},800);
			});
			
			$(".up-arrow").click(function(){
				$(".description_text").scrollTo({top:'-=100px', left:'+=0px'},800);
			});
			
			
			
			
			$("#play").click(function(){
				if (play==1)
				{
					play=0;
					$("#play-button").attr('src', './images/button.png');
				}
				else
				{
					play=1;
					$("#play-button").attr('src', './images/pause.png');
				}
					
			});
			
			$("#next").click(function(){
									  
				play=0;
				counter++;
				$("#play-button").attr('src', './images/button.png');
				var $active = $('#slideshow DIV.inside_slideshow_active');

				if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
			
				if ($active.next().length)
				{
					$next = $active.next();
				}
				else
				{
					$next = $('#slideshow DIV:first')
					counter = 1;
				}
			
				$active.addClass('inside_slideshow_last_active');
				$(".inside_slideshow_last_active").fadeOut("slow");
				
				document.getElementById("counter").innerHTML =counter;
				
				$next.css()
					.addClass('inside_slideshow_active')
					.fadeIn("slow", function() {
						$active.removeClass('inside_slideshow_active inside_slideshow_last_active');
					});	
				
			});
			
			$("#previous").click(function(){
									  
				play=0;
				counter--;
				$("#play-button").attr('src', './images/button.png');
				var $active = $('#slideshow DIV.inside_slideshow_active');

				if ( $active.length == 0 ) $active = $('#slideshow DIV:first');
				
				if ($active.prev().length)
				{
					$prev = $active.prev();
				}
				else
				{
					$prev = $('#slideshow DIV.inside_slideshow:last')
					counter = document.getElementById("total").innerHTML;
				}
			
				$active.addClass('inside_slideshow_last_active');
				$(".inside_slideshow_last_active").fadeOut("slow");
				
				document.getElementById("counter").innerHTML =counter;
				
				$prev.css()
					.addClass('inside_slideshow_active')
					.fadeIn("slow", function() {
						$active.removeClass('inside_slideshow_active inside_slideshow_last_active');
					});	
				
			});
			
	});



function slideSwitch() {
	if (play==1)
	{ 
		counter++;
		var $active = $('#slideshow DIV.inside_slideshow_active');
	
		if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
		
		if ($active.next().length)
		{
			$next = $active.next();
		}
		else
		{
			$next = $('#slideshow DIV:first')
			counter = 1;
		}
			
	
		$active.addClass('inside_slideshow_last_active');
		$(".inside_slideshow_last_active").fadeOut("slow");
		
		document.getElementById("counter").innerHTML =counter;
	
		$next.css()
			.addClass('inside_slideshow_active')
			.fadeIn("slow", function() {
				$active.removeClass('inside_slideshow_active inside_slideshow_last_active');
			});
	}
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});
