function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function GetContent() {

   document.getElementById("sSite").value = document.getElementById("content").innerHTML
   //document.write('<input type="hidden" name="sSite" value="'+html+'">');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}


function PokazZwin(id){
	var div = document.getElementById(id);

	if(div.style.display == 'none'){
		div.style.display = 'block';
	}else{
		div.style.display = 'none';
	}
}

var timeout = 250;
var timeoutObjectReferences = Array ();


function toggleCombo  (comboListDivId)
{
	//var comboListDivId = 'comboList';
	if ( document.getElementById ( comboListDivId ).style.display == 'none' )
	{
		showLayer ( comboListDivId );
	}
	else
	{
		hideLayer ( comboListDivId );
	}
}

function showLayer ( layerId )
{
	var onMouseOverEvent = 'clearTimeout( timeoutObjectReferences [\'' + layerId + '\'] )';
	var onMouseOutEvent = 'hideLayer(\'' + layerId + '\')';

	var objectReference = document.getElementById ( layerId );

	clearTimeout(timeoutObjectReferences [ layerId ] );

	objectReference.style.display = '';

	objectReference.onmouseout = function ()
	{
		//eval ( onMouseOutEvent );
	};

	document.onclick = function ()
	{
		eval ( onMouseOutEvent );
	};
	objectReference.onmouseover = function ()
	{
		eval ( onMouseOverEvent );
	};
}

function hideLayer ( layerId )
{
	timeoutObjectReferences [ layerId ] = setTimeout ( "document.getElementById ( '" + layerId + "' ).style.display = 'none'", timeout );
}

function ustawHidden(hidden,value,select,tekst,LayerToHide){
	document.getElementById (LayerToHide).style.display = 'none';
	document.getElementById(hidden).value=value;
	document.getElementById(select).innerHTML=tekst;
}

function drukuj(id,typ){
	displayWindow('drukuj.php?id='+id+'&typ='+typ,670,600);
}

function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + 'resizable=no,scrollbars=no,menubar=no' );
}

function SendNewsletter(value)
{
 if (value == 0) document.getElementById('opcjanews').value='off';
 else document.getElementById('opcjanews').value='on';

 document.newsletter.submit();
}



//DODAJ DO ULUBIONYCH
function addToBookmarks( sTitle, sHref )
	{
	//Wersja skryptu 1.0
	//Modyfikacji dokonał: Krzysztof Samelko
	//Data: 2008-05-12

	if( window.sidebar && window.sidebar.addPanel )
		{
		//Gecko (Netscape 6 etc.) - add to Sidebar
		window.sidebar.addPanel( sTitle, sHref, '' );
		}
	else if( window.external && ( navigator.platform == 'Win32' || ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) )
		{
		//IE Win32 or iCab - checking for AddFavorite produces errors for no
		//good reason, so I use a platform and browser detect.
		//adds the current page page as a favourite; if this is unwanted,
		//simply write the desired page in here instead of 'location.href'
		window.external.AddFavorite( window.location.href, document.title );
		}
	else if( window.opera && window.print )
		{

		//window.open('js/opera_dodaj_do_ulubionych.php','','width=150,height=50');
		//Opera 6+ - add as sidebar panel to Hotlist
		return true;
		}
	else if( document.layers )
		{
		//NS4 & Escape - tell them how to add a bookmark quickly (adds current page,
		//not target page)
		window.alert( 'Proszę kilknąć Ctrl+D aby dodać strone do ulubionych' );
		}
	else
		{
		//other browsers - tell them to add a bookmark (adds current page, not target page)
		window.alert( 'Proszę użyć menu przeglądarki by utworzyć dodać strone do ulubionych' );
		}
	return false;
	}
//DODAJ DO ULUBIONYCH

function navHover() {

	var lis = document.getElementById("navmenu").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}

function PokazZdjecieRef(id) {
    //symulacja kliknięcia na linka z podpiętym thickboxem
    $("#refer"+id).click();
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

//podmiana na naglowki flashowe
//podmieniany tekst powinien byc w tagu z atrybutem "rel" rozpoczynajacym sie na "textbox..." - ladowany jest taki plik jak t atrybucie "rel"
function FlashHeaders() {
    var  i=0;
    $.each($("[class^=textbox]"), function(){
    id = 'h'+i;
    $(this).attr('id', id);
    tekst = trim($(this).text());
    textbox = $(this).attr('class');
    if(textbox == 'textbox_stronaglowna')
        width = 300;
    else
        width = 600;
		// WEBROOT już jest :P po co to dublować?
		
		//jak tekst jest za dlugi to proba wyswietlenia w 2 linijkach 
		if(tekst.length > 75){
			//pierwsza spacja po 70 znaku
			przelamanie = tekst.indexOf(" ", 65);
			if(przelamanie > 75 || przelamanie == -1)
			  przelamanie = tekst.indexOf(" ", 60);
			if(przelamanie > 75 || przelamanie == -1)
			  przelamanie = tekst.indexOf(" ", 55);
			tekst1 = tekst.substr(0, przelamanie);
			tekst2 = tekst.substr((przelamanie+1));
			//wstawienie spana, zeby go podmienic na drugiego flasha
			i=i+1;
			var id2 = 'h'+i;
			$(this).after('<span id="'+id2+'"></span>');
			
			swfobject.embedSWF(document.WEBROOT+'template/flash/'+textbox+'.swf?tekst='+tekst1, id, width, "24", "8.0.0", "expressInstall.swf",
				/* FLASHVARS	*/	{  },
				/* PARAMS 		*/	{ swliveconnect: true, wmode: "transparent", scale: "noborder", salign: "tl", align: "left" },
				/* ATTRIBUTES	*/	{ id: id, name: id }
			);


			swfobject.embedSWF(document.WEBROOT+'template/flash/'+textbox+'.swf?tekst='+tekst2, id2, width, "24", "8.0.0", "expressInstall.swf",
				/* FLASHVARS	*/	{  },
				/* PARAMS 		*/	{ swliveconnect: true, wmode: "transparent", scale: "noborder", salign: "tl", align: "left" },
				/* ATTRIBUTES	*/	{ id: id2, name: id2 }
			);
			i=i+1;
		} else {
			swfobject.embedSWF(document.WEBROOT+'template/flash/'+textbox+'.swf?tekst='+tekst, id, width, "24", "8.0.0", "expressInstall.swf",
				/* FLASHVARS	*/	{  },
				/* PARAMS 		*/	{ swliveconnect: true, wmode: "transparent", scale: "noborder", salign: "tl", align: "left" },
				/* ATTRIBUTES	*/	{ id: id, name: id }
			);
			i=i+1;
		}
    
  });
}

function FlashFiles() {
    var  i=0;
	var aktywne = 0;
    $.each($("[class^=flash_]"), function(){
    id = 'a'+i;
    $(this).attr('id', id);
    tekst = $(this).text();
    name = $(this).attr('class');
	
	if($('#aktywne'))
		aktywne = $('#aktywne').val();
    if(name == 'flash_index') {
        width = 961;
        height = 296;
    } else if(name == 'flash_podstrony') {
        width = 961;
        height = 147;
    } else if(name == 'flash_mapa_dziedzictwo') {
        width = 303;
        height = 169;
    } else if(name == 'flash_mapa_podmenu') {
        width = 225;
        height = 230;
    } else if(name == 'flash_mapa_urzedy' || name == 'flash_mapa_robidz') {
        width = 651;
        height = 269;
    } else if(name == 'flash_mapa_wykaz_muzeum') {
        width = 320;
        height = 284;
    } else if(name == 'flash_kobidz_dla_dzieci') {
        width = 651;
        height = 499;
    }
    	swfobject.embedSWF(document.WEBROOT+'template/flash/'+name+'.swf', id, width, height, "8.0.0", "expressInstall.swf",
			/* FLASHVARS	*/	{ zmienna: tekst, aktywne: aktywne },
			/* PARAMS 		*/	{ swliveconnect: true, wmode: "transparent", scale: "noborder", salign: "tl", align: "left" },
			/* ATTRIBUTES	*/	{ id: id, name: id }
		);
    i=i+1;
  });
}
//pola w rejestracji
function SelectFormFields(typ) {
    if(typ == 's') {
        $("#specjalisci_form").show();
        $("#zarzadcy_form").hide();
        $("#zarzadcy_form input").attr('disabled', 'disabled');
        $("#specjalisci_form input").removeAttr('disabled');
    } else if(typ == 'z') {
        $("#specjalisci_form").hide();
        $("#zarzadcy_form").show();
        $("#specjalisci_form input").attr('disabled', 'disabled');
        $("#zarzadcy_form input").removeAttr('disabled');
    }
}


//zalezne od rodzaju wlasnosci
function ShowHideFields(typ) {
    if(typ == 0) {
        $("#zarzadcy_form_instytucja").hide();
        $("#zarzadcy_form_instytucja input").attr('disabled', 'disabled');
    } else if (typ == 1) {
        $("#zarzadcy_form_instytucja").show();
        $("#zarzadcy_form_instytucja input").removeAttr('disabled');
    }
}

function initRegisterForm(typ, wlasnosc) {
    SelectFormFields(typ);
    if(wlasnosc == 1)
        ShowHideFields(1);
    $(".error").focus(
        function() {
            if($(this).attr('class') == 'error') {
                $(this).removeClass('error');
                $(this).val('');
            }
        }
    );
}



function dodajTooltip(){
	$("#menu_n span, #menu_s span, #menu_z span, #menu_w span").tooltip({
	   showURL: false,
	   left: -10,
       top: -37,
	   track: true
	});
}

function CheckMail() {
    mail = $("#mail").val();
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if((mail == '') || (reg.test(mail) == false)) {
        $("#mail").attr('class', 'error');
        $("#mail").val('nieprawidłowy adres e-mail');
        $(".error").focus(
            function() {
                if($(this).attr('class') == 'error') {
                    $(this).removeClass('error');
                    $(this).val('');
                }
            }
        );
        return false;
    } else {
        return true;
    }

}

function ShowFullKurier(id) {
	$('#kurier'+id).slideDown('normal');
}

//wybranie województwa z mapki flashowej
function SelectWojewodztwo(id) {
	if(id) {
		//muzea
		if(document.getElementById("m_wojewodztwo")) {
			document.getElementById("m_wojewodztwo").value = id;
		} else if (document.getElementById("dla_dzieci")) {
			idm = new Array();
			idm[1] = 782;
			idm[2] = 783;
			idm[3] = 784;
			idm[4] = 785;
			idm[5] = 792;
			idm[6] = 787;
			idm[7] = 786;
			idm[8] = 788;
			idm[9] = 789;
			idm[10] = 790;
			idm[11] = 791;
			idm[12] = 793;
			idm[13] = 794;
			idm[14] = 795;
			idm[15] = 796;
			idm[16] = 797;
			location.href = "idm,"+idm[id]+".html";
		} else if (document.getElementById("dla_mlodziezy")) {
			idm = new Array();
			idm[1] = 891;
			idm[2] = 892;
			idm[3] = 893;
			idm[4] = 894;
			idm[5] = 895;
			idm[6] = 896;
			idm[7] = 897;
			idm[8] = 898;
			idm[9] = 899;
			idm[10] = 900;
			idm[11] = 901;
			idm[12] = 902;
			idm[13] = 903;
			idm[14] = 904;
			idm[15] = 905;
			idm[16] = 906;
			location.href = "idm,"+idm[id]+".html";
		}else {
			//urzędy ochrony zabytków
			var idm = document.getElementById("idm").value;
			location.href = "idm,"+idm+",u_wojewodztwo,"+id+".html";
		}
	}
}
$(document).ready(function(){
    FlashHeaders()
    FlashFiles();
    $('#login_error').focus(
        function(){
            $(this).val('');
            $(this).removeAttr('id');
        }
    );
    dodajTooltip();
	$('.absmiddle').attr('align', 'absmiddle');

		if($.browser.msie){
			$('#artykul .galeria a').hover(
					function(){ $(this).children('img.lupa').css({'height':'144px','width':'144px','display':'block'}); },
					function(){ $(this).children('img.lupa').css({'height':'0px','width':'144px','display':'none'}); }
			);
		}
	$('#brak_flasha').show();
});
