$(document).ready(function(){
	
	$("#TopMenu ul ul").css({display: "none"}); // Opera Fix
	$("#TopMenu li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(200);
	},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
	});
	
	$('a.Rep').each(function(){
		var e = $(this).attr("href").replace("/","").split(".html")[0]+"@"+$(this).attr("rel");
		$(this).attr({"href":"mailto:"+e});
		$(this).text(e);
	});
	
	$(".lightbox").lightbox();
	
	$("table.tableFormat").each(function(){
		$(this).find("tr:first").not("td table tr").addClass("first");
		$(this).find("tr:odd").not("td table tr").addClass("lp");
		$(this).find("tr:last").css({borderBottom:"none"});
	});
	
	$("img.Resize").each(function(){
		var tw = $(this).attr("width");
		var th = $(this).attr("height");
		if(!isNaN(tw)&&!isNaN(th)) {
			var ts = $(this).attr("src").split("/");
			$(this).attr({"src":"/galeria/"+ts[ts.length-1]+"?xmax="+tw+"&ymax="+th+"&crop"});
		}
	});
	
	$("table.excel, table.tabelka").each(function(){
		//$(this).find("tr:first").not("td table tr").addClass("first");
		$(this).find("tr:odd").not("tr.first").addClass("lp");
		$(this).find("tr").find("td:first").addClass("nw");
	});
	
	$("#Captcha img").click(function(){
		$(this).animate({ opacity: 'hide' }, "fast",null,function(){
			$(this).attr({"src":"/captcha.jpg?sid="+ Math.round(Math.random()*100000) });
			$(this).animate({ opacity: 'show' }, "slow");
		});
	});
	
});

function EmbedSWF(url,place,w,h) {
	var flashvars = false;
	var params = {	'menu': 'false' };
	var attributes = false;
	swfobject.embedSWF(url, place, w, h, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function ccD2H(c) {
	var nc = c.substr(4,(c.length-5)).split(", ");
	var ret = '';
	for(var i=0;i<3;i++) {
		var b = (nc[i]*1).toString(16);
		ret += (b.length<2?'0':'')+b;
	}
	return ret;
}

function PokazOboz(){
	var oid = $("#Oboz").val();
	if(oid.length>0) {
		$("#InfoPlace").animate({ height: 'hide', opacity: 'hide' }, "fast", null, function(){
			url = "/PokazOboz/"+oid+"/index.json";
			$.ajax({
				url: url,
				cache: true,
				success: function(p){
					$("#InfoPlace").html(p);
					$("#InfoPlace").animate({ height: 'show', opacity: 'show' }, "slow");
				}
			});		
			$("#InfoPlace").html("");
		});
	}else{
		$("#InfoPlace").animate({ height: 'hide', opacity: 'hide' }, "fast", null, function(){
			$("#InfoPlace").html("");
		});
	}
}

function CheckForm() {
	var o = $("#Oboz");
	var n = $("#Name");
	var e = $("#Email");
	var p = $("#Phone");
	var ad = $("#Address");
	var i = $("#Info");
	var c = $("#FCode");
	
	if(o.val().length==0) return ShowError("Proszę wybrać obóz.");
	if(n.val().length==0) return ShowError("Proszę wpisać swoje imię.");
	if(e.val().length==0) return ShowError("Proszę wpisać swój email.");
	if(!checkEmail(e.val())) return ShowError("Proszę POPRAWNIE wpisać swój email.");
	if(p.val().length==0) return ShowError("Proszę wpisać swój telefon kontaktowy.");
	if(ad.val().length==0) return ShowError("Proszę wpisać swój adres.");
	if(c.val().length!=5) return ShowError("Proszę przepisać kod z obrazka.");
	
	return true;
}

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

function ShowError(txt) {
	var content = '<div id="Question"><div class="txt">'+txt+'</div><div class="butt2"><input type="submit" name="" value="Zamknij" class="Button nyroModalClose" /></div></div>';
	$.nyroModalManual({
		closeButton: '',
		modal: true,
   	bgColor: '#000',
		minHeight: 100,
   	content: content
   });
	return false;
}
