jQuery(function( $ )
{
	// check for IE
	var MSIE = navigator.userAgent.toLowerCase().indexOf('msie') > -1;
	
	
	
	// Smooth scrolling
	$.localScroll({ duration: 2500 });

	
	
	// remove default hovers and fade in hover effect for nav
	$('head').append('<style type="text/css">#header ul li.gallery a:hover { background-position: 0px 0px; } #header ul li.about a:hover { background-position: -139px 0px; } #header ul li.contact a:hover { background-position: -251px 0px; } #portfolio ul li.gallery a:hover { background-position: 0px 0px; } #portfolio ul li.about a:hover { background-position: -144px 0px; } #portfolio ul li.contact a:hover { background-position: -268px 0px; } #contact ul.nav li.gallery a:hover { background-position: 0px 0px; } #contact ul.nav li.about a:hover { background-position: -143px 0px; } #contact ul.nav li.contact a:hover { background-position: -267px 0px; } #portfolio .content ul li a:hover span { display: none; } #portfolio .content ul li a:hover span.hover { display: block; } #portfolio-wrapper ul li a:hover span, #portfolio-wrapper p.img a:hover span { display: none; } #portfolio-wrapper ul li a:hover span.hover, #portfolio-wrapper p.img a:hover span.hover { display: block; }</style>');	


	$('ul.nav li a').each(function ()
	{
		$(this).append('<span class="hover"><!-- --></span>')
		var $span = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () { $span.stop().fadeTo(500, 1); }, function () { $span.stop().fadeTo(500, 0); });
	});
	
	
	// thumbnail hover effects
	$('#portfolio .content ul li a').each(function ()
	{
		$(this).children('span').addClass('hover');
		var span = $(this).children('span.hover');
		span.css('opacity', 0);
		
		if (MSIE == false) { $(this).hover(function () { span.stop().fadeTo(500, 1); }, function () { span.stop().fadeTo(500, 0); }); }
		else { $(this).hover(function () { span.css('opacity', 1); }, function () { span.css('opacity', 0) }); }
	});
	
	
	// Transition between category page and product page
	jQuery('#portfolio .content ul li a').click(function()
	{
		var relativeurl = $(this).attr('href');
		var toLoad = relativeurl+' #portfolio-wrapper';
	
		$('#wrapper').before('<div id="overlay"><!-- --></div>');
		var overlayheight = $('#footer').position().top;
		overlayheight = overlayheight + ($('#footer p').position().top + 41);

		$('#overlay').css({height: overlayheight, opacity: 0 });
		$('#overlay').animate({opacity: 1}, 800);
		
		$('#wrapper').before('<div id="portfolio-container"></div>');
		
		var portheight = $(this).parent().position().top;
		portheight = portheight + $('#portfolio .content').position().top +978;

		var windowwidth = $(window).width();
		var getportleft = windowwidth-1000;
		var portleft = getportleft/2;
		portleft = Math.floor(portleft);

		if (MSIE == false) { $('#portfolio-container').css({top: portheight, left: portleft, opacity: 0 }); }
		else { $('#portfolio-container').css({top: portheight, left: portleft }); }
		
		$('#portfolio-container').load(toLoad,loadscript);
		function loadscript() { $.getScript("/assets/templates/voodoobeans/js/image-swap.js"); }
		$.scrollTo('#portfolio-container', { duration: 800 });
		return false;
	});
	
	
	
	


	// TwitPic
	$('#twitpic_badge_container_v1 a').removeAttr('style');
	$('#twitpic_badge_container_v1 div img').each(function ()
	{
		var twitdescription = $(this).parent().parent().parent().children('span').html();
		var twitlink = $(this).parent().attr('href');
		var twitpic = $(this).attr('src');
		$(this).parent().parent().parent().remove();
		
		$('#twitpic_badge_container_v1').append('<p class="img"><a href="'+twitlink+'" target="_blank"><img src="'+twitpic+'" alt="" /><span class="hover"><!-- --></span></a></p>\n<p class="description">'+twitdescription+'</p>\n<div class="clear"><!-- --></div>\n\n');
	});
	$('#twitpic_badge_container_v1 div:first').remove();
	
	
	$('#twitpic_badge_container_v1 p.img a').each(function ()
	{
		var $twitspan = $('> span.hover', this).css('opacity', 0);
		$(this).hover(function () { $twitspan.stop().fadeTo(500, 1); }, function () { $twitspan.stop().fadeTo(500, 0); });
	});

});