Cufon.replace("", {hover: true});
$(document).ready(function(){
	$('#head .search').validator();
	
	$("a[rel='gallery']").colorbox({
		transition:"fade",
		current: "zdjęcie {current} z {total}",
		previous: "poprzednie",
		next: "następne",
		close: "zamknij"
	});
	
	$("a[rel='product']").colorbox({
		transition:"fade",
		current: "zdjęcie {current} z {total}",
		previous: "poprzednie",
		next: "następne",
		close: "zamknij"
	});
	
	$('.product_info .photos .big img').hide();
	$('.product_info .photos .big img').first().show();
	$('.product_info .photos .big img').first().addClass('see');
	$('.product_info .photos .small img').click(function(){
		$('.product_info .photos .big img').fadeOut();
		$('.product_info .photos .big img.see').removeClass('see');
		$('.product_info .photos .big img').eq($('.product_info .photos .small img').index(this)).fadeIn();
		$('.product_info .photos .big img').eq($('.product_info .photos .small img').index(this)).addClass('see');
	});
	$('.product_info .photos .zoom').click(function(){
		$('.product_info .photos .big img.see').click();
	});
/*	.product_info .photos .big img{width: 260px; position: absolute;}
.product_info .photos .small*/

	setPhotoGallery();
});

var length;
var current;
var last;
var buttons = '';

function setPhotoGallery()
{
	length = $('.banners .banner').length;
	current = 0;
	last = length-1;
	$('.banners .banner').hide();
	$('.banners .banner').last().show();
	for(var i = 0; i < length; i++)
		buttons += '<a class="button b'+i+'">'+(i+1)+'</a>';
	$('.banners .buttons').html(buttons);
	$('.banners .button').click(function(){
		$('.banners .banner').clearQueue();
		last = current;
		current = $(this).index();
		change_click();
	});
	change();
}

function change()
{
	$('.banners .button.active').removeClass('active');
	$('.banners .button:eq('+current+')').addClass('active');
	$('.banners .banner').fadeOut(1000);
	$('.banners .banner:eq('+current+')').fadeIn(1000).delay(4000).fadeIn(1, change);
	current = current == length-1?0:current+1;
	last = current == 0?length-1:current-1;
}

function change_click()
{
	$('.banners .button.active').removeClass('active');
	$('.banners .button:eq('+current+')').addClass('active');
	$('.banners .banner').fadeOut(1000);
	$('.banners .banner:eq('+current+')').fadeIn(1000);
	current = current == length-1?0:current+1;
	last = current == 0?length-1:current-1;
}

