$(function() {

	Cufon.replace("h1");
	Cufon.replace("h2");
	
	$("#nav > li[class!=active] > ul").hide();
	
	$("#nav > li > a").click(function() {
	
		if($(this).parent().attr("class") == "active") {
			
			$(this).parent().removeClass("active");
			$(this).next().slideUp(500);
			
		}
		else{
			
			if($(this).next().size())
				$(this).parent().addClass("active");
			$(this).next().slideDown(500);
		
		}
		
		if($(this).next().size()) {
			return false;
		}
		
	});

	if($("#visual").size()) {

		$("#visual > ul[id=show] > li:not(#visual > ul[id=show] > li:first)").hide();
		$("#thumbLay a:first").addClass("active");
		var visualShow = $("#visual > ul[id=show] > li:first");
		var prevVisualShow;
			
			function showSlide(slideIndex) {
				
				visualShow.fadeOut(500);
				prevVisualShow = visualShow;
				visualShow = $("#visual > ul[id=show] > li:eq(" + slideIndex + ")");
				if(visualShow.size() == 0)
					visualShow = $("#visual > ul[id=show] > li:last");
				visualShow.fadeIn(500);
				
			}
			
			var i = 0;
			$("#thumbLay a").click(function() {
				
				if($(this).attr("class") != "active") {
				
					$("#thumbLay a").removeClass("active");
					$(this).addClass("active");
					showSlide($("#thumbLay a").index(this));
				
				}
				
				return false;
				
			});
			
			function setThumbActive(slideIndex) {
				
				$("#thumbLay a").removeClass("active");
				$("#visual > ul[id=thumbLay] > li:eq(" + slideIndex + ") a").addClass("active");
			
			}
			
			$("#visual .left").parent().click(function() {
				
				visualShow.fadeOut(500);
				prevVisualShow = visualShow;
				visualShow = visualShow.prev();
				if(visualShow.size() == 0)
					visualShow = $("#visual > ul[id=show] > li:last");
				visualShow.fadeIn(500);
				
				setThumbActive($("#show li").index(visualShow));
				
				return false;
			
			});
			
			$("#visual .right").parent().click(function() {
				
				visualShow.fadeOut(500);
				prevVisualShow = visualShow;
				visualShow = visualShow.next();
				if(visualShow.size() == 0)
					visualShow = $("#visual > ul[id=show] > li:first");
				visualShow.fadeIn(500);
				
				setThumbActive($("#show li").index(visualShow));
				
				return false;
				
			});
	
	}

	$("#language img").hover(function() {
		
			$(this).attr("src", $(this).attr("src").replace(".png", "_hover.png"));
		
	}, function() {
	
			$(this).attr("src", $(this).attr("src").replace("_hover", ""));
	
	});
	
	$("#language img").each(function () {
		
		if($(this).attr("src").match("_hover"))
			$(this).unbind("mouseover").unbind("mouseout");
	
	});

});