/*
Script Name: Simple Javascript Browser/OS detection
Authors: Harald Hope, Tapio Markula, Websites: http://techpatterns.com/
http://www.nic.fi/~tapio1/Teaching/index1.php3
Script Source URI: http://techpatterns.com/downloads/javascript_browser_detection.php
Version 2.0.1
Copyright (C) 08 August 2004

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

Lesser GPL license text:
http://www.gnu.org/licenses/lgpl.txt

*/

var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;

d = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( nua.indexOf( 'Linux' ) != -1 );

if ( !d.layers ){
	dom = ( d.getElementById );
	op = ( nua.indexOf( 'Opera' ) != -1 );
	konq = ( nua.indexOf( 'Konqueror' ) != -1 );
	saf = ( nua.indexOf( 'Safari' ) != -1 );
	moz = ( nua.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	ie = ( d.all && !op );
	ie4 = ( ie && !dom );

	/*
	ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
	Opera will register true in this test if set to identify as IE 5
	*/

	ie5x = ( d.all && dom );
	ie5mac = ( mac && ie5x );
	ie5xwin = ( win && ie5x );
}

function browser_css( ) {
	d = document;// shorthand so we don't have to write out document each time..
	if ( ie5mac ) {
		d.write('<link rel="stylesheet" type="text\/css" href="/css/default.css"/>');
	}
	else if ( d.layers ){
		d.write('<link rel="stylesheet" type="text\/css" href="/css/css_moz.css"/>');
	}
	else if ( ie4 ){
		d.write('<link rel="stylesheet" type="text\/css" href="/css/default.css"/>');
	}
	else if ( moz ){
		d.write('<link rel="stylesheet" type="text\/css" href="/css/css_moz.css"/>');
	}
	else {
		d.write('<link rel="stylesheet" type="text\/css" href="/css/default.css"/>');
	}
}


// Menu

var menuTimeout = 400;
var menuOffsetWidth = 0;
var menuOffsetHeight = -1;

var menuId = 'menu';
var menuTree = new Array();
var menuSections = new Array();
var menuSectionsCountHide = new Array();
var menuSectionsVisible = new Array();

var menuBrowser = navigator.userAgent.toLowerCase();
var menuBrowserIsOpera = menuBrowser.indexOf('opera') != -1;
var menuBrowserIsIE = menuBrowser.indexOf('msie') != -1 && !menuBrowserIsOpera;
//alert(navigator.userAgent);
    
function gallery(id,cat,imgs,lang){
	url = "/gallery.php?id="+id+"&cat="+cat+"&imgs="+imgs+"&lang="+lang;
	width = "450";
	height = "350";
	newwindow=window.open(url,name,'height='+height+',width='+width);
	if (window.focus) {newwindow.focus()}
}

function menuInit() {
    menuMakeIds(document.getElementById(menuId).childNodes, menuTree, menuId, 0, 0, 0);
    for (var i = 0; i < menuSections.length; i++) {
        menuSectionsCountHide[menuSections[i]] = 0;
    }
    for (var i = 0; i < menuSections.length; i++) {
        menuInitSection(menuSections[i], menuGetTreeById(menuSections[i]));
    }
}

function menuMakeIds(nodes, tree, id, lastOW, lastBLW, lastBRW) {
    for (var i = 0; i < nodes.length; i++) {
        switch (nodes[i].className) {
            case "top":
            case "box-right":
                id = id + "-" + tree.length;
                nodes[i].id = id;
                if (menuBrowserIsIE && document.compatMode && document.compatMode != "BackCompat") {
                    if (nodes[i].className == "box-right" && nodes[i].currentStyle) {
                        var tmp;
                        tmp = lastBLW + lastBRW;
                        if (tmp) {
                            tmp = Math.floor(tmp / 2) + 1;
                        }
                        nodes[i].style.width = lastOW - ( parseInt(nodes[i].currentStyle.paddingLeft) + parseInt(nodes[i].currentStyle.paddingRight) ) - tmp;
                    }
                }
                tree[tree.length] = new Array();
                tree = tree[tree.length - 1];
                break;
            case "box":
                nodes[i].id = id + "-" + tree.length;
                tree[tree.length] = new Array();
                break;
        }
        var className = new String(nodes[i].className);
        if (menuBrowserIsIE && !(document.compatMode && document.compatMode != "BackCompat")) {
            if (className == "box" || className == "box-hover") {
                nodes[i].style.width = "100%";
            }
        }
        if (className == "section") {
            if (!menuBrowserIsIE) {
                nodes[i].style.width = "auto";
            }
            nodes[i].style.left = (lastOW + menuOffsetWidth) + "px";
            nodes[i].style.top = menuOffsetHeight + "px";
        }
        if (className.substr(0, 7) == "section") {
            menuSections[menuSections.length] = id;
            nodes[i].id = id + "-section";
            lastOW = nodes[i].offsetWidth;
            if (nodes[i].currentStyle) {
                lastBLW = parseInt(nodes[i].currentStyle.borderLeftWidth);
                lastBRW = parseInt(nodes[i].currentStyle.borderRightWidth);
            }
        }
        if (nodes[i].childNodes) {
            menuMakeIds(nodes[i].childNodes, tree, id, lastOW, lastBLW, lastBRW);
        }
    }
}

function menuInitSection(id_section, tree) {
    eval("document.getElementById('"+id_section+"').onmouseover = function() {"+
        "menuShow('"+id_section+"');"+
        "if (document.getElementById('"+id_section+"').className == 'box-right') {"+
            "document.getElementById('"+id_section+"').className = 'box-right-hover';"+
        "}"+
    "}");
    eval("document.getElementById('"+id_section+"').onmouseout = function() {"+
        "setTimeout(\"menuTryHide('"+id_section+"', \"+menuSectionsCountHide['"+id_section+"']+\")\", menuTimeout);"+
        "if (document.getElementById('"+id_section+"').className == 'box-right-hover') {"+
            "document.getElementById('"+id_section+"').className = 'box-right';"+
        "}"+
    "}");
    for (var i = 0; i < tree.length; i++) {
        var id = id_section + "-" + i;
        if (tree[i].length == 0) {
            eval("document.getElementById('"+id+"').onmouseover = function() {"+
                "menuShow('"+id_section+"');"+
                "document.getElementById('"+id+"').className = 'box-hover';"+
            "}");
            eval("document.getElementById('"+id+"').onmouseout = function() {"+
                "setTimeout(\"menuTryHide('"+id_section+"', \"+menuSectionsCountHide['"+id_section+"']+\")\", menuTimeout);"+
                "document.getElementById('"+id+"').className = 'box';"+
            "}");
        }
    }
}

function menuShow(id_section) {
    var sections = menuGetIdParentsArrById(id_section, true);
    for (var i = 0; i < sections.length; i++) {
        menuSectionsCountHide[sections[i]]++;
    }
    for (var i = 0; i < menuSectionsVisible.length; i++) {
        if (!menuArrayContains(sections, menuSectionsVisible[i])) {
            menuHide(menuSectionsVisible[i]);
        }
    }
    document.getElementById(id_section + "-section").style.zIndex = 99;
    document.getElementById(id_section + "-section").style.visibility = 'visible';
    menuSectionsVisible = sections;
}

function menuTryHide(id_section, count) {
    if (count == menuSectionsCountHide[id_section]) {
        var sections = menuGetIdParentsArrById(id_section, true);
        if (menuArraysEqual(sections, menuSectionsVisible)) {
            for (var i = 0; i < sections.length; i++) {
                menuHide(sections[i]);
            }
        } else {
            menuHide(id_section);
        }
    }
}

function menuHide(id_section) {
    document.getElementById(id_section + "-section").style.visibility = 'hidden';
    document.getElementById(id_section + "-section").style.zIndex = -1;
}

function menuGetTreeById(id) {
    var a = id.split("-");
    a.shift();
    var s = "";
    for (var i = 0; i < a.length; i++) {
        s += ("[" + a[i] + "]");
    }
    return eval("menuTree" + s);
}

function menuGetIdParentsArrById(id, includeSelf) {
    var a = id.split("-");
    var ret = new Array();
    if (includeSelf) {
        ret[ret.length] = id;
    }
    while (a.length > 2) {
        a.pop();
        ret[ret.length] = a.join("-");
    }
    return ret;
}

function menuArrayContains(a, s) {
    var found = false;
    for (var i = 0; i < a.length; i++) {
        if (a[i] == s) {
            found = true;
            break;
        }
    }
    return found;
}

function menuArraysEqual(a1, a2) {
    if (a1.length != a2.length) {
        return false;
    }
    for (var i = 0; i < a1.length; i++) {
        if (a1[i] != a2[i]) {
            return false;
        }
    }
    return true;
}


function expandcontent(cid){
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}

function redir(sel) {
	document.location = sel.options[sel.options.selectedIndex].value;
}
function printpage(){
	document.print();
	//window.print();
	return true;
}