$(document).ready(function () {

	var $panels = $('.panel');
	var max = $(panel_list).length;
	
	if (max > 0) {
		LoadImage(0, max);
	}

	function LoadImage(index,max) {
		if(index < max) {
			
			var curr = $("#panel_" + index);

			var img = new Image();

			$(img).load(function () {
				
				$(this).hide();
				$(curr).removeClass('loading').append(this);
				
				$(this).fadeIn('slow',function() {
					LoadImage(index+1, max);
				});
				
				var popup = $('<div class="popup"><p>' + panel_list[index][2] + ': <a href="' + panel_list[index][0] + '" target="app-bits_link">More on this app &rsaquo;</a></p></div>').hide();
				$(curr).append(popup);
				
				$(this).click(function() {
					if ($(popup).is(":visible")) { $(popup).fadeOut(); }
					else { $(popup).fadeIn(); }
				});
				
				$(this).parent().mouseenter(function() {
					$(popup).fadeIn();
				});
				$(this).parent().mouseleave(function() {
					$(popup).fadeOut();
				});
				
			})
			.error(function () {
				$(curr).remove();
				LoadImage(index+1, max);
			})
			.attr('src', panel_list[index][1]);
			
		}
		else {
		}
	}

	$('#work_slider').serialScroll({
	  items: $panels,
	  prev: '#previous',
	  next: '#next',
	  axis: 'x',
	  offset: 0,
	  duration: 500,
	  lazy:true,
	  easing: 'swing'
	});

	/* Form */
	
	$("#email").focus(function() {
		if ($(this).val() == 'Enter your email address') {
			$(this).val('');
		}
	});
	$("#email").blur(function() {
		if ($(this).val() == '') {
			$(this).val('Enter your email address');
		}
	});
	
	$("#message").focus(function() {
		if ($(this).html() == 'Tell me your name and a bit about what you need..') {
			$(this).html('');
		}
	});
	$("#message").blur(function() {
		if ($(this).html() == '') {
			//alert($(this).html());
			//$(this).html('Tell me your name and a bit about what you need..');
		}
	});
	
/*	$(".submit").focus(function() {
		if ($("#message").html() == 'Tell me your name and a bit about what you need..') {
			$("#message").html('');
		}
	});
*/	
	$('#contact_form').validate();
	$.localScroll();
	$(document).pngFix();
});

