var foto = [];
var wybr_obr = 0;

$(function(){
	
	Cufon.replace('#MainMenu a',{ hover: true }); //,textShadow: '1px 1px #6F6F6F'
	Cufon.replace('h2 a, h3 a',{ hover: true });
	Cufon.replace('#Page .Text h2, #Page .Text h3, #Page .Box span.Title, #UserPanel h2'); //,{ textShadow: '1px 1px #4F4A4A' }
	
	$('a.Rep,a.RepGB').each(function(){
		var e = $(this).attr("href").replace("/","").split(".html")[0]+"@"+$(this).attr("rel");
		$(this).attr({"href":"mailto:"+e});
		if($(this).attr('class').indexOf('RepGB')==-1) $(this).text(e);
	});
	
	$("a.fancybox,a[target=fancybox]").fancybox({
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'image'
	});
	$(".Text img[align=left]").addClass("marginRight");
	$(".Text img[align=right]").addClass("marginLeft");
	
	$("#List .Content").find(" p:last").css({"padding-bottom":"0px"});
	
	$("#Page .Box a").hover(function(){
		$(this).find(".Title").stop(true,true).animate({ opacity: 'show' });
	},function(){ 
		$(this).find(".Title").stop(true,true).animate({ opacity: 'hide' });
	});
	$("#Page .Box a.fancybox").hover(function(){
		$(this).fadeTo("fast",.7);
	},function(){ 
		$(this).fadeTo("fast",1);
	});
	
	$("#List .Row .Title").click(function(){
		var par = $(this).parent();
		var act = $("#List .Row.Activ");
		if(par.attr("class").indexOf("Activ")!=-1) {
			par.find(".Content").stop(true,true).animate({ opacity: 'hide', height: 'hide' },"fast",null,function(){ par.removeClass("Activ"); });
		}else{
			act.find(".Content").stop(true,true).animate({ opacity: 'hide', height: 'hide' },"fast",null,function(){ act.removeClass("Activ"); });
			par.find(".Content").stop(true,true).animate({ opacity: 'show', height: 'show' },"slow",null,function(){ par.addClass("Activ"); });
			if(par.find(".GoogleMap").length){
				RedrawMap();
			}
		}
	});
	
	$("p.Arrow a").wrapInner("<span/>");
	$("#Page .LeftBackground").height( ($("#Page .RightCol").outerHeight()-360) )
	
	$("#LostPasswordButton").click(function(){
		$.fancybox({
			'autoScale'	: true,
			'content'	: '<div id="LostPassForm"><form action="" method="post"><p>'+FormCom1+'</p><input type="text" name="LostPassLogin" /><button type="submit" name="SendLostPass" id="SendLostPassButton"><span>Wyślij ></span></button></form></div>'
		});
		return false;
	});
	
});

$(window).load(function(){
	if($("#Akordeon").length) {
		$("#Akordeon").pk_accordion_gallery({min_width: 80,elem_opacity:0.9});
	}
})

function PlayWideo(n) {
	if($("#"+n).length) {
		$f(n).play();
	}
	return void(null);
}
function checkNewsletterEmail() {
	if(!checkEmail($("#NewsletterEmail").val())) return ShowError(FooterError[0]);
	return true;
}
function CheckContactForm() {
	
	var name = $("#CFName").val();
	var phone = $("#CFPhone").val();
	var email = $("#CFEmail").val();
	var text = $("#CFText").val();
	
	if(!name.length) return ShowError(FormError[0]);
	if(!phone.length) return ShowError(FormError[1]);
	if(!email.length) return ShowError(FormError[2]);
	if(!checkEmail(email)) return ShowError(FormError[3]);
	if(!text.length) return ShowError(FormError[4]);
	
	return true;
}

function checkEmail(x){return/^[\w\.-]+@([\w-]+\.)*[a-z]{2,4}$/.test(x)}

function ShowError(txt) {
	$.fancybox({
		'autoScale'			: true,
		'content'			: '<div id="Question"><div class="txt">'+txt+'</div></div>'
	});
	return false;
}

function ShowMessage(txt) {
	$.fancybox({
		'autoScale'			: true,
		'content'			: '<div id="Question"><div class="txt">'+txt+'</div></div>'
	});
	return false;
}

