new Image().src = "images/projectloader.gif";

$(document).ready(function(){
	// Email form
	$("#email").focus( function(){
		if( $(this).val() == 'Input your email here' )
			$(this).val( '' );
	}).blur( function(){
		if( $(this).val() == '' )
			$(this).val( 'Input your email here' );
	});
	
	// Projects
	$(".projectTrigger").each( function(){
		var bigProjectId = $(this).attr("class").split(' ')[0].replace("project", "").replace("trigger", "");
		
		$(this).click( function( event ){
			window.location.hash = ('#' + $('.project' + bigProjectId).attr("class").split(' ')[0]);
		});
	});
	
	$(".zoom, .cross, .projectText").click(function(){
		window.location.hash = '';
	});
	
	
	// Animated Scrollbar
	$(".scrolltrigger").hover(
		function(){
			$(".hscrollerbar").animate({height: "13px"}, 100  );
		},
		function(){
			$(".hscrollerbar").animate({height: "7px"}, 100  );
		}
	);

	// Link styling
	$(".work").hover(
		function(){
			$(".work").css("textDecoration","none");
		},

		function(){
			$(".work").css("textDecoration","underline");;
		}
	);

	// Project Crosses
	$(".crosszone").hover(
		function(){
		  $(".cross").css("display","block").animate({ opacity: "1"},200);
		},
		
		function out(){
			$(".cross").animate({ opacity: "0"},200)
			$().doTimeout( 'delay', 200, function(){
				$(".cross").css("display","none")
			})
		}
	);

	$(".activatecross").click(function(){
		$(".cross").css("display","block").animate({ opacity: "1"},200);
	});

	$(".bigimage").click( function(){
		$(".cross").animate({ opacity: "0"},200)
		$().doTimeout( 'delay2', 200, function(){
			$(".cross").css("display","none")
		});
	});
	
	// PERMALINKS
	oldHash = '';
	$.doTimeout( 500, function(){
		if( window.location.hash != oldHash ){
			$('.detail').each( function(){
				if( $(this).css("margin-top") == '0px' ){
					$(this).animate({marginTop: "100%"},{ duration: 350, easing:'expoin',
						complete: function(){
							$(this).css("margin-top","-1000%");
						}
					});
				}
			});
			
			var newHash = window.location.hash;
			if( newHash && newHash != '#' ){
				var element = $('.' + window.location.hash.substring(1));
				element.css("margin-top","100%");
				element.animate({marginTop: "0px"},{ duration: 500, easing:'expoout' } );
			}
			oldHash = window.location.hash;
		}
		return true;
	});
	
	// Image Preloader
	$( 'img.projectTrigger' ).each( function(){
		var projectId = $(this).attr("class").split(' ')[0].replace("project", "").replace("trigger", "");
		$(this).hide();
		$(this).after('<div class="loadingProject"></div>');
		$(this).add('.project'+projectId+' img').onImagesLoad({ 
			selectorCallback: function( selector ){
				$(this).siblings('div.loadingProject').fadeOut();
				$(this).fadeIn();
			}
		});
	});
	
	// Reveal site
	$('.loading').hide();
});	
new Image().src = "images/projectloader.gif";

$(document).ready(function(){
	// Email form
	$("#email").focus( function(){
		if( $(this).val() == 'Input your email here' )
			$(this).val( '' );
	}).blur( function(){
		if( $(this).val() == '' )
			$(this).val( 'Input your email here' );
	});
	
	// Projects
	$(".projectTrigger").each( function(){
		var bigProjectId = $(this).attr("class").split(' ')[0].replace("project", "").replace("trigger", "");
		$(this).click( function( event ){
			window.location.hash = ('#' + $('.project' + bigProjectId).attr("class").split(' ')[0]);
		});
	});
	
	$(".zoom, .cross, .projectText").click(function(){
		window.location.hash = '';
	});
	
	
	// Animated Scrollbar
	$(".scrolltrigger").hover(
		function(){
			$(".hscrollerbar").animate({height: "13px"}, 100  );
		},
		function(){
			$(".hscrollerbar").animate({height: "7px"}, 100  );
		}
	);

	// Link styling
	$(".work").hover(
		function(){
			$(".work").css("textDecoration","none");
		},

		function(){
			$(".work").css("textDecoration","underline");;
		}
	);

	// Project Crosses
	$(".crosszone").hover(
		function(){
		  $(".cross").css("display","block").animate({ opacity: "1"},200);
		},
		
		function out(){
			$(".cross").animate({ opacity: "0"},200)
			$().doTimeout( 'delay', 200, function(){
				$(".cross").css("display","none")
			})
		}
	);

	$(".activatecross").click(function(){
		$(".cross").css("display","block").animate({ opacity: "1"},200);
	});

	$(".bigimage").click( function(){
		$(".cross").animate({ opacity: "0"},200)
		$().doTimeout( 'delay2', 200, function(){
			$(".cross").css("display","none")
		});
	});
	
	// PERMALINKS
	oldHash = '';
	$.doTimeout( 500, function(){
		if( window.location.hash != oldHash ){
			$('.detail').each( function(){
				if( $(this).css("margin-top") == '0px' ){
					$(this).animate({marginTop: "100%"},{ duration: 350, easing:'expoin',
						complete: function(){
							$(this).css("margin-top","-1000%");
						}
					});
				}
			});
			
			var newHash = window.location.hash;
			if( newHash && newHash != '#' ){
				var element = $('.' + window.location.hash.substring(1));
				element.css("margin-top","100%");
				element.animate({marginTop: "0px"},{ duration: 500, easing:'expoout' } );
			}
			oldHash = window.location.hash;
		}
		return true;
	});
	
	// Image Preloader
	$( 'img.projectTrigger' ).each( function(){
		var projectId = $(this).attr("class").split(' ')[0].replace("project", "").replace("trigger", "");
		$(this).hide();
		$(this).after('<div class="loadingProject"></div>');
		$(this).add('.project'+projectId+' img').onImagesLoad({ 
			selectorCallback: function( selector ){
				$(this).siblings('div.loadingProject').fadeOut();
				$(this).fadeIn();
			}
		});
	});
	
	// Reveal site
	$('.loading').hide();
});	
