
function strpos (haystack, needle, offset) {
	var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
	return i === -1 ? false : i;
	}

document.createElement('section');
document.createElement('header');
document.createElement('address');
document.createElement('nav');
document.createElement('footer');
document.createElement('hgroup');
document.createElement('menu');

$(document).ready(function() {
	
	koa_ustawProjekt();
	koa_uruchomProjekt();
	
	});

$(window).bind("load", function() {
	koa_ustawProjekt();
	});
	

$(window).resize(function() {
	koa_ustawProjekt();
	});


var koa_coMaBycWlaczone = new Array();
var koa_toStronaGlowna = true;
var koa_toJestTragicznaPrzegladarka = false;


/* ustawia na ekranie inne elementy projektu */
function koa_ustawProjekt() {
	
	if ($("DIV#podstronaTresc").length) {
		var koa_toStronaGlowna = false;
	} else {
		var koa_toStronaGlowna = true;
		}
	
	if (koa_toStronaGlowna) {
		var najnizszyElement = Math.max(
			$("DIV#glownaPrawa").offset().top+$("DIV#glownaPrawa").height()+10,
			$("DIV#glownaLewa").offset().top+$("DIV#glownaLewa").height()+10,
			$(window).height()-$("DIV#stopka").height()-10
			);
	} else {
		var najnizszyElement = Math.max(
			$("DIV#glownaLewa").position().top+$("DIV#glownaLewa").height()+30,
			$("DIV#podstronaTresc").offset().top+$("DIV#podstronaTresc").height()+30,
			$(window).height()-$("DIV#stopka").height()-10
			);
		najnizszyElement = najnizszyElement;
		}
	$("DIV#stopka").css("top", najnizszyElement + "px");
	$("DIV#stopka").show();
	
	}

/* uruchamia mechanizmy obsługi projektu */
function koa_uruchomProjekt() {
	
	if ($("DIV#podstronaTresc").length) {
		var koa_toStronaGlowna = false;
	} else {
		var koa_toStronaGlowna = true;
		}
	
	
	if (strpos(navigator.userAgent, "MSIE 6") || strpos(navigator.userAgent, "MSIE 7") || strpos(navigator.userAgent, "MSIE 8")) {
		// nie bede robic rogow
		/*
		DD_roundies.addRule('#menuGlowne', '10px');
		DD_roundies.addRule('#menuGlowne A', '10px');
		DD_roundies.addRule('.podMenu', '10px');
		DD_roundies.addRule('.podMenu A', '10px');
		if (koa_toStronaGlowna) {
			DD_roundies.addRule('DIV.boksy', '10px');
			DD_roundies.addRule('DIV#pasekZeZdjeciami', '10px');
			DD_roundies.addRule('DIV#zdjeciaSterowka', '0 0 10px 10px');
			}
		*/
		koa_toJestTragicznaPrzegladarka = true;
	} else {
		$("#menuGlowne").corner(10);
		$("#menuGlowne A").corner(10);
		$(".podMenu").corner(10);
		$(".podMenu A").corner(10);
		if (koa_toStronaGlowna) {
			$("DIV.boksy").corner();
			$("DIV#pasekZeZdjeciami").corner();
			$("DIV#zdjeciaSterowka").corner("bl br");
			}
		}
	
	$("#menuGlowne A").bind("mouseover", function() {
		$(this).addClass("n")
		});
	$("#menuGlowne A").bind("mouseout", function() {
		$(this).removeClass("n")
		});
	
	if (koa_toStronaGlowna) {
		$("DIV.boksy:last").css("marginRight", "0px");
		}
	
	if (strpos(navigator.userAgent, "MSIE")) {
		$("DIV#menuGlowne A:last").css("paddingRight", "16px");
	} else {
		$("DIV#menuGlowne A:last").css("paddingRight", "18px");
		}
	
	if (koa_toStronaGlowna) {
		$("DIV#akredytacje").html($("DIV#alok-akredytacje").html());
		}
	
	$("#strefa-rodzica-adres-email").bind('click focusin keydown', function() { koa_czyscPole('strefa-rodzica-adres-email'); });
	$("#strefa-rodzica-adres-email").bind('blur', function() { koa_uzupelnijPole('strefa-rodzica-adres-email'); });
	koa_uzupelnijPole('strefa-rodzica-adres-email');
	$("#newsletter-adres-email").bind('click focusin keydown', function() { koa_czyscPole('newsletter-adres-email'); });
	$("#newsletter-adres-email").bind('blur', function() { koa_uzupelnijPole('newsletter-adres-email'); });
	koa_uzupelnijPole('newsletter-adres-email');
	
	if (koa_toStronaGlowna) {
		koa_pokazFotografie();
		}
	
	
	$("DIV#menuGlowne A[data-identyfikator], DIV.podMenu[data-identyfikator]").mouseover(function() {
		$('DIV.podMenu[data-identyfikator!="' + $(this).attr("data-identyfikator") + '"]').hide();
		$('DIV.podMenu[data-identyfikator="' + $(this).attr("data-identyfikator") + '"]').show();
		var pozycjaGornego = $('DIV#menuGlowne A[data-identyfikator="' + $(this).attr("data-identyfikator") + '"]').offset().left;
		var pozycjaStartowa = $('DIV#menuGlowne').position().left;
		if (koa_toStronaGlowna) {
			var kraniecObrazka = $('DIV#glownaPrawa').offset().left + $('DIV#glownaPrawa').width();
		} else {
			var kraniecObrazka = $('DIV#glownaTresc').offset().left + $('DIV#glownaTresc').width();
			}
		pozycjaGornego = pozycjaGornego-pozycjaStartowa;
		var roznicaOdKranca = kraniecObrazka-(pozycjaGornego+pozycjaStartowa+$('DIV.podMenu[data-identyfikator="' + $(this).attr("data-identyfikator") + '"]').width()+8);
		if (roznicaOdKranca < 0) {
			pozycjaGornego = pozycjaGornego + roznicaOdKranca;
			}
		$('DIV.podMenu[data-identyfikator="' + $(this).attr("data-identyfikator") + '"]').css("marginLeft", pozycjaGornego + "px");
		koa_coMaBycWlaczone[$(this).attr("data-identyfikator")] = "tak";
		});
	$("DIV.podMenu[data-identyfikator]").mouseout(function() {
		//alert(koa_coMaBycWlaczone[$(this).attr("data-identyfikator")]);
		//$('DIV.podMenu[data-identyfikator="' + $(this).attr("data-identyfikator") + '"]').hide();
		koa_coMaBycWlaczone[$(this).attr("data-identyfikator")] = "nie";
		setTimeout("koa_wylaczMenu('" + $(this).attr("data-identyfikator") + "');", 1000);
		});
	
	
	$("DIV#podstronaTresc IMG").filter(function() {
		if ($(this).css("float") == "right") {
			$(this).css("margin", "20px");
			$(this).css("marginRight", "0px");
		} else if ($(this).css("float") == "left") {
			$(this).css("margin", "20px");
			$(this).css("marginLeft", "0px");
			}
		});
	
	}

/* obsluguje pasek */
var pasekObrazkowTimeout;
function koa_pokazFotografie(numer) {
	
	// czyszcze timeouty
	clearTimeout(pasekObrazkowTimeout);
		
	// ewentualnie zmieniamy aktualna zawartosc
	if (numer) {
		$("DIV#zdjeciaSterowka-ikonki").attr("data-wybrana", numer);
		}
	
	var numerDoPokazania = $("DIV#zdjeciaSterowka-ikonki").attr("data-wybrana");
	var sumaObrazkow = $("DIV#zdjeciaSterowka-ikonki").attr("data-ikonek");
	var nowyOpisIkonek = "";
	
	// ukrywam wszystkie i pokazuje wybrany
	$("DIV#zdjeciaSterowka SPAN").hide();
	$("DIV#zdjeciaSterowka SPAN#opisZdjecia-" + numerDoPokazania + "").show();
	
	// zmieniam fotografie
	$("DIV#pasekZeZdjeciami").css("backgroundImage", "url(/koala/plik/galeria-" + numerDoPokazania + "_nn" + zdjeciaDoPaska[numerDoPokazania] + ".jpg)");
	
	// przelaczam ikonki sterujace
	for (i=1; i<=sumaObrazkow; i++) {
		if (i == parseInt(numerDoPokazania)) {
			nowyOpisIkonek = nowyOpisIkonek + '<img src="/koala/plik/ikonka-galerii-a_nn14.png" alt="" onClick="koa_pokazFotografie(' + i + ');">';
		} else {
			nowyOpisIkonek = nowyOpisIkonek + '<img src="/koala/plik/ikonka-galerii-n_nn20.png" alt="" onClick="koa_pokazFotografie(' + i + ');">';
			}
		}
	$("DIV#zdjeciaSterowka-ikonki").html(nowyOpisIkonek);
	
	// obliczam pokazanie nastepnego
	var nastepnyObrazek = parseInt(numerDoPokazania) + 1;
	if (nastepnyObrazek > sumaObrazkow) { nastepnyObrazek = 1; }
	pasekObrazkowTimeout = setTimeout("koa_pokazFotografie(" + nastepnyObrazek + ");",5000);
	
	}

function koa_czyscPole(idPola) {
	if ($("#" + idPola).attr("value") === $("#" + idPola).attr("data-value")) {
		$("#" + idPola).attr("value", "");
		}
	}
function koa_uzupelnijPole(idPola) {
	if ($("#" + idPola).attr("value") === "") {
		$("#" + idPola).attr("value", $("#" + idPola).attr("data-value"));
		}
	}

function koa_wylaczMenu(idMenu) {
	if (koa_coMaBycWlaczone[idMenu] !== "tak") {
		$('DIV.podMenu[data-identyfikator="' + idMenu + '"]').hide();
		}
	}
