﻿/*root*/

var BMSEVENTS = {

    //initialize
    init: function(){
    
        $('body').addClass('js');
        
        //flash player version needed
        BMSEVENTS.flash.version = '10.0.0';
        
        BMSEVENTS.utils.init();
        
        //check for browser and flash player/version
        if (BMSEVENTS.utils.browserAndVersion() === 'ie6') {
            BMSEVENTS.utils.showErrorSceen('browser');
            
        }
        else 
            if (!swfobject.hasFlashPlayerVersion(BMSEVENTS.flash.version)) {
            
                if (swfobject.ua.pv[0] === 0) {
                
                    //no flash player at all
                    BMSEVENTS.utils.installFlashPlayerError();
                    
                }
                
                else {
                
                    //wrong version
                    BMSEVENTS.utils.installFlashPlayer();
                    
                }
                
            }
            else {
            
                BMSEVENTS.flash.init();
                BMSEVENTS.events.init();
                
            }
        
    },
    
    //helper
    utils: {
    
        //initialize helper
        init: function(){
        
            BMSEVENTS.utils.setInputField('search');
            BMSEVENTS.utils.setInputField('newsletter');
            BMSEVENTS.utils.setBrowserSpecs();
            BMSEVENTS.utils.clearNoScript();
            
        },
        
        getTimestamp: function(){
        
            var timestamp = new Date();
            return timestamp.getTime();
            
        },
        
        getHash: function(){
        
            var tempHash = window.location.hash;
            var hash = tempHash.substring(1);
            
            return hash;
        },
        
        getFileName: function(){
        
            var tempHref = window.location.href;
            var lastSlash = tempHref.lastIndexOf('/');
            var fileName = tempHref.substring(lastSlash + 1);
            
            return fileName;
        },
        
        //return browser and version
        browserAndVersion: function(){
        
            if ($.browser.msie && $.browser.version <= 6) {
                return 'ie6';
            }
            else 
                if ($.browser.msie && $.browser.version > 6 && $.browser.version < 8) {
                    return 'ie7';
                }
                else 
                    if ($.browser.msie && $.browser.version > 7 && $.browser.version < 9) {
                        return 'ie8';
                    }
                    else {
                        return 'zz';
                    }
            
        },
        
        //flash player does not exist at all or expressinstall is aborted
        installFlashPlayerError: function(){
        
            BMSEVENTS.utils.showErrorSceen('flash');
            
        },
        
        //express install flash player
        installFlashPlayer: function(){
        
            /* express install did not work in safari
             $('body').append('<div id="expressInstall"></div>')
             
             var attributes = {
             data: '/js/flash/expressInstall.swf',
             width: '600',
             height: '240'
             };
             var parameter = {
             menu: false
             };
             var id = 'expressInstall';
             var canceled = BMSEVENTS.utils.installFlashPlayerError;
             
             swfobject.showExpressInstall(attributes, parameter, id, canceled);
             */
            BMSEVENTS.utils.showErrorSceen('flash');
            
        },
        
        //info text in searchfield is set/unset via title-tag and highlighted
        setInputField: function(input){
        
            var blurColor;
            var hoverColor;
            
            var $infoTextTemp = $('#searchInput').add('#newsletterInput');
            
            $infoTextTemp.unbind('focus', 'blur').bind('focus', function(){
            
                if ($(this)[0].title) {
                    if ($(this).val() === $(this)[0].title) {
                        $(this).val('');
                    }
                }
                
                $(this).addClass('active');
                $(this).parent('div').addClass('active');
                
            }).bind('blur', function(){
            
                if ($(this)[0].title) {
                    if ($(this).val() === '') {
                        $(this).val($(this)[0].title);
                    }
                }
                
                $(this).removeClass('active');
                $(this).parent('div').removeClass('active');
                
            }).blur();
            
        },
        
        setBrowserSpecs: function(){
        
            //ie specifics
            if ($.browser.msie && $('#outerWrapper').length !== 0) {
            
                if ($('#outerWrapper').width() < 1004) {
                    $('#outerWrapper').css({
                        overflowX: 'auto'
                    });
                }
                else {
                    $('#outerWrapper').css({
                        overflowX: 'hidden'
                    });
                }
                
            }
            
            //opera specifics
            if ($.browser.opera) {
            
                $('#header').css({
                    left: '-8px'
                });
                
                $('#outerWrapper').css({
                    /*position: 'fixed',*/
                    width: '100%',
                    top: '0px',
                    left: '0px'
                });
                
            }
            
        },
        
        //debug helper returning console.log or alerts
        debug: function(){
        
            var location = window.location + '';
            
            if (location.indexOf('127.0.0.1:8000') !== -1 || location.indexOf('BMSEVENTS.bmsevents.hu') !== -1 || location.indexOf('') !== -1) {
            
                var debugMode = true;
                var debugModeAlert = false;
                
                if (debugMode) {
                
                    var debugString = '';
                    var i = BMSEVENTS.utils.debug.arguments.length;
                    
                    do {
                        i--;
                        debugString += i + 1 + '. ' + BMSEVENTS.utils.debug.arguments[i] + '\n';
                    }
                    while (i > 0);
                    
                    if ($.browser.mozilla) {
                        console.log(debugString);
                    }
                    else 
                        if (debugModeAlert) {
                            window.alert(debugString);
                        }
                }
                
            }
            
        },
        
        //change location
        changeLocation: function(){
        
            window.location = BMSEVENTS.utils.newLocation;
            
        },
        
        clearNoScript: function(){
        
            $('div.noscript').remove();
            $('noscript').remove();
            
        },
        
        showErrorSceen: function(reason){
        
            $('#headerNavSub').find('span.preview').add('#leftNav').add('#leftNavHeader').add('#rightContent').add('#onlineStoreTeaser').add('#lifestyleTeaser').add('#socialLinks').add('abdeckerFooter').remove();
            
            if ($('#changeCountry').length !== 0) {
            
                var content = '<div id="headerNav">';
                content += '<div id="headerNavLogo">';
                content += '<a href="/">';
                content += '<img src="_shared.headerNav.logo.png" alt="BMSEVENTS" title="BMSEVENTS" />';
                content += '</a>';
                content += '</div>';
                content += '</div>';
                
                $('#content').html(content);
                
            }
            
            $('body').css({
                background: '#ffffff'
            }).removeClass('js');
            
            $('#content').css({
                minHeight: '545px',
                height: '545px',
                background: '#ffffff'
            });
            
            $('#backgroundImg').add('#innerContent').remove();
            
            $('#headerNav').css({
                background: 'url(error.headerNav.bg.gif)'
            });
            
            var errorHTML = '<div id="warning">';
            
            switch (reason) {
                case 'flash':
                    errorHTML += errorContent.flash.message + '<br />';
                    errorHTML += '<a href="' + errorContent.flash.url + '">' + errorContent.flash.link + '</a>';
                    break;
                case 'browser':
                    errorHTML += errorContent.browser.message + '<br />';
                    errorHTML += '<a href="' + errorContent.browser.url1 + '">' + errorContent.browser.link1 + '</a>';
                    errorHTML += '<a href="' + errorContent.browser.url2 + '">' + errorContent.browser.link2 + '</a>';
                    break;
            }
            errorHTML += '</div>';
            errorHTML += '<div id="errorImage"></div>';
            
            $('#headerNav').append(errorHTML);
            
        },
        
        //layer für datenschutz, nutzungsbedingungen
        showLayer: function(target){
        
            $('#' + target).css({
                display: 'block'
            });
            
            setTimeout(function(){
            
                $('body').bind('click', function(){
                
                    $('#' + target).css({
                        display: 'none'
                    });
                    
                    $('a.close').unbind('click');
                    $('body').unbind('click');
                    
                });
                
                $('a.close').bind('click', function(){
                
                    $('#' + target).css({
                        display: 'none'
                    });
                    
                    $('body').unbind('click');
                    $('a.close').unbind('click');
                    
                    return false;
                    
                });
                
                $('div.layer').bind('click', function(){
                
                    return false;
                    
                });
                
            }, 100);
            
        }
        
    },
    
    //global events
    events: {
    
        //initialize event handlers
        init: function(){
        
            //resize events
            $(window).resize(function(){
            
                BMSEVENTS.utils.setBrowserSpecs();
                
                BMSEVENTS.flash.updateSize();
                BMSEVENTS.flash.getOffsetX();
                
                BMSEVENTS.events.getMousePosition();
                
            });
            
            //click event
            $('a').live('click', function(){
            
                BMSEVENTS.utils.newLocation = $(this).attr('href');
                
                var target = $(this).attr('target');
                
                if (target !== '_top' && target !== '_parent' && target !== '_self') {
                
                    if (BMSEVENTS.utils.newLocation.indexOf('.pdf') !== -1 || BMSEVENTS.utils.newLocation.indexOf('http://') !== -1 || BMSEVENTS.utils.newLocation.indexOf('https://') !== -1) {
                    
                    
                        window.open(BMSEVENTS.utils.newLocation);
                        
                        return false;
                        
                    }
                    
                }
                else 
                    if ($('div.flash').length !== 0) {
                    
                    
                        if (!BMSEVENTS.flash.readyCounter || !BMSEVENTS.flash.loadedCounter) {
                        
                            return true;
                            
                        }
                        else {
                        
                            //fade out flash content, flash movie will return true and set the link free if content is faded out
                            BMSEVENTS.flash.fadeOut();
                            
                        }
                        return false;
                        
                    }
                    else {
                    
                        //no flash to fade out, link is executed
                        return true;
                        
                    }
                
            });
            
            $('a.videoLink').live('click', function(){
            
                var videoAliasTemp = $(this).attr('hash');
                var videoAlias = videoAliasTemp.substring(1);
                
                BMSEVENTS.flash.showVideoLayer(videoAlias);
                
                return false;
                
            });
            
            $('#newsletterSubmit').live('click', function(){
            
                if ($('#newsletterInput').attr('title') === $('#newsletterInput').attr('value')) {
                
                    $('#newsletterInput').attr('value', '');
                    
                }
                
                $('#newsletterForm').submit();
                
            });
            
            $('#searchSubmit').live('click', function(){
            
                if ($('#searchInput').attr('title') === $('#searchInput').attr('value')) {
                
                    $('#searchInput').attr('value', '');
                    
                }
                
                $('#searchForm').submit();
                
            });
            
            $('#footerSound').children('a').bind('click', function(){
            
                BMSEVENTS.flash.soundClickEvent();
                return false;
                
            });
            
            //Preview Bilder Fade on Mouseover
            if (BMSEVENTS.utils.browserAndVersion() === 'ie8' || BMSEVENTS.utils.browserAndVersion() === 'ie7') {
            
                $('#headerNavSub a').not('.active').hoverIntent(function(){
                
                    var target = $(this).parent().children('span');
                    
                    target.css({
                        display: 'block'
                    });
                    
                }, function(){
                
                    var target = $(this).parent().children('span');
                    
                    target.css({
                        display: 'none'
                    });
                    
                });
            }
            else {
                $('#headerNavSub a').not('.active').hoverIntent(function(){
                
                    var parent = $(this);
                    var target = $(this).parent().children('span');
                    
                    target.css({
                        display: 'block',
                        opacity: 0
                    });
                    
                    target.animate({
                        opacity: 1
                    }, {
                        duration: 300,
                        complete: function(){
                        
                            parent.addClass('mouseOver');
                            
                        }
                        
                    });
                    
                }, function(){
                
                    var parent = $(this);
                    var target = $(this).parent().children('span');
                    
                    if (parent.hasClass('mouseOver')) {
                    
                        parent.removeClass('mouseOver');
                        
                        target.animate({
                            opacity: 0
                        }, {
                            duration: 150,
                            complete: function(){
                            
                                target.css({
                                    display: 'none'
                                });
                                
                            }
                            
                        });
                        
                    }
                    else {
                    
                        target.stop().animate({
                            opacity: 0
                        }, {
                            duration: 50,
                            complete: function(){
                            
                                target.css({
                                    display: 'none'
                                });
                                
                            }
                            
                        });
                        
                    }
                    
                });
            }
            
            BMSEVENTS.events.getMousePosition();
            
        },
        
        getMousePosition: function(){
        
            //catch scroll event to enable highlighting in flash
            $('#outerWrapper').bind('scroll', function(){
            
                if ($('#moduleFlashSwf').length !== 0) {
                
                    if (BMSEVENTS.events.mouseX === undefined) {
                        BMSEVENTS.events.mouseX = 0;
                    }
                    if (BMSEVENTS.events.mouseY === undefined) {
                        BMSEVENTS.events.mouseY = 0;
                    }
                    
                    var offsetModuleX = $('#moduleFlashSwf').offset().left;
                    var mouseX = BMSEVENTS.events.mouseX;
                    var offsetModuleY = $('#moduleFlashSwf').offset().top * -1;
                    var mouseY = offsetModuleY + BMSEVENTS.events.mouseY;
                    
                    $('div.flash').find('object').each(function(){
                    
                        try {
                            //function inside flash
                            this.scrollOffset(offsetModuleY, offsetModuleX);
                            this.scrollContent(mouseX, mouseY);
                        } 
                        catch (e) {
                            //could not connect to flash movie (maybe not loaded jet)
                            //return false;
                        }
                        
                    });
                    
                }
                
            });
            
            //emag article 
            $('#outerWrapper').bind('scroll', function(){
            
                if ($('#articleFlashSwf').length !== 0) {
                
                    if (BMSEVENTS.events.mouseX === undefined) {
                        BMSEVENTS.events.mouseX = 0;
                    }
                    if (BMSEVENTS.events.mouseY === undefined) {
                        BMSEVENTS.events.mouseY = 0;
                    }
                    
                    var offsetModuleX = $('#articleFlashSwf').offset().left;
                    var mouseX = BMSEVENTS.events.mouseX;
                    var offsetModuleY = $('#articleFlashSwf').offset().top * -1;
                    var mouseY = offsetModuleY + BMSEVENTS.events.mouseY;
                    
                    $('div.flash').find('object').each(function(){
                    
                        try {
                            //function inside flash
                            this.scrollOffset(offsetModuleY, offsetModuleX);
                            this.scrollContent(mouseX, mouseY);
                        } 
                        catch (e) {
                            //could not connect to flash movie (maybe not loaded jet)
                            //return false;
                        }
                        
                    });
                    
                }
                
            });
            
            //catch mouse position to enable highlighting in flash (while/after scrolling)
            $('#outerWrapper').bind('mousemove', function(e){
                BMSEVENTS.events.mouseX = e.pageX;
                BMSEVENTS.events.mouseY = e.pageY;
            });
            
        }
        
    },
    
    //flash communication & control
    flash: {
    
        //init flash functions
        init: function(){
        
            BMSEVENTS.flash.scrollToTop();
            BMSEVENTS.flash.prepareFlashContent();
            
        },
        
        //prepare html and flash content
        prepareFlashContent: function(){
        
            if (flashContent.background && $('div.backgroundScroll').length !== 0) {
            
                var id = 'backgroundScrollFlash';
                
                $('div.backgroundScroll').addClass('flash').append('<div id="' + id + '"></div>');
                
                var swfObjectData = {
                    source: flashContent.background.source,
                    id: id,
                    width: '100%',
                    height: '100%',
                    center: true,
                    flashvars: flashContent.background.flashvars,
                    params: flashContent.background.params
                };
                
                BMSEVENTS.flash.initSwfObject(swfObjectData);
            }
            
            if (flashContent.background && $('div.backgroundFixed').length !== 0) {
            
                var id = 'backgroundFixedFlash';
                
                $('div.backgroundFixed').addClass('flash').append('<div id="' + id + '"></div>');
                
                var swfObjectData = {
                    source: flashContent.background.source,
                    id: id,
                    width: '100%',
                    height: '100%',
                    center: true,
                    flashvars: flashContent.background.flashvars,
                    params: flashContent.background.params
                };
                
                BMSEVENTS.flash.initSwfObject(swfObjectData);
            }
            
            if (flashContent.module && $('div.module').length !== 0) {
            
                var id = 'moduleFlash';
                
                $('div.module').addClass('flash').append('<div id="' + id + '"></div>');
                
                var width;
                if (!flashContent.module.width) {
                    var width = '100%';
                }
                else {
                    var width = flashContent.module.width;
                }
                
                var height;
                if (!flashContent.module.height) {
                    var height = '100%';
                }
                else {
                    var height = flashContent.module.height;
                }
                
                var center;
                if (!flashContent.module.center) {
                    var center = false;
                }
                else {
                    var center = true;
                }
                
                if (!flashContent.module.flashvars) {
                    flashContent.module.flashvars = {};
                }
                
                flashContent.module.flashvars.stageHeight = $('body').height();
                flashContent.module.flashvars.stageWidth = $('#content').width();
                
                var swfObjectData = {
                    source: flashContent.module.source,
                    id: id,
                    width: width,
                    height: height,
                    center: center,
                    flashvars: flashContent.module.flashvars,
                    params: flashContent.module.params
                };
                
                BMSEVENTS.flash.initSwfObject(swfObjectData);
                
            }
            
            if (flashContent.teaser && $('div.teaser').length !== 0) {
            
                var id = 'teaserFlash';
                
                $('div.teaser').addClass('flash').append('<div id="' + id + '"></div>');
                
                var width;
                if (!flashContent.teaser.width) {
                    var width = '100%';
                }
                else {
                    var width = flashContent.teaser.width;
                }
                
                if (!flashContent.teaser.flashvars) {
                    flashContent.teaser.flashvars = {};
                }
                
                flashContent.teaser.flashvars.stageHeight = $('body').height();
                flashContent.teaser.flashvars.stageWidth = $('#content').width();
                
                var swfObjectData = {
                    source: flashContent.teaser.source,
                    id: id,
                    width: width,
                    height: '295',
                    center: true,
                    flashvars: flashContent.teaser.flashvars,
                    params: flashContent.teaser.params
                };
                
                BMSEVENTS.flash.initSwfObject(swfObjectData);
                
            }
            
        },
        
        //init swfobject  
        initSwfObject: function(data){
        
            if (!data.source) {
                data.source = '';
            }
            
            if (!data.id) {
                data.id = '';
            }
            
            if (!data.width) {
                data.width = '100%';
            }
            
            if (!data.height) {
                data.height = '100%';
            }
            else {
                //TODO: mac ff flashplayer bug
                if ($.os.mac && $.browser.mozilla) { // 
                    var height = data.height + ' ';
                    if (height.indexOf('%') === -1) {
                        data.height = parseInt(height) + 1;
                    }
                    var width = data.width + ' ';
                    if (width.indexOf('%') === -1) {
                        data.width = parseInt(width) + 1;
                    }
                }
            }
            
            if (!data.version) {
                data.version = BMSEVENTS.flash.version;
            }
            
            if (!data.expressInstall) {
                data.expressInstall = null;
            }
            
            if (!data.flashvars) {
                data.flashvars = {};
            }
            
            if (!data.flashvars.moduleCSS) {
                data.flashvars.moduleCSS = flashContent.moduleCSS;
            }
            if (!data.flashvars.moduleXML) {
                data.flashvars.moduleXML = flashContent.moduleXML;
            }
            if (!data.flashvars.layoutXML) {
                data.flashvars.layoutXML = flashContent.layoutXML;
            }
            data.flashvars.lcKEY = flashContent.lcKEY;
            
            if (!data.params) {
                data.params = {
                    wmode: 'transparent', //opaque
                    allowScriptAccess: 'always',
                    menu: false
                };
            }
            else {
                if (!data.params.wmode) {
                    data.params.wmode = 'transparent'; //opaque
                }
                if (!data.params.allowScriptAccess) {
                    data.params.allowScriptAccess = 'always';
                }
                if (!data.params.menu) {
                    data.params.menu = false;
                }
            }
            
            if (!data.attributes) {
                data.attributes = {};
                data.attributes.id = data.id + 'Swf';
            }
            else 
                if (!data.attributes.id) {
                    data.attributes.id = data.id + 'Swf';
                }
            
            if (!data.callback) {
                data.callback = null;
            }
            
            swfobject.embedSWF(data.source, data.id, data.width, data.height, data.version, data.expressInstall, data.flashvars, data.params, data.attributes, data.callback);
            
            //TODO: mac ff flashplayer bug
            if ($.os.mac && $.browser.mozilla) { //
                swfobject.createCSS('#' + data.attributes.id, 'margin-top:-1px; margin-left:-1px;', null, true);
                
            }
            
            BMSEVENTS.flash.setHeight();
            
            if (data.id === 'moduleFlash') {
            
                BMSEVENTS.flash.initSwfMacMousewheel('moduleFlashSwf');
                
            }
            
            var width = data.width + ' ';
            if (data.center && width.indexOf('%') === -1) {
            
                var marginLeft = Math.ceil(width / 2);
                swfobject.createCSS('#' + data.attributes.id, 'left:50%; margin-left:-' + marginLeft + 'px; position:absolute;', null, true);
                
            }
        },
        
        //scroll to top
        scrollToTop: function(duration){
        
            if (!duration || duration == 'undefined') {
                duration = 0;
            }
            
            $('#outerWrapper').scrollTo(0, duration);
            
        },
        
        //scroll to position
        scrollToPosition: function(position, duration){
        
            if (!position || position == 'undefined') {
                position = 0;
            }
            
            if (!duration || duration == 'undefined') {
                duration = 0;
            }
            
            $('#outerWrapper').scrollTo(position, duration);
            
        },
        
        //set flash 100% height
        setHeight: function(){
        
            if ($.browser.chrome || $.browser.safari) {
            
                var height = $('#content').height() + $('#footer').height();
                
                swfobject.createCSS('#moduleFlashSwf', 'height:' + height + 'px;', null, true);
                swfobject.createCSS('#backgroundScrollFlashSwf', 'height:' + height + 'px;', null, true);
                
            }
            
        },
        
        //init swf mac mousewheel
        initSwfMacMousewheel: function(target){
        
            try {
            
                swfmacmousewheel.registerObject(target);
                
            } 
            catch (e) {
                //return false;
            }
            
        },
        
        //show/hide background which is not needed
        setBackground: function(fixed){
        
            if (!fixed) {
                $('div.backgroundFixed').children('object').css({
                    display: 'none'
                });
            }
            else {
                $('div.backgroundScroll').children('object').css({
                    display: 'none'
                });
            }
            
        },
        
        //hide Teaser
        hideTeaser: function(){
        
            $('#footer').css({
                height: '100px',
                marginTop: '-100px'
            }).children('div.teaser').css({
                display: 'none'
            });
            
        },
        
        //set to height other than 100%
        setFlashHeight: function(target, height){
        
            swfobject.createCSS('#' + target + 'FlashSwf', 'height:' + height + 'px;', null, true);
            
            var moduleHeight;
            var teaserHeight;
            var footerHeight;
            
            switch (target) {
                case 'teaser':
                    
                    moduleHeight = $('div.module').height();
                    teaserHeight = height;
                    footerHeight = teaserHeight + 100;
                    
                    $('div.teaser').css({
                        height: height + 'px'
                    });
                    
                    $('#footerNavInner').css({
                        marginTop: '50px'
                    });
                    
                    $('#footer').css({
                        height: footerHeight + 'px',
                        marginTop: '-' + footerHeight + 'px'
                    });
                    
                    if ($('#footer .teaser').length !== 0) {
                    
                        $('#footer .teaser').css({
                            visibility: 'visible'
                        });
                        
                    }
                    
                    break;
                case 'module':
                    
                    moduleHeight = height;
                    teaserHeight = $('div.teaser').height();
                    footerHeight = teaserHeight + 100;
                    
                    $('div.module').css({
                        height: height + 'px'
                    });
                    
                    break;
            }
            
            $('div.flash').find('object').each(function(){
            
                try {
                    //function inside flash
                    this.setModuleHeight(moduleHeight);
                } 
                catch (e) {
                    //could not connect to flash movie (maybe not loaded jet)
                    //return false;
                }
                
            });
            
            var contentHeight = moduleHeight + footerHeight;
            
            BMSEVENTS.flash.positionTeaser(contentHeight);
            
        },
        
        //change teaser position for pv 
        positionTeaser: function(posY){
        
            $('#content').css({
                minHeight: posY + 'px'
            });
            
            if ($('#innerContent').length !== 0) {
            
                $('#innerContent').css({
                    height: posY + 'px'
                });
                
            }
            
            BMSEVENTS.flash.setHeight();
            
            if ($('#footer .teaser').length !== 0) {
            
                $('#footer .teaser').css({
                    visibility: 'visible'
                });
                
            }
            
        },
        
        //update size of flash movie (after resize)
        updateSize: function(){
        
            var height = $('body').height();
            var width = $('#content').width();
            
            //external interface call to flash movies 
            $('div.flash').children('object').each(function(){
            
                try {
                    //function inside flash
                    this.setStageHeight(height);
                    this.setStageWidth(width);
                } 
                catch (e) {
                    //could not connect to flash movie (maybe not loaded jet)
                    //return false;
                }
                
            });
            
        },
        
        //sound button wurde geklickt
        soundClickEvent: function(){
        
            //external interface call to flash movies to fade in
            $('div.flash').children('object').each(function(){
            
                try {
                    //function inside flash
                    this.soundClickEvent();
                } 
                catch (e) {
                    //could not connect to flash movie (maybe not loaded jet)
                    //return false;
                }
                
            });
            
        },
        
        //set sound button on/off
        setSoundButton: function(state){
        
            switch (state) {
                case 'on':
                    $('#soundOff').css({
                        display: 'none'
                    });
                    $('#soundOn').css({
                        display: 'block'
                    });
                    break;
                case 'off':
                    $('#soundOff').css({
                        display: 'block'
                    });
                    $('#soundOn').css({
                        display: 'none'
                    });
                    break;
            }
            
        },
        
        
        hbTvPlayVideo: function(id){
        
            $('div.backgroundScroll').find('object').each(function(){
            
                try {
                    //function inside flash
                    this.playVideo(id);
                } 
                catch (e) {
                    //could not connect to flash movie (maybe not loaded jet)
                    //return false;
                }
                
            });
            
        },
        
        showVideoLayer: function(videoAlias){
        
            BMSEVENTS.flash.scrollToTop(200);
            
            setTimeout(function(){
            
                if ($('#videoLayer').length === 0) {
                
                    var videoLayer = '<div id="videoLayerBg"></div>';
                    videoLayer += '<div id="videoLayer" class="flash"><a href="#close" class="close">' + textContent.close + '</a><div id="videoLayerFlash"></div></div>';
                    
                    $('#outerWrapper').append(videoLayer);
                    
                    $('#videoLayerBg').css({
                        opacity: 0
                    }).animate({
                        opacity: 0.9
                    }, {
                        duration: 400,
                        complete: function(){
                        
                            var swfObjectData = {
                                source: '/assets/mainLoader.swf',
                                id: 'videoLayerFlash',
                                width: '765',
                                height: '432',
                                center: true,
                                flashvars: {
                                    stageWidth: '765',
                                    stageHeight: '432',
                                    moduleCSS: '/style/style.emag.hbTV.css',
                                    moduleXML: path + 'emag/hbTV/data/overlayPlayer.xml',
                                    layoutXML: '',
                                    videoAlias: videoAlias
                                },
                                params: {
                                    wmode: 'opaque',
                                    bgColor: '#000000',
                                    allowFullscreen: true
                                },
                                attributes: {
                                    id: 'videoLayerFlashSwf'
                                }
                            };
                            
                            BMSEVENTS.flash.initSwfObject(swfObjectData);
                            
                            $('#videoLayer').css({
                                display: 'block'
                            });
                            
                            $('#videoLayerBg').add('#videoLayer a.close').bind('click', function(){
                            
                                $('#videoLayer').add('#videoLayerBg').css({
                                    display: 'none'
                                });
                                
                                return false;
                                
                            });
                            
                            $('#videoLayer').bind('click', function(){
                            
                                return false;
                                
                            });
                            
                        }
                        
                    });
                    
                }
                else {
                
                    $('#videoLayerBg').css({
                        display: 'block',
                        opacity: 0
                    }).animate({
                        opacity: 0.9
                    }, {
                        duration: 400,
                        complete: function(){
                        
                            var swfObjectData = {
                                source: '/assets/mainLoader.swf',
                                id: 'videoLayerFlashSwf',
                                width: '765',
                                height: '432',
                                center: true,
                                flashvars: {
                                    stageWidth: '765',
                                    stageHeight: '432',
                                    moduleCSS: '/style/style.emag.hbTV.css',
                                    moduleXML: path + 'emag/hbTV/data/overlayPlayer.xml',
                                    layoutXML: '',
                                    videoAlias: videoAlias
                                },
                                params: {
                                    wmode: 'opaque',
                                    bgColor: '#000000',
                                    allowFullscreen: true
                                },
                                attributes: {
                                    id: 'videoLayerFlashSwf'
                                }
                            };
                            
                            BMSEVENTS.flash.initSwfObject(swfObjectData);
                            
                            $('#videoLayer').css({
                                display: 'block'
                            });
                            
                        }
                        
                    });
                    
                }
                
            }, 250);
            
        },
        
        showSoundButton: function(){
        
            $('#soundOff').add('#soundOn').css({
                visibility: 'visible'
            });
            
        },
		
		setTo100Percent: function(){
			
			if ($('#content').length !== 0) {
				
				$('#content').css({
					minHeight: '100%'
				});
				
			}
			
		},
        
        analytics: function(klickname, clicktype){
        
            var target = webtrekk.contentId + '.' + klickname;
            
            //wt_sendinfo(target, clicktype);
            
        },
        
        getTracksMenuHeight: function(){
        
            var height = $('#leftNav').height() + 100;
            
            return height;
            
        },
        
        getOffsetX: function(){
        
            var offsetX;
            
            if ($('#teaserFlashSwf').length !== 0) {
            
                offsetX = $('#teaserFlashSwf').offset().left;
                
            }
            else 
                if ($('#moduleFlashSwf').length !== 0) {
                
                    offsetX = $('#moduleFlashSwf').offset().left;
                    
                }
            
            if (offsetX !== 'undefined') {
            
                $('div.flash').find('object').each(function(){
                
                    try {
                        //function inside flash
                        this.setOffsetX(offsetX);
                    } 
                    catch (e) {
                        //could not connect to flash movie (maybe not loaded jet)
                        //return false;
                    }
                    
                });
                
            }
            
        },
        
        //force fade in if flash callback 'loaded' takes more than 8 seconds
        fadeInTimeout: function(){
        
            clearTimeout(BMSEVENTS.flash.timeout);
            
            BMSEVENTS.flash.timeout = window.setTimeout(function(){
            
                BMSEVENTS.flash.fadeIn();
                
            }, 8000);
            
        },
        
        //force page change if flash callback 'fadedOut' takes more than 4 seconds
        fadeOutTimeout: function(){
        
            clearTimeout(BMSEVENTS.flash.timeout);
            
            BMSEVENTS.flash.timeout = window.setTimeout(function(){
            
                BMSEVENTS.utils.changeLocation();
                
            }, 4000);
            
        },
        
        //external interface callback from flash if movie is ready (added to stage)
        ready: function(){
        
            //count flash movies, which are ready
            if (!BMSEVENTS.flash.readyCounter) {
                BMSEVENTS.flash.readyCounter = 1;
            }
            else {
                BMSEVENTS.flash.readyCounter += 1;
            }
            
            BMSEVENTS.flash.fadeInTimeout();
            
        },
        
        //external interface callback from flash if movie content is loaded and ready to fade in
        loaded: function(){
        
            //count flash movies, whose content is loaded
            if (!BMSEVENTS.flash.loadedCounter) {
                BMSEVENTS.flash.loadedCounter = 1;
            }
            else {
                BMSEVENTS.flash.loadedCounter += 1;
            }
            
            //init fade in if ready & loaded counters are the same
            if (BMSEVENTS.flash.readyCounter === BMSEVENTS.flash.loadedCounter) {
            
                BMSEVENTS.flash.fadeIn();
                
            }
        },
        
        //fade in flash content
        fadeIn: function(){
        
            clearTimeout(BMSEVENTS.flash.timeout);
            
            //external interface call to flash movies to fade in
            $('div.flash').children('object').each(function(){
            
                try {
                    //function inside flash
                    this.fadeIn();
                } 
                catch (e) {
                    //could not connect to flash movie (maybe not loaded jet)
                    //return false;
                }
                
            });
            
        },
        
        //fade out flash content
        fadeOut: function(){
        
            BMSEVENTS.flash.fadeOutTimeout();
            
            //external interface call to flash movies to fade out
            $('div.flash').children('object').each(function(){
            
                try {
                    //function inside flash
                    this.fadeOut();
                } 
                catch (e) {
                    //could not connect to flash movie (maybe not loaded jet)
                    //return false;
                }
                
            });
            
        },
        
        //external interface callback from flash if movie content is faded out
        fadedOut: function(){
        
            //count flash movies, which are faded out
            if (!BMSEVENTS.flash.fadedOutCounter) {
                BMSEVENTS.flash.fadedOutCounter = 1;
            }
            else {
                BMSEVENTS.flash.fadedOutCounter += 1;
            }
            
            //init change page if faded out and loaded counters are the same
            if (BMSEVENTS.flash.fadedOutCounter === BMSEVENTS.flash.loadedCounter) {
            
                clearTimeout(BMSEVENTS.flash.fadeOutTimeout);
                BMSEVENTS.utils.changeLocation();
                
            }
            
        }
        
    }

};


//initialize all
$(document).ready(function(){

    BMSEVENTS.init();
    
});

