$(document).ready(function(){
	$("h1").click(function(){
		window.location('index.html');
	});	
	
	$(".main_content a").each(function() {
		if ($(this).attr('href').indexOf('http://') > -1) {
			$(this).click(function() {				
				window.open($(this).attr('href'), 'outside_window', "");
				return false;
			});
		}
	});
	
	$('div.main_content .label_input_pair input:text').addClass('text');
	
	$('a.submit').click(function() {
		$(this).parent().submit();
		return false;
	});
	
	/* Random photo for content background */
	$('body:not(.home) div.main_content').css('backgroundImage', 'url(/images/content_bg/bg_image'+ Math.floor((Math.random() * 13 + 1)) +'.jpg)');
	
	
	/* Photo Feature */
	
	// Load first item
	$(".photo_feature")
		.css('backgroundImage', "url("+ $(".photo_feature li:first a").attr('href') +")")
		.find("li:first").addClass('active');
	$(".photo_feature").find("p").text($(".photo_feature li:first img").attr('alt'));

	// Display text on hover
	$(".photo_feature").hover(
		function() {
			$(this).find('p').fadeIn("slow");
		},
		function() {
			$(this).find('p').fadeOut("slow");
		}	
	);
	
	// Load the large image, text and set active thumbnail on click
	$(".photo_feature li a").click(function(){
		var feature_box = $(this).parents('div.photo_feature');
		var new_image = $(this).attr('href');		
		
		feature_box.find('li').removeClass('active');
		$(this).parent().addClass('active');
		
		feature_box.css('backgroundImage', 'url('+new_image+')');
				
		feature_box.find('p').text($(this).find('img').attr('alt'));
		
		return false;	
	});
	
	// Animate the thumbnails on hover
	$(".photo_feature li a").hover(
		function() {
			$(this).find("img").dequeue().animate({
				top: "-5px"
			}, 300)
		},
		function() {
			$(this).find("img").animate({
				top: 0
			}, 300)
		}	
	);
	/* End Photo Feature */
	
	
	/* Contact Form Labels */
	// Animate the label to fade back if there's no text input already
	$('.box_contact input, .box_contact textarea').focus(function(){
		if ($(this).val() == '') {
			if (jQuery.support.opacity) {
				$(this).parent().find('label span').animate({opacity: 0.5}, "fast");
			} else {
				$(this).parent().find('label span').hide();				
			}
		} else {
			$(this).parent().find('label span').css('opacity', 0);
		}
	});

	// Animate the label to fade up if the box is still empty	
	$('.box_contact input, .box_contact textarea').blur(function(){
			if ($(this).val() == '') {
				if (jQuery.support.opacity) {
					$(this).parent().find('label span').animate({opacity: 1}, "fast");
				} else {
					$(this).parent().find('label span').fadeIn('fast');					
				}
			} else {
				$(this).parent().find('label span').css('opacity', 0);
			}
	});
	
	// Hide the label if text is put into the box
	$('.box_contact input, .box_contact textarea').keypress(function(){
		$(this).parent().find('label span').css('opacity', 0);
	});
	
	$('.box_contact input, .box_contact textarea').attr('value', '');
	/* End Contact Form Labels */
});