//galerie - funkcje ogolne

function wind() {
this.top = document.viewport.getScrollOffsets().top;
this.left = document.viewport.getScrollOffsets().left;
this.width = document.viewport.getDimensions().width;
this.height = document.viewport.getDimensions().height;
}

function top_okna(mwidth) {
var okno = new wind();
$("plakat").style.top = (okno.top + 20) + 'px';
$("plakat").style.width = mwidth + 'px';
$("plakat").show();
nagore_d($("plakat"));
}

function schowaj() {
	$("plakat").style.display="none";
	$("plakat_title").innerHTML = "";
	$("sztaluga").innerHTML = "";	
}

//galerie - obrazki


var sklimg = '';
var imgskl;
var menuskl = '';
var sklh = 400;
var sklw = 530;
//---------- glaeria home ------
var coll;

function make_gallery() {
coll = $A($$('img.gl'));
}

function duzy_one_new(teni) {
	//ustalam menu
	menuskl = '';
	var ile = coll.length;
	var si = 0;	
	si = teni - 1;
	if(si > -1) {
		menuskl += '<li class="gprev"><a onclick="duzy_one_new('+ si +')"><img src="image/szklo.gif"/></a></li>';	
	}
		si = teni + 1;
		if(si < ile) {
		menuskl += '<li class="gnext"><a onclick="duzy_one_new('+ si +')"><img src="image/szklo.gif"/></a></li>';	
		}
		
	menuskl = '<div style="height:30px"><ul class="galglosa" id="ggla">'+ menuskl +'</ul></div>';
	//ustalam objImg
	adresd = coll[teni].src.replace('min100_','');
	Image.prototype.link = 'http://eko.org.pl';
	imgskl = new Image();
	Image.prototype.link = 'http://eko.org.pl';
	imgskl.src = adresd;
	imgskl.link = coll[teni].alt;
	imgskl.name = coll[teni].title;
	ustaw_okno();

}

//------------------

function duzy(elm,event) {
	//ustalam menu
	menuskl = '';
	//ustalam ogjImg
	adres = elm.src;
	adresa = adres.replace('min_','');
	adresb = adresa.replace('minheadline_','');
	adresc = adresb.replace('minpan_','');
	adresd = adresc.replace('min100_','');
	Image.prototype.link = '';
	imgskl = new Image();
	Image.prototype.link = '';
	imgskl.src = adresd;
	imgskl.name = elm.title;
	imgskl.link = '';
	ustaw_okno();
}



function duzy_go(elm,event,links) {
	//ustalam menu
	menuskl = '';
	//ustalam ogjImg
	adres = elm.src;
	adresd = adres.replace('min_','');
	Image.prototype.link = '';
	imgskl = new Image();
	Image.prototype.link = '';
	imgskl.src = adresd;
	imgskl.name = elm.title;
	imgskl.link = links;
	ustaw_okno();
	
}


function duzy100(elm,event) {
	//ustalam menu
	menuskl = '';
	adres = elm.src;
	adresd = adres.replace('min100_','');
	//ustalam objImg
	Image.prototype.link = '';
	imgskl = new Image();
	Image.prototype.link = '';
	imgskl.src = adresd;
	imgskl.name = elm.title;
	imgskl.link = '';
	ustaw_okno();

}

function duzy_one(teni) {
	//ustalam menu
	menuskl = '';
	var ile = galglosa.length;
	var si = 0;	
	si = teni - 1;
	if(si > -1) {
		menuskl += '<li class="gprev"><a onclick="duzy_one('+ si +')"><img src="image/szklo.gif"/></a></li>';	
	}
		si = teni + 1;
		if(si < ile) {
		menuskl += '<li class="gnext"><a onclick="duzy_one('+ si +')"><img src="image/szklo.gif"/></a></li>';	
		}
		
	menuskl = '<div style="height:30px;"><ul class="galglosa" id="ggla">'+ menuskl +'</ul></div>';
	//ustalam objImg
	adresd = galglosa[teni].imgadres.replace('min_','');
	Image.prototype.link = 'index_korzensko.php';
	imgskl = new Image();
	Image.prototype.link = 'index_korzensko.php';
	imgskl.src = adresd;
	imgskl.name = galglosa[teni].imgname;
	imgskl.link = '';
	ustaw_okno();
}

function ustaw_okno() {

	$("sztaluga").innerHTML = menuskl + "<img src='image/szklo.gif' width='"+ sklw +"' height='"+ sklh +"'/>";
	$("plakat_title").innerHTML = imgskl.name;
		if(imgskl.link != '') {
			$("plakat_title").innerHTML += ' <a href="'+ imgskl.link +'">zobacz</a>';
		}
	ukryj_flashe(true);
	top_okna(sklw)
	sklimg = setInterval(skaluj_img, 100);
}

function skaluj_img() {
	_opacity($("plakat"), 60);
	sklw = 530;
	try {
	$('ggla').hide();
	}catch (e) {
	
	}
	if(imgskl.complete) {
	//pokaz menu
	try {
	$('ggla').show();
	}catch (e) {
	
	}
	_opacity($("plakat"), 100)
		$("sztaluga").innerHTML = menuskl + "<img src='" + imgskl.src + "' width='"+ imgskl.width +"' height='"+ imgskl.height +"'/>";
			if(imgskl.width > 300) {
				sklw = imgskl.width;
			}
		sklh = imgskl.height;
		$("plakat").style.width = sklw + 'px';
		clearInterval(sklimg);
	}
}


var Rotat = Array();
var Rot = 0;
var Rot_inval;

function rotate(glowny,skladowe) {
	elm = $(glowny);
	Rotat = $A($$('div.' + skladowe));
	if(!Rotat.length) {
		return false;
	}
	rot_zeruj();
	Rotat[Rot].show();
	//Rot_inval = setInterval(rotshow, 5000);
	//zbuduj elementy i dodaj do obiekti
	var x = Array();
	var xtop = 200;
	var xleft = 50;
	for(i = 0; i < Rotat.length; i++) {
		x.push(document.createElement("div"));
		x[i].width = 15;
		x[i].height = x[i].width;
		x[i].setStyle({width:x[i].width + 'px'});
		x[i].setStyle({height:x[i].width + 'px'});
		x[i].setStyle({position:'absolute'});
		xtopx = xtop + 'px';
		xleftx = xleft + (i * (x[i].width + 15)) + 'px'; 
		x[i].setStyle({top:xtopx});
		x[i].setStyle({left:xleftx});
		x[i].setStyle({background:'white'});
		x[i].setStyle({padding:'5px'});
		x[i].setStyle({color:'#000000'});
		x[i].setStyle({cursor:'pointer'});
		x[i].setStyle({opacity:'0.5'});
		x[i].innerHTML = i + 1;
		switch (i) {
			case 0:	x[i].observe('mouseover', pokazthis0);	break; 
			case 1:	x[i].observe('mouseover', pokazthis1);	break;
			case 2:	x[i].observe('mouseover', pokazthis2);	break;
			case 3:	x[i].observe('mouseover', pokazthis3);	break;
			case 4:	x[i].observe('mouseover', pokazthis4);	break; 
			case 5:	x[i].observe('mouseover', pokazthis5);	break; 
			case 6:	x[i].observe('mouseover', pokazthis6);	break;
			case 7:	x[i].observe('mouseover', pokazthis7);	break;
			case 8:	x[i].observe('mouseover', pokazthis8);	break;
			case 9:	x[i].observe('mouseover', pokazthis9);	break;
		}
		elm.insertBefore(x[i], elm.firstChild);
	}

}

function pokazthis0(event) { if(Rot != 0) { Rot = 0;	rotshow();} }
function pokazthis1(event) { if(Rot != 1) { Rot = 1;	rotshow();} }
function pokazthis2(event) { if(Rot != 2) { Rot = 2;	rotshow();} }
function pokazthis3(event) { if(Rot != 3) { Rot = 3;	rotshow();} }
function pokazthis4(event) { if(Rot != 4) { Rot = 4;	rotshow();} }
function pokazthis5(event) { if(Rot != 5) { Rot = 5;	rotshow();} }
function pokazthis6(event) { if(Rot != 6) { Rot = 6;	rotshow();} }
function pokazthis7(event) { if(Rot != 7) { Rot = 7;	rotshow();} }
function pokazthis8(event) { if(Rot != 8) { Rot = 8;	rotshow();} }
function pokazthis9(event) { if(Rot != 9) { Rot = 9;	rotshow();} }

function rot_zeruj() {
	for(i = 0; i < Rotat.length; i++) {
		Rotat[i].hide();
	}
}

var pRotI;
var pRot = 0;
function rotshow() {
	rot_zeruj();
	/*
	Rot++;
	if(Rot > (Rotat.length - 1)) {
		Rot = 0;
	}
	*/
	Rotat[Rot].show();
	pRot = 0;
	Rotat[Rot].setStyle({opacity:0});
	pRotI = setInterval(alpharot, 30);
}

function alpharot() {
	pRot += 0.1;
	if(pRot > 0.8) {
		clearInterval(pRotI);
		pRot = 1;
		Rotat[Rot].setStyle({opacity:1});
	}
	_opacity(Rotat[Rot], pRot * 100);
}


function imgingalery(imgadres, imgname) {
	this.imgadres=imgadres;
	this.imgname=imgname; 
}

function thgalery(elm,event) {
	adres = elm.src;
	adresd = adres.replace('/imgturysta/_thumbs/Images/','/imgturysta/image/');
	$("sztaluga").innerHTML = "<img src='" + adresd + "' width='530'/>";
	$("plakat_title").innerHTML = elm.title;
	ukryj_flashe(true);
	top_okna(530);
}

function duzy_media(elm,event) {
	adres = elm.src;
	adresd = adres.replace('min_','');
	$("sztaluga").innerHTML = "<img src='" + adresd + "' />";
	$("plakat_title").innerHTML = elm.title;
	ukryj_flashe(true);
	top_okna(530);
}

function ukryj_flashe(stan) {
	var widok = 'visible';	
	stan?widok='hidden':false;
		$$('object').each(function(item) {
			item.setStyle({visibility:widok});
		});
		$$('embed').each(function(item) {
			item.setStyle({visibility:widok});
		});
	
}

//galerie video mp3
function pokaz_wideo_kom(nr,rodzaj) {
	schowaj();
	adres = 'wideo_'+ rodzaj +'_' + nr;
	my_video = $(adres);
	$("sztaluga").innerHTML = my_video.innerHTML;
	top_okna_badaj(my_video);
	}

function top_okna_badaj(elm) {
var okno = new wind();
$("plakat").style.top = (okno.top + 20) + 'px';
$("plakat").style.width = elm.getDimensions().width + 'px';
$("plakat").show();
nagore_d($("plakat"));
}	
	
	
function pokaz_fla_kom(nr,rodzaj) {
	adres = 'wideo_'+ rodzaj +'_' + nr;
	var my_video = $(adres);
	adres_fla = my_video.innerHTML;
	pokaz_fla(adres_fla);
}

function pokaz_wideo_div(obj, szer) {
	schowaj();
	var adres = obj;
	var my_video = $(adres);
	$("sztaluga").innerHTML = my_video.innerHTML;
	top_okna(szer);
	}

function pokaz_fla(adres) {
	schowaj();
//==============
	var w = 690;
	var h = 400;		
	$('sztaluga').innerHTML = '<div id="player">player</div>';

	var pqs = new ParsedQueryString();
	var parameterNames = pqs.params(false);
	var parameters =
    			{	id: "1"
    			,	configuration: "assets/configuration.xml"
    			,	url: adres
    			,	backgroundColor: "0xffffff"
    			,	autoHideControlBar: "true"
    			,	autoSwitchQuality: "true"
    			,	autoPlay: "true"
    			};
    		
    		for (var i=0; i<parameterNames.length; i++)
    		{
    			var parameterName = parameterNames[i];
    			parameters[parameterName]
    				=	pqs.param(parameterName)
    				||	parameters[parameterName];
    		}
				
    		swfobject.embedSWF
				( "OSMFPlayer.swf"
				, "player"
				, w , h
				, "10.0.0"
				, {}
				, parameters
				, { allowFullScreen: "true" }
				, { name: "OSMFPlayer" }
				);	
//=============	
	top_okna(690);
}

function pokaz_fla_title(adres_fla,tytul) {
	schowaj();
	pokaz_fla(adres_fla);
	$('sztaluga').innerHTML += tytul;
}

function graj_fla(adres,iden,w,h,gram,klatka) {
	okno = $(iden);
	okno.innerHTML = '<div id="player'+ iden +'">player</div>';
	var pqs = new ParsedQueryString();
	var parameterNames = pqs.params(false);
	var parameters =
    			{	id: "1"
    			,	configuration: "assets/configuration.xml"
    			,	url: adres
    			,	backgroundColor: "0xffffff"
    			,	autoHideControlBar: "true"
    			,	autoSwitchQuality: "true"
    			,	autoPlay: "true"
    			};
    		
    		for (var i=0; i<parameterNames.length; i++)
    		{
    			var parameterName = parameterNames[i];
    			parameters[parameterName]
    				=	pqs.param(parameterName)
    				||	parameters[parameterName];
    		}
				
    		swfobject.embedSWF
				( "OSMFPlayer.swf"
				, "player" + iden
				, w , h
				, "10.0.0"
				, {}
				, parameters
				, { allowFullScreen: "true" }
				, { name: "OSMFPlayer" }
				);
}

// inne funkcje - bejrki
function kolor(elm,barwa) {
	elm.style.backgroundColor = barwa
}

function kolor_txt(elm,barwa) {
	elm.style.color = barwa
}
	
function powrot(taty) {
	var x = document.getElementById('info_page').style
	taty?x.display = 'block':x.display = 'none'
}

	
function blink(elm, nr) {
	switch(nr) {
		case 2:
			//elm.style.background = "#414766";
			break;
		case 1:
			//elm.style.background = "#343A57";
			break;
	}
	elm.style.letterSpacing = "+" + (nr - 1) + "px"
}

function _opacity(elm, o) {
var opc = o/100;
elm.setStyle({ opacity: opc });
/*
  var obj = elm.style;
  obj.MozOpacity = (o / 100); // Mozilla i FireFox
  obj.KhtmlOpacity = (o / 100); // Safari < 1.2



  obj.opacity = (o / 100); // Safari 1.2, nowszy FireFox i Mozilla
  obj.filter = "alpha(opacity=" + o + ")"; // Internet Explorer
*/
}	

function _opacity_id(iden, o) {
var obj = document.getElementById(iden);
var opc = o/100;
obj.setStyle({ opacity: opc });
/*
  var obj = document.getElementById(iden).style;
  obj.MozOpacity = (o / 100); // Mozilla i FireFox
  obj.KhtmlOpacity = (o / 100); // Safari < 1.2
  obj.opacity = (o / 100); // Safari 1.2, nowszy FireFox i Mozilla
  obj.filter = "alpha(opacity=" + o + ")"; // Internet Explorer
*/
}	

function set_src(box, elm) {
	$(box).src = elm.src
}


function czysc_formularz(elm) {
	$('imie').value = ''
	$('nazwisko').value = ''	
	$('nazwa_firmy').innerHTML = ''
	$('adres').innerHTML = ''
	$('kod_pocztgowy').value = ''
	$('miasto').value = ''
	$('mail').value = ''
	$('telefon').value = ''
	$('uwagi').innerHTML = ''
	$('dzien_1').checked = false
	$('dzien_2').checked = false
	elm.submit()
}
		
function pokaz_ekranik(stan, event, tresc) {
	var ek = $('ekranik' );
	var topstrony = document.body.scrollTop;
	var coordx = event.clientX;
	var coordy = event.clientY;
	//rozpoznanie szerokosci okna przegladarki
	if(window.innerWidth) {
		var szerwindow = window.innerWidth;
	}
	if(document.body.offsetWidth)	{
		var szerwindow = document.body.offsetWidth;
	}

	var posx = coordx - Math.ceil((szerwindow - 800) / 2)  - 5
	var closepng = '<img src="image/close.png" onclick="ukryj_ekranik()" align="right">'
	ek.style.display = 'block'
	ek.style.top = (topstrony + coordy - 5) + 'px'
	ek.style.left = posx + 'px'
	ek.innerHTML =  closepng + '<ol>' + tresc + '</ol>'
}

function ukryj_ekranik() {
	var ek = document.getElementById('ekranik' );
	ek.style.display = 'none'
	ek.innerHTML = ''
}


function pokaz_tablo(kt,dt, tresc, kw, kh) {

	x = $("ekran_kal");
	x.innerHTML = "<img src='image/close.png' onclick='ukryj_tablo()' align='right' style='cursor:pointer'><ol>" + tresc + "</ol>"
	x.style.display = "block";
	x.style.top = ((kh + 2) * kt)+ 10 + "px";
	x.style.left = ((kw + 2) * dt) - (-10 + kw)  +  "px";
	x.style.zIndex = 100;
	_opacity(x, 80);
}

function ukryj_tablo() {
	var ek = $('ekran_kal' );

	ek.hide();
	ek.innerHTML = '';
	ek.style.zIndex = auto;
	
}

function pokaz_legende(stan_leg) {
	var leg = document.getElementById('legenda')

	if(stan_leg) {
		leg.style.display = "block";
		_opacity_id("legenda", 80)
		stan_leg = true;
	}
	else
	{
		leg.style.display = "none"
		stan_leg = false;
	}
}

function go_do(adres) {
	document.location.href = adres
}

function menu_napis(tresc, elm) {
_opacity(elm,75);
mtkst = document.getElementById('napis');
mtkst.innerHTML = tresc;
}

function nd(elm, swi) {
elm.style.backgroundPosition = "-" + swi + "px 0";
}

function ng(elm, swi) {
elm.style.backgroundPosition = "-" + swi + "px -5px";
}

function ndg(elm, swi, shi) {
elm.style.backgroundPosition = "0px -" + shi + "px";
}

function ngg(elm) {
elm.style.backgroundPosition = "0px 0px";
}
//w bok
function nhd(elm, swi) {
elm.style.backgroundPosition = "10px " + swi + "px";
}
// do zera
function nhg(elm, swi) {
elm.style.backgroundPosition = "5px " + swi + "px";
}

function gnd(elm, swi) {
elm.style.backgroundPosition = "-" + swi + "px 0";
}

function gng(elm, swi) {
elm.style.backgroundPosition = "-" + swi + "px -50px";
}

function rogi() {
	var toobr = $A($$('div.mamba'));
	toobr.each( function(item) {
		wi = item.style.width;
		item.width = parseInt(wi.replace('px',''));
		hi = item.style.height;
		item.height = parseInt(hi.replace('px',''));
		var x = Array();
		for(i = 0; i < 4; i++) {
			x.push(document.createElement("div"));
			x[i].width = 25;
			x[i].height = x[i].width;
			x[i].setStyle({width:x[i].width + 'px'});
			x[i].setStyle({height:x[i].width + 'px'});
			xtop = 0;
			xleft = 0;
			switch (i) {
				case 0:
					x[i].setStyle({background:'url(image/rog.png) 0 0 no-repeat'});
				break;
				case 1:
					x[i].setStyle({background:'url(image/rog.png) -25px 0 no-repeat'});
					xleft = item.width - x[i].width + 'px';
				break;
				case 2:
					x[i].setStyle({background:'url(image/rog.png) -50px 0px no-repeat'});
					xtop = item.height - x[i].height  + 'px';
				break;
				case 3:
					x[i].setStyle({background:'url(image/rog.png) -90px 0 no-repeat'});
					xtop = item.height - x[i].height  + 'px';
					xleft = item.width - x[i].width + 'px';
				break;
			}
			x[i].setStyle({position:'absolute'});
			x[i].setStyle({top:xtop});
			x[i].setStyle({left:xleft});
			item.insertBefore(x[i], item.firstChild);
		}
	})
}

function odsun(elm, ile) {
elm.style.backgroundPosition = ile + "px 0";
}

function do_kina(nr,baza) {
	schowaj();
	adres = 'ajax_doKina.php?art=' + nr + '&baza=' + baza;
	makeRequest("sztaluga",adres);
	top_okna(530);
	}

function sprawdz_quiz()	{
		$('quiz_enter').hide();
		$('quiz_adres').show();
}

function gehen_mit() {
	schowaj();
	adres = 'ajax_gehenmit.php';
	makeRequest("sztaluga",adres);
	top_okna(530);
	}

var Wkolo = Class.create({
  initialize: function(name, ile) {
    this.nr = 0;
    this.name  = name;
    this.ile = ile;
	this.zeruj();
	rn = this.name + "0";
	$(rn).show();
  },
  zeruj: function() {
     var rn = "";
     for(var i = 0; i < this.ile; i++) {
      rn = this.name + i;
      $(rn).hide();
	 }
	},
  rotujm: function() {
    this.zeruj();
	this.nr++;
	if(this.nr > (this.ile - 1)) {
		this.nr = 0;
	}
	rn = this.name + this.nr.toString();
	$(rn).show();
  }
});
