
/* zmienne językowe w zewnętrznym skrypcie */

function myDeActivateAll(elementId)
{
	var el = document.getElementById(elementId);
	myDeActivateSiblings(el);
	myDeActivate(el);
	
	var els = document.getElementById('opisy').getElementsByTagName('div');
	for (var i=els.length-1; i>=0; i--)
	{
		classNameRemove(els[i], 'nonjsmarker');
	}

	var el = document.getElementById('showAll');
		el.innerHTML = myPokazAllHTML;
		el.active = false;


}


function mySetActiveEl(elementId) 
{
	
	if (!isArray(elementId))
		test = Array(elementId);
	else 
		test = elementId;
	


	for(i=0; i<test.length; i++) 
	{
		var el = document.getElementById(test[i]);		
		if (el.active)
		{
			myDeActivate(el);
		}
		else
		{
			if (i == 0) myDeActivateSiblings(el);
			myActivate(el);
		}
	}
}
/**/


function classNameRemove(el, name)
{
	if (el.className == "undefined")
		el.className  = new String('');
	el.className = el.className.replace(name, '');	
}

function classNameAdd(el, name)
{
	classNameRemove(el, name);
	if (el.className == "undefined")
		el.className  = new String('');
	el.className = el.className + ' ' + name;
}



function myDeActivate(el)
{
	var el_ramka = document.getElementById( el.id + '_r');

	classNameRemove(el, 'active');
	classNameRemove(el_ramka, 'ac');

	el.active = false;


	/* pobierz pierwszy poddiv pierwszego diva == "ukryj" */
	var subdivs = el.getElementsByTagName('div');
	if (subdivs.length>0)
	{
		var firstDiv = subdivs[0];
		var subsubdivs = firstDiv.getElementsByTagName('div');
		if (subsubdivs.length>0) {
			subsubdivs[0].innerHTML = myPokazElHTML;
			if (subsubdivs.length>1) subsubdivs[1].innerHTML = myPokazFoto;
		}
		
	}
	myHideGal();
}

function myActivate(el) 
{
	var el_ramka = document.getElementById( el.id + '_r');

	classNameAdd(el, 'active');
	classNameAdd(el_ramka, 'ac');

	el.active = true;


	/* pobierz pierwszy poddiv pierwszego diva == "ukryj" */
	var subdivs = el.getElementsByTagName('div');
	if (subdivs.length>0)
	{
		var firstDiv = subdivs[0];
		var subsubdivs = firstDiv.getElementsByTagName('div');
		if (subsubdivs.length>0){		
			subsubdivs[0].innerHTML = myUkryjElHTML
		/*	subsubdivs[1].innerHTML = myPokazFoto;*/
		}
	}
}


function myDeActivateSiblings(el)
{
	var nextS = el.nextSibling;
	var prevS = el.previousSibling;
	
	while (nextS != null)
	{
		if (nextS.nodeName == 'DIV')
			if (nextS.id != 'showAll')
				myDeActivate(nextS);
		nextS = nextS.nextSibling;
	}
	while (prevS != null)
	{
		if (prevS.nodeName == 'DIV') 
			if (prevS.id != 'showAll')
			myDeActivate(prevS);
		prevS = prevS.previousSibling;
	}

}

function myActivateSiblings(el)
{
	var nextS = el.nextSibling;
	var prevS = el.previousSibling;
	
	while (nextS != null)
	{
		if (nextS.nodeName == 'DIV')
			if (nextS.id != 'showAll')
			myActivate(nextS);
		nextS = nextS.nextSibling;
	}
	while (prevS != null)
	{
		if (prevS.nodeName == 'DIV')
			if (prevS.id != 'showAll')
			myActivate(prevS);
		prevS = prevS.previousSibling;
	}

}



function myActivateAll()
{
	var el = document.getElementById('showAll');
	if (el.active == true)
	{
		myDeActivateSiblings(el);
		el.innerHTML = myPokazAllHTML;
		el.active = false;
	}
	else
	{
		myActivateSiblings(el);
		el.innerHTML = myUkryjAllHTML;
		el.active = true;
	}
	
}


/* http://blogs.wdevs.com/Sukumar/archive/2005/05/10/3335.aspx */
function isArray(a)
 {
  return isObject(a) && a.constructor == Array;
 }
 

function isObject(a)
 {
     return (typeof a == 'object' && !!a) || isFunction(a);
 }
 
  function isFunction(a)
 {
      return typeof a == 'function';
 }
 /**/



function  myShowGal(name , galSize) {
	var gal = document.getElementById("gal");
	var galeria = document.getElementById("mapa_galeria");
	galeria.innerHTML = '';

// pokaż diva z galerią
	switch(galSize){
		case 'small':
		case 'midi':
			classNameAdd(gal, galSize);
			break;
	}
	classNameAdd(gal, 'disp');

//załaduj galerię do diva
	var path = galFiles +'gal.php?gal=' + name + '&lang=' + language;

	if (window.XMLHttpRequest) {
		requester = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		requester = new ActiveXObject("Microsoft.XMLHTTP");
	}
	requester.onreadystatechange = myHandler;
	requester.open("GET", path);
	requester.send(null);
}
	
function myHandler()
{
	var galeria = document.getElementById("mapa_galeria");	
	var gal = document.getElementById("gal");
	if (requester.readyState == 4)
	{
		if (requester.status == 200)
		{
		el = document.createElement('div');
		el.innerHTML = requester.responseText;
		galeria.innerHTML = el.innerHTML;
		}
	}
	return true;
}


/**/

function  myHideGal() {
	var gal = document.getElementById("gal");	
	if (gal) {
		classNameRemove( gal, 'disp'); 
		classNameRemove( gal, 'small');
		classNameRemove( gal, 'midi');		
	}
}



// http://developer.apple.com/internet/webcontent/iframe.html

var IFrameObj; // our IFrame object
function myShowGal_2(name , smallGal) {
 	var GalIdName = String('galRamka');
		
  if (!document.createElement) {return true};
  var IFrameDoc;
//  var URL = 'server.html';
	var path = galFiles +'?gal=' + name;

	var galEl = document.getElementById('gal');
		classNameAdd( galEl, 'disp');
		if(smallGal == '1' ) classNameAdd( galEl, 'small');
	
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {

	  
//      var tempIFrame=galEl.createElement('iframe');
	{
		var dv = document.createElement ('div');
		dv = document.body.appendChild (dv);
		dv.innerHTML = '<iframe id="' + GalIdName + '" name="' + GalIdName + '" borderframe="0"></iframe>'
		var iframe = document.getElementById("galRamka")
	}

      tempIFrame.setAttribute('id',GalIdName);
      tempIFrame.setAttribute('name',GalIdName);
      tempIFrame.setAttribute('frameborder',0);

		IFrameObj = galEl.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames[GalIdName];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="'  + GalIdName + '"';
      iframeHTML+=' name="'+ GalIdName + '" frameborder="0"';
      iframeHTML+= '"><\/iframe>';
      galEl.innerHTML+=iframeHTML;
	  
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('galRamka');
      IFrameObj.document.location.replace = function(location) {
        //this.iframe.src = location;
		iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('myShowGal_2()',50);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
//		alert('ns6-2');
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
//		alert('ie5.5/ie6');
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
//		alert('ie5');
  } else {
  	alert('else');
    return true;
  }

  IFrameDoc.location.replace(path);
// alert('aaa');
  return false;
}



function myToggleShowOnMap(elname)
{
	var el = document.getElementById(elname);
	if (el.active == true)
	{
		classNameRemove(el, 'ac');
		el.active = false;
	}
	else
	{
		classNameAdd(el, 'ac');
		el.active = true;
	}
	
}



function myOnLoad(param){
	myDeActivateAll(param);
}
