﻿function timeStamp() {
    var time = new Date();
    return time.getTime();
}
$(document).ready(function() {
    if (!Silverlight.isInstalled("4.0.50303")) {
        $('.silverlight').css('display', 'block');
        $('.sl').css('display', 'block');
        if ($('body').hasClass('start') && $('input[name=hfCurView]').val() == "") {
            $.ajax({
                url: 'SilverlightSwitch.axd',
                data: { "silverlight": "0", "nocache": timeStamp() },
                complete: function() {
                    $('input[name=hfCurView]').val("0");
                }
            });
        } else if ($('input[name=hfCurView]').val() == "") {
            $.ajax({
                url: 'SilverlightSwitch.axd',
                data: { "silverlight": "0", "nocache": timeStamp() },
                complete: function() {
                    var overlay = $('.slBox');
                    overlay.css({
                        'top': ($(window).height() - $('.slBox').height()) / 2,
                        'left': ($(window).width() - 530) / 2,
                        'display': 'block'
                    });
                    $('.closeSlBox').click(function() {
                        overlay.css('display', 'none');
                        $('#overlay').remove();
                    });
                    $('input[name=hfCurView]').val("0");
                }
            });
        }
    }

    $('span.silverlight').click(function() {
        var overlay = $('.slBox');
        overlay.css(
            {
                'top': ($(window).height() - $('.slBox').height()) / 2,
                'left': ($(window).width() - 530) / 2,
                'display': 'block'
            });
        $('<div id="overlay">').css({
            'position': 'absolute',
            'top': 0,
            'left': 0,
            'width': $(window).width(),
            'height': $(window).height(),
            'background': '#000',
            'opacity': 0.5,
            'z-index': 99,
            'display': 'none'
        }).appendTo('body').css('display', 'block');
        $('.closeSlBox').click(function() {
            overlay.css('display', 'none');
            $('#overlay').remove();
        });
    });

//    $('.navi').children('ul').hideNaviTop();
    $('.navi').children('ul').children('li').each(function() {
        $(this).hideLi();
    });

    $('.navi').children('ul').children('li').children('ul').hideNaviTop2();

    //    $('.imageList').setSlider();
    if (isMobile()) {
        $('.imageList a').click(function() {
            if (!$(this).hasClass('active')) {
                $('.imageList a').removeClass('active');
                $(this).addClass('active');
                var href = $(this).attr('href');
                var src = $(this).find('img.hide').attr('src');
                var text = $(this).find('img.hide').attr('alt');
                var image = $('.gallery .image img');
                image.fadeOut(function() {
                    image.parent().attr('href', href);
                    image.attr('src', src).fadeIn();

                });
                $('.gallery .text').fadeOut(function() {
                    $(this).html(text).fadeIn();
                });
            }
            return false;
        });
    } else {
        $('.imageList a').hover(function() {
            var smallImage = $(this);
            var count = 0;
            $('.imageList a').each(function() {
                if ($(this).hasClass('active')) {
                    count++;
                }
            });
            if (count > 1) {
                $('.imageList a').removeClass('active');
            }
            if (!smallImage.hasClass('active')) {
                $('.imageList a').removeClass('active');
                smallImage.addClass('active');
                var href = smallImage.attr('href');
                var src = smallImage.find('img.hide').attr('src');
                var text = smallImage.find('img.hide').attr('alt');
                var image = $('.gallery .image img');
                image.fadeOut(function() {
                    image.parent().attr('href', href);
                    image.attr('src', src).fadeIn(function() { image.css({ 'opacity': '1', 'display': 'block' }) });

                });
                $('.gallery .text').fadeOut(function() {
                    $(this).html(text).fadeIn(function() {
                        $(this).css({ 'opacity': '1', 'display': 'block' })
                    });
                });
            }

        });
    }


    $('.tooltip').each(function() {
        $(this).tooltip();
    });

    $('img.tellIcon').hover(function() {
        $(this).attr('src', 'templates/Bilder/corporate/bubbleHover.png');
    }, function() {
        $(this).attr('src', 'templates/Bilder/corporate/bubble.png');
    });

    $('img.favBtn').hover(function() {
        $(this).attr('src', 'templates/Bilder/corporate/favHover.png');
    }, function() {
        $(this).attr('src', 'templates/Bilder/corporate/fav.png');
    });

    $('img.fbIcon').hover(function() {
        $(this).attr('src', 'templates/Bilder/corporate/facebookHover.png');
    }, function() {
        $(this).attr('src', 'templates/Bilder/corporate/facebook.png');
    });
    if (parseInt($(window).width()) <= 1250) {
        $('.metaNavi').css({
            'left': 0,
            'top': 118,
            'height': 230,
            'background': '#2f2b28',
            'opacity': 0.9,
            'padding-top': 20,
            'padding-left': 10
        });
        $('div.gallery div.text').css({
            'left': 180
        });
    }
    OverlayLang();
});

$.fn.hideNaviTop2 = function() {
    if ($(this).children('li.sel').find('ul').length > 0) {
        $('.navOverlayTop2').css('display', 'block');
    }

    $(this).children('li').hover(function() {
        if (!$(this).hasClass('sel') && $(this).find('ul').length > 0) {
            $(this).parent().children('li.sel').find('ul').css('display', 'none');
            $('.navOverlayTop2').css('display', 'block');
        }
        if (!$(this).hasClass('sel') && $(this).find('ul').length < 1) {
            $(this).parent().children('li.sel').find('ul').css('display', 'none');
            $('.navOverlayTop2').css('display', 'none');
        }
        if ($(this).hasClass('sel') && $(this).find('ul').length > 0) {
            $(this).parent().children('li.sel').find('ul').css('display', 'block');
            $('.navOverlayTop2').css('display', 'block');
        }
    }, function() {
        if (!$(this).hasClass('sel')) {
            if ($(this).parent().children('li.sel').find('ul').length > 0) {
                $(this).parent().children('li.sel').find('ul').css('display', 'block');
                $('.navOverlayTop2').css('display', 'block');
            } else {
                $(this).parent().children('li.sel').find('ul').css('display', 'none');
                $('.navOverlayTop2').css('display', 'none');
            }
        }

        if ($(this).hasClass('sel') && $(this).find('ul').length > 0) {
            $(this).parent().children('li.sel').find('ul').css('display', 'block');
            $('.navOverlayTop2').css('display', 'block');
        }

        if ($(this).hasClass('sel') && $(this).find('ul').length < 1) {
            $(this).parent().children('li.sel').find('ul').css('display', 'none');
            $('.navOverlayTop2').css('display', 'none');
        }
    });
}

function IsIE8Browser() {

    var rv = -1;

    var ua = navigator.userAgent;

    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");

    if (re.exec(ua) != null) {

        rv = parseFloat(RegExp.$1);

    }

    return (rv == 4);

}

function OverlayLang() {

    var overlay = $('.boxOverlay');
    var left = ($(window).width() - 530) / 2;
    var top = ($(window).height() - overlay.height()) / 2;

    $('.switch').click(function() {
        var url = $(this).attr('href');
        $('.left', overlay).slideUp(function() {
            $('.oView').slideDown();
        });
        $('.btnOK').click(function() {
            window.location.href = url;
            return false;
        });
        $('.btnAbort').click(function() {
            $('.oView').slideUp(function() {
                $('.left', overlay).slideDown();
            });
            return false;
        });
        return false;
    });

    overlay.css(
    {
        'left': left,
        'top': top
    });

    $('.lang').click(function() {
        overlay.css('display', 'block');
        $('<div id="overlay">').css({
            'position': 'absolute',
            'top': 0,
            'left': 0,
            'width': $(window).width(),
            'height': $(window).height(),
            'background': '#000',
            'opacity': 0.5,
            'z-index': 99,
            'display': 'none'
        }).appendTo('body').css('display', 'block');
        return false;
    });

    $('.closeBoxOverlay').click(function() {
        overlay.css('display', 'none');
        $('#overlay').remove();
    });
}

$.fn.hideLi = function() {
    var li = $(this);
    var curLi;
    if (li.find('ul li.zwLevel').length > 0) {
        var pos = 0;
        var sel = false;
        if (li.find('a.sel').length > 0) {
            li.find('ul li').each(function() {
                var li = $(this);
                if (li.hasClass('zwLevel')) {
                    pos = li.index();
                    li.show();
                } else {

                    li.hide();
                }

                if (li.find('a').hasClass('sel')) {
                    sel = true;
                    //                li.parent().find('li.zwLevel:eq(' + pos + ')').show();
                    for (var i = (li.index() - 1); i >= pos; i--) {
                        li.parent().find('li:eq(' + i + ')').show();
                    }

                }

                if (sel && li.index() > pos) {
                    li.show();
                }

                if (li.next().hasClass('zwLevel')) {
                    sel = false;
                }

            });
        } else {
            li.children('ul').children('li').each(function() {
                if (!$(this).hasClass('zwLevel')) {
                    $(this).hide();
                }
            });
        }
    }
}


function isMobile() {
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/iPad/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/android/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/opera mini/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/blackberry/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/pre/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/palm os/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/palm/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/plucker/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/xiino/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/elaine/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/iris/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/3g_t/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/windows ce/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/opera mobi/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/windows ce; smartphone;/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/windows ce; iemobile/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/mobi/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/htc/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/htc_touch/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/phone/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/lg/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/sonyericsson/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/samsung/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/nokia/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/sony cmd/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/motorola/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/symbian/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/smartphone/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/wap/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/vodafone/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/o2/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/kindle/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/mobile/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/psp/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/treo/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/mini 9.5/i))) {
        return true;
    }
    if ((navigator.userAgent.match(/Opera Mobile/i))) {
        return true;
    }
    
    return false;
} 
