function feedBox(html) {
	document.getElementById("expandBox").innerHTML = html;
}

function showBox() {
	document.getElementById("collapseBox").style.display = "none";
	document.getElementById("expandBox").style.display = "block";
	window.scrollBy(0,-100000);
}

function hideBox() {
	document.getElementById("expandBox").style.display = "none";
	document.getElementById("collapseBox").style.display = "block";
}

function callFrame(cls, id) {
	document.getElementById("innerFrame").src= "/get.php?cls="+cls+"&id="+id;
}

function appendBefore(elem) {
	var reference = elem.parentNode;
	var target = reference.parentNode;
	var div = document.createElement('div');
	div.innerHTML = document.getElementById('prototype').innerHTML;
	target.insertBefore(div, reference);
}

/* cause insertAfter method does not exist (??) */
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

function appendAfter(elem) {
	var reference = elem.parentNode;
	var target = reference.parentNode;
	var div = document.createElement('div');
	div.innerHTML = document.getElementById('prototype').innerHTML;
	insertAfter(target, div, reference);
}

function appendNew(elem) {
	var target = document.getElementById('propbox');
	var div = document.createElement('div'); 
	div.innerHTML = document.getElementById('prototype').innerHTML; 
	target.appendChild(div);
}

/* manipulacia s city selektorom */

var blurable = true;
var type = "";

function expandCitySel(what) {
    type=what;
    oCitySel = document.getElementById('city-sel-hl');
    setInterval('blurable = true;', 250);
    oCitySel.size = oCitySel.length;
    oCitySel.focus();
    blurable = false;
}

function collapseCitySel() {
    if (!blurable) return false;
    type = "";
    oCitySel = document.getElementById('city-sel-hl');
    oCitySel.size = 1;
    return true;
}

function goCity(what) {
	document.location.replace(document.getElementById(what).options[document.getElementById(what).selectedIndex].value+"/"+type);
}

var filter_select = 0;
var filter_input = 0;
var filter_value = "";
var filter_timer = 0;
var gallery_offset = 0;
var gallery_tgt = 0;
var scroll_step = 0;
var scroll_max = 0;
var c, l, r;

function filterSelect(input) {
	filter_select = Object(input.parent);
	clearTimeout(filter_timer);
	filter_timer = setTimeout("doFilterSelect();", 3000);
}

function doFilterSelect() {
	alert(filter_select.getElementsByTagName("SELECT"));
}

function scrollGallery(offs) {
	c = new Object(document.getElementById("galleryContainer"));
	l = new Object(document.getElementById("left-button"));
	r = new Object(document.getElementById("right-button"));
	gallery_tgt = gallery_offset + offs;
	scroll_step = Math.abs(offs);
	if (offs < 0) mof = -7; else mof = 7;
	setTimeout("doScrollGallery("+mof+");", 5);
}

function doScrollGallery(offs) {
	var b = true;
	gallery_offset += offs;
	if (gallery_offset >= 0) {
		gallery_offset = 0;
		b = false;
		l.style.display = "none";
	} else if (l.style.display == "none") {
		l.style.display = "block";
	}

	if (gallery_offset <= (c.parentNode.clientWidth - scroll_max)) {
		gallery_offset = c.parentNode.clientWidth - scroll_max;
		b = false;
		r.style.display = "none";
	} else if (r.style.display == "none") {
		r.style.display = "block";
	}
	if (offs < 0 && gallery_offset < gallery_tgt) {
		gallery_offset = gallery_tgt;
		b = false;
	}
	if (offs > 0 && gallery_offset > gallery_tgt) {
		gallery_offset = gallery_tgt;
		b = false;
	}
	c.style.left = gallery_offset+"px";
	if (Math.abs(gallery_offset - gallery_tgt) > (scroll_step/2)) offs = offs * 1.3; 
	if (Math.abs(gallery_offset - gallery_tgt) < (scroll_step/2)) offs = offs / 1.25;
	if (Math.abs(offs) < 2) offs = (offs/Math.abs(offs))*2;
	if (Math.abs(offs) > 50) offs = (offs/Math.abs(offs))*50;
	if (b) setTimeout("doScrollGallery("+offs+");", 5);
}

activatePage = function() {
	activateList("nav_ctr");
	activateList("nav_lang");
	if (document.getElementById('galleryContainer')) scroll_max = document.getElementById('galleryContainer').parentNode.scrollWidth;
}

function activateList(nav) {
        if (document.all&&document.getElementById) {
                navRoot = document.getElementById(nav);
                for (i=0; i<navRoot.childNodes.length; i++) {
                        node = navRoot.childNodes[i];
                        if (node.nodeName=="LI") {
                                node.onmouseover=function() {
                                        this.className+=" over";
                                }
                                node.onmouseout=function() {
                                        this.className=this.className.replace(" over", "");
                                }
                        }
                }
        }
}

window.onload=activatePage;

function enlargeImage(pid) {
	window.open('/photoview.php?pid='+pid, 'gallery', 'scrollbars=0, status=0, toolbar=0, menubar=0, location=0, resizable=1, width=320, height=240');
}

