//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 
		

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
		if(document.documentElement.clientHeight) pageHeight =  document.documentElement.clientHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll != windowWidth){	
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function pop_pic(pic_num)
{
	var dimensions = getPageSize();
	pic_num = parseFloat(pic_num);
	
	element = document.getElementById('overlaydiv');
	element.style.width = dimensions[0] + 'px';
	element.style.height = dimensions[1] + 'px';
	
	document.getElementById('overlaydiv').style.visibility = 'visible';

	document.getElementById('loading').style.visibility = 'visible';
	centerLoading()
	
	w = dimensions[2];
	h = dimensions[3];
	
	elem = document.createElement('div');
	elem.id = "pop";
	
	//dynamicaly generate an image element
	pic_elem = document.createElement('img');
	pic_elem.id = "pic";
	pic_elem.onclick = pop_close;
	elem.appendChild(pic_elem);
	
	//creating navigation
	navig = document.createElement('div');
	navig.id = "navig"
	navig.style.background = "#FFF";

	navig.style.marginTop = "10px";
	navig.style.marginBottom = "10px";
	navig.style.width = "100%";
	navig.style.textAlign = "center";
	
	navig.innerHTML = '';
	
	navig.innerHTML = '<span>'+txt_picture+' '+ (pic_num + 1) +' '+ txt_from +' ' + dynimages.length +'</span>';
	
	switch(parseFloat(pic_num))
	{
		case 0:
			navig.innerHTML += '<a href="javascript:pop_close();pop_pic('+ (parseFloat(pic_num)+1) +')" id="popup_next" title="'+ txt_next +'">'+ txt_next +'</a>';
			break;
		case (dynimages.length - 1):
			navig.innerHTML += '<a href="javascript:pop_close();pop_pic('+ (parseFloat(pic_num)-1) +')" id="popup_previous" title="'+ txt_previous +'" >'+ txt_previous +'</a>&nbsp;&nbsp;&nbsp;<a href="javascript:pop_close()" id="popup_close" title="'+ txt_close +'">'+ txt_close +'</a>';
			break;
		default:
			navig.innerHTML += '<a href="javascript:pop_close();pop_pic('+ (parseFloat(pic_num)-1) +')" id="popup_previous" title="'+ txt_previous +'">'+ txt_previous +'</a>&nbsp;&nbsp;&nbsp;<a href="javascript:pop_close();pop_pic('+ (parseFloat(pic_num)+1) +')" id="popup_next" title="'+ txt_next +'">'+ txt_next +'</a>';
			break;
	}

	document.getElementById('picpopup').appendChild(elem);
	
	//ako ima zaglavie ili opisanie, gi pokazvame
	if(dynimages[pic_num][1] != '')
	{
		pic_descript = document.createElement('div');
		pic_descript.id = "descript";
		pic_descript.innerHTML = '<hr /><strong>' + dynimages[pic_num][1] + '</strong><br />';
		if(dynimages[pic_num][2] != '')
		{
			pic_descript.innerHTML += dynimages[pic_num][2] + '<br />';
			pic_descript.style.height = "30px";
		}
		else pic_descript.style.height = "15px";
		
		pic_descript.style.width = "100%";
		pic_descript.style.background = "#dcdcdc";
		pic_descript.style.marginTop = "3px";
		
		pic_descript.style.textAlign = "center";
		
		//appending description div
		document.getElementById('picpopup').appendChild(pic_descript);
	}
	
	document.getElementById('picpopup').appendChild(navig);


	pic_elem.onload = function()
	{
		elem = document.getElementById('pop');
		this.style.marginBottom = "3px";
		this.style.width = this.width + 'px';
		this.style.height = this.height + 'px';	
		
		elem.style.width = this.width + 'px';
		elem.style.height = this.height + 'px';
		
		setTimeout(function() {centerpop_pic(pic_num)}, 200);
	}
	
	setTimeout( function() {pic_elem.src = dynimages[pic_num][0] + "?" + Math.random() * 1000}, 1);
}


function pop_video()
{
	var dimensions = getPageSize();
	
	element = document.getElementById('overlaydiv');
	element.style.width = dimensions[0] + 'px';
	element.style.height = dimensions[1] + 'px';
	
	document.getElementById('loading').style.visibility = 'visible';
	
	w = dimensions[2];
	h = dimensions[3];
	
	elem = document.createElement('div');
	elem.id = "pop";
	elem.style.width = "300px";
	elem.style.height = "200px";
	
	HTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="200" id="vid1" align="middle">';
	HTML += '<param name="quality" value="high" />';
	HTML += '<param name="movie" value="../flash/vid1.swf" />';
	HTML += '<param name="bgcolor" value="#000000" />';
	HTML += '<embed src="../flash/vid1.swf" quality="high" bgcolor="#000000" width="300" height="200" name="vid1" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	elem.innerHTML = HTML;
	
	document.getElementById('picpopup').appendChild(elem);
	
	setTimeout(centerpop, 100);
}

function pop_video2()
{
	var dimensions = getPageSize();
	
	element = document.getElementById('overlaydiv');
	element.style.width = dimensions[0] + 'px';
	element.style.height = dimensions[1] + 'px';
	
	document.getElementById('loading').style.visibility = 'visible';
	
	w = dimensions[2];
	h = dimensions[3];
	
	elem = document.createElement('div');
	elem.id = "pop";
	elem.style.width = "355px";
	elem.style.height = "305px";
	
	HTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="350" height="250" id="vid1" align="middle">';
	HTML += '<param name="quality" value="high" />';
	HTML += '<param name="movie" value="../flash/flash2/movie2.swf" />';
	HTML += '<param name="bgcolor" value="#000000" />';
	HTML += '<embed src="../flash/flash2/movie2.swf" quality="high" bgcolor="#000000" width="355" height="305" name="vid1" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	elem.innerHTML = HTML;
	
	document.getElementById('picpopup').appendChild(elem);
	
	setTimeout(centerpop, 100);
}




function pop_close()
{
	document.getElementById('picpopup').style.visibility = 'hidden';
	document.getElementById('overlaydiv').style.visibility = 'hidden';
	document.getElementById('loading').style.visibility = 'hidden';
	document.getElementById('picpopup').innerHTML = '';
}



function centerpop()
{
	scrollY = ( document.documentElement ) ? document.documentElement.scrollTop : document.body.scrollTop;
	popup = document.getElementById('pop');

	picpopup_div = document.getElementById('picpopup');
	
	picpopup_div.style.marginLeft = (0 - (parseInt(popup.style.width)/2)) + 'px';
	picpopup_div.style.marginTop = (0 - (parseInt(popup.style.height)/2)+scrollY) + 'px';
	picpopup_div.style.width = popup.style.width;
	
	
	if((parseInt(popup.style.width) + 50) > w)
	{
		popup.style.width = (w - 50) + 'px';
		centerpop();
	}
	if((parseInt(popup.style.height) + 50) > h)
	{
		popup.style.height = (h - 50) + 'px';
		centerpop();
	}
	document.getElementById('loading').style.visibility = 'hidden';
	picpopup_div.style.visibility = 'visible';
	document.getElementById('overlaydiv').style.visibility = 'visible';
	
}

function centerpop_pic(pic_num)
{
	if(dynimages[pic_num][1] != '')
	
	scrollY = ( document.documentElement ) ? document.documentElement.scrollTop : document.body.scrollTop;
	popup = document.getElementById('pop');

	picpopup_div = document.getElementById('picpopup');
	
	picpopup_div.style.marginLeft = (0 - (parseInt(popup.style.width)/2)) + 'px';
	picpopup_div.style.marginTop = (0 - (parseInt(popup.style.height)/2)+scrollY) + 'px';
	picpopup_div.style.width = popup.style.width;
	
	
	if((parseInt(popup.style.width) + 50) > w)
	{
		popup.style.width = (w - 50) + 'px';
		centerpop();
	}
	if((parseInt(popup.style.height) + 50) > h)
	{
		popup.style.height = (h - 50) + 'px';
		centerpop();
	}
	document.getElementById('loading').style.visibility = 'hidden';
	picpopup_div.style.visibility = 'visible';
	document.getElementById('overlaydiv').style.visibility = 'visible';
	
}

function centerLoading()
{
	scrollY = ( document.documentElement ) ? document.documentElement.scrollTop : document.body.scrollTop;

	loading_div = document.getElementById('loading');
	loading_div.style.marginLeft = ( - 110) + 'px';
	loading_div.style.marginTop = (scrollY) + 'px';
	
	return true;
}