showcase = {
	init: function(){
		$('.preview').click(this.swapImages);
		
		$('.preview').removeAttr('target').each(function(){
				$(this).attr('href','#'+this.children[0].alt)
		});
	},
	swapImages: function(e){
		$(this).replaceWith($('.preview').filter(':hidden').show()).appendTo('.page').hide().click(showcase.swapImages);
		$('.splash img').filter(':visible').hide();
		$('.splash img').filter('[alt='+ $(this).children('img').attr('alt') +']').show();
		if($(this).hasClass('headline'))
			$('.imgOverlay').show();
		else
			$('.imgOverlay').hide();
		return false;
	}
};

contact = {
	delay: 60,
	send: function(){
		$('#ajaxIndicator').show();
		var data = $('#contactForm').serializeArray();
		$.ajax({
			url: 'send.php',
			type: 'POST',
			dataType: "json",
			data: data,
			success: function(json_data) {
				$('#ajaxIndicator').hide();
				if(json_data.status == 'sent'){
					$('#error').hide();
					$('#contactForm').fadeOut(function(){
							$('#success').fadeIn();
					});
				}
				else{
					contact.handleError(json_data);
				}
			}
		});
		return false;
	},
	handleError: function(data){
		if(data.status == 'invalid'){
			$('#invalid').show();
			$('#time').hide();
			$('#error').fadeIn();
		}
		else if(data.status == 'error'){
			$('#time').show().find('span').text(data.timeleft);
			$('#invalid').hide();
			$('#error').fadeIn();
		}
	}
};

$(function(){
	if($('body').hasClass('showcase')){
		showcase.init();
	}
	
	/*$('.special a').click(function(){
		window.open('special.html', 'special', 'width=1000,height=750');
		return false;		
	});
	
	$('#nav .close').click(function(){
		window.close();	
	});*/
});

