$(document).ready(function(){

	$(".menu-bottom").hide();

	$(".menu").hover(function(){
		$(this).find(".menu-top").slideUp("fast");
		$(this).find(".menu-bottom").slideDown("fast");
	});
	
	$(".menu").mouseleave(function(){
		$(this).find(".menu-top").slideDown("fast");
		$(this).find(".menu-bottom").slideUp("fast");
	});

	$("#share img").hover(function(){
		$(this).animate({
			opacity:"1"
		},"fast");
	});
	
	$("#share img").mouseleave(function(){
		$(this).animate({
			opacity:"0.5"
		},"fast");
	});

	var current=1;

	$("#pic2").hide();
	$("#pic3").hide();
	$("#pic4").hide();
	
	$("#prev").animate({opacity:"0"});
	
	$("#next").hover(function(){
		$("#next img").animate({
			opacity:"1"
		},"fast");
	});
	
	$("#next").mouseleave(function(){
		$("#next img").animate({
			opacity:"0.2"
		},"fast");
	});
	
	$("#prev").hover(function(){
		$("#prev img").animate({
			opacity:"1"
		},"fast");
	});
	
	$("#prev").mouseleave(function(){
		$("#prev img").animate({
			opacity:"0.2"
		},"fast");
	});

	
	/*SLIDERFUNC*/
	
	$("#next").click(function(){
		if(current==1){
			$("#pic1").hide();
			$("#pic2").animate({width: 'show'});
			current=2;
			$("#prev").animate({opacity:"1"});
		}
		else if(current==2){
			$("#pic2").hide();
			$("#pic3").animate({width: 'show'});
			current=3;
			$("#next").animate({opacity:"0"});
		}
		
		
	});
	
	$("#prev").click(function(){
		if(current==2){
			$("#pic2").hide();
			$("#pic1").animate({width: 'show'});
			current=1;
			$("#prev").animate({opacity:"0"});
		}
		
		else if(current==3){
			$("#pic3").hide();
			$("#pic2").animate({width: 'show'});
			current=2;
			$("#next").animate({opacity:"1"});
		}
		
	});
	
	/*TESTIFUNC*/
	
	var current2=1;
	
	$("#testimoni2").hide();
	$("#testimoni3").hide();
	
	$("#next2").click(function(){
		if(current2==1){
			$("#testimoni1").hide();
			$("#testimoni2").fadeIn("slow");
			current2=2;
		}
		else if(current2==2){
			$("#testimoni2").hide();
			$("#testimoni3").fadeIn("slow");
			current2=3;
		}
		
		else if(current2==3){
			$("#testimoni3").hide();
			$("#testimoni1").fadeIn("slow");
			current2=1;
		}
		
	});
	
	$("#prev2").click(function(){
		if(current2==1){
			$("#testimoni1").hide();
			$("#testimoni3").fadeIn("slow");
			current2=3;
		}
		
		else if(current2==2){
			$("#testimoni2").hide();
			$("#testimoni1").fadeIn("slow");
			current2=1;
		}
		
		else if(current2==3){
			$("#testimoni3").hide();
			$("#testimoni2").fadeIn("slow");
			current2=2;
		}
	});
	
	var current3=1;
	
	$("#galeri2").hide();
	$("#galeri3").hide();
	
	$("#next3").click(function(){
		if(current3==1){
			$("#galeri1").hide();
			$("#galeri2").fadeIn("slow");
			current3=2;
		}
		else if(current3==2){
			$("#galeri2").hide();
			$("#galeri3").fadeIn("slow");
			current3=3;
		}
		
		else if(current3==3){
			$("#galeri3").hide();
			$("#galeri1").fadeIn("slow");
			current3=1;
		}
		
	});
	
	$("#prev3").click(function(){
		if(current3==1){
			$("#galeri1").hide();
			$("#galeri3").fadeIn("slow");
			current3=3;
		}
		
		else if(current3==2){
			$("#galeri2").hide();
			$("#galeri1").fadeIn("slow");
			current3=1;
		}
		
		else if(current3==3){
			$("#galeri3").hide();
			$("#galeri2").fadeIn("slow");
			current3=2;
		}
	});
	
	$(".box-founder-detail").hide();
	
	$(".box-founder").hover(function(){
		$(this).find(".box-founder-detail").slideDown("fast");
		$(this).find("img").animate({opacity:"1"},"fast");
	});
	
	$(".box-founder").mouseleave(function(){
		$(this).find("img").animate({opacity:"0.5"},"fast");
		$(this).find(".box-founder-detail").slideUp("fast");
	});
	
	$(".box-galeri-content").hover(function(){
		$(this).find("img").animate({opacity:"1"},"fast");
	});
	
	$(".box-galeri-content").mouseleave(function(){
		$(this).find("img").animate({opacity:"0.5"},"fast");
	});
	
	
	$("#galeri-full").hide();
	
	$(".box-galeri-content").click(function(){
		
		var cur_img = $(this).find("img").attr("src");
		$('#galeri-full-img').attr("src",cur_img);
		$("#galeri-full").fadeIn("fast");
	});
	
	$(".close").click(function(){
		$("#galeri-full").fadeOut("fast");
	});
	
	$(".produk-desk").hide();
	
	$(".produk-content").hover(function(){
		$(this).find(".produk-judul").slideUp("fast");
		$(this).find(".produk-desk").slideDown("fast");
	});
	
	
	$(".produk-content").mouseleave(function(){
		$(this).find(".produk-desk").slideUp("fast");
		$(this).find(".produk-judul").slideDown("fast");
	});
	
	$(".hidden-info").hide();
	
	$(".tanda-tanya img").hover(function(){
		$(this).parent().parent().find(".hidden-info").fadeIn("fast");
	});
	
	$(".field input").focus(function(){
		$(".hidden-info").hide();
		$(this).parent().parent().find(".hidden-info").fadeIn("fast");
	});
	
	$(".field textarea").focus(function(){
		$(".hidden-info").hide();
		$(this).parent().parent().find(".hidden-info").fadeIn("fast");
	});
	
	$(".tanda-tanya").mouseleave(function(){
		$(this).parent().parent().find(".hidden-info").fadeOut("fast");
	});
	
	
});

function slidePress() {
	if(current==1){
		$("#next").click(function(){
			$("#pic1").hide("slow");
			$("#pic2").show("slow");
			current=2;
		});
		$("#prev").click(function(){
			$("#pic1").hide("slow");
			$("#pic4").show("slow");
			current=4;
		});
	}
	
	else if(current==2){
		$("#next").click(function(){
			$("#pic2").hide("slow");
			$("#pic3").show("slow");
			current=3;
		});
		$("#prev").click(function(){
			$("#pic2").hide("slow");
			$("#pic1").show("slow");
			current=1;
		});
	}
	
	else if(current==3){
		$("#next").click(function(){
			$("#pic3").hide("slow");
			$("#pic4").show("slow");
			current=4;
		});
		$("#prev").click(function(){
			$("#pic3").hide("slow");
			$("#pic2").show("slow");
			current=2;
		});
	}
	
	else if(current==4){
		$("#next").click(function(){
			$("#pic4").hide("slow");
			$("#pic1").show("slow");
			current=1;
		});
		$("#prev").click(function(){
			$("#pic4").hide("slow");
			$("#pic3").show("slow");
			current=3;
		});
	}
	
}


function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	
	
}
