function onLoad() {
    bindSearchInputAction();
    bindVerticalMenuBehaviour();
}

function bindSearchInputAction() {
    var inputElement = document.getElementById('searchQuery');

    inputElement.onfocus = function() {
        if( inputElement.value === "szukana fraza" ) {
            inputElement.value = "";
        }
    };

    inputElement.onblur = function() {
        if( inputElement.value.length === 0 ) {
            inputElement.value = "szukana fraza";
        }
    };
}

function bindVerticalMenuBehaviour() {
    var menuElement = document.getElementById('verticalMainMenu');

    var linksTab = menuElement.getElementsByTagName('a');
    
    for( var i = 0; i < linksTab.length; i++ ) {
        var link = linksTab[i];
        
        link.onmouseover = function() {
            setNextLinkBackground(this, 'hide');
        };

        link.onmouseout = function() {
            setNextLinkBackground(this, 'show');
        };
    }

    return false;
}

function setNextLinkBackground( link, mode ) {
    var nextRow = link.parentNode.nextSibling;
            // console.log(link.title);
    if (( nextRow == null )||(link.title=="RSS")) {
        return false;
    }

    if( nextRow.nodeType == 3 ) {
        nextRow = nextRow.nextSibling;
    }

    if( arguments[1] == 'hide' ) {
        nextRow.getElementsByTagName('a')[0].className = 'emptyBackground';
    }

    if( arguments[1] == 'show' ) {
        nextRow.getElementsByTagName('a')[0].className = '';
    }         
}


function Preloader(){}

Preloader.prototype = {
    images    : new Array(),
    imagesUrl : new Array(),

    initialize : function() {
        this.imagesUrl[0]  = "http://zprp.pl/gfx/menu/aktualnosci.gif";
    	this.imagesUrl[1]  = "http://zprp.pl/gfx/menu/aktualnosci_hover.gif";
    	this.imagesUrl[2]  = "http://zprp.pl/gfx/menu/ZPRP.gif";
    	this.imagesUrl[3]  = "http://zprp.pl/gfx/menu/ZPRP_hover.gif";
    	this.imagesUrl[4]  = "http://zprp.pl/gfx/menu/historia.gif";
    	this.imagesUrl[5]  = "http://zprp.pl/gfx/menu/historia_hover.gif";
    	this.imagesUrl[6]  = "http://zprp.pl/gfx/menu/kluby.gif";
    	this.imagesUrl[7]  = "http://zprp.pl/gfx/menu/kluby_hover.gif";
    	this.imagesUrl[8]  = "http://zprp.pl/gfx/menu/regulaminy.gif";
    	this.imagesUrl[9]  = "http://zprp.pl/gfx/menu/regulaminy_hover.gif";
    	this.imagesUrl[10] = "http://zprp.pl/gfx/menu/przepisy.gif";
    	this.imagesUrl[11] = "http://zprp.pl/gfx/menu/przepisy_hover.gif";
    	this.imagesUrl[12] = "http://zprp.pl/gfx/menu/wydawnictwa.gif";
    	this.imagesUrl[13] = "http://zprp.pl/gfx/menu/wydawnictwa_hover.gif";
    	this.imagesUrl[14] = "http://zprp.pl/gfx/menu/kontakt.gif";
    	this.imagesUrl[15] = "http://zprp.pl/gfx/menu/kontakt_hover.gif";
    },

    load : function() {
        for ( var i = 0; i < this.imagesUrl.length; i ++ ) {
            this.images[i] = new Image();
            this.images[i].asd = i;
            this.images[i].onload = function(e) {
                    //console.log(this.asd);
                };
            this.images[i].src = this.imagesUrl[i];
        };
    }
}
