﻿function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

function IsFlash() {
    if (!FlashDetect.installed)
        return false;
    if (FlashDetect.major < 10 && FlashDetect.revision <= 45)
        return false;
    return true;
}

function hideBubbles() {
    jQuery('.Corner').hide();
    jQuery('#mapExpander').hide();
    jQuery('.BOX').hide();
    jQuery('.PopUp').hide();
}

jQuery(document).ready(function() {
    if (!IsFlash()) {
        jQuery('#flash').hide();
    }
    jQuery('.NoFlashListItemText p').each(function(i) {

        var height = jQuery(this).height();
        var width = jQuery(this).width();

        if (width > 200 && height < 50) {
            while (jQuery(this).height() < 64 && jQuery(this).width() > 200) {
                width -= 30;
                jQuery(this).width(width);
            }
            width += 30;
            jQuery(this).width(width);
        }
    });
    jQuery('.NoFlash_Arcordion_Content p').each(function(i) {
        var height = jQuery(this).height();
        var width = jQuery(this).width();
        if (width > 200 && height < 40) {
            while (jQuery(this).height() < 40 && jQuery(this).width() > 200) {
                width -= 30;
                jQuery(this).width(width);
            }
            width += 30;
            jQuery(this).width(width);
            jQuery(this).parent().parent().parent().width(width);
        }
    });
    jQuery('.NoFlash_Arcordion_Content').hide();
    jQuery('.PopUp.BOTTOM').css('margin-bottom', '-684px');
    jQuery('.TOP').each(function() {
        var position = jQuery(this).position();
        jQuery(this).css('top', position.top + 684);
    });
    jQuery('.PopUp').hide();

    jQuery('.NoFlash_FP_Trigger').mouseover(function() {
        var id = jQuery(this).attr('id');
        if (!jQuery('#' + id + '_popup:visible').length) {
            jQuery('.PopUp:visible').hide(0, function() {
                var closePop = jQuery(this);
                if (closePop.attr('fc').length > 0 && IsFlash())
                    getFlashMovieObject('hsb').viewPerson(closePop.attr('fc'), 'out');
                closePop.hide();
            });
            var headline = jQuery(this);
            if (headline.attr('fc').length > 0 && IsFlash())
                getFlashMovieObject('hsb').trigEvent(headline.attr('fc'), 'over');
            var id = headline.attr('id');
            var popup = jQuery('#' + id + '_popup').css({ "z-index": "5001" }).fadeIn(200);
            popup.bind('mouseleave', function() {
                if (popup.attr('fc').length > 0 && IsFlash())
                    getFlashMovieObject('hsb').trigEvent(popup.attr('fc'), 'out');
                jQuery(this).fadeOut(200, function() { $(this).css({ "z-index": "200" }); });
                jQuery(this).unbind('mouseleave');
            });

        }
    });

    jQuery('.NoFlash_Arcordion').mouseover(function() {
        var acordion = jQuery(this);
        acordion.parent().find('.NoFlash_Arcordion').each(function() {
            if (jQuery(this).html() != acordion.html()) {
                jQuery(this).find('.NoFlash_Arcordion_Content').hide();
                jQuery(this).find('.NoFlash_Arcordion_Title_Hover').removeClass().addClass('NoFlash_Arcordion_Title');
            }

        });
        acordion.find('.NoFlash_Arcordion_Content').show();
        acordion.find('.NoFlash_Arcordion_Title').removeClass().addClass('NoFlash_Arcordion_Title_Hover');
    });




    jQuery('.ND_MainNavigationHolder a').each(function(i) {
        if (!jQuery(this).hasClass('custombox')) {
            var index = i;
            jQuery(this).click(function() {
                hideBubbles();
                if (IsFlash()) {
                    getFlashMovieObject('hsb').changeRoom(i, this.href);
                    this.blur;
                    return false;
                }
            });
        }
    });

    jQuery('a.FlashNavi').click(function() {
        jQuery(this).removeClass('FlashNavi');
        hideBubbles();
        if (IsFlash()) {
            getFlashMovieObject('hsb').changeRoom(jQuery(this).attr('class'), this.href);
            this.blur;
            return false;
        }
    });

});

