$(document).ready(function(){

	//preload portfolio images
	image1 = new Image();
	image2 = new Image();
	image3 = new Image();
	image4 = new Image();
	image5 = new Image();
	image6 = new Image();
	image7 = new Image();
	image8 = new Image();
	image9 = new Image();
	image10 = new Image();
	image11 = new Image();
	image12 = new Image();
	image13 = new Image();
	image14 = new Image();
	image15 = new Image();
	image16 = new Image();
	image17 = new Image();
	image18 = new Image();
	image19 = new Image();
	image20 = new Image();
	image21 = new Image();
	image22 = new Image();
	image23 = new Image();
	image24 = new Image();
	image25 = new Image();
	image26 = new Image();
	image27 = new Image();
	
	image1.src = 'http://www.ratchet-torrents.com/images/veritebrowser.jpg';
	image2.src = 'http://www.ratchet-torrents.com/images/uofrbrowser.jpg';
	image3.src = 'http://www.ratchet-torrents.com/images/ndpbrowser.jpg';
	image4.src = 'http://www.ratchet-torrents.com/images/alcatbrowser.jpg';
	image5.src = 'http://www.ratchet-torrents.com/images/napkinbrowser.jpg';
	image6.src = 'http://www.ratchet-torrents.com/images/veritetitle.png';
	image7.src = 'http://www.ratchet-torrents.com/images/uofrtitle.png';
	image8.src = 'http://www.ratchet-torrents.com/images/ndptitle.png';
	image9.src = 'http://www.ratchet-torrents.com/images/alcattitle.png';
	image10.src = 'http://www.ratchet-torrents.com/images/napkintitle.png';
	image11.src = 'http://www.ratchet-torrents.com/images/pmenu_item1.jpg';
	image12.src = 'http://www.ratchet-torrents.com/images/pmenu_item1_hover.jpg';
	image13.src = 'http://www.ratchet-torrents.com/images/pmenu_item2_hover.jpg';
	image14.src = 'http://www.ratchet-torrents.com/images/pmenu_item3.jpg';
	image15.src = 'http://www.ratchet-torrents.com/images/pmenu_item4_hover.jpg';
	image16.src = 'http://www.ratchet-torrents.com/images/pmenu_item5_hover.jpg';
	image17.src = 'http://www.ratchet-torrents.com/images/button_update_hover.jpg';
	image18.src = 'http://www.ratchet-torrents.com/images/button_email_hover.jpg';
	image19.src = 'http://www.ratchet-torrents.com/images/button_gameplan_hover.jpg';
	image20.src = 'http://www.ratchet-torrents.com/images/nav_home_on.gif';
	image21.src = 'http://www.ratchet-torrents.com/images/nav_who_on.gif';
	image22.src = 'http://www.ratchet-torrents.com/images/nav_what_on.gif';
	image23.src = 'http://www.ratchet-torrents.com/images/nav_portfolio_on.gif';
	image24.src = 'http://www.ratchet-torrents.com/images/nav_blog_on.gif';
	image25.src = 'http://www.ratchet-torrents.com/images/nav_contact_on.gif';
	image26.src = 'http://www.ratchet-torrents.com/images/pmenu_navprev_hover.jpg';
	image27.src = 'http://www.ratchet-torrents.com/images/pmenu_navnext_hover.jpg';

	
});

function GTPItem(id) {
	
	//what's the left margin?
	if(id == 1) {
		leftmar = '0px';
	}
	if(id == 2) {
		leftmar = '107px';
	}
	if(id == 3) {
		leftmar = '215px';
	}
	if(id == 4) {
		leftmar = '322px';
	}
	if(id == 5) {
		leftmar = '430px';
	}
	
	//reset all to blank
	resetAll();
	
	//fade stage
	fadeStage();
	
	$('#portfolio_hover').animate({"marginLeft": leftmar}, "normal", function() {
		$('#menuitem'+id).css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item'+id+'_hover.jpg)');
		
		//load stage
		loadStage(id);
		
	});
	
}

function resetAll() {
	
	$('#menuitem1').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item1.jpg)');
	$('#menuitem1').hover(function() {
		$('#menuitem1').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item1_hover.jpg)');
	}, function() {
		$('#menuitem1').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item1.jpg)');
	});
	$('#menuitem2').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item2.jpg)');
	$('#menuitem2').hover(function() {
		$('#menuitem2').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item2_hover.jpg)');
	}, function() {
		$('#menuitem2').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item2.jpg)');
	});
	$('#menuitem3').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item3.jpg)');
	$('#menuitem3').hover(function() {
		$('#menuitem3').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item3_hover.jpg)');
	}, function() {
		$('#menuitem3').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item3.jpg)');
	});
	$('#menuitem4').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item4.jpg)');
	$('#menuitem4').hover(function() {
		$('#menuitem4').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item4_hover.jpg)');
	}, function() {
		$('#menuitem4').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item4.jpg)');
	});
	$('#menuitem5').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item5.jpg)');
	$('#menuitem5').hover(function() {
		$('#menuitem5').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item5_hover.jpg)');
	}, function() {
		$('#menuitem5').css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item5.jpg)');
	});
	
}

function fadeStage() {
	$('#stage').fadeOut('fast');
}

function loadStage(id) {
	//grab data
	$("#stage").load('http://www.ratchet-torrents.com/news/stages/'+id+'.php', function() {
		$("#stage").fadeIn('fast');
	});
	
	$('#menuitem'+id).hover(function() {
		$('#menuitem'+id).css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item'+id+'_hover.jpg)');
	}, function() {
		$('#menuitem'+id).css('background-image', 'url(http://www.ratchet-torrents.com/images/pmenu_item'+id+'_hover.jpg)');
	});
	
}

function nlSubscribe() {
	var email = document.getElementById('nlinputbox').value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	$('#nlerror').hide();
	if (filter.test(email)) {
		$('#newsletterinput').html('<div style="text-align: center; padding-top: 13px;"><img src="http://www.ratchet-torrents.com/images/loader.gif"></div>');
		$.get("/includes/ajax/newsletter.php", { subscribe: email },
		  function(data){
		  	$('#newsletterinput').fadeOut('fast', function() {
		  		$('#newsletterinput').html('<div style="padding: 6px; text-align: center; margin-top: 11px; background-color: #e3f2ff; color: #3392e9; font-weight: bold; font-size: 0.8em;">Thank you for subscribing!</div>');	
		  		$('#newsletterinput').fadeIn('fast');
		  	});	    
		  });		
	} else {
		$('#nlerror').html('<div style="padding: 6px; text-align: center; margin-top: 11px; background-color: #ffd6d6; color: #c10000; font-weight: bold; font-size: 0.8em;">Oops! That e-mail address is invalid.</div>');
		$('#nlerror').fadeIn('fast');
	}

}