$(document).ready(function(){
	
	// Fancy Box
	$('a#flashChiquita').fancyZoom();
	$('a#flashMaglite').fancyZoom();
	$('a#flashMiller').fancyZoom();
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------	
	
	// Remove flash divs if IE - (Internet Explorer SUCKS!)
	jQuery.each(jQuery.browser, function(i) {
		if($.browser.msie){
			$("div#flash_chiquita").remove();
			$("div#flash_maglite").remove();
			$("div#flash_miller").remove();
		}
	});
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	
	// Image preloader
	jQuery(function( $ ){			
		var $links = $('ul.thumbs a');
		$links.preload();
	});
				
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------	
	
	
	// Add classes first and last to first and last project
	$("div#portfolio div.projbox:first").addClass('first');
	$("div#portfolio div.projbox:last").addClass('last');
	
	// Add class last to last paragraph in project description
	$("div#portfolio div.projbox li.projdescription p:last-child").addClass('last');
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	
	// Add check boxes to form
	$("form#contactform div.indv_box input, form#contactform textarea").after("<span class='checked'/>");
		
	// Form Focus - remove text
	$("form#contactform input.text, form#contactform textarea").focus(function() {
		if (this.value == this.defaultValue) {
			$(this).val("");
		};
	});
	
	// Form Blur - Return Text
	$("form#contactform input, form#contactform textarea").blur(function() {
		if (this.value == ''){  
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
		
		if (this.value == this.defaultValue) {
			$(this).next("span").fadeOut(2000);
		};
		
		if (this.value != '' && this.value != this.defaultValue && this.id != 'email') {
			$(this).next("span").fadeIn(2000);
		};		
				
		this.value = trim(this.value);
	});
	
	// Trim String
	function trim(stringToTrim) {
		return(stringToTrim.replace(/^\s+|\s+$/g,""));
	}
	
	// Email Validation
	$("form#contactform input#email").blur(function() {
		var emailToVal = this.value;
	
		if (this.value == this.defaultValue) {
			$(this).next("span").fadeOut(2000);
		};
		
		if (this.value != '' && this.value != this.defaultValue) {
			var emailPattern = /^\w+([\.\-]?\w+)*@{1}\w+([\.\-]?\w+)*(\.{1}[a-zA-Z]{2,4})+$/;
			var validation = emailPattern.test(emailToVal);
	
			if (validation) {
				$(this).next("span").fadeIn(2000);
			} else {				
				$(this).next("span").fadeOut(500);
			}
		}
	});
	
	// Clear all checked values
	$("form#contactform input.reset").click(function() {
		$("form#contactform input, form#contactform textarea").next("span").fadeOut(500);
	});
	
	//--------------------------------------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------
	
	// Portfolio switch elements
	$("ul.thumbs a").click(function(){
	
		if ($(this).attr("name") != 'flash') {
						
			var projName	=	$(this).attr("name");
			var largePath	=	$(this).attr("href");
			var largeAlt	=	$(this).attr("title");

			$("img#"+projName).fadeTo(500, 0);

			setTimeout(function(){
				$("img#"+projName).attr({ src: largePath, alt: largeAlt });

				setTimeout(function(){
					$("img#"+projName).fadeTo(800, 100)
				}, 100);

			}, 500);
		};
		
		return false;
	});
	
	
	
});
