var JSCALENDAR = false;
var JSCALENDAR_ID = [];

var Browser = {
    _init : function() {
        var t = this, d = document, w = window, na = navigator, ua = na.userAgent, i, nl, n, base, p;
        t.isOpera = w.opera && opera.buildNumber;
        t.isWebKit = /WebKit/.test(ua);
        t.isOldWebKit = t.isWebKit && !w.getSelection().getRangeAt;
        t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
        t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
        t.isGecko = !t.isWebKit && /Gecko/.test(ua);
        t.isMac = ua.indexOf('Mac') != -1;
    }
};

function ContainerList(containerElem) {
    var items = $A($(containerElem).select("li"));
    if (items && items.length >=1) {
        items.each(function(item) {
            Event.observe(item,'mouseover',function() {
                Element.addClassName(this,'listItem_hover');
            }.bind(item));
            Event.observe(item,'mouseout',function() {
                Element.removeClassName(this,'listItem_hover');
            }.bind(item));
        });
    }
}

window.onload = function(){
    if (JSCALENDAR) {
        JSCALENDAR_ID.each( function(c) {
            var myCode = ''+c+' = new Epoch("epoch_popup","popup",document.getElementById(\''+c+'\'))';
            eval(myCode);
        });
    }
    if ($('introshow_menu') && $('introshow_object')) {
        I.init('introshow');
    }
    if ($('introshowH_menu') && $('introshowH_object')) {
        I.init('introshowH');
    }
    if ($('I_menu') && $('I_object')) {
        I.init('I');
    }
    if (document.getElementById('objectgallery')) {
        gallery.init();
    }
//if ($('containerList')) {
//	 ContainerList('containerList');
//}
}

var INTRO = {
    count:0,
    counter:0,
    menus:null,
    objects:null,
    pe:null,

    init:function(elemIdName){
        this.menus = $A($(elemIdName+'_menu').select("li"));
        this.objects = $A($(elemIdName+'_object').select("li"));
        this.count = this.menus.length-1;
        INTRO.debug('pocet objektov = '+this.count);
        this.pe = new PeriodicalExecuter(this.run, 2);
    },

    run:function(){
        this.counter = this.counter ? this.counter + 1 : 1;
        INTRO.debug(this.counter+ '>= '+INTRO.count +" = "+this.counter > INTRO.count);
        if (this.counter > INTRO.count) {
            this.counter = 0;
            INTRO.debug('');
        }
        INTRO.debug('counter '+this.counter);
        INTRO.set(this.counter);

    },

    call:function(num){
        this.pe.stop();
        INTRO.counter = num;
        this.pe = new PeriodicalExecuter(this.run, 1);


    },

    debug:function(info){
        if ($('debug')) {
            $('debug').innerHTML += info+"<br/>";
        }
    },

    set:function(id){
        if (INTRO.objects[id-1]) {
            INTRO.objects[id-1].hide();
            INTRO.menus[id-1].firstChild.removeClassName('active');
            INTRO.debug('vymazava '+(id-1));
        }else if(id==0){
            INTRO.objects[INTRO.count].hide();
            INTRO.menus[INTRO.count].firstChild.removeClassName('active');
            INTRO.debug('vymazava '+INTRO.count);
        }

        if (INTRO.objects[id]) {
            INTRO.objects[id].show();
            INTRO.menus[id].firstChild.toggleClassName('active');
            INTRO.debug('aktivuje '+id);
            INTRO.debug('');
        }
    }

}


var lit = {
    focus:function(elem,text){
        var elem = $(elem);
        elem.value = "";
    },

    blur:function(elem,text){
        var elem = $(elem);
        if (elem.value == "") {
            elem.value = text;
        }
    }
}

var lip = {
    focus:function(elem,text){
        var elem = $(elem);
        elem.value = "";
        elem.type = 'password';
    },

    blur:function(elem,text){
        var elem = $(elem);
        if (elem.value == "") {
            elem.type = 'text';
            elem.value = text;
        }
    }
}