// JavaScript Document
$(document).ready(function(){
	//fancyBox setup
	$(".boxes").fancybox();
	$('#fancybox-wrap').css({
	  top: '500',
	  left: '500'
	});
	
	//project setup
	$(".image").fadeTo(0,0).hide();
	$(".projekt").css("background-color","transparent");
	$(".text").hide();
	$(".title").css("width","139px");
	$(".close").hide();
	
	//close a project
	var isActive = false;
	function closeIt(el){
			if(!isActive){
				isActive = true;
				el.parent().css("background-color", "transparent");
				el.animate({width: "139px"},200);
				el.find(".text").fadeOut(50);
				el.find(".close").hide(200);
				el.next().fadeTo(200,0, function(){
						el.next().slideUp(300);
						el.removeClass("openTitle");
						isActive = false;
					});
			}
		}
	//open a project
	function openIt(el){
		if(!isActive){
				isActive = true;
				el.addClass("openTitle");
				el.parent().css("background-color", "#fff");
				el.animate({width: "436px"},400);
				el.find(".text").delay(400).fadeIn(500);
				el.find(".close").show(400);
				el.next().slideDown(400, function(){
					el.next().fadeTo(600, 1);
					isActive = false;
					});
		}	
		}
	//toggle open/close project
	$(".title").click(function(){
		if($(this).next().is(":visible")){
			closeIt($(this));
		}else{
			openIt($(this));
		}
		});//end Click
		
	$(".thumb").click(function(){
		if($(this).parent().find(".image").is(":visible")){
			closeIt($(this).next());
		}else{
			openIt($(this).next());
		}
		});//end Click
	
	//show hover style even when mouse-over the thumb
	$(".thumb").hover(function(){
			//switch on hover
			$(this).parent().find(".title").addClass("openTitle");
		}, function(){
			//dont switch if open!
			if($(this).parent().find(".image").is(":hidden")){
				$(this).parent().find(".title").removeClass("openTitle");
			}
			});
	//image-hover closeButton
	$(".title, .thumb").hover(function(){
			$(this).parent().find(".close img").attr("src","images/schliessen_aktiv.png");
		}, function(){
			$(this).parent().find(".close img").attr("src","images/schliessen_inaktiv.png");
			});
	
	});
