function validateKontakt(AForm, jezyk)
{
	var imie= new Array();
	var email= new Array();
	var tresc= new Array();
	var sztuk= new Array();
	
	imie[1] = 'Wpisz imię!';
	email[1] = 'Adres e-mail jest niepoprawny!';
	tresc[1] = 'Wpisz adres!';
	sztuk[1] = 'Nieprwidłowa liczba sztuk!';
	
	imie[2] = 'Incorect E-mail!';
	email[2] = 'Incorect Name!';
	tresc[2] = 'Incorect address!';
	sztuk[2] = 'Incorect pieces!';
	
	imie[3] = 'Wpisz imię';
	email[3] = 'Adres e-mail jest niepoprawny!';
	tresc[3] = 'Wpisz adres';
	sztuk[3] = 'Nieprwidłowa liczba sztuk!';
	
	var e_mail = AForm.email.value;
	var reg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

	if (!reg.test(e_mail))
	{
		alert(email[jezyk]);
		return false;
	}
	
	if(!AForm.imie.value){
		alert(imie[jezyk]);
		return false;
	}
	
	if(!AForm.tresc.value){
		alert(tresc[jezyk]);
		return false;
	}	
}

function wstawZdjecie(zdjecie)
{
	document.getElementById("fotka_produkt").innerHTML='<img src="'+zdjecie+'" alt="" />';
}

function wstawZdjecieBuy(zdjecie, id_koloru)
{
	document.getElementById("fotka_produkt_buy").innerHTML='<img src="'+zdjecie+'" alt="" />';
	document.getElementById("hidden").innerHTML= '<input type="hidden" name="id_koloru" value="'+id_koloru+'" />';
}

$(document).ready(function() {

	//Speed of the slideshow
	var speed = 5000;
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#slider').width());	
	$('#gallery').width($('#slider').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li, #mask-excerpt, #excerpt li').height($('#slider').height());
	
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);	
	
	$('#gallery li:first, #excerpt li:first').addClass('selected');

	//Pause the slidershow with clearInterval
	$('#btn-pause').click(function () {
		clearInterval(run);
		return false;
	});

	//Continue the slideshow with setInterval
	$('#btn-play').click(function () {
		run = setInterval('newsscoller(0)', speed);	
		return false;
	});
	
	//Next Slide by calling the function
	$('#btn-next').click(function () {
		newsscoller(0);	
		return false;
	});	

	//Previous slide by passing prev=1
	$('#btn-prev').click(function () {
		newsscoller(1);	
		return false;
	});	
	
	//Mouse over, pause it, on mouse out, resume the slider show
	$('#slider').hover(
	
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0)', speed);	
		}
	); 	
	
});


function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);		
	$('#mask-excerpt').scrollTo(next_excerpt, 800);					
	
}

function slideShow() {

	//Set the opacity of all images to 0
	$('#gall a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gall a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gall .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gall .caption').css({width: $('#gall a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gall .content').html($('#gall a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gall a.show')?  $('#gall a.show') : $('#gall a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gall a:first') :current.next()) : $('#gall a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gall .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gall .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
	
	//Display the content
	$('#gall .content').html(caption);
	
}

