$(document).ready(function() {
	var windowHeight;
	var contactHeight;
	var quickNavHeight;
	var scrollTop;
	var contactAnimation=0;
	
	$(window).bind("resize", repositionContactanim);
	$(window).bind("resize", repositionQuickNav);
	$(window).bind("scroll", repositionContactanim);
	$(window).bind("scroll", repositionQuickNav);
	
	
	$('#navigation a.contact').click(function(){
			repositionContact();
			if(contactAnimation == 1) {
				closeContact();
			} else {
				openContact();
			}
			return false;	
	});
	
	$('img.close').click(function(){
		closeContact();
	});
	
	function repositionContact() {
		windowHeight = $(window).height();	
		scrollTop = $(window).scrollTop();
		contactHeight = $('#contact-form').height();
		windowHeight = (windowHeight - (contactHeight+40)) / 2;
		$('#contact-form').css({'top':windowHeight+scrollTop+'px'});
	};
	
	function repositionContactanim() {
		windowHeight = $(window).height();
		scrollTop = $(window).scrollTop();
		contactHeight = $('#contact-form').height();
		windowHeight = (windowHeight - (contactHeight+40)) / 2;
		if (windowHeight+scrollTop >= 0){
			$('#contact-form').stop().animate({'top':windowHeight+scrollTop+'px'});
		} else {
			$('#contact-form').stop().animate({'top':'0px'});
		}
	};
	
	function repositionQuickNav() {
		windowHeight = $(window).height();
		scrollTop = $(window).scrollTop();
		quickNavHeight = $('#quick-nav').height();
		windowHeight = (windowHeight - (quickNavHeight+40)) / 2;
		$('#quick-nav').stop().animate({'top':windowHeight+scrollTop+'px'});
	};
	
	$('#footer').after('<div id="quick-nav"><div id="quick-nav-button"><img src="/images/quick-navigation.gif" width="9" height="95" alt="Quick Navigation" /></div><ul><li><a href="/wordpress" title="HOME">HOME</a></li><li><a href="blog" title="BLOG">BLOG</a></li><li><a href="portfolio" title="PORTFOLIO">PORTFOLIO</a></li><li><a href="music" title="MUSIC">MUSIC</a></li><li class="last"><a href="contact" title="CONTACT">CONTACT</a></li></ul></div>');
	
	$('#quick-nav-button').toggle(function(){
			$('#quick-nav').animate({'width':'130px'});	
		 },function(){
			$('#quick-nav').animate({'width':'19px'});					  
	});
	
	$('#quick-nav li.last a').click(function(){
			repositionContact();
			if(contactAnimation == 1) {
				closeContact();
			} else {
				openContact();
			}
			return false;	
	});
	
	function closeContact() {
			repositionContact();
			$('#contact-form').animate({'marginLeft':'-340px'},function(){
				contactAnimation = 0;
			});
	}
	
	function openContact() {
			$('#contact-form').animate({'marginLeft':'0px'},function(){
				contactAnimation = 1;
			});
	}
	repositionQuickNav();
});
