/*
JavaScript Gallery v1.4
Copyright (C) 2008 Aptus s.c.
All rights reserved
Change date: 15.06.2009
*/

var jsgId='JSgallery';
var jsgImgPath='i/';
var jsgDefaultId='jsg';

var jsgActive=null;
var jsgGalleries=[];
var jsgCallback=false;
var jsgSrc;

function jsgMove()
{
	var e=document.getElementById(jsgId);
	if(e)
		e.style.top = document.documentElement.scrollTop + 'px';	
}

function jsgOnScroll(e)
{
		jsgMove();
}

function jsgResize()
{
	var ew = 0;
	var eh = 0;
	if(typeof(window.innerWidth) == 'number'){
		ew = window.innerWidth;
		eh = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		ew = document.documentElement.clientWidth;
		eh = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		ew = document.body.clientWidth;
		eh = document.body.clientHeight;
	}
	
	var e=document.getElementById(jsgId);
	if(e) {
		var es=e.style;
		if(es.display!='none') {
			es.display='none';
			es.width=ew+'px';
			es.height=eh+'px';
			es.display='';
		}
	}
}

function jsgOnResize(e)
{
	jsgResize();
}


function jsgLoad(e)
{
	jsgMove();
}

function jsgImgClick(e)
{
	var img=document.getElementById(jsgId+'_image');
	if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
		var ew = document.documentElement.clientWidth;
	else
		var ew = document.getElementsByTagName('body')[0].clientWidth;
	var x=e ? e.pageX : event.clientX;
	if(x<ew/2)
		jsgActive.prev();
	else
		jsgActive.next();
}

function jsgImgOver()
{
	document.getElementById(jsgId+'_navcntr').style.display = 'block';
}

function jsgImgOut()
{
	document.getElementById(jsgId+'_navcntr').style.display = 'none';
}

function jsgInit()
{
	var e=document.getElementById(jsgId);
	if(!e) {
		window.onresize=jsgOnResize;
		var e=document.createElement('div');
		e.id=jsgId;
		try{e.style.position = 'fixed';} catch(err){e.style.position='absolute';};
		var browser_ver = parseInt(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5,navigator.appVersion.length));
		if(navigator.appName=="Microsoft Internet Explorer" && browser_ver<=6)
			e.style.position='absolute';
		if(e.style.position=='absolute')
			window.onscroll=jsgOnScroll;
		e.style.left='0px';
		e.style.top='0px';
		var bg='';
		if(typeof e.style.opacity!='undefined')
			bg ='<div style="background-color:#000; opacity:0.6; z-index:9995; position:absolute; width:100%; height:100%;"></div>';		
		else if(typeof e.style.filter!='undefined')
      bg ='<div style="background-color:#000; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=60); z-index:9995; position:absolute; width:100%; height:100%;"></div>';    
		else			
			e.style.backgroundImage='url('+jsgImgPath+'jsg_bg.gif)';
		e.innerHTML=bg+'<table style="position:relative;width:100%;height:100%;z-index:9999;" id="'+jsgId+'_window"><tr><td style="vertical-align:middle;text-align:center;"><table style="margin:auto;text-align:left;" cellspacing=0 cellpadding=0 class="jsg"><tr><td class="jheader"><a href="javascript:jsgClose();void(0);"><img src="'+jsgImgPath+'jsg_close.gif"></a><span id="'+jsgId+'_title"></span></td></tr><tr><td class="image"><div style="position:relative;" id="'+jsgId+'_image_container"><img src="" id="'+jsgId+'_image"><div style="position:absolute;width:100%;top:20%;left:0;display:none;" class="navcntr" id="'+jsgId+'_navcntr"></div></div></td></tr><tr><td class="jfooter" id="'+jsgId+'_footer"><div class="navi" id="'+jsgId+'_navi"></div><span id="'+jsgId+'_desc"></span></td></tr></table></td></tr></table>';
		document.body.appendChild(e);
		e=document.getElementById(jsgId);
		var img=document.getElementById(jsgId+'_image');
		//if(img.addEventListener && e.style.position=='absolute')
			//img.addEventListener('load',jsgLoad,false);
		var img_cont = document.getElementById(jsgId+'_image_container');
		img_cont.onclick=jsgImgClick;			
		img_cont.onmouseover=jsgImgOver;
		img_cont.onmouseout=jsgImgOut;		
	}
	if(e.style.position=='absolute')
		jsgMove();
	e.style.display='';	
}

function jsgClose()
{
	var e=document.getElementById(jsgId);
	if(e) {
		e.style.display='none';
		document.getElementById(jsgId+'_image').src='';
	}
	jsgActive=null;
}

function jsgShow(i)
{
	this.current=i;
	var img=this.images[i];	
	document.getElementById(jsgId+'_image').src=typeof(img)=='object' ? img[0] : img;		
	var desc=(this.title.length>0 || this.images.length>1) ? (i+1)+'/'+this.images.length+' '+(typeof(img)=='object' ? img[1] : '') : '';
	var title=(this.title.length>0 || this.images.length>1) ? this.title : typeof(img)=='object' ? img[1] : '';
	var navi = this.images.length>1 ? '<a href="javascript:jsgActive.first();void(0);"><img src="'+jsgImgPath+'jsg_first.gif"></a><a href="javascript:jsgActive.prev();void(0);"><img src="'+jsgImgPath+'jsg_prev.gif"></a><a href="javascript:jsgActive.next();void(0);"><img src="'+jsgImgPath+'jsg_next.gif"></a><a href="javascript:jsgActive.last();void(0);"><img src="'+jsgImgPath+'jsg_last.gif"></a>' : '';
	var navcntr = '';
	if(this.images.length>1){
		navcntr += i!==0 ? '<img style="float:left;border-left:none;" src="'+jsgImgPath+'jsg_arrowl.gif">' : '';
		navcntr += i!=this.images.length-1 ? '<img style="float:right;border-right:none;" src="'+jsgImgPath+'jsg_arrowr.gif">' : '';
	}
	
	document.getElementById(jsgId+'_navi').innerHTML = navi;
	document.getElementById(jsgId+'_navcntr').innerHTML = navcntr;
	document.getElementById(jsgId+'_desc').innerHTML = desc;
	document.getElementById(jsgId+'_title').innerHTML = title;
	
	window.setTimeout(jsgResize,100); //ie6, safari fix
}

function jsgOpen(i)
{
	jsgInit();
	jsgActive=this;	
	this.show(i);
}

function jsgFirst()
{
	this.show(0);
}

function jsgPrev()
{
	if(this.current>0)
		this.show(this.current-1);
}

function jsgNext()
{
	if(this.current<this.images.length-1)
		this.show(this.current+1);
}

function jsgLast()
{
	this.show(this.images.length-1);
}

function jsgFind(i)
{
	var c;
	for(c=0; c<this.images.length; c++)
		if(i==(typeof(this.images[c])=='object' ? this.images[c][0] : this.images[c]))
			return c;
	return null;
}

function JSgallery(g,t)
{
	this.images=g;
	this.title=t;
	this.open=jsgOpen;
	this.show=jsgShow;
	this.first=jsgFirst;
	this.prev=jsgPrev;
	this.next=jsgNext;
	this.last=jsgLast;
	this.find=jsgFind;
	this.move=true;
}

function jsgFindImages(e,d)
{
	var img=new Array();
	var i,j;
	for(i=0; i<e.childNodes.length; i++)
		if(e.childNodes[i].tagName) {
			if(e.childNodes[i].tagName=='IMG' && e.childNodes[i].onclick) {
				e.childNodes[i].onclick();
				img.push([jsgSrc,e.childNodes[i].title]);
			}
			else if(e.childNodes[i].tagName=='A' && e.childNodes[i].id==d) {
				img.push([e.childNodes[i].href,e.childNodes[i].title]);
			}
			var img2=jsgFindImages(e.childNodes[i],d);
			for(j=0; j<img2.length; j++)
				img.push(img2[j]);
		}
	return img;
}

function jsgClick(i,e,d)
{
	var l=false;
	var jsgTmp;
	if(jsgCallback) {
		jsgSrc=i;
		return;
	}
	if(typeof(i)=='object') {


		d=e;
		e=i;
		i=i.href;
	}
	if(typeof(e)=='object')
		l=true;
	else
		d=e;
	if(typeof(d)=='undefined')
		d=jsgDefaultId;
	if(l || typeof(jsgGalleries[d])=='undefined') {
		var bl;
		if(l) {
			var eh=e;
			while(e) {

				if(e.id==d) {
					bl=e;
					break;
				}
				e=e.parentNode;
			}
			if(!bl) {
				jsgTmp=new JSgallery([i],eh.title);
				jsgTmp.single=true;
				jsgTmp.open(0);
				return false;
			}
		}
		else
			bl=document.getElementById(d);
		if(!bl)
			return;
		jsgCallback=true;
		var img=jsgFindImages(bl,d+'i');
		jsgCallback=false;
		jsgTmp=new JSgallery(img,bl.title);
		if(!l)
			jsgGalleries[d]=jsgTmp;
	}
	else
		jsgTmp=jsgGalleries[d];
	jsgTmp.open(jsgTmp.find(i));
	return false;
}

/* OTHER */

function dlg_flash(path,width,height,transp)
{
	var browser_ver = parseInt(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5,navigator.appVersion.length));
	var ie8less = navigator.appName=="Microsoft Internet Explorer" && browser_ver<=7;
	if(ie8less){
		document.write('<OBJECT codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'" id="top1" ALIGN="left">');
		document.write('<PARAM NAME="movie" VALUE="'+path+'"><PARAM NAME="quality" VALUE="high">');
		if(transp==1)
			document.write('<PARAM NAME="wmode" VALUE="transparent">');
	}
	document.write('<EMBED src="'+path+'" quality=high ');
	if(transp==1)
		document.write('wmode=transparent ');
	document.write('WIDTH="'+width+'" HEIGHT="'+height+'" NAME="prezentacja" ALIGN="left" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
	if(ie8less)
		document.write('</OBJECT>');
}

function toggleMenu(elem)
{
	if(elem.nodeName.toLowerCase()=='a'){
		while(elem.nodeName.toLowerCase()!='div'){
			elem = elem.nextSibling;
				if(!elem)
				return;
		}
		elem.parentNode.className=='btn4'?elem.parentNode.className='btn2':elem.parentNode.className='btn4';
		if(elem.className=='buttons' && elem.style.display=='none')
			elem.style.display='block';
		else if(elem.className=='buttons' && elem.style.display=='block')
			elem.style.display='none';
	}
	else{
		childs = elem.childNodes;
		for(var i=0;i<childs.length;i++)
			if(childs[i].className=='buttons' && childs[i].style.display=='none')
				childs[i].style.display='block';
			else if(childs[i].className=='buttons' && childs[i].style.display=='block')
				childs[i].style.display='none';
	}
}

function toggleClass(elem,a)
{
	if(a==1){
		if(elem.className=='btn2')
			elem.className='btn4';
		else
			elem.className='btn2';
		clearClass();
	}
	else{
		switch(elem.className){
			case 'btn2':elem.className='btn';break;
			case 'btn3':elem.className='btn4';break;
			case 'btn4':elem.className='btn3';break;
			default: elem.className='btn2';break;
		}
	}
}

function mouse_over(elem){
	switch(elem.className){
		case 'btn':elem.className='btn2';break;
		case 'btn3':elem.className='btn4';break;
		default: elem.className='btn2';break;
	}
}

function mouse_out(elem){
	switch(elem.className){
		case 'btn2':elem.className='btn';break;
		case 'btn4':elem.className='btn3';break;
		default: elem.className='btn';break;
	}
}

function clearClass(){
	var menu = document.getElementById('menu');
	if(!menu)
		return;
	items = menu.getElementsByTagName('div');
	for(var i=0;i<items.length;i++){
		if(items[i].nodeName.toLowerCase()=='div' && items[i].className=='btn3')
			items[i].className='btn';
	}
}

var sub_click = false;
window.onload = function(){
	var menu = document.getElementById('menu');
	if(!menu)
		return;
	items = menu.getElementsByTagName('div');
	for(var i=0;i<items.length;i++){
		if(items[i].nodeName.toLowerCase()=='div' && (items[i].className=='btn' || items[i].className=='btn3')){
			items[i].onmouseover = function(){mouse_over(this);}
			items[i].onmouseout = function(){mouse_out(this);}
			items[i].onclick = function(){if(sub_click){sub_click=false;}else{toggleClass(this,1);}}
		}
		if(items[i].nodeName.toLowerCase()=='div' && items[i].className=='subitems')
			items[i].onclick = function(){sub_click=true;}
	}
}