var maxExamples = 4;
var currentExample = 0;

$(document).ready(function() {

  $(document).pngFix();

  $("#iphone").animate({
    left: "0px"
  }, 600);

  $("img.switch0").hover(function() {
    $(".scroll").animate({ left: "0px" }, 350);
    $("#steps li.step1").fadeIn("slow");
    $("#steps li.step2").fadeOut("fast");
    $("#steps li.step3").fadeOut("fast");
    $("#steps li.step4").fadeOut("fast");
  },
		function() {
		  $(this).addClass("done");
		});

  $("img.switch1").hover(function() {
    $(".scroll").animate({ left: "-225px" }, 350);
    $("#steps li.step1").fadeOut("fast");
    $("#steps li.step2").fadeIn("slow");
    $("#steps li.step3").fadeOut("fast");
    $("#steps li.step4").fadeOut("fast");
  },
		function() {
		  $(this).addClass("done");
		});

  $("img.switch2").hover(function() {
    $(".scroll").animate({ left: "-450px" }, 350);
    $("#steps li.step1").fadeOut("fast");
    $("#steps li.step2").fadeOut("fast");
    $("#steps li.step3").fadeIn("slow");
    $("#steps li.step4").fadeOut("fast");
  },
		function() {
		  $(this).addClass("done");
		});

  $("img.switch3").hover(function() {
    $(".scroll").animate({ left: "-675px" }, 350);
    $("#steps li.step1").fadeOut("fast");
    $("#steps li.step2").fadeOut("fast");
    $("#steps li.step3").fadeOut("fast");
    $("#steps li.step4").fadeIn("slow");
  },
		function() {
		  $(this).addClass("done");
		});

  $("img.switch4").hover(function() {
    $(".scroll").animate({ left: "-900px" }, 350);
    $("#steps li.step1").fadeOut("fast");
    $("#steps li.step2").fadeOut("fast");
    $("#steps li.step3").fadeOut("fast");
    $("#steps li.step4").fadeIn("slow");
  },
		function() {
		  $(this).addClass("done");
		});

  $("img.switch5").hover(function() {

    if (currentExample < (maxExamples - 1)) {
      currentExample++;
    } else {
      currentExample = 0;
    }

    var nextFolder = 'images/Examples/' + currentExample + '/';

    $(".scroll").image(nextFolder + 'Screenshot0.jpg');
    $(".scroll").image(nextFolder + 'Screenshot1.jpg');
    $(".scroll").image(nextFolder + 'Screenshot2.jpg');
    $(".scroll").image(nextFolder + 'Screenshot3.jpg');
    $(".scroll").image(nextFolder + 'Screenshot4.jpg');

    for (var i = 0; i < 5; i++) {
      $(".scroll img:first").remove();
    }

    $(".scroll").animate({ left: "-225px" }, 350);
    $("#steps li.step1").fadeOut("fast");
    $("#steps li.step2").fadeIn("slow");
    $("#steps li.step3").fadeOut("fast");
    $("#steps li.step4").fadeOut("fast");
  },
		function() {
		  $(this).addClass("done");
		});


		$.fn.image = function(src, f, e) {
		  var i = new Image();
		  var t = $(this);
		  $(i).load(function() { t.append($(this)); f }).error(e).attr('src', src);
		}
  /*
  $('#screenshots a#one').fancyZoom({directory: '/images/'});
  $('#screenshots a#two').fancyZoom({directory: '/images/'});
  $('#screenshots a#three').fancyZoom({directory: '/images/'});
  $('#screenshots a#four').fancyZoom({directory: '/images/'});
  */
  $("input.sign-name").focus(function() {
    if ($(this).val() == "Enter your name")
      $(this).val('');
  });
  $("input.sign-name").blur(function() {
    if ($(this).val() == "")
      $(this).val('Enter your name');
  });

  $("input.sign-email").focus(function() {
    if ($(this).val() == "Enter your email address")
      $(this).val('');
  });
  $("input.sign-email").blur(function() {
    if ($(this).val() == "")
      $(this).val('Enter your email address');
  });

  $("#head span a").hover(function() {
    $(this).children().stop(true, true);
    $(this).children().fadeIn("fast");
  },
		function() {
		  $(this).children().fadeOut("fast");
		});

  $("#head strong").hover(function() {
    $(this).stop(true, true);
    $(this).fadeTo("fast", 0.8);
  },
		function() {
		  $(this).fadeTo("fast", 1.0);
		});

  $("#head h1 a").hover(function() {
    $(this).children().stop(true, true);
    $(this).children().fadeIn("fast");
  },
		function() {
		  $(this).children().fadeOut("fast");
		});

  /*$('#screenshots a#one').hover(function(){
  $("#screenshots img").stop(true, true);
  $('#screenshots a#two img, #screenshots a#three img, #screenshots a#four img').fadeTo("fast", 0.4);
  },
  function(){
  $('#screenshots a#two img, #screenshots a#three img, #screenshots a#four img').fadeTo("slow", 1.0);
  }
  );
	
	$('#screenshots a#two').hover(function(){
  $("#screenshots img").stop(true, true);
  $('#screenshots a#one img, #screenshots a#three img, #screenshots a#four img').fadeTo("fast", 0.4);
  },
  function(){
  $('#screenshots a#one img, #screenshots a#three img, #screenshots a#four img').fadeTo("slow", 1.0);
  }
  );
	
	$('#screenshots a#three').hover(function(){
  $("#screenshots img").stop(true, true);		
  $('#screenshots a#one img, #screenshots a#two img, #screenshots a#four img').fadeTo("fast", 0.4);
  },
  function(){
  $('#screenshots a#one img, #screenshots a#two img, #screenshots a#four img').fadeTo("slow", 1.0);
  }
  );
	
	$('#screenshots a#four').hover(function(){
  $("#screenshots img").stop(true, true);
  $('#screenshots a#one img, #screenshots a#two img, #screenshots a#three img').fadeTo("fast", 0.4);
  },
  function(){
  $('#screenshots a#one img, #screenshots a#two img, #screenshots a#three img').fadeTo("slow", 1.0);
  }
  );*/

});