var ie = null;
var w3 = null;

if (typeof document.addEventListener != "undefined") {
    w3 = true;
}else if(typeof document.attachEvent != "undefined") {
    ie = true;
}


window.onload = function (){
    if (document.getElementById("rightMenu")){
        rightMenuHover();    
    }
    
//     if (document.getElementById("topMenu")){
//         topMenuHover();
//     }
    
    if (document.getElementById("newsTableList")){
        newsRowsHover();
    }
}

function rightMenuHover(){
    var rightMenu = document.getElementById("rightMenu");
    for(var i=0; i < rightMenu.rows.length; i++){
        if (rightMenu.rows.item(i).cells.item(0).nodeName == 'TD'){
            if (w3 == true) {
                rightMenu.rows.item(i).cells.item(0).addEventListener("mouseover", function (e){ this.className += "Hover"; }, false);
                rightMenu.rows.item(i).cells.item(0).addEventListener("mouseout", function (e){ this.className = this.className.substr(0, this.className.indexOf('Hover')); }, false);
            } else if (ie == true) {
                rightMenu.rows.item(i).cells.item(0).attachEvent("onmouseover", function (){ window.event.srcElement.className += "Hover"; });
                rightMenu.rows.item(i).cells.item(0).attachEvent("onmouseout", function (){ window.event.srcElement.className = window.event.srcElement.className.substr(0, window.event.srcElement.className.indexOf('Hover')); });
            }
        }
    }
}

function topMenuHover(){
    //get menu
    var topMenu = document.getElementById("topMenu");
    //get images
    var topImages = topMenu.getElementsByTagName("img");

    for (var i=0; i < topImages.length; i++){
        preloadImages(topImages[i].src, '_hover');
        var src = topImages[i].src;
        if (w3 == true) {
            topImages[i].addEventListener("mouseover",function (){
                    this.setAttribute('orgSrc', this.src);
                    this.src = hoverImage(this.src, '_hover');

            },false);
            topImages[i].addEventListener("mouseout",function (){
                    this.src = this.getAttribute('orgSrc');

            },false);
        }else if (ie == true){
            topImages[i].attachEvent("onmouseenter", function (){var el = window.event.srcElement; el.setAttribute('orgSrc', el.src); el.src = hoverImage(el.src, '_hover');});
            topImages[i].attachEvent("onmouseleave", function (){window.event.srcElement.src = window.event.srcElement.getAttribute('orgSrc');});
        }
    }
}

function newsRowsHover(){
    var table = document.getElementById("newsTableList");
    
    for(i=1; i < table.rows.length; i++){
        if (w3 == true) {
            table.rows.item(i).addEventListener("mouseover", function (e){ this.className += "Hover"; }, false);
            table.rows.item(i).addEventListener("mouseout", function (e){ this.className = this.className.substr(0, this.className.indexOf('Hover')); }, false);
        } else if (ie == true) {
            table.rows.item(i).attachEvent("onmouseenter", function (){ window.event.srcElement.className += 'Hover' });
            table.rows.item(i).attachEvent("onmouseleave", function (){ window.event.srcElement.className = window.event.srcElement.className.substr(0, window.event.srcElement.className.indexOf('Hover')); });
        }
    }
}
var printWindow;
function printPage(){
    printWindow = window.open('print.html','printWindow');
    if (w3 == true){
        printWindow.addEventListener("load", copyContent, false);
    }else if (ie == true) {
        printWindow.attachEvent("onload", copyContent);
    }
}

function copyContent(e){
    if (!e) {
        var e = window.event;
    }

    if (ie == true){
        var win = printWindow;
    }else if(w3 == true){
        var win = this;
    }

    if (win){
        win.document.body.innerHTML = "<div style='width: 15cm; margin:auto'>"+printWindow.opener.document.getElementById('mainContent').innerHTML+"<div style='clear: both'>Copyright © 2003 - 2005 www.OniOna.net. Kopiowanie bez zezwolenia zabronione</div></div>";
        win.print();
    }
}
var imgDebug;

function hoverImage(image, suffix){
    var img = image.substring(0, image.indexOf('.gif')) + suffix + '.gif';
    imgDebug += 'H:'+img+'\n';
    return img;
}

function normalImage(image, suffix){
    var img = image.substring(0, image.indexOf(suffix +'.gif')) + '.gif';
    imgDebug += 'N:'+img+'\n';
    return img;
}

function emailToFriend(){
    var mailWindow = window.open('mail.php','mailWindow','scrollbars=no,menubar=no,height=300,width=400');
}

function imageDebug(){
    alert(imgDebug);
}
