(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

jQuery.preLoadImages("img/blueprint_bg.png","img/blueprint_strapline.png","img/dotted_line.png","img/step_1.png", "img/step_2.png", "img/step_3.png", "img/step_4.png");

$(document).ready(function() {

	$("#lets_work_together").fadeIn('fast', function(){
		$("#lets_work_together").addClass('animated').addClass('bounce');
	});
	/*
$("#strapline").fadeIn('slow',function(){
		$("#step_1").fadeIn(1000, function(){
			$("#step_2").fadeIn(1000, function(){
				$("#step_3").fadeIn(1000, function(){
					$("#step_4").fadeIn(1000, function(){
						$("#dotted_line").animate({ width:'977' },2500,function(){
							$("#lets_work_together").fadeIn('fast', function(){
							$("#lets_work_together").addClass('animated').addClass('bounce');
						})
						});
					});
				});
			});
		});
	});
*/
	
	$("#newsletter_signup").bind('focus', function(){
		if($("#newsletter_signup").val()=="Enter your email to keep in touch"){
			$("#newsletter_signup").val('');
		}
	});
	$("#newsletter_signup").bind('blur', function(){
		if($("#newsletter_signup").val()==""){
			$("#newsletter_signup").val('Enter your email to keep in touch');
		}
	});
	
	$("#close_message").bind('click', function(){
		$(".success_message").fadeOut();
		$(".error_message").fadeOut();
	});
});

function contact(){
	if($("#contact_icon").attr('src')=="img/talk_to_us.png"){
		$("#form_only").css('left','0');
		$('#contact_form').animate({ height:'420px' }, function(){
			$('#contact_holder').fadeIn();
		} );  
		$("#contact_icon").attr('src','img/scrap_that.png');
	}else{
		$('#contact_holder').fadeOut();
		$('#contact_form').animate({ height:'0' });  
		$("#contact_icon").attr('src','img/talk_to_us.png');
	}
}

function send_contact(){
	$("#send_contact_btn").html('Sending…');
	var interest = $("#contact_interest").val();
	var name = $("#contact_name").val();
	var email = $("#contact_email").val();
	var tel = $("#contact_tel").val();
	var comments = $("#contact_comments").val();
	$.post("scripts/ajax-calls.php", { action:'sendContact', interest:interest, name:name, email:email, tel:tel, comments:comments }, function(data){
		if(data==1){
			$("#form_only").animate({ left: '-600px'});
			$("#send_contact_btn").html('Submit query');
			$("#contact_interest").val('');
			$("#contact_name").val('');
			$("#contact_email").val('');
			$("#contact_tel").val('');
			$("#contact_comments").val('');
		}
	});	
}

function project(id){
	$('div[rel*="intro"]').stop(true, true).fadeIn();
	$('div[rel*="intro"]').fadeOut('fast', function(){
		$("#slider_holder").addClass('slider-wrapper').addClass('theme-orman');
	});
	if( $('.error_message').is(':visible') || $('.success_message').is(':visible')) {
		$(".success_message").hide();
		$(".error_message").hide();
		$("#helpto").css('margin-top','0');
		$("#poet").css('margin-top','0');
		$("#local_account").css('margin-top','0');
	}
	$("#project_content").html($("#"+id+"_content").html());
	$("#lets_work_together").fadeOut();
	switch(id){
	
	case 'helpto':
	$("#slider_holder").html('<div id="slider" class="nivoSlider" style="display:none; width:975px; height:349px; top:1px; left:1px"><img src="img/helpto_1.jpg" alt="" /><img src="img/helpto_2.jpg" alt="" /><img src="img/helpto_3.jpg" alt="" /></div>');
	$("#poet").animate({ 
		opacity: 0,
    	left: '1000'
	});
	$("#local_account").animate({ 
		opacity: 0,
    	left: '1200'
	}, function(){
		$("#project_content").fadeIn('slow');
	});
	break;
	
	case 'poet':
	$("#slider_holder").html('<div id="slider" class="nivoSlider" style="display:none; width:975px; height:349px; top:1px; left:1px"><img src="img/poet_1.jpg" alt="" /><img src="img/poet_2.jpg" alt="" /></div>');
	$("#helpto").animate({ 
		opacity: 0,
    	left: '-600'
	});
	$("#poet").animate({ 
    	left: '50'
	});
	$("#local_account").animate({ 
		opacity: 0,
    	left: '1200'
	}, function(){
		$("#project_content").fadeIn('slow');
	});
	break;
	
	case 'local_account':
	$("#slider_holder").html('<div id="slider" class="nivoSlider" style="display:none; width:975px; height:349px; top:1px; left:1px"><img src="img/local_account_1.jpg" alt="" /></div>');
	$("#helpto").animate({ 
		opacity: 0,
    	left: '-800'
	});
	$("#poet").animate({ 
    	left: '-400'
	});
	$("#local_account").animate({ 
    	left: '50'
	}, function(){
		$("#project_content").fadeIn('slow');
	});
	break;

	}
	$('#slider').nivoSlider({
		pauseTime: 5000,
		effect: 'slideInLeft',
		directionNavHide: false,
		captionOpacity: 0,
	    controlNavThumbs:true
	});
	setTimeout('$("#slider").fadeIn()',300);
	$('#'+id+'_view_link').fadeOut('fast', function(){
		$('#'+id+'_close').fadeIn('fast');
		$('#'+id+'_close_link').fadeIn('fast');
	});
}

function close_project(id){
	$('#project_content').fadeOut('slow', function(){
		$('#'+id+'_close').fadeOut();
		$('#'+id+'_close_link').fadeOut('fast', function(){
			$('#'+id+'_view_link').fadeIn();
		});
		$("#poet").animate({ 
			opacity: 100,
	    	left: '370'
		});
		$("#helpto").animate({ 
			opacity: 100,
	    	left: '50'
		});
		$("#local_account").animate({ 
			opacity: 100,
	    	left: '690'
		}, function(){
			$('#slider').fadeOut('fast',function(){ 
				$('#slider').data('nivo:vars').stop = true;
				$("#slider_holder").html();
				$("#slider_holder").removeClass('slider-wrapper').removeClass('theme-orman');
				$('div[rel*="intro"]').fadeIn('fast');
				$("#lets_work_together").fadeIn();
			});
		});
	});
}
