var isIE = navigator.appName.indexOf("Microsoft") > -1 || navigator.appName.indexOf("Opera") > -1 ? true:false;
var isFilters = navigator.appName.indexOf("Microsoft") > -1 ? true:false;
if(location.toString().indexOf("www") != -1) location.replace("http://grden.pl");
var jaki;
var sekcja;
var bodzio;
var debug;
// cookie
var tomek_expi = new Date( );
var dni = tomek_expi.getTime( ) + (200 * 24 * 60 * 60 * 1000);
tomek_expi.setTime(dni);
///
var mail = "Tomek Grden <tomek@akrat.pl>";
///
function chlang(lang,sec){
	document.cookie = "lang=" + lang + "; expires=" + tomek_expi.toGMTString( );
	jaki = lang;
	sekcja = sec;
	timeout: 2000,
advAJAX.setDefaultParameters({ 
group: "main",
onInitialization : function(obj) {document.getElementById(obj.tag).innerHTML = "<div id='" + obj.tag +"_preloader'></div>"},
onError : function(obj) { document.getElementById(obj.tag).innerHTML = "Error loading... " + obj.status + " : " + obj.url},  
onSuccess : function(obj) {
objXml = obj.responseXML;
	var co = "";
	img = "";
	pNode = objXml.documentElement;
	if(pNode.nodeName != "imgs"){
	for(n = 0; n < pNode.childNodes.length;n++){
		if(pNode.childNodes[n].nodeType == 1 && pNode.childNodes[n].attributes[0].value == lang){
		co = isIE ? pNode.childNodes[n].text : pNode.childNodes[n].textContent;
		}
	}
	document.getElementById(obj.tag).innerHTML = co;
	asy = document.getElementsByTagName("a");
	for(as = 0; as < asy.length;as++){
		asy[as].onfocus = function() { this.blur();}
		}
	}else{
	for(o = 0;o < pNode.childNodes.length;o++){
		if(pNode.childNodes[o].nodeType == 1){
			isrc = pNode.childNodes[o].getAttribute('src');
			iwidth = pNode.childNodes[o].getAttribute('width');
			iheight = pNode.childNodes[o].getAttribute('height')
		img += "<a href='javascript:dispImg(\"" + isrc +"\"," + iwidth + "," + iheight +")'height='85'><img src='../" + pNode.childNodes[o].getAttribute("src") + "' height='90'/></a>";
		}
	}
	document.getElementById(obj.tag).innerHTML = img;
	pNodeChild = isIE ? pNode.childNodes[0]:pNode.childNodes[1];
	document.getElementById("bigImg").setAttribute("src",pNodeChild.getAttribute("src"));
	document.getElementById("bigImg").setAttribute("width",pNodeChild.getAttribute("width"));
	document.getElementById("bigImg").setAttribute("height",pNodeChild.getAttribute("height"));
	}
	if(obj.tag == "nav" || obj.tag == "podmenu"){
	markNav();
		}
		//
	var pMenu = document.getElementById("pMenu");
	//
	if(pMenu){	
	var master = pMenu.parentNode;
	var pMenuSection = pMenu.getAttribute("section");
	var pMenuCont = document.createElement("div");
	pMenuCont.setAttribute("id","podmenu");
	pMenuCont.style.height = "18px";
	pMenuCont.style.border = "none 0px white";
	master.appendChild(pMenuCont);
	var zywy = master.replaceChild(pMenuCont,pMenu);	
	advAJAX.get({ group: "main", tag: "podmenu", url: pMenuSection + ".xml" });
	}
}
});

	advAJAX.get({ group: "main", tag: "nav", url: "nav.xml" });
	advAJAX.get({ group: "main", tag: "chlang_top", url: "lang.xml" });
	advAJAX.get({ group: "main", tag: "tresc", url: sekcja + ".xml" });
	advAJAX.get({ group: "main", tag: "news", url: "news.xml" });
	advAJAX.get({ group: "main", tag: "chlang_bottom", url: "lang.xml" });
	//advAJAX.download({tag:"stopka",url:"images.php?kat=images"});

}
///
function chsection(jaka,file){
	urchinTracker(file + ".xml");
	if(file == "home"){
		document.getElementById("homeImg").style.top = "18px";
		document.getElementById("pic").style.visibility = "hidden"
		document.getElementById("news").style.display = "none";
	}else{
		wysun();
		document.getElementById("news").style.display = "block";
	}
	sekcja = file;
	markNav();
advAJAX.get({group: "main",tag: "tresc",url: file + ".xml"});
//am = document.getElementsByTagName("a");
//document.location.replace("./?section=" + file);
//
	
}
function wysun(){
st = setInterval(function(){
hI = document.getElementById("homeImg");
hIt = hI.offsetTop;
//alert(hIt);
if(hIt > -530){
	hI.style.top = (hIt - 20) + "px";
}else{
	document.getElementById("pic").style.visibility = "visible";
	clearInterval(st);
}
				},10);
}
///
window.onload = function(){
	//this.name = "okno_glowne";
	/*
dc = document.cookie;
ciastko = new Object();
	if(dc && dc != ""){
		dcVal = dc.split(";");
		for(i = 0 ; i < dcVal.length;i++){
		dcEl = dcVal[i].split("=");
		ciastko[dcEl[0]] = dcEl[1];
		if(dcEl[0] == "lang"){
		jaki = dcEl[1];
		}
		navEl = document.getElementById("nav");
		navAel = navEl.childNodes;
			for(i=0;i<navAel.length;i++){
				if(navAel[i].nodeType == 1){
			navAel[i].onclick = markNav;
				}
			}
		}
		document.cookie = "lang=" + ciastko.lang + "; expires=" + tomek_expi.toGMTString( );
		chlang(ciastko.lang,'home');
	}else{
		chlang('pol','home');
	}
*/
bodzio = document.getElementsByTagName("body")[0];
debug = document.createElement("div");
debug.setAttribute("style","position:absolute;left:0px;top:0px");
bodzio.appendChild(debug);
chlang('pol','home');
loc = document.location.toString();
locS = loc.indexOf("section");
	if(locS != -1){
	gdzie = loc.split("=")[1];
	chsection(jaki,gdzie.split(".")[0]);
	}
	
}
function al(t){
nA = document.createElement("div");
nA.innerHTML = t;
nA.id = "debuger";
debug.appendChild(nA);
}
//
function prevDiv(dir){
	urchinTracker(dir);
	flasze = document.getElementsByTagName("object");
	/*if(flasze){
	for(fl = 0 ; fl<= flasze.length;fl++){
	flasze[fl].parentNode.parentNode.removeChild(flasze[fl].parentNode);	
	}}*/
	ch = document.body.clientHeight; 
	sh = document.body.scrollHeight;
	shP = document.body.parentNode.scrollHeight;
	//alert(sh + " : " + shh);
var prDiv = document.createElement("div");
prDiv.setAttribute("id","prDiv");
prDiv.setAttribute("align","center");
//prDiv.style.left = (document.body.scrollWidth / 2) - (770 / 2) + "px";
//prDiv.style.height = isIE ? document.body.clientHeight + "px" : window.innerHeight + "px";
//
var prBgDiv = document.createElement("div");
prBgDiv.setAttribute("id","prBgDiv");

prBgDiv.style.height = shP + "px";//(document.body.parentNode.offsetHeight) + "px"; //isIE ? document.body.parentNode.offsetHeight + "px" : window.innerHeight + "px";
al = 0;
at = setInterval(function(){
						  if(al < 7){
							if(isFilters){
							//prBgDiv.filters.alpha.opacity = (al++) * 10 ;
							}else{
							prBgDiv.style.opacity = (al++)/10;
							}
						  }else{
						  clearInterval(at);
						  }
						  },50);
//
document.getElementById("holder").appendChild(prBgDiv);
document.getElementById("holder").appendChild(prDiv);
//
var prDivClose = document.createElement("div");
prDivClose.setAttribute("id","prDivClose");
prDiv.appendChild(prDivClose);
//
dispDiv = document.createElement("div");
dispDiv.setAttribute("id","dispDiv");
prDiv.appendChild(dispDiv);
//
var selDiv = document.createElement("div");
selDiv.setAttribute("id","selDiv");
prDiv.appendChild(selDiv);
advAJAX.get({ group: "main", tag: "selDiv", url: "images.php?kat=images/" + dir });
//
/*var lDiv = document.createElement("div");
lDiv.setAttribute("id","lDiv");
prDiv.appendChild(lDiv);
*/
//
im = document.createElement("img");
im.id = "bigImg";
im.src = "../images/fimg.gif";
//
imf = document.createElement("img");
imf.id = "fbigImg";
imf.src = "../images/fimg.gif";
imf.style.height = "550px";
dispDiv.appendChild(imf);
dispDiv.appendChild(im);
//
prDivClose.onclick = function(){ 
prDiv.parentNode.removeChild(prDiv);
if(isFilters) prBgDiv.parentNode.removeChild(prBgDiv);
cl = 7;
clI = setInterval(function(){
						 if(cl > 0){
							 if(isFilters){
							//prBgDiv.filters.alpha.opacity = (--cl) * 10 ;
							}else{
							prBgDiv.style.opacity = (--cl)/10;
							}
						 }else{
	prBgDiv.parentNode.removeChild(prBgDiv);
	clearInterval(clI);
						 }
							},50);
	};
}
function markNav(){
	//al("jest: " + document.getElementById("podmenu"));
navDiv = document.getElementById("nav");
podmenuDiv = document.getElementById("podmenu");
navDivCh = navDiv.childNodes;


for(n = 0; n < navDivCh.length; n++){
	if(navDivCh[n].nodeType == 1){
		sekcjaId = navDivCh[n].getAttribute('id');
		if(sekcjaId == sekcja){
	navDivCh[n].style.background = "#CCCCCC";
		}else{
			navDivCh[n].style.background = "#FFFFFF";
			}
	}
}
if(podmenuDiv){
	podmenuDivCh = podmenuDiv.childNodes;
for(n = 0; n < podmenuDivCh.length; n++){
	if(podmenuDivCh[n].nodeType == 1){
		sekcjaId = podmenuDivCh[n].getAttribute('id');
		if(sekcjaId == sekcja){
	podmenuDivCh[n].style.background = "#e0e0e0";
		}else{
			podmenuDivCh[n].style.background = "#FFFFFF";
			}
}}
}
}
function dispImg(i,w,h){
bImg = document.getElementById("bigImg");
bImg.setAttribute("src",i);
bImg.style.width = w + "px";
bImg.style.height = h + "px";
}
function chCss(){
lin = document.getElementsByTagName("link")[1];
lin.disabled ? lin.disabled = false : lin.disabled = true;
}
function mailMe(){
document.location = "mailto:" + mail;	
}
function launchMovie(src,w,h,target){
		urchinTracker(src);
swf = '<div id="' + target +'_toKill" class="video">';
swf += '<div align="right"><a href="javascript:killMe(\'' + target + '\')">&times;</a></div>';
swf += '<object width="' + w + '" height="' + h + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="center" id="'+src+'_video">';
swf += '<param name="movie" value="video/video_player.swf"/>';
swf += '<param name="flashvars" value="video='+src+'"/>';
swf += '<embed src="video/video_player.swf" type="application/x-shockwave-flash" flashvars="video='+src+'" width="' + w + '" height="' + h + '" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
swf += '</object><br/>';
swf += '</div>';
document.getElementById(target).innerHTML = swf;
}
function launchAudio(src,target){
	urchinTracker(src);
swf = '<div id="' + target +'_toKill" class="video">';
swf += '<div align="right"><a href="javascript:killMe(\'' + target + '\')">&times;</a></div>';
swf += '<object width="380" height="80" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" align="center" id="'+src+'_audio">';
swf += '<param name="movie" value="mp3/mp3_player.swf"/>';
swf += '<param name="flashvars" value="audio='+src+'"/>';
swf += '<embed src="mp3/mp3_player.swf" type="application/x-shockwave-flash" flashvars="audio='+src+'" width="380" height="80" pluginspage="http://www.macromedia.com/go/getflashplayer" id="'+src+'_video"/>';
swf += '</object>';
swf += '</div>';
document.getElementById(target).innerHTML = swf;
var costam = "";
setTimeout(function(){
emb = document.getElementsByTagName("object")[0];
for(var coo in emb){
	costam += coo + " :" + emb[coo] + "<br/>";
}
	//al(costam);
					},500);
}
function killMe(doZabicia){
martwy = document.getElementById(doZabicia + "_toKill");
martwy.parentNode.removeChild(martwy);
}
