function Init() {
	SetColumnsHeight();
	LightboxInit('#Content');
	EventsInit();
//	$('#Top').each(function(){InsertFlash('fla/top.swf', 950, 265, 'Top');});
	$('#Menu .button').each(function(){
		var sz = $(this).children('.link').width();
//		$(this).css('width', sz);
		$(this).width(sz);
		$(this).children('.linkSub').each(function(){
			$(this).width(sz);
			if ($(this).height() > 35) {
				n = $(this).height() / 35;
				h = 36 / n;
				if (h < 12) h = 12;
				$(this).children('span').css('line-height', h + 'px');
			}
		});
	});
}

function Zaokraglij(co, ile) {
	li = Math.pow(10, ile);
	w = Math.round(co * li) / li;
	return w;
}

function SetColumnsHeight() {
	h1 = $('#ContentLeft .body').height() + 85;
	h2 = $('#ContentRight').height();
	if (h1 > h2) $('#ContentRight').height(h1);
	else if (h1 < h2) $('#ContentLeft .body').height(h2 - 85);
}

function LightboxInit(divName) {
	$(divName + " A").each(function(){
		if (UseLightbox($(this).attr('href'))) $(this).attr('name', 'UseLBox');
	});
	$(divName + " A[name='UseLBox']").lightBox();
	$(divName + " A[name='UseLBox']").attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne.");
}

function UseLightbox(string) {
	if (string.indexOf('.jpg') > 0) return true;
	if (string.indexOf('.jpeg') > 0) return true;
	if (string.indexOf('.gif') > 0) return true;
	if (string.indexOf('.png') > 0) return true;
	if (string.indexOf('.bmp') > 0) return true;
	if (string.indexOf('.tif') > 0) return true;
	return false;
}

function InsertFlash(fla, w, h, div) {
	var so = new SWFObject(fla, "mymovie", w, h, "8", "transparent");
   so.addParam("wmode", "transparent");
   so.write(div);
}

function EventsInit() {
	$('.button').hover(function(){
		$(this).css('height', 'auto');
	}, function(){
		$(this).css('height', '70px');
	});
	
	$('.withSub').click(function(){
		if (parseInt($(this).attr('name')) == 0) {
			$(this).attr('name', 2);
			$('.linkLeft[name="1"]').each(function(){$(this).click();});
			$(this).next().animate({height: 'show'}, 'slow', null, function(){
																									$(this).prev().attr('name', 1);
																								  });
		} else if (parseInt($(this).attr('name')) == 1) {
			$(this).attr('name', 2);
			$(this).next().animate({height: 'hide'}, 'slow', null, function(){
																									$(this).prev().attr('name', 0);
																								  });
		}
	});
}

if (window.addEventListener) {
	window.addEventListener("load", Init, false);
}else if (window.attachEvent) {
	window.attachEvent("onload", Init);
}