// JavaScript Document

$(function(){
	if($('body').hasClass('random')){
		var maxBG=6;
		$('body').toggleClass('random bg_' + Math.ceil(Math.random() * maxBG));
	}else if($('body').hasClass('randomMe')){
		var maxBG=2;
		$('body').toggleClass('randomMe myBg_' + Math.ceil(Math.random() * maxBG));
	}
	var H=[],S=[];
	$('#nav img').each(function(i,E){
		S[i]=$(E).attr('src');
		H[i]=new Image();
		H[i].src=S[i].replace(/\.png$/,'_h.png');
		H[i].alt='';
		$(E).mouseleave(function(){
			$(this).attr('src',S[i]);
		}).mouseenter(function(){
			$(this).attr('src',H[i].src);
		})
		var potWrap=S[i].replace(/.*\/([A-Z]+)\.png/i,'$1.html');
		if(potWrap=='store.html'){
			$(E).wrap('<a href="http://store.ridingthehermes.com/" />');
		}else if(potWrap=='blog.html'){
			$(E).wrap('<a href="http://edwardjuan.blogspot.com/" />');
		}else{
			$(E).wrap('<a href="' + potWrap + '" />');
		}
	});
	var bottom,top,ini,stuck;
	bottom=35;
	top=942;
	ini=stuck=true;
	$(window).bind('scroll resize',function(){
		if((stuck || ini) && $(window).height() < bottom + top + $('#nav').height()){
			$('#nav').css({bottom:bottom + 'px',top:'auto'});
			stuck=ini=false;
		}else if((!stuck || ini) && $(window).height() >= bottom + top + $('#nav').height()){
			$('#nav').css({bottom:'auto',top:top + 'px'});
			ini=false;
			stuck=true;
		}
	}).resize();
	/*
	$(window).bind('scroll resize',function(){
		if($(window).scrollTop() + $(window).height() >= 1008){
			$('#nav').css({bottom:'auto',top:'942px'});
		}else if(true){
			$('#nav').css({bottom:'35px',top:'auto'});
		}
	}).resize();
	*/
	$('<img src="img/copyright.png" id="copyright" border="0" alt="copyright" />').appendTo($('#nav > div')).animate({opacity:1},1000);
});

