(function($){
  $.fn.showdelay = function(){
    var delay = 0;
    return this.each(function(){
      $(this).delay(delay).fadeIn(2000);
      	delay += 2000;
    });
  };
})(jQuery);


$(document).ready(function() {

	setTimeout(function(){
		//$("div#welcomeView").fadeOut(500);
		$("div#welcomeView").animate({
			opacity: '0.15',
			}, 500, function() {
		});		

		$("div#bulletsView").fadeIn(2000);

		$('div#devicesView ul').animate({
			right: '0',
			}, 1500, function() {
		});

		
	}, 2000);
	
	setTimeout(function() {
		$("div#devicesView p").fadeIn(3000);
		$("div#devicesView p").fadeOut(2000);
		$('#iphone img').showdelay();

	}, 4000);

	$('#iphone').click(function() {
		$("#devicesView ul li#ipad").css("background-position", "0px 0px");
		$("#devicesView ul li#iphone").css("background-position", "0px -200px");
		$("div.ipad").css("display","none");
		$("div.iphone").slideDown(500);
		//$("header.content").css({"-moz-box-shadow": "0px 1px 0px #bbb, 0px 2px 0px #eee", "-webkit-box-shadow": "0px 1px 0px #bbb, 0px 2px 0px #eee", "box-shadow": "0px 1px 0px #bbb, 0px 2px 0px #eee"});
	});
	$('#ipad').click(function() {
		$("#devicesView ul li#iphone").css("background-position", "0px 0px");
		$("#devicesView ul li#ipad").css("background-position", "0px -275px");
		$("div.iphone").css("display", "none");
		$("div.ipad").slideDown(500);
		//$("header.content").css({"-moz-box-shadow": "0px 1px 0px #bbb, 0px 2px 0px #eee", "-webkit-box-shadow": "0px 1px 0px #bbb, 0px 2px 0px #eee", "box-shadow": "0px 1px 0px #bbb, 0px 2px 0px #eee"});
	});
	
	$('.name').click(function() {
		$(".name").attr('value','');
	});
	$('.email').click(function() {
		$(".email").attr('value','');
	});
	$('.textarea').click(function() {
		$(".textarea").attr('value','');
	});

	$('#submit').click(function () {		

		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var message = $('textarea[name=message]');
		var data = 'name=' + name.val() + '&email=' + email.val() + '&message='  + encodeURIComponent(message.val());

		$.ajax({
			url: "send.php",	
			type: "GET",		
			data: data,		
			cache: false,

			success: function (html) {				
				if (html==1) {
					$('.form').hide();
					$('.done').fadeIn('slow');
				} else {
					$('.form').hide();
					$('.notdone').fadeIn('slow');
				}		
			}
		});
		return false;
	});	


});
