$(document).ready(function()
	{	
	
	
		
		$.fn.vAlign = function() {
			return this.each(function(i){
			var h = $(this).height();
			var oh = $(this).outerHeight();
			var mt = (h + (oh - h)) / 2;	
			$(this).css("margin-top", "-" + mt + "px");	
			$(this).css("top", "50%");
			$(this).css("position", "absolute");	
			});	
		};
		
		$('#rotator').cycle({
			fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			speed: 4000 
		});

		
		
	
		$("#home_image").css("display", "none");
		
		$("#home_image").show( "drop", 
                      {direction: "right"}, 1500 );
                      
        $("#menu").css("display", "none");
		
		$("#menu").show( "slide", 
                      {direction: "right"}, 1500 );
                      
        /*$("#logo").css("display", "none");
		
		$("#logo").show( "slide", 
                      {direction: "left"}, 1500 );  */                          
		
		$(".menu, .port_menu").fadeTo(1, 0.4);
		
		$("#social_icns a img").fadeTo(1, 0.7);
		
		$("#info_panel").show( "fold", 
                      {direction: "bottom"}, 1500 );
	
	

    	$("#illustration").click(function()
    	{
    	
    		
    		$("#right").html("");
    		
    	});
    	
    	$('#illustration').one('click', function() 
    	{
  			showUser(lifestyle);
		});
    	
    	
    		
    		$("input, textarea").not("#send_form").hover
	(
	
		function () //on mouseover fade to 1
		{
			$(this).css("background-color", "#eee");
	   	    	
		}, 
		
		function () //on mouse out fade to 0.7
		{
			$(this).css("background-color", "#fff");
		}
		
	);

	$("input, textarea").not("#page3 form #send").focus(function()
    {
    
   		$(this).val("");
    
    });	
		$("#send_form").click(function()
	    {
    
	    	var name = $("#name").val();
	    	var email = $("#email").val();
	    	var message = $("#message").val();
	    	var subject = $("#subject").val();
	    	var telephone = $("#telephone").val();
			
				var dataString = "name=" + name + "&email=" + email + "&message=" + message + "&telephone=" + telephone + "&subject=" + subject;
    	
		    	$.ajax(
		    	{
		    		type: "POST",
		    		url: "php/send_mail.php",
		    		data: dataString,
		    		success: function()
		    		{
		    			$("#message_pop").fadeIn(300).delay(4000).fadeOut(2000);
		    			
					}
				});
    		
    
    		return false;
    	});
		
	
	 		
	
		$("#logo").toggle
		(
      		function () {
       			 $("#info_panel").hide( "fold", 
                      {direction: "bottom"}, 1500 );
     		 },
     		 function () {
       			 $("#info_panel").show( "fold", 
                      {direction: "bottom"}, 1500 );
    	  }
    	  
    	  );
		
		$("#social_icns a img").hover
		(
		  	function () //on mouseover fade to 1
		  	{
		    	$(this).fadeTo(500, 1);
		    
		    	
		  	}, 
		 	function () //on mouse out fade to 0.7
		 	{
		   		 $(this).fadeTo(500 , 0.7); 
		  	}
		);
		
		
		$(".menu").hover
		(
		  	function () 
		  	{
		    	$(this).fadeTo(500, 1);
		    	
		    
		    	
		  	}, 
		 	function () 
		 	{
		   		 $(this).fadeTo(500 , 0.6); 
		  	}
		);
		
		$(".port_menu").hover
		(
		  	function () 
		  	{
		    	$(this).fadeTo(500, 1);
		    	$(this).css("color" , "#f355a4");
		    
		    	
		  	}, 
		 	function () 
		 	{
		   		 $(this).fadeTo(500 , 0.6);
		   		 $(this).css("color" , "#000");
		   		 
		   		 
		  	}
		);
		
		$("#port_menu a").click(function()
		{
		
			//Clear container
			$("#right").html("");
		
		});
		
		$("#link_list a").hover
		(
		  	function () 
		  	{
		    	$(this).css("font-weight", "bolder");		    	
		    
		    	
		  	}, 
		 	function () 
		 	{
		   		 $(this).css("font-weight", "500");
		  	}
		);
			
	});
	
function thumb(){
	$("#txtHint img").hover(
	  function () {
		$("#txtHint img").not(this).fadeTo(1,0.5);	
	  },
	  function () {
		  $("#txtHint img").fadeTo(1,1);
	  }

	);
	

}	
 	$("#txtHint img").live("click",function()
	{
			
		//store image SRC
		var img_name = $(this).attr("src");
		var img_desc = $(this).attr("alt");
		var img_alt = $(this).attr("desc");
		

		var section = $("head").attr("section");
		
		//store index of /
		var last = img_name.lastIndexOf('/');
		
		//store image name length
		var length = img_name.length;
		
		//create substring
		var img_name = img_name.substr(last+1, length  );
		
		//create final image src
		var large_image = 'images/' + section + '/full/' + img_name;
	  	
	  	//insert image html to container
	  	$("#right").html("<p class='caption'><img src='" + large_image + "'/><span><big>" + img_desc + "</big>" + img_alt + "</span></p>");
	  	
	  	  	
	 	
	  	$('#right img').load(function() 
	  	{
  			
			
			$("p.caption").each(function()
			{
			$(this)
				// Add the following CSS properties and values
				.css({
					 // Height equal to the height of the image
					"height" : $(this).children("img").height() + "px",
					// Width equal to the width of the image
					"width" : $(this).children("img").width() + "px"
				})
				// Select the child "span" of this p.caption
				// Add the following CSS properties and values
				.children("span").css(
	
					// Width equal to p.caption
					// But subtract 20px to callibrate for the padding
					"width", $(this).width() - 20 + "px")
	
				// find the <big> tag if it exists
				// And then add the following div to break the line
				.find("big").after('<div class="clear"></div>');
	
				// When you hover over p.caption
				$("p.caption").hover(function()
				{
	
					// Fade in the child "span"
					$(this).children("span").stop().fadeTo(400, 1);
					}, function(){
					// Once you mouse off, fade it out
					$(this).children("span").stop().delay(600).fadeOut(400);
				});
	
			});
			checkHeight();
		});
	  	
	});
	
	
function navigate_to_advertising()
{

	$("#illustration").click();
	$("#advertising").click();
	
}

function navigate_to_fashion()
{

	$("#illustration").click();
	$("#fashion").click();
	
}

	

function theRotator() {

	
	//Set the opacity of all images to 0
	$('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',5000);
	
}

// Rotate

function rotate() 
{	
	//Get the first image
	var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
	
	//Set the fade in effect for the next image, the 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');
	
	
}


//Check Height

function checkHeight()
{


		
		var img_height = $("#right img").height();
		
	  	//set image to display:none - ready for fade in
	  
	  	if(img_height < 393)
		{
			
			$("p.caption").vAlign();
		
		}
		
		
		
		

}






	
	function showUser(str)
	{

		var str = $(str).attr('id');
		
		var section = str;
		
		$("head").attr("section", section);
		
		
		
		
		if (str=="")
		{
		  document.getElementById("txtHint").innerHTML="";
		  return;
		} 
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		}
		else
		{	
		  // code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function()
		{
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		  {
		  		if(str == "fashion" || str == "lifestyle" || str == "advertising")
		  		{
		  		
		  				$("#images_counter").html("");
		  				$("#txtHint").html(xmlhttp.responseText);
			
				  	 $("#txtHint").css("display", "hidden");
				  	 $("#txtHint").show( "slide", 
		                      {direction: "left"}, 600 );
		  		  		  $("#txtHint a").quickpaginate({ perpage: 9, showcounter: true, pager : $("#images_counter") });
						thumb();
		  		}
		  		
		  		else
		  		{
		  				$("#images_counter").html("");
					  $("#txtHint").html(xmlhttp.responseText);
			
				  	 $("#txtHint").css("display", "hidden");
				  	 $("#txtHint").show( "slide", 
		                      {direction: "left"}, 600 );
		                      thumb();
		                      
                      
                  }    
		  }
		}
		xmlhttp.open("GET","php/showimg_live.php?q="+str,true);
		xmlhttp.send();
	}

