﻿$(document).ready(function(){

	$('#portfolio_opis').containedStickyScroll({
        duration: 300,
        unstick: true,
        closeChar: '' 
    });
	
	$("#glowna_portfolio img").mouseover(function(){
		//$(this).attr("src", "images/"+$(this).attr("id")+"_on.jpg");
		this.src = this.src.replace("_off","_on");
	}).mouseout(function(){
		//$(this).attr("src", "images/"+$(this).attr("id")+"_off.jpg");
		this.src = this.src.replace("_on","_off");
	});

	$(".portfolio_wstecz img").mouseover(function(){
		this.src = this.src.replace("_off","_on");
	}).mouseout(function(){
		this.src = this.src.replace("_on","_off");
	});
	
	$(".hover").mouseover(function(){
		this.src = this.src.replace("_off","_on");
	}).mouseout(function(){
		this.src = this.src.replace("_on","_off");
	});

	$('#slides').slides({
		preload: true,
		preloadImage: 'grafika/loading.gif',
		play: 5000,
		pause: 3000,
		preload: true,
		fadeSpeed: 500,
		hoverPause: true
	});

	
	$(".portfolio_lista img").hover(
			function() {
				$(this).fadeTo("fast", 0.6);
			},
			function() {
				$(this).fadeTo("fast", 1);
		});

	function portfolio_filtr( filterVal )
	{
		var i = 0;
		
		if(filterVal == 'all') {
			$('#portfolio .portfolio_lista').fadeIn('slow').removeClass('hidden');
			$("#portfolio > :nth-child(4n+4)").css("margin-right", 0);

			$(".portfolio_lista").each( function() 
			{
				i=(i+1); 
				if( i%4 == 0 )
				{
					$(this).css("margin-right", 0);
				}
				else
				{
					$(this).css("margin-right", 16);
				}
			});
			
		} else {
			$('#portfolio .portfolio_lista').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
					
					i=(i+1); 
					if( i%4 == 0 )
					{
						$(this).css("margin-right", 0);
					}
					else
					{
						$(this).css("margin-right", 16);
					}
				}
			});
		}

		return false;
	}

	$('#filter a').live('click', function() {
		
		$(this).css('outline','none');
		$('#filter .aktywny').removeClass('aktywny');
		$(this).addClass('aktywny');

		//var filterVal = $(this).text().toLowerCase().replace(' ','-');

		var filterVal = $(this).attr('rel');
	
		$.post("portfolio_filtr.php", {"filter": filterVal});

		portfolio_filtr( filterVal );
	});


	$("#portfolio > :nth-child(4n+4)").css("margin-right", 0);
	
	$('#filter a').each(function() {
		if( $(this).hasClass('aktywny') )
		{
			var filter = $(this).attr('rel');
			if ( filter != 'all')
			{
				portfolio_filtr( filter );
			}
		}
	});
	
	
});


