$(document).ready(function(){
	
	$('html').addClass('js-active');
	
	// Sidebar Link Functionality
	$('#sidebar-selections a').not('.img-s').not('#wp-calendar a').not('#selected-posts a').each(function(){
			$(this).parent().css({'height':$(this).height(), 'overflow':'hidden', 'position':'relative'});
			$(this).css({'position':'relative', 'display':'block', 'top':'0', 'color': $(this).css('color')});
			$(this).append('<div style="color: #D22026;">' + $(this).html() + '</div>');
		})
		.mouseover(function(){
			var newTop = ($(this).parent().height() * -1) + 'px'; 
			$(this).stop().animate({
				top: newTop
			},100);
		})
		.mouseout(function(){
			$(this).stop().animate({
				top: "0"
			},200);				   
		});
		
	// Selected Posts links functionality
	/*$('#sidebar-selections h2 a').each(function(){
			$(this).parent().css({'height':$(this).height(), 'overflow':'hidden', 'position':'relative'});
			$(this).css({'position':'relative', 'display':'block', 'top':'0'});
			$(this).append('<div style="color: #D22026; margin-top: 2px;">' + $(this).html() + '</div>');
		})
		.mouseover(function(){
			var newTop = ($(this).parent().height() * -1) + 'px'; 
			$(this).css({'color':'#999999'}).stop().animate({
				top: newTop
			},100);
		})
		.mouseout(function(){
			$(this).stop().animate({
				top: "0"
			},200);				   
		});
	*/
	// Header Navigation Functionality
	$('#hd-nav a').each(function(){
			$(this).initImgLink('#D22026');		
		})
		.mouseover(function(){
			var newTop = ($(this).parent().height() * -1) + 'px'; 
			
			$(this).stop().animate({
				top: newTop
			},100);
		})
		.mouseout(function(){
			$(this).stop().animate({
			   top: "0"
			},200);
		});
	
	// Merchandise Navigation Functionality
	$('#merch-cats a').each(function(){
			$(this).initImgLink('#D22026');		
		})
		.mouseover(function(){
			var newTop = ($(this).parent().height() * -1) + 'px'; 
			
			$(this).stop().animate({
				top: newTop
			},100);
		})
		.mouseout(function(){
			$(this).stop().animate({
			   top: "0"
			},200);
		});
		
	//Services Page	
	$('#services-cats a').each(function(){
			$(this).initImgLink('#D22026');		
		})
		.mouseover(function(){
			var newTop = ($(this).parent().height() * -1) + 'px'; 
			
			$(this).stop().animate({
				top: newTop
			},100);
		})
		.mouseout(function(){
			$(this).stop().animate({
			   top: "0"
			},200);
		});
});

jQuery.fn.initImgLink = function(linkColor) {
	var bgPosition = '0 0';
	switch( this.attr('id') ){
	case "hd-nav-portfolio" :
		bgPosition = '0 0';
		break;
	case "hd-nav-merch" :
		bgPosition = '-129px 0';
		break;
	case "hd-nav-about" :
		bgPosition = '-284px 0';
		break;
	case "hd-nav-contact" :
		bgPosition = '-372px 0';
		break;
	case "hd-nav-blog" :
		bgPosition = '-484px 0';
		break;
	case "merch-prints" :
		bgPosition = '-3px -170px';
		break;
	case "merch-apparel" :
		bgPosition = '-72px -170px';
		break;
	case "merch-toolkit" :
		bgPosition = '-147px -170px';
		break;
	case "merch-desktops" :
		bgPosition = '-226px -170px;';
		break;
	case "merch-icons" :
		bgPosition = '-320px -170px';
		break;
	case "services-suites" :
		bgPosition = '0 -465px';
		break;
	case "services-web" :
		bgPosition = '-139px -465px';
		break;
	case "services-branding" :
		bgPosition = '-249px -465px';
		break;
	case "services-tech" :
		bgPosition = '-340px -465px';
		break;
	case "services-media" :
		bgPosition = '-456px -465px';
		break;	
	default:
		bgPosition = '0 0';
	}
	this.parent().css({'height':this.height(), 'overflow':'hidden', 'position':'relative'});
	this.css({'position':'relative', 'display':'block', 'top':'0', 'backgroundPosition':bgPosition});
	
	var bgpCleaned1 = bgPosition;
	//IE7 is having problems with this...
	var bgpCleaned2 = bgpCleaned1.replace('px','');
	var bgpCleaned = bgpCleaned2.replace('px','');
	var bgH = bgpCleaned.substring(0, bgpCleaned.indexOf(' '));
	var bgV = bgpCleaned.substring(bgpCleaned.indexOf(' ')+1, bgpCleaned.length)-13;
	var bgPosition = bgH + "px " + bgV + "px";
	this.append('<div style="color:' + linkColor + '; background-position: ' + bgPosition + ';height: 13px;">' + this.html() + '</div>');
}

