
$(document).ready(function(){
$('#overlay').hide();

var wasHere = readCookie('wasHere');
if($('body').hasClass('mainPage')) {
	if(wasHere != '1') {
 		$('#priNav').hide();
		$('#content').hide();
		$('.mainPhoto').hide();
		$('#label').hide();	

		$('#homeLink').animate({ top: 35 }, 800 );
		$('#label').fadeIn(2000);

		setTimeout("$('#borderTop').animate({ opacity: 1, left: -80 }, 400)", 700);
		setTimeout("$('#borderBottom').animate({ opacity: 1, right: -30 }, 600)", 700);
		setTimeout("$('#priNav').fadeIn(500)", 1600);
		setTimeout("$('#content').slideDown(500)", 1400);
		setTimeout("$('.mainPhoto').fadeIn(1200)", 1800);
} else {
	$('#borderTop').css('opacity','1').css('left','-80px');
	$('#borderBottom').css('opacity','1').css('right','-30px');
	$('#homeLink').css('top','35px');
}
}

createCookie('wasHere','1', 1000);

$('.mainPhoto').hover(
	function() {			
			$('.flowersTop',this).css('height','163px');
			$('.flowersBottom',this).css('height','163px');
			
			$('.flowersTop',this).fadeIn(800);		
			$('.flowersBottom',this).fadeIn(800);			
},
	function() {
		$('.flowersTop',this).css('height',0);
		$('.flowersBottom',this).css('height',0);
		$('.flowersTop',this).fadeOut(200);
		$('.flowersBottom',this).fadeOut(200);
}
);


clearInputs('input[type=text]');


$('#cta').hover(
	function() { $('#hoverBg',this).fadeIn(400); },
	function() { $('#hoverBg',this).fadeOut(200); }
);

$('.group').hover(
		function() { $(this).children('span').slideDown(200); },
		function() {  $(this).children('span').slideUp(50); }
);


$('#cta').hover(
	function() { $('#hoverBg',this).fadeIn(800); },
	function() { $('#hoverBg',this).fadeOut(400); }
);	


//$('input[type=text]').focus(function() { $(this).val(''); });
//$('textarea').focus(function() { $(this).val(''); });
$('form').submit(function() {
	if(($('input[type=text]',this).val() == '') || ($('input[type=text]',this).val() == "E-mail i/lub telefon kontaktowy")) {
		var check = confirm('Zostawiłaś/eś puste pole kontaktu. Jesteś pewna/ien, że chcesz wysłać taką wiadomość?');
		if(check) { return true; }
		else {  return false; }	
	}
});

if(jQuery().fancybox) {
$('a.thumbLink').fancybox({
	'overlayShow'			: true,
	'zoomSpeedIn'			: 600,
	'zoomSpeedOut'			: 500,
	/*'easingIn'			: 'easeOutBack',
	'easingOut'				: 'easeInBack',*/
	'overlayColor'			: '#000',
	'enableEscapeButton'	: true,
	'overlayOpacity'		: 0.8,
	'imageScale'			: true
});
}

toggleRetouch('.retouchContainer','.slide');

	
});

function createCookie(name,value,expDate) { 
/* expDate wyrazony w minutach */
	if (expDate) {
		var date = new Date();
		date.setTime(date.getTime()+(expDate*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}   
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
				return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function setHeight(which) {
	var div = $(which);
	div.css({height: div.height()});
}
function clearInputs(el) {
		$('input[type=text]').focus(function() { 
			elVal = $(this).val();
			$(this).val(''); 
		});
		$('input[type=text]').change(function() { 
			elVal = $(this).val();
		});
		$('input[type=text]').focusout(function() { 
			$(this).val(elVal); 
		});
}

function toggleRetouch(container) {
	$(container).each(function() {
		$('.slide02',this).mouseover(function() { $(this).fadeOut(200); });
		$('.slide01',this).mouseout(function() { $('.slide02').fadeIn(250); });
	});
}


