
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}


function newWin(name, url, width, height, args) {

    var popupurl = url;
    var newWin = new Object();

    newWin.args = args;
    newWin.url = url;
    newWin.name = name;
    newWin.width = width;
    newWin.height = height;

    if (document.layers) { // browser is NN
        newWin.left = window.screenX + ((window.outerWidth - newWin.width) / 2);
        newWin.top = window.screenY + ((window.outerHeight - newWin.height) / 2);
        var attr = 'screenX=' + newWin.left + ',screenY=' + newWin.top + ',resizable=yes,width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
    } else { // browser is MSIE
        newWin.left = (screen.width - newWin.width) / 2;
        newWin.top = (screen.height - newWin.height) / 2;
        var attr = 'left=' + newWin.left + ',top=' + newWin.top + ',resizable=yes,width=' + newWin.width + ',height=' + newWin.height + ',' + newWin.args;
    }
    newWin.win = window.open(newWin.url, newWin.name, attr);
    if ((!newWin.win) || (newWin.win.closed)) { // probably popup-blocker active
        popupblocker_alert();
        return;
    }
    newWin.win.opener = self;
    newWin.win.focus();
}

function changeBg(object, color) {
    object.style.backgroundColor = color;
}





/* Dropdownmenu Shopnavigation, jquery */
var shopnav_hide_timeout;
var shopnav_show_timeout;
var active_object;

function show_shopnav() {

    $(".shopnav_layer").hide();
    if (typeof active_object == "object") {
        var layername = "#" + active_object.id + "_layer";
        var offset = $(active_object).position();
        var left = offset.left;
        var tablewidth = 984;
        var layerwidth = 458;
        if (left + layerwidth > tablewidth) {
            left = tablewidth - layerwidth;
        }
        $(layername).css({
            'left': left,
            'top': offset.top + 27
        });
        $(layername).show();
    }
}

function hide_shopnav() {
    if (typeof active_object == "object") {
        if ($(active_object).hasClass('tab_not_active')) {
            var bg_name=$(active_object).attr("data-bgbutton");
            if (bg_name) {
                bg_name="bg_shopnav_"+bg_name+".jpg";
            } else {
                bg_name="row_grey_center.jpg";
            }
            $(active_object).css('background-image','url('+dtimg+bg_name+')');
        }
        var layername = "#" + active_object.id + "_layer";
        $(layername).hide();
        active_object=undefined;
    }
}

$(document).ready(function() {

    /* Dropdownmenu Shopnavigation */
    if ($('table#shopnav_row1 td, table#shopnav_row2 td')) {
        $('table#shopnav_row1 td, table#shopnav_row2 td').mouseover(function() {
            if (typeof shopnav_hide_timeout == "number") {
                window.clearTimeout(shopnav_hide_timeout);
                delete shopnav_hide_timeout;
            }
            if (typeof shopnav_show_timeout == "number") {
                window.clearTimeout(shopnav_show_timeout);
                delete shopnav_show_timeout;
            }
            active_object = this;
            if ($(active_object).hasClass('tab_not_active')) {
                var farbe = active_object.id.split("_");
                var image_url = dtimg + "bg_shopnav_" + farbe[2] + ".jpg";
                $(active_object).css('background-image', 'url(' + image_url + ')');
                $(active_object).children("a").css('color', 'white');
            }
            shopnav_show_timeout = window.setTimeout(show_shopnav, 300);
        }).mouseout(function() {
            if ($(active_object).hasClass('tab_not_active')) {
                var bg_name = $(active_object).attr("data-bgbutton");
                if (bg_name) {
                    bg_name = "bg_shopnav_" + bg_name + ".jpg";
                    $(active_object).children("a").css('color', 'white');
                } else {
                    bg_name = "row_grey_center.jpg";
                    $(active_object).children("a").css('color', 'black');
                }
                $(active_object).css('background-image', 'url(' + dtimg + bg_name + ')');
            }
            shopnav_hide_timeout = window.setTimeout(hide_shopnav, 100);
        });
    }

    if ($('.shopnav_layer')) {
        $('.shopnav_layer').mouseout(function() {
            if ($(active_object).hasClass('tab_not_active')) {
                var bg_name = $(active_object).attr("data-bgbutton");
                if (bg_name) {
                    bg_name = "bg_shopnav_" + bg_name + ".jpg";
                    $(active_object).children("a").css('color', 'white');
                } else {
                    bg_name = "row_grey_center.jpg";
                    $(active_object).children("a").css('color', 'black');
                }
                $(active_object).css('background-image', 'url(' + dtimg + bg_name + ')');
            }
            shopnav_hide_timeout = window.setTimeout(hide_shopnav, 100);
        }).mouseover(function() {
            if ($(active_object).hasClass('tab_not_active')) {
                var farbe = active_object.id.split("_");
                var image_url = dtimg + "bg_shopnav_" + farbe[2] + ".jpg";
                $(active_object).css('background-image', 'url(' + image_url + ')');
                $(active_object).children("a").css('color', 'white');
            }
            if (typeof shopnav_hide_timeout == "number") {
                window.clearTimeout(shopnav_hide_timeout);
                delete shopnav_hide_timeout;
            }
        });
    }

    /* zuletzt gesehen Karussell */
    if ($('#mycarousel, #prodcomaprecarousel')) {
        $('#mycarousel, #prodcomaprecarousel').jcarousel({
            scroll: 4,
            animation: 1000
        });
    }

    if ($('#mycarouselwide, #prodcomaprecarouselwide')) {
        $('#mycarouselwide, #prodcomaprecarouselwide').jcarousel({
            scroll: 5,
            animation: 1000
        });
    }

});



/*
    SelectorLayer
        der Komplette Layer
    SelectorMask
        Hintergrund
    SelectorHeadline
        Kopfzeile oder Schliessen-Bereich (SelectorLayer, wenn nicht angegeben)
*/
function NwsShowLayer(params) {

     if ( !params.headline ) {
        params.headline = params.layer;
    }

    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    $(params.mask).css({'width':maskWidth,'height':maskHeight});
    $(params.mask).fadeIn(1000);
    $(params.mask).fadeTo('slow', 0.8);
    var winH = $(window).height();
    var winW = $(window).width();
    $(params.layer).css('top',  winH / 2 - $(params.layer).height() / 2);
    $(params.layer).css('left', winW / 2 - $(params.layer).width()  / 2);
    $(params.layer).fadeIn(2000);

    $(params.headline).click(function(){
        $(params.mask).hide();
        $(params.layer).hide();
    });

    $(params.mask).click(function(){
        $(params.mask).hide();
        $(params.layer).hide();
    });

}
