var browsepage = 0;
var prevlink = '';
var nextlink = '';
function lc_swapit(id,on) { if (ob=find_handle(id)) { on?ob.visibility="visible":ob.visibility="hidden"; } }
function find_handle(id) { if (document.getElementById) { if (!(document.getElementById(id))) { return false; } return document.getElementById(id).style; } else if (document.layers) return document.layers[id]; else if (document.all) return document.all[id].style; else return false; }
function find_object(id) {
    if (document.getElementById) { if (!(document.getElementById(id))) { return false; } return document.getElementById(id); } else return false;
}
function sw_imageview() { lc_swapit('view_detailed',0);lc_swapit('view_flash',1); }
function div_swapdisplay(id) {
    if (ob=find_handle(id)) {
        on = ob.display == "none" ? "block" : "none";
        ob.display = on;
    }
}
function email(user,host,cc_user, cc_host) {
    if (cc_user) {
        cc='?cc='+cc_user+'\@'+cc_host;
    } else {
        cc='';
    }
    window.location='mailto:'+user+'\@'+host+cc;
}
function emailHTML (id, user, host) {
    if ((host != '') && (user !='') && (o = find_object(id))) {
        o.innerHTML = user+"@"+host;
    }
}
function bigpic_onload() {
    if (o = find_object('login_hint')) {
        o.style.visibility = 'visible';
    }
    s2_refresh();
}
function set_bigpic(id, file, id2, link, id3, caption, dl_link, dl,  idx, get_comments, browse) {
    if (browse == undefined) browse = 1;
    if (get_comments == undefined) get_comments = 1;
    if (l = find_object('bigpic')) {
        if (o = find_object('login_hint')) {
            o.style.visibility = 'hidden';
        }
        var reg = new RegExp('^(.*\/)([a-zA-Z_]*)([^\/]+)$', 'i');
        if (file.search(reg) >=0) {
            if (RegExp.$2 == '') {
                file = RegExp.$1 + 'b' + RegExp.$3;
            }
        }
        html = '<img id="pic_image" style="border:2px solid;" src="'+file+'">';
        l.innerHTML = html;
        if (o = find_object('imageindex')) {
            o.innerHTML = idx+1;
        }
        if (o = find_object('pic_image')) {
            try {
                o.onload = setTimeout("bigpic_onload()", 2000);
            } catch(e) {
                o.onload = 'setTimeout("bigpic_onload()", 2000);';
            }
            //o.onload = alert('marha');
        }
    }
    if (o = find_object(id)) {
        o.src=file;
        if (browse && get_comments) {
            try {
                comments[0].comment_refresh();
            } catch (e) {}
        }
    }
    if (o = find_object(id2)) {
        if (link == '') {
//            o.href = "javascript:alert('Ulogujte se da biste videli sliku bez vodenog \u017eiga ili u ve\u0107em formatu!');";
            o.href = "login.php";
            o.target = "_self";
        } else {
            s = link.substring(0, 9);
            if (s == 'javascript') {
                o.target="_top";
            } else {
                o.target = "_blank";
            }
            o.href=link;
        }
    }
    if (o = find_object(id3)) {
        try {
            var s = decodeURIComponent(caption);
        } catch(e) {
            s = unescape(caption);
        }
        o.innerHTML = s.replace(/\\'/g, "'");
        var od = find_object('imagedescription_'+idx);
        if (od) {
            o.innerHTML += '<div style="margin-top:5px;font-weight:normal;">' + od.innerHTML + '</div>';
        }

    }
    if (o = find_object('download')) {
        o.href=dl_link; 
        o.innerHTML = dl ? 'download' : 'naru\u010di';
    }
    if (browse) {
        show_about(false);
    }
    
}
var flashVersion = 0;
function getFlashVersion() {
	var agent = navigator.userAgent.toLowerCase(); 
	
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
            if (flashPlugin.description.indexOf('7.') != -1) flashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('flashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
		document.write('flashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
		document.write('flashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
		document.write('flashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
		document.write('flashVersion = 3 \n');
		document.write('end if');
		document.write('</scr' + 'ipt\> \n');
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	// Can't detect in all other cases
	else {
		flashVersion = flashVersion_DONTKNOW;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;
function popwindow(page,same, width, height) {
    if (!width) {
        width=320;
    }
    if (!height) {
        height = 200;
    }
  winopts = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,titlebar=no,width="+width+",height="+height;
  ShowFrame = window.open(page, 'pw'+same, winopts);
}
var n = 0;
var b468_id;
var b140_id;
var eventlocation = "";
function init_banners(b468, b140) {
    b468_id = b468;
    b140_id = b140;
}
function order_photo() {
    winopts = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=770,height=501";
    ShowFrame = window.open("order_photo.php?dir="+dir+"&event_id="+event_id+"&image="+image+"&table="+table, 'pwi', winopts);
}
function s(i) {
    image=i;
    try {
        comments[0].image = i;
        comment_header.location = "comment_header.php?dir="+dir+"&event_id="+event_id+"&image="+image+"&table="+table;    
    } catch (e) {}
    n++; 
    if (!(n % 3)) { b468.location = 'http://www.box.rs/ifr/if.php?a='+b468_id; }
    if (!(n % 5)) { b140.location = 'http://www.box.rs/ifr/if.php?a='+b140_id; }  
}
function s2(i) {
    image=i;
    try {
        comments[0].image = i;
    } catch (e) {}
    n++; 
}
function s2_refresh() {
    if (n) {
        b468.location = 'http://www.box.rs/ifr/if.php?a='+b468_id; 
        if (!(n % 3)) { b140.location = 'http://www.box.rs/ifr/if.php?a='+b140_id; }  
    }
}
function confirm_action(link, warn) {
    if (confirm(warn)) {
        window.location=link;
    }
}
var online_request;
var active = false;
function get_online() {
    if (!active) {
        active = true; 
        online_request = new xmlhttp_request(baseurl+"templates/includes/online.htm", online_response, 'guest');
    }
}
function online_response (type) {
    try {
        var ar = online_request.response.split(' ');
        var o;
        var v;
        if ((o = find_object('visit')) && ar.length) {
            v = parseInt(ar[0]);
            if  (isNaN(v)) v = '';
            o.innerHTML = v;
        }
        if ((o = find_object('guest')) && (ar.length > 1)) {
            v = parseInt(ar[1]);
            if  (isNaN(v)) v = '';
            o.innerHTML = v;
        }
    } catch (e) {}
    active = false;
}
function init_online() {
    get_online();
    setInterval("get_online()", 60000);
}


var us_div = new Array;
function us_add_div(idx) {
    us_div[us_div.length] = 0; 
}
function us_refresh() {
    prefix="div_"; 
    for (i=0;i<us_div.length;i++) {
        id =  prefix + i;
        if (us_div[i]) on=1; else on=0;
        lc_swapit(id,on);
    }
}

function us_mouseover(idx) {
    us_div[idx] = 1;
    setTimeout('us_refresh()',200);
}
function us_mouseout(idx) {
    us_div[idx] = 0;
    setTimeout('us_refresh()',200);
}

var div_keys = Array();
var div_visible = Array();
var mouse_x;
var mouse_y;
var layer_request;
function add_layer(key) {
    idx = div_keys.length;
    div_keys[idx] = key;
    div_visible[idx] = 0;
}
function refresh_layer() {
    for (i=0;i<div_keys.length;i++) {
        id = 'div_'+div_keys[i];
        if (div_visible[i]) on=1; else on=0;
        if (on) { 
            ob=find_object(id);
            if (ob) {
                if (ob.innerHTML == '') { 
                    layer_request = new xmlhttp_request("rss.php?html=1", layer_response, div_keys[i]);
                }
            }
            
        }
        lc_swapit(id,on);
            
    }
}
function layer_mouseover(key, is_over) {
    for (i=0;i<div_keys.length;i++) {
        if (div_keys[i] == key)
            div_visible[i] = is_over;
    }
    setTimeout('refresh_layer()', 200);
}
function layer_response(layer) {
    o = find_object('div_'+layer);
    if (o) {
        try {
            o.innerHTML = layer_request.response;
        } catch (e) {}
    }
    
}
function show_dl(id, show) {
    if (h = find_handle('downloaded_'+id)) {
        h.visibility = show ? 'visible':'hidden';
    }
}
function order(item_id, item_type) {
    if (item_type == undefined) item_type = 'image';
    popwindow('order.php?item_id='+item_id+'&item_type='+item_type+'&pic='+escape(document.images['pic_image'].src), 'pworder', 550, 600);
    
}
function SetCookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
function sg_ofs(r,attr) {
    var o=0; 
    while(r) {
        o+=r[attr]; r=r.offsetParent; 
    } 
    return o;  
}
function set_dl_pos(str_idx) {
    var dl_idx = str_idx.split("_");
    var abs_idx;
    var i;
    var hleft;
    var htop;
    for (i=0;i<dl_idx.length;i++) {
        abs_idx = dl_idx[i];
        if ((o = find_object('pic_link_'+abs_idx)) && (h = find_handle('downloaded_'+abs_idx))) {
            hleft = sg_ofs(o,"offsetLeft");
            htop = sg_ofs(o, "offsetTop");
            h.left = hleft;
            h.top = htop;
        }
    }
}
function show_about(on) {
    if (on == undefined) on = true;
    if ((hbr = find_handle('browse')) && (hab = find_handle('about'))) {
        if (on || hab.display == "block") {
            set_prevnext(!on);
        }
//        hbr.display = on ? 'none' : 'block';
//        hab.display = on ? 'block' : 'none';
        if (h = find_handle('click_browse')) {
            h.display = hab.display;
        }
        if (h = find_handle('click_about')) {
            h.display = hbr.display;
        }
    }
    var t = on ? 'event' : 'image';
    try {
        if (t != comments[0].table) {
            comments[0].comment_refresh(t);
        }
    } catch(e) {}
}
function set_prevnext(on) {
    var addlink = '';
    if (on) {
        addlink = '&browse=1';
    }
    if ((prevlink == '') && (o = find_object('prev_top'))) {
        prevlink = o.href
    }
    if ((nextlink == '') && (o = find_object('next_top'))) {
        nextlink = o.href
    }
    if ((ot = find_object('prev_top')) && (ob = find_object('prev_bottom'))) {
        ot.href = prevlink + addlink; 
        ob.href = prevlink + addlink; 
    }
    if ((ot = find_object('next_top')) && (ob = find_object('next_bottom'))) {
        ot.href = nextlink + addlink; 
        ob.href = nextlink + addlink; 
    }
}
function nl_switch(datum) {
    var os = find_object('newsletter_bysection');
    var od = find_object('newsletter_bydate');
    var ou = find_object('newsletter_byupdate');
    var ls = find_object('link_bysection');
    var ld = find_object('link_bydate');
    var lu = find_object('link_byupdate');
    var ss = find_object('sel_bysection');
    var sd = find_object('sel_bydate');
    var su = find_object('sel_byupdate');
    if (os && od && ou && ls && ld && lu) {
        os.style.display = datum == 0 ? 'block' : 'none';
        od.style.display = datum == 1 ? 'block' : 'none';
        ou.style.display = datum == 2 ? 'block' : 'none';
        ss.style.visibility = datum == 0 ? 'visible' : 'hidden';
        sd.style.visibility = datum == 1 ? 'visible' : 'hidden';
        su.style.visibility = datum == 2 ? 'visible' : 'hidden';
        ls.style.color = datum == 0 ? '#d00b0b' : '#333';
        ld.style.color = datum == 1 ? '#d00b0b' : '#333';
        lu.style.color = datum == 2 ? '#d00b0b' : '#333';
    }
}
var mover = new Array();
function movie_over(id, over) {
    mover[id] = over;
    setTimeout('do_movie_over(\''+id+'\', '+over+')', 1000);
}
function do_movie_over(id, over) {
    if (mover[id]  == over) {
        for (mid in mover) {
            var o = find_object(mid);
            if (o) {
                if (over) {
                    o.style.display = mid == id ? 'block' : 'none';
                    o.style.width = mid == id ? '360px' : '140px';
                    o.style.height = mid == id ? '370px' : '160px';
                } else {
                    o.style.display = 'block';
                    o.style.width = '140px';
                    o.style.height = '160px';
                }
            }
        }
    }
}
function insertAfter(newElement,targetElement) {
    var parent = targetElement.parentNode;
    if (parent.lastChild == targetElement) {
        parent.appendChild(newElement);
    } else {
        parent.insertBefore(newElement,targetElement.nextSibling);
    }
}
function show_alert() {
    var oa = find_object('alert');

    var ot = find_object('toppic');
    if (ot) {
        oa.style.left = findPosX(ot) + 480 + 'px';
        oa.style.top = findPosY(ot) + 'px';
    }
    oa.style.display = 'block';
    oa.style.zIndex = 10000;

}
function close_alert() {
    find_object('alert').style.display = 'none';
    setcookie('pn_alert_closed', 1, 4);
}
function setcookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
} 
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent!=null) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    } else if (obj.y) curtop += obj.y;
    return curtop;
}
