document.write('<style type="text/css">  div.portfolio_item { display:none; } </style>');

$(document).ready( function() {
	
	/* Main page */
	$("div.portfolio_thumb").fadeTo( 0, 0.6 );
	$("div.portfolio_thumb").mouseover( function() {
		$(this).fadeTo( 500, 1 );
	})
	
	$("div.portfolio_thumb").mouseleave( function() {
		$(this).fadeTo( 500, 0.6 );
	});
	/* Main page end */
	
	
	
	
	var hash = window.location.hash;
	var selector = "div.portfolio_item:first";
	if( hash && $(hash).length > 0 )
	{
		selector = hash;
	}
	
	$(selector).fadeIn(500);
	
	
	
	
	
	
	$("div.portfolio_item").each(
		function( i )
		{
			$(this).attr("id", "_"+$(this).attr("id"));
			$(this).html( '<p><a href="" class="prev_arrow" title="Poprzedni projekt"><img src="theme/zapalka.net/arrow-left.png" alt="" /></a><a href="" class="next_arrow"  title="Następny projekt"><img src="theme/zapalka.net/arrow-right.png" alt="" /></a></p>' + $(this).html() + '<p><a href="" class="prev">Poprzedni projekt</a><a href="" class="next">Następny projekt</a></p>');
		}
	);
	
	$("a.prev, a.prev_arrow").each(
			function( i )
			{
				if( $(this).parent().parent().prev().length > 0 )
				{
					$(this).click( function(event) {
						event.stopPropagation();
						event.preventDefault();
						
						showPrev( $(this).parent().parent() );
						
					});
					
					$(this).attr("href", window.location+"#"+$(this).parent().parent().prev().attr("id"));
				}
				else
				{
					$(this).hide();
				}
			}
	);
	
	$("a.prev_arrow").mouseover( function() {
		$(this).animate({marginLeft:0}, 200);
	}).mouseleave( function() {
		$(this).animate({marginLeft:5}, 200);
	});
	
	$("a.next_arrow").mouseover( function() {
		$(this).animate({marginRight:0}, 200);
	}).mouseleave( function() {
		$(this).animate({marginRight:5}, 200);
	});
	
	$("a.next, a.next_arrow").each(
			function( i )
			{
				if( $(this).parent().parent().next().length > 0 )
				{
					$(this).click( function(event) {
						event.stopPropagation();
						event.preventDefault();
						
						showNext( $(this).parent().parent() );
						
					});
					
					$(this).attr("href", window.location+"#"+$(this).parent().parent().next().attr("id").substr(1));
				}
				else
				{
					$(this).hide();
				}
			}
	);
	
	function showNext( item )
	{
		$(item).animate({marginLeft:-800}, 300, function(){
			$(this).hide();
			$(this).css("margin-left", 0);
			$(this).next().fadeIn(500);
			
			window.location.hash = "#"+$(this).next().attr("id").substr(1);
		});
	}
	
	function showPrev( item )
	{
		$( item ).animate({marginLeft:800}, 300, function(){
			$(this).hide();
			$(this).css("margin-left", 0);
			
			$(this).prev().fadeIn(500);

			
			window.location.hash = "#"+$(this).prev().attr("id").substr(1);
		});
	}
});
