
$(document).ready(function() {

$("#contact").hide();
$("#message").hide();

// Set references
  var references = [];
   references["aimshop"] = 3;
   references["ifv"] = 3;
   references["pokernationen"] = 3;
   references["mertz"] = 2;
   references["salonnews"] = 3;
   references["titties"] = 2;
   references["whoa"] = 3;

// Set variables
  var textbox = "#refinfoText";
  var startRef = "aimshop";
  var getattRef = startRef;
  
	$.fn.setReferenceText = function(getDiv, getReference, action) {		
		if(action == true) {
			$(getDiv).load("getReferences.php?ref=" + getReference).show();
		} else {
			$(getDiv).load("getReferences.php?ref=" + getReference);
		}			
	}
	
	$.fn.setAttr = function(getRef) {		
			return getRef;
	}
    
 // Ref small thumbs
   var divActive = "<div class='active'></div>";
   var classHover = "<div class='hover'></div>";
   var classActive = "<div class='active'></div>";
   
    $("div.thumb").append(classHover);
    $("div.thumb").append(classActive);

	$("div.thumb").children("img").mouseover(function() { // Mouseover-effekt p� thumbs
		
		$(this).parent().children("div.hover")
			.stop()
			.css({"display": "none", "opacity": "0.2", "background": "#FFFFFF"})
			.fadeIn(250);
			
	});
	
	
	$("div.thumb").children("img").mouseout(function() { // Mouseout-effekt p� thumbs
			
		$(this).parent().children("div.hover")
			.fadeOut("slow");				
	});
	
		
	$("div.thumb").children("img").click(function() { // Klik p� thumb
		
		if($("#contactButton").attr("class") == "clicked"){
			$("#contactButton").removeAttr("class");
			$("#containerReferences").animate({marginLeft: 0 }, function(){ $("#contact").hide(); });
		}
		
		var attRef = $(this).attr("alt");		
		var getattRef = $().setAttr(attRef);

			$().setReferenceText(textbox, getattRef, false);

		$("div.active").fadeOut("slow");

	
		$(this).parent().children("div.active")
			.stop()
			.css({"display": "none", "opacity": "0.5", "background": "#FFFFFF"})
			.fadeIn(250);
				
		var templateRef1 = '<div id="refinfoLayer"><div id="refinfoIcon">mere info</div><div id="refinfoText"></div></div>';
		var	templateRef2 = '<div id="slider"><ul id="reflist"></ul></div>';
		
		$("slider").animate({opacity: 0},1000);
		$("#slider").html(templateRef1 + templateRef2);		
		
		
		$("#slider ul").animate({ opacity: 0 }, 1, 
		
				function() { // Skift forreste reference-billede
						
						$("#slider ul").css("margin","0px");
						$("#slider").css("margin","1px");
						
						
						var refHTML = "<li><img src='images/ref/" + attRef + "/1.png' alt='" + attRef + "' /></li>";
						$("#slider ul").html(refHTML).animate({ opacity: 1 }, 1000, 
						
								function() { // Inds�t dias-liste
									
									var i = 2;
									for($i = 2; $i <= references[attRef]; $i++){
										
										var refHTMLlist = "<li><img src='images/ref/" + attRef + "/" + i++ + ".png' alt='' /></li>";																					
										$("ul#reflist").append(refHTMLlist);										
									}
									$("#slider").easySlider();
									
								});
						
				});	
		
	});	
	
	
	$("#refinfoIcon").live('click',function () {
			var layer = "#refinfoLayer";
			var icon = "#refinfoIcon";
			var textbox = "#refinfoText";

			var textInformation = "mere info";
			var textClose = "luk";

			var folded = $(this).html();
			var attRefli = $("#slider ul li img").attr("alt");
		
			if(folded == textInformation) {
				
				  $(layer).animate( 
					  { marginLeft: 12 }, 
					  500, 'easeInCubic', 
					  function() { $(icon).fadeOut(); }
				  ).animate( 
					  { width: 764, height: 229 }, 
					  1200, 'easeInCubic', 
					  function() { 
						  $(icon).html(textClose).fadeIn(); 
						  
							$().setReferenceText(textbox, attRefli, true);
							
					  }
				  );
				  
			} else {

				  $(textbox).hide();
				  $(layer).animate( 
						  { width: 23, height: 23 }, 
						  500, 'easeInCubic', 
						  function() { 							
							$(icon).fadeOut(); 							
						  }
					  ).animate( 
						  { marginLeft: 756 }, 
						  1200, 'easeInCubic', 
						  function() { 
							$(layer).animate(
								       { width: 66, marginLeft: 711 },
								       500, 'easeInCubic',
			                                               function() {
										$(icon).html(textInformation).fadeIn();
							               });
							 
						  }
					  );
				
			}
	
	});


	$("#contactButton").click(function() {
				
		if($(this).attr("class")){
		  $(this).removeAttr("class");
		  $("#containerReferences").animate({marginLeft: 0 }, function(){ $("#contact").hide(); });
        
		} else {
		  $(this).attr("class","clicked");
		  $("#containerReferences").animate({marginLeft: -950 });
		  $("#contact").show();
		}
		

	});

	$("input").click(function() {
		$("input").removeClass("hover");
		$("textarea").removeClass("hover");
		$(this).addClass("hover");

			var fieldvalue = $(this).val();

if(fieldvalue == "Navn"){
	$(this).val("");
}
if(fieldvalue == "Email") {
	$(this).val("");
}
if(fieldvalue == "Telefon") {
	$(this).val("");
}

$("input").blur(function() {
	if($(this).val() == ""){
		$(this).val( $(this).attr("id") );
	}
});


	});

	$("textarea").click(function() {
		$("input").removeClass("hover");
		$("textarea").removeClass("hover");
		$(this).addClass("hover");
	});


        $(document).ready(function() { 
            $('#myForm').ajaxForm(function() { 
                $("#message").html('Din besked er nu sendt');
		$("#message").fadeIn();
		
            }); 
        });
    
});
