function Init() {
	SetSize();
	LightboxInit();
	EventsInit();
	
	$('#ContentRight').find('A').each(function(){
		if ((!$(this).attr('id')) && (!$(this).attr('class'))) $(this).addClass('link');
	});
}

function Wyrownaj() {
	cl = parseInt($('#Column_left').height());
	cr = parseInt($('#Column_right').height());
	(cl>cr)?c=cl:c=cr;
	$('#Column_left').height(c + 'px');
	$('#Column_right').height(c + 'px');
}

function Zaokraglij(co, ile) {
	li = Math.pow(10, ile);
	w = Math.round(co * li) / li;
	return w;
}

function SetSize() {
	contentLeft_h = $('#ContentLeft').height();
	contentRight_h = $('#ContentRight').height();
	if (contentLeft_h < contentRight_h) $('#ContentLeftContactBox').css('margin-top', (contentRight_h - contentLeft_h) + 'px');
}

function LightboxInit() {
	$("#ContentRight A").each(function(){
		if (UseLightbox($(this).attr('href'))) $(this).attr('name', 'UseLBox');
	});
	$("#ContentRight A[name='UseLBox']").lightBox();
/*	if ($("#ContentRight A[name='UseLBox']").attr("title") != 'undefined') $("#ContentRight A[name='UseLBox']").attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne."); */
	
	$("#ContentRight A[name='UseLBox']").each(function(){
/*		$(this).lightBox();*/
		if (($(this).attr("title") == undefined) || ($(this).attr("title").length == 0)) $(this).attr("title", "Kliknij z boku zdjęcia aby zobaczyć następne.");
	});
}

function UseLightbox(string) {
	if (string.toLowerCase().indexOf('.jpg') > 0) return true;
	if (string.toLowerCase().indexOf('.jpeg') > 0) return true;
	if (string.toLowerCase().indexOf('.gif') > 0) return true;
	if (string.toLowerCase().indexOf('.png') > 0) return true;
	if (string.toLowerCase().indexOf('.bmp') > 0) return true;
	if (string.toLowerCase().indexOf('.tif') > 0) return true;
	return false;
}

function EventsInit() {
	$('.wyprawyTable TR').hover(function(){
		$(this).addClass('blink');
	}, function(){
		$(this).removeClass('blink');
	});
	
	$('.wyprawyTable TR').click(function(){
		var id = $(this).attr('id').substr(2);
		var attributes = $('#attributes').val();
		document.location.href = 'index.php' + attributes + '&id=' + id;
	});
	
	$('.searchButton').click(function(){
		$('#SearchForm').submit();
	});
}

if (window.addEventListener) {
	window.addEventListener("load", Init, false);
}else if (window.attachEvent) {
	window.attachEvent("onload", Init);
}