var Strenesse = {
    init: function(){
    
        this.loadBackgroundImage('default');
        
        //Entfernen noScript Anzeige wg. Opera
        $("noscript").add("div.noscriptBg").add("div.noscriptContent").remove();
        
        // input boxes: product search and newsletter input, empty value onfocus
        // $('#product-search-sword').attr('title', $('#product-search-sword').val());
        $('#footer-nl-email').attr('title', $('#footer-nl-email').val());
        $('#product-search-sword, #footer-nl-email').focus(function(){
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }
        });
        /*$('#footer-nl-email').focus(function(){
         if ($(this).val() == $(this).attr('title')) {
         $(this).val('');
         }
         $('#product-search-sword').focus(function(){
         if ($(this).val() == 'Produktsuche' || $(this).val() == 'Product Search') {
         $(this).val('');
         }*/
        $('#product-search-sword, #footer-nl-email').blur(function(){
            if ($(this).val() == '') {
                $(this).val($(this).attr('title'));
            }
        });
        
        // Mouseover bei #menu:
        // Wenn Mauszeiger über dem Menücontainer sitzt und #menu-content eine Klasse
        // "pv-menu" hat, dann diese entfernen und bei Mouseout wieder reinschreiben. Ansonsten nix tun.
        if ($('#menu-content').hasClass('pv-menu')) {
            $('#menu').mouseenter(function(){
                $('#menu-content').removeClass('pv-menu')
            });
            $('#menu').mouseleave(function(){
                $('#menu-content').addClass('pv-menu')
            });
        }
        
        //Ausnahme für Kategorien, die nicht verlinkt sind
        $('a', $('#menu')).each(function(){
            var href = $(this).attr('href');
            var firstLetter = href.substring(0, 1);
            
            if (firstLetter === '#') {
            
                var endClassName = href.indexOf('?');
                var className = href.substring(1, endClassName);
                
                $(this).parent().addClass('subhead');
                $(this).parent().addClass(className);
            }
        });
        
        $('li.subhead a', $('#menu')).click(function(){
            return false;
        });
        
        // back to article link
        $('#link-back-to-article').live('click', function(){
            history.back();
        });
        
        // message popups
        $('.buttonlink-cancel').live('click', function(){
            Strenesse.closeMessageBox();
            return false;
        });
        if ($('.buttonlink-cancel:visible').length) {
            Strenesse.closeMessageBoxOutside();
        }
        
        // hide all the containers of the teasers
        if ($('#plinestart-teaser-container').length) {
            $('.product-teaser').children().hide();
            window.setTimeout(function(){
                Strenesse.slideProductTeaser();
            }, 1000);
        }
        
        
        // tease the text on the startpage
        if ($('#startpage-text').length) {
            window.setTimeout(function(){
                $('#startpage-text').fadeIn('slow').css({
                    display: 'block'
                });
            }, 500);
        }
        
        // float in the 3 teasers on the start page
        if ($('#startpage-teaser-container').length) {
            var teaserContainer = $('#startpage-teaser-container').children();
            var delay = 500;
            teaserContainer.each(function(){
                var container = $(this);
                container.css('height', container.height());
                container.hide();
                container.children().hide();
                window.setTimeout(function(){
                    Strenesse.slideStartpageTeaser(container);
                }, delay);
                delay = delay + 500;
            });
        }
        
        // make all teaser container completely clickable
        $('#stc-start .product-teaser, #ps-start .product-teaser').each(function(){
            $(this).css('cursor', 'pointer');
            var lnk = $(this).find('a').attr('href');
            $(this).click(function(){
                window.location.href = lnk;
                return false;
            });
        });
        
        // check if there is a navigation arrow
        /*
        if ($('#stc-navlayer-left').length) {
            $('.stc-navlayer-on').hide();
            $('.stc-navlayer-off').show();
            $('#stc-navlayer-left, #stc-navlayer-right').bind('mouseenter', function(){
                $(this).find('.stc-navlayer-on').show();
                $(this).find('.stc-navlayer-off').hide();
            });
            $('#stc-navlayer-left, #stc-navlayer-right').bind('mouseleave', function(){
                $(this).find('.stc-navlayer-on').hide();
                $(this).find('.stc-navlayer-off').show();
            });
        }
        */
        
        if ($('#details-row-pictures div.details-icon').length > 3) {
            var iconList = $('#details-row-pictures .iconlist');
            iconList.wrapInner('<div id="details-pictures-iconlist-inner"></div>');
            Strenesse.slidePictureIcons('start');
            $('#details-arrowLeft').click(function(){
                Strenesse.slidePictureIcons('left');
                return false;
            });
            $('#details-arrowRight').click(function(){
                Strenesse.slidePictureIcons('right');
                return false;
            });
        }
        
        if ($('#twitterOuter').length !== 0) {
            Strenesse.showTwitterFeed();
        }
        
    },
    
    slidePictureIcons: function(direction){
        var posLeft = parseInt($('#details-pictures-iconlist-inner').css('marginLeft'));
        var itemWidth = parseInt($('#details-pictures-iconlist-inner div.details-icon:first').outerWidth());
        var totalWidth = $('#details-pictures-iconlist-inner div.details-icon').length * itemWidth;
        $('#details-pictures-iconlist-inner').width(totalWidth);
        switch (direction) {
            case 'start':
                $('#details-pictures-iconlist-inner').css('marginLeft', '0px');
                $('#details-arrowRight').addClass('details-arrowRightOn');
                $('#details-arrowRight').removeClass('details-arrowRightOff');
                break;
            // allow slideLeft as long as the first item is not visible yet
            case 'left':
                if (posLeft < 0) {
                    $('#details-arrowLeft').unbind('click');
                    $('#details-pictures-iconlist-inner').animate({
                        'marginLeft': (posLeft + itemWidth) + 'px'
                    }, 'fast', function(){
                        $('#details-arrowLeft').click(function(){
                            Strenesse.slidePictureIcons('left');
                            return false;
                        });
                    });
                    $('#details-pictures-iconlist-inner').animate({
                        'marginLeft': (posLeft + itemWidth) + 'px'
                    }, 'fast');
                    $('#details-arrowRight').addClass('details-arrowRightOn');
                    $('#details-arrowRight').removeClass('details-arrowRightOff');
                    posLeft += itemWidth;
                }
                if (posLeft >= 0) {
                    $('#details-arrowLeft').addClass('details-arrowLeftOff');
                    $('#details-arrowLeft').removeClass('details-arrowLeftOn');
                }
                break;
            // allow slideRight as long as the last item is not visible yet
            case 'right':
                var totalWidth = ($('#details-pictures-iconlist-inner div.details-icon').length - 3) * itemWidth;
                if (Math.abs(posLeft) <= (totalWidth - itemWidth)) {
                    $('#details-arrowRight').unbind('click');
                    $('#details-pictures-iconlist-inner').animate({
                        'marginLeft': (posLeft - itemWidth) + 'px'
                    }, 'fast', function(){
                        $('#details-arrowRight').click(function(){
                            Strenesse.slidePictureIcons('right');
                            return false;
                        });
                    });
                    $('#details-pictures-iconlist-inner').animate({
                        'marginLeft': (posLeft - itemWidth) + 'px'
                    }, 'fast');
                    $('#details-arrowLeft').addClass('details-arrowLeftOn');
                    $('#details-arrowLeft').removeClass('details-arrowLeftOff');
                    posLeft -= itemWidth;
                }
                if (Math.abs(posLeft) > (totalWidth - itemWidth)) {
                    $('#details-arrowRight').addClass('details-arrowRightOff');
                    $('#details-arrowRight').removeClass('details-arrowRightOn');
                }
                break;
        }
    },
    
    rotate360: function(direction){
        document.getElementById('flash-element').rotateFlash360(direction);
        //$("#flash-element").rotateFlash360(direction);
    
    },
    
    slideStartpageTeaser: function(teaserContainer){
        var container = $(teaserContainer);
        var endWidth = container.width();
        container.width('0px');
        container.show();
        container.animate({
            'width': endWidth
        }, {
            'duration': 'slow',
            'queue': false,
            'complete': function(){
                container.children().fadeIn();
                Strenesse.rotateStartpageTeaserItems(container, 1);
            }
        });
        container.mouseenter(function(){
            container.addClass('startpage-teaser-mouseover');
            Strenesse.stopProgress(container.find('.product-teaser-progressbar'));
        });
        container.mouseleave(function(){
            container.removeClass('startpage-teaser-mouseover');
            var current = Strenesse.getCurrentActiveStartpageTeaserItem(container);
            Strenesse.rotateStartpageTeaserItems(container, current, true);
        });
        container.find('a.product-teaser-image-text-text a').click(function(){
            var pos = parseInt($(this).innerHTML);
            Strenesse.showStartpageTeaserItem(container, pos);
            return false;
        });
    },
    
    slideProductTeaser: function(){
        var teaserContainer = $('#plinestart-teaser-container').children(':first');
        var endWidth = teaserContainer.width();
        teaserContainer.width('0px');
        teaserContainer.show();
        
        teaserContainer.animate({
            'width': endWidth
        }, {
            'duration': 'slow',
            'queue': false,
            'complete': function(){
            
                var children = teaserContainer.children();
                // show the first image
                window.setTimeout(function(){
                    $(children.get(0)).fadeIn(200);
                }, 200);
                
                window.setTimeout(function(){
                    $(children.get(1)).fadeIn(200);
                    $(children.get(2)).fadeIn(200);
                }, 600);
                
                // show the first text
                window.setTimeout(function(){
                    $(children.get(3)).fadeIn(200);
                }, 1000);
                
                if ($("#teaser-image-2").length != 0) {
                    var length = teaserContainer.find('.plinestart-teaser-singleimage').length;
                    Strenesse.rotateProductTeaserItems(length, 1);
                }
                
            }
        });
        
        
        teaserContainer.mouseenter(function(){
            if ($("#teaser-image-2").length != 0) {
                Strenesse.stopProgress($('#plinestart-teaser-progressbar'));
            }
        });
        
        teaserContainer.mouseleave(function(){
            if ($("#teaser-image-2").length != 0) {
                var length = teaserContainer.find('.plinestart-teaser-singleimage').length;
                var current = Strenesse.getCurrentActiveProductTeaserItem();
                Strenesse.rotateProductTeaserItems(length, current, true);
            }
        });
        
        $('#plinestart-teaser-progressbarNext').click(function(){
            var currentActive = Strenesse.getCurrentActiveProductTeaserItem();
            var teaserLength = $('#plinestart-teaser-images').find('.plinestart-teaser-singleimage').length;
            var pos;
            if (currentActive === teaserLength) {
                pos = 1;
            }
            else {
                pos = currentActive + 1;
            }
            Strenesse.showProductTeaserItem(pos);
            return false;
        });
        
        $('#plinestart-teaser-progressbarPrev').click(function(){
            var currentActive = Strenesse.getCurrentActiveProductTeaserItem();
            var teaserLength = $('#plinestart-teaser-images').find('.plinestart-teaser-singleimage').length;
            var pos;
            if (currentActive === 1) {
                pos = teaserLength;
            }
            else {
                pos = currentActive - 1;
            }
            Strenesse.showProductTeaserItem(pos);
            return false;
        });
        
    },
    
    getCurrentActiveProductTeaserItem: function(){
        var activeLink = $('#plinestart-teaser-images').find('.active');
        var activeId = activeLink.attr('id');
        if (activeId) {
            activeId = activeId.substring(13);
            return parseInt(activeId);
        }
        else {
            return 0;
        }
    },
    
    showProductTeaserItem: function(nextActive){
        var currentActive = Strenesse.getCurrentActiveProductTeaserItem();
        if (currentActive != nextActive) {
            $('div[id*=teaser-image-]').fadeOut('fast').removeClass('active');
            $('div[id*=teaser-text-]').hide();
            $('#teaser-image-' + nextActive).fadeIn('fast').addClass('active');
            $('#teaser-text-' + nextActive).fadeIn('fast');
        }
    },
    
    rotateProductTeaserItems: function(totalItems, currentActive, resume){
    
        var callbackFn = function(){
            var nextActive = (currentActive < totalItems ? currentActive + 1 : 1);
            $('div[id*=teaser-image-]').fadeOut('fast').removeClass('active');
            $('div[id*=teaser-text-]').hide();
            $('#teaser-image-' + nextActive).fadeIn('fast').addClass('active');
            $('#teaser-text-' + nextActive).fadeIn('fast');
            Strenesse.rotateProductTeaserItems(totalItems, nextActive);
        };
        
        this.animateProgress($('#plinestart-teaser-progressbar'), 4000, callbackFn, resume);
    },
    
    getCurrentActiveStartpageTeaserItem: function(container){
        var activeLink = $(container.find('.product-teaser-image-text-text a.active'));
        var activeId = activeLink.attr('id');
        if (activeId) {
            activeId = activeId.substr(-1);
            return parseInt(activeId);
        }
        return false;
    },
    
    showStartpageTeaserItems: function(container, nextActive){
        var currentActive = Strenesse.getCurrentActiveStartpageTeaserItem(container);
        if (currentActive != nextActive) {
            if (currentActive) {
                $(container.find('.product-teaser-inner').get(currentActive - 1)).fadeOut('fast');
                $(container.find('.product-teaser-image-text-text a').get(currentActive - 1)).removeClass('active');
            }
            $(container.find('.product-teaser-inner').get(nextActive - 1)).fadeIn('fast');
            $(container.find('.product-teaser-image-text-text a').get(nextActive - 1)).addClass('active');
        }
    },
    
    rotateStartpageTeaserItems: function(container, currentActive, resume){
        var totalItems = container.find('.product-teaser-inner').length;
        var callbackFn = function(){
            var nextActive = (currentActive < totalItems ? currentActive + 1 : 1);
            $(container.find('.product-teaser-inner').get(currentActive - 1)).fadeOut('fast');
            $(container.find('.product-teaser-image-text-text a').get(currentActive - 1)).removeClass('active');
            $(container.find('.product-teaser-inner').get(nextActive - 1)).fadeIn('fast');
            $(container.find('.product-teaser-image-text-text a').get(nextActive - 1)).addClass('active');
            Strenesse.rotateStartpageTeaserItems(container, nextActive);
        };
        this.animateProgress(container.find('.product-teaser-progressbar'), 4000, callbackFn, resume);
    },
    
    animateProgress: function(outercontainer, duration, callbackCompleteFn, resume){
    
        var innercontainer = outercontainer.children(':first');
        
        if (!resume) {
            innercontainer.width('0px');
        }
        else {
            var currentPercentage = parseInt(innercontainer.width()) / parseInt(outercontainer.width());
            var currentDuration = (currentPercentage * duration);
            duration = duration - currentDuration;
        }
        
        innercontainer.animate({
            'width': '195px'
        }, {
            'easing': 'linear',
            'complete': callbackCompleteFn,
            'duration': duration
        });
    },
    
    stopProgress: function(outercontainer){
    
        var innercontainer = outercontainer.children(':first');
        innercontainer.stop();
    },
    
    // functions to exchange the background image
    loadBackgroundImage: function(key, completeFn){
    
        if (Strenesse.Images) {
            var keys = $('#content-area-container').data('lastBackgrounds') || new Array();
            if (key == 'last') {
                key = $(keys).get(keys.length - 2);
            }
            
            var imgDetails = Strenesse.Images[key];
            
            if (imgDetails) {
                this.stopCurrentBackgroundFlash();
                if (imgDetails.src.indexOf('.swf') != -1) {
                    this.loadBackgroundFlash(key, completeFn);
                }
                else {
                    $('#content-area-container').height('auto');
                    if (typeof completeFn == 'undefined') {
                        var completeFn = function(){
                        };
                    }
                    
                    if ($.inArray(key, keys) == -1) {
                        //$('#picture-placeholder').one('load', function(){ //not working in safari (2.load)
                        completeFn();
                        $('#content-area-container').css('background-image', 'url("' + imgDetails.src + '")');
                        $('#zoom-click-area').height($('#picture-placeholder').height() - 80);
                        //}); //not working in safari (2.load)
                    }
                    else {
                        // call the complete Function directly as it was already loaded once
                        completeFn();
                        $('#content-area-container').css('background-image', 'url("' + imgDetails.src + '")');
                    }
                    $('#picture-placeholder').attr('src', imgDetails.src);
                    // make an exception for the storefinder to don't care about the height of the BG image
                    if (imgDetails.src.indexOf('bg_stores.jpg') != -1) {
                        $('#picture-placeholder').hide();
                    }
                    else {
                        $('#picture-placeholder').show();
                    }
                    $('#zoom-click-area').height($('#picture-placeholder').height() - 80);
                }
                
                keys.push(key);
                $('#content-area-container').data('lastBackgrounds', keys);
            }
        }
    },
    
    flashElementId: 'flash-element',
    flashContainerId: 'flash-container',
    flashBackgroundRunning: false,
    loadBackgroundFlash: function(key, completeFn){
    
        // create the needed container around the content-area
        if (!$('#contentifflash-container').length) {
            if ($('#contentifflash-container-disabled').length) {
                $('#contentifflash-container-disabled').attr('id', 'contentifflash-container');
            }
            else {
                $('#content-area').wrap('<div id="contentifflash-container"></div>');
            }
            $(window).resize(this.centerBackgroundFlash);
        }
        
        // if the flash element was deleted before (because of "stopCurrentBackgroundFlash()"), we add it again
        if (!$('#' + this.flashContainerId).length) {
            $('#contentifflash-container').parent().prepend('<div id="' + this.flashContainerId + '"></div>');
        }
        
        // if the flash element was deleted before (because of "stopCurrentBackgroundFlash()"), we add it again
        if (!$('#' + this.flashElementId).length) {
            $('#' + this.flashContainerId).append('<div id="' + this.flashElementId + '"></div>');
        }
        
        
        var flashDetails = Strenesse.Images[key];
        var params = {
            'wmode': 'transparent',
            'allowFullScreen': true,
            'loop': false
        };
        var attributes = {
            'id': this.flashElementId,
            'name': this.flashElementId,
            'loop': false
        };
        var flashVars = {};
        
        flashVars.lang = strlang.toUpperCase();
        
        // Erkennung der Startseite anhand von Slideshow -> kein 360° Steuerung
        
        
        //Video-Files müssen IMMER ein "Slideshow" im Filename haben! (Großgeschrieben!)
        if (flashDetails.src.indexOf('Slideshow') != -1) {
            // flashVars.videoUrl = "/out/strenesse/src/Flash/video/video.flv";
        	swfobject.embedSWF(flashDetails.src, this.flashElementId, '1280', '800', '9.0.0', false, flashVars, params, attributes);
            $('#picture-container').css('display', 'none');
            //$('#flash-container').css('z-index', '1');
            if ($("div#flash-element").length > 0) {
          		if (strlang == "de") {
          			$("div#flash-element").html("<a href='/New-Arrivals-Women/' class='noFlashLink'><img src='/out/strenesse/src/Flash/img/01.jpg' /></a>");
          		}
          		else {
          			$("div#flash-element").html("<a href='/en/New-Arrivals-Women/' class='noFlashLink'><img src='/out/strenesse/src/Flash/img/01.jpg' /></a>");
          		}
          	}
        }
        else if (flashDetails.src.indexOf('WM-Buch') != -1) {
                // flashVars.videoUrl = "/out/strenesse/src/Flash/video/video.flv";
                // swfobject.embedSWF(flashDetails.src, this.flashElementId, '1280', '800', '9.0.0', false, flashVars, params, attributes);
                $('#contentifflash-container').css({
                    height: '80px'
                });
                swfobject.embedSWF('/out/strenesse/src/images/wm/buch/WM-Buch.swf', this.flashElementId, '1280', '800', '9.0.0', false, flashVars, params, attributes);
                $('#picture-container').css('display', 'none');
                
                //No Flash Fallback
                if ($("div#flash-element").length > 0) {
                    if (strlang == "de") {
                    //$("body").append("<div id='noFlash360'><a href='http://get.adobe.com/de/flashplayer/' target='_blank'><img src='/out/strenesse/src/images/get_adobe_flash_player.gif' /></a><br /><br />F&uuml;r ein optimales Shopping-Erlebnis <br />im Strenesse Online Shop ben&ouml;tigen <br />Sie den aktuellen Adobe Flash Player<br /><br /><a href='http://get.adobe.com/de/flashplayer/' target='_blank'>Download Adobe Flash Player</a></div>");
                    }
                    else {
                    //$("body").append("<div id='noFlash360'><a href='http://get.adobe.com/de/flashplayer/' target='_blank'><img src='/out/strenesse/src/images/get_adobe_flash_player.gif' /></a><br /><br />For an optimal shopping experience in the<br />Strenesse Online Shop you need<br />the current version of Adobe Flash Player<br /><br /><a href='http://get.adobe.com/en/flashplayer/' target='_blank'>Download Adobe Flash Player</a></div>");
                    }
                }
            }
            else {
            
                flashVars.basePath = "/out/strenesse/src/Flash/";
                flashVars.rotationSwf = flashDetails.src;
                
                              
                swfobject.embedSWF('/out/strenesse/src/Flash/Loader.swf', this.flashElementId, '1280', '800', '9.0.0', false, flashVars, params, attributes);
                //swfobject.embedSWF(flashDetails.src, this.flashElementId, '1280', '800', '9.0.0', false, flashVars, params, attributes);
                
                
                
                //No Flash 
                if ($("div#flash-element").length > 0) {
                	if (strlang == "de") {
                		$("body").append("<div id='noFlash360'><a href='http://get.adobe.com/de/flashplayer/' target='_blank'><img src='/out/strenesse/src/images/get_adobe_flash_player.gif' /></a><br /><br />F&uuml;r ein optimales Shopping-Erlebnis <br />im Strenesse Online Shop ben&ouml;tigen <br />Sie den aktuellen Adobe Flash Player<br /><br /><a href='http://get.adobe.com/de/flashplayer/' target='_blank'>Download Adobe Flash Player</a></div>");
                	}
                	else {
                		$("body").append("<div id='noFlash360'><a href='http://get.adobe.com/de/flashplayer/' target='_blank'><img src='/out/strenesse/src/images/get_adobe_flash_player.gif' /></a><br /><br />For an optimal shopping experience in the<br />Strenesse Online Shop you need<br />the current version of Adobe Flash Player<br /><br /><a href='http://get.adobe.com/en/flashplayer/' target='_blank'>Download Adobe Flash Player</a></div>");
                	}
                }
                
                
                // Flash verfügbar             
                else {
                
                    //360 Grad Rotation Flash Steuerung
                    if ($("#product-details").length !== 0) {
                    
                        var visMessage = false;
                        var mLength = $("#messages-inner").children("div").length;
                        
                        for (i = 0; i < mLength; i++) {
                            if ($("#messages-inner").children("div:eq(" + i + ")").css("display") === "block") {
                                visMessage = true;
                            }
                        }
                        
                        if (!visMessage) {
                            $("body").append("<div id='rotationSteuerung'><div class='arrLeft'></div><div class='arrRight'></div></div>")
                            
                            $("#rotationSteuerung div.arrLeft").bind("mousedown", function(e){
                                Strenesse.rotate360("links");
                                Strenesse.rotate360.stop = false;
                            }).bind("mouseup", function(e){
                                if (!Strenesse.rotate360.stop) {
                                    Strenesse.rotate360("stop");
                                    Strenesse.rotate360.stop = true;
                                }
                            }).bind("mouseleave", function(e){
                                if (!Strenesse.rotate360.stop) {
                                    Strenesse.rotate360("stop");
                                    Strenesse.rotate360.stop = true;
                                }
                                
                            });
                            
                            $("#rotationSteuerung div.arrRight").bind("mousedown", function(e){
                                Strenesse.rotate360("rechts");
                                Strenesse.rotate360.stop = false;
                            }).bind("mouseup", function(e){
                                if (!Strenesse.rotate360.stop) {
                                    Strenesse.rotate360("stop");
                                    Strenesse.rotate360.stop = true;
                                }
                            }).bind("mouseleave", function(e){
                                if (!Strenesse.rotate360.stop) {
                                    Strenesse.rotate360("stop");
                                    Strenesse.rotate360.stop = true;
                                }
                            });
                        }
                    }
                }
            }
        //swfobject.embedSWF(flashDetails.src, this.flashElementId, '1280', '800', '9.0.0', false, flashVars, params, attributes);
        this.flashBackgroundRunning = true;
        if (typeof completeFn == 'function') {
            completeFn();
        }
        $('#content-area-container').height('800px');
        $('#zoom-click-area').height('880px');
        // center it
        this.centerBackgroundFlash();
    },
    
    centerBackgroundFlash: function(){
        var leftPos = Math.round(($(window).width() - 1280) / 2);
        if (leftPos < 0) {
            leftPos = 0;
        }
        
        var conWidth = $(window).width() - (2 * leftPos);
        
        //$('#flash-container').css('left', leftPos);
        $('#flash-container').css({
            left: leftPos,
            width: conWidth,
            overflowX: "hidden"
        });
    },
    
    stopCurrentBackgroundFlash: function(){
        if (this.flashBackgroundRunning && $('#' + this.flashElementId).length) {
            swfobject.removeSWF(this.flashElementId);
            $("#rotationSteuerung").add("#noFlash360").remove();
            $('#' + this.flashContainerId).empty();
            $('#contentifflash-container').attr('id', 'contentifflash-container-disabled');
            this.flashBackgroundRunning = false;
        }
    },
    
    isMessageBoxOpen: function(){
        var messageBox = false;
        $('.message-popup').each(function(){
            if ($(this).css('display') == 'block') {
                messageBox = $(this);
                return false;
            }
        });
        return messageBox;
    },
    
    displayMessageBox: function(messageBoxId){
    
        Strenesse.closeMessageBox();
        
        $("#rotationSteuerung").css({
            display: "none"
        });
        
        $("#noFlash360").remove();
        
        var box = $('#' + messageBoxId);
        // calculate the vertical alignment to center it
        
        var windowHeight = $(window).height();
        var windowScroll = $(window).scrollTop();
        var boxHeight = box.height();
        var topPos;
        if (box.attr('id') === 'message-product-careinfo') {
            if (boxHeight > 600) {
                topPos = 26;
            }
            else {
                topPos = 90;
            }
        }
        else {
            if ($('#content-area-container').height() < windowScroll + Math.round((windowHeight - boxHeight) / 2) + boxHeight + 15) {
                topPos = $('#content-area-container').height() - boxHeight - 15;
            }
            else {
                topPos = windowScroll + Math.round((windowHeight - boxHeight) / 2);
            }
        }
        
        box.css({
            'position': 'absolute',
            'top': topPos
        });
        box.fadeIn();
        Strenesse.Products.closeZoom();
        $('#zoom-click-area').hide();
        Strenesse.closeMessageBoxOutside();
    },
    
    closeMessageBoxOutside: function(){
        $('#zoom-click-area').hide();
        $('.message-popup').bind('click', function(evt){
            if (!$(evt.target).hasClass('buttonlink-cancel')) {
                evt.stopImmediatePropagation();
            }
        });
        $('body').bind('click', function(evt){
            Strenesse.closeMessageBox();
        });
    },
    
    closeMessageBox: function(){
        $("#rotationSteuerung").css({
            display: "block"
        });
        
        $("#noFlash360").remove();
        
        $('.message-popup').hide();
        if (Strenesse.Products.isZoomAvailable()) {
            $('#zoom-click-area').show();
        }
        $('body').unbind('click');
        $('.message-popup').unbind('click');
    },
    
    showTwitterFeed: function(){
    
        $(".twitter", $('#twitterOuter')).tweet();
    },
    
    basketShowDelivery: function(){
    
        $('.cartview-singleitem').css({
            height: 'auto',
            overflow: 'hidden',
            display: 'block'
        }).animate({
            height: '0px'
        }, {
            duration: 150,
            complete: function(){
                $('.cartview-singleitem').css({
                    display: 'none'
                });
            }
        });
        
        $('#basket_availability').css({
            height: '0px',
            overflow: 'hidden',
            display: 'block'
        }).animate({
            height: '265px'
        }, {
            duration: 150,
            complete: function(){
                $('#basket_availability').css({
                    height: 'auto',
                    overflow: 'visible'
                });
            }
        });
        
    },
    
    basketHideDelivery: function(){
    
        $('.cartview-singleitem').css({
            height: '0px',
            overflow: 'hidden',
            display: 'block'
        }).animate({
            height: '108px'
        }, {
            duration: 150,
            complete: function(){
                $('.cartview-singleitem').css({
                    height: 'auto',
                    overflow: 'visible'
                });
            }
        });
        
        $('#basket_availability').css({
            height: 'auto',
            overflow: 'hidden',
            display: 'block'
        }).animate({
            height: '0px'
        }, {
            duration: 150,
            complete: function(){
                $('#basket_availability').css({
                    display: 'none'
                });
            }
        });
        
    }
    
};

Strenesse.Flash = {
    initSwfObject: function(data){
    
        if (!data.version) {
            data.version = '9.0.0';
        }
        
        if (swfobject.hasFlashPlayerVersion(data.version)) {
        
            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.expressInstall) {
                data.expressInstall = false;
            }
            
            if (!data.flashvars) {
                data.flashvars = {};
            }
            
            if (!data.params) {
                data.params = {
                    wmode: 'opaque',
                    allowScriptAccess: 'always',
                    menu: false
                };
            }
            else {
                if (!data.params.wmode) {
                    data.params.wmode = '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;
            }
            
            $('#' + data.id).append('<div id="' + data.attributes.id + '"></div>');
            if ($('#' + data.id).length !== 0) {
                swfobject.embedSWF(data.source, data.attributes.id, data.width, data.height, data.version, data.expressInstall, data.flashvars, data.params, data.attributes);
            }
            //TODO: mac ff flashplayer bug
            if ($.os.mac && $.browser.mozilla) {
                swfobject.createCSS('#' + data.attributes.id, 'margin-top:-1px; margin-left:-1px;', null, true);
                
            }
            
        }
        else {
        
            if (!data.alternativeContent) {
            
                Strenesse.Flash.showError(data);
                
            }
            else {
            
                Strenesse.Flash.showAlternativeContent(data);
                
            }
            
        }
        
    },
    
    showError: function(data){
    
        if (strlang == "de") {
            $('#' + data.id).append("<div class='noFlash'><a href='http://get.adobe.com/de/flashplayer/' target='_blank'><img src='/out/strenesse/src/images/get_adobe_flash_player.gif' /></a><br /><br />F&uuml;r ein optimales Shopping-Erlebnis <br />im Strenesse Online Shop ben&ouml;tigen <br />Sie den aktuellen Adobe Flash Player<br /><br /><a href='http://get.adobe.com/de/flashplayer/' target='_blank'>Download Adobe Flash Player</a></div>");
        }
        else {
            $('#' + data.id).append("<div class='noFlash'><a href='http://get.adobe.com/de/flashplayer/' target='_blank'><img src='/out/strenesse/src/images/get_adobe_flash_player.gif' /></a><br /><br />For an optimal shopping experience in the<br />Strenesse Online Shop you need<br />the current version of Adobe Flash Player<br /><br /><a href='http://get.adobe.com/en/flashplayer/' target='_blank'>Download Adobe Flash Player</a></div>");
        }
        
    },
    
    showAlternativeContent: function(data){
    
        var content = '<img src="' + data.alternativeContent + '" width="' + data.width + '" height="' + data.height + '" />';
        
        $('#' + data.id).append(content);
        
    }
};


Strenesse.Forms = {
    init: function(){
    
        // Service Language Selection
        $('#service-language-selection .language-selection-col2').css('display', 'none');
        $('#service-language-selection .language-selection-col a').live('click', function(){
            $(this).parents('.language-selection-col').find('.active').each(function(){
                $(this).removeClass('active');
            });
            $(this).addClass('active');
            $('#service-language-selection .language-selection-col2').css('display', 'block');
            return false;
        });
        
        
        // Mallstart Language Selection
        $('#splash-language-selection .col-2').css('display', 'none');
        $('#splash-language-selection .col-1 a').live('click', function(){
            $(this).parents('.col-1').find('.active').each(function(){
                $(this).removeClass('active');
            });
            $(this).addClass('active');
            $('#splash-language-selection .col-2').css('display', 'block');
            return false;
        });
        
        if (!navigator.userAgent.match(/iPad/i)) {
            // radio boxes
            $('.div-input-checkbox-radio').live('click', function(){
                Strenesse.Forms.selectRadiobox($(this));
                return false;
            });
            
            // checkboxes
            $('.div-input-checkbox-checkbox').live('click', function(){
                Strenesse.Forms.selectCheckbox($(this));
                return false;
            });
        }
        else {
        
            $('.form-row-checkbox .div-input-checkbox-checkbox').add('.form-row-checkbox .div-input-checkbox-checked').add('.form-row-checkbox .div-input-checkbox-radio').add('.form-row-checkbox .div-input-radio-selected').css({
                background: 'none',
                overflow: 'visible',
                height: '17px',
                width: '17px'
            });
            
            $('.form-row-checkbox input').css({
                visibility: 'visible',
                width: '17px',
                height: '17px'
            });
            
            $('#account-newsletter-subscription .div-input-checkbox-text').css({
                marginLeft: '5px',
                marginTop: '6px'
            });
            
        }
        
        // Basket & Checkout
        $('input#shipping-address').parent().parent().click(function(){
            $('input#shipping-address').attr('checked', true);
            document.order.submit();
        });
        
        // Contact
        $('#service-contact-submitbutton .buttonlink').live('click', function(){
            /*
             if ($('#firstname').val() == "" ||
             $('#name').val() == "" ||
             $('#email').val() == "" ||
             $('#subject').val() == "" ||
             $('#contact-message').val() == "") {
             $('.error').css('visibility', 'visible');
             return false;
             }
             else {
             */
            $('#form-service-contact').submit();
            // }
        });
        
        // Newsletter
        $('#account-newsletter-subscription .buttonlink').live('click', function(){
            if ($('#subscribenl-email').val() == "") {
                $('.error').css('visibility', 'visible');
                return false;
            }
            else {
                $('#form-nlsubscribe').submit();
            }
        });
        
        if ($('input#shipping-address').attr('name') == 'blhideshipaddress') {
            $('input#shipping-address').parent('.div-input-checkbox-checkbox').addClass('div-input-checkbox-checked');
        }
        if ($('input#confirm-legal:checked').length) {
            $('input#confirm-legal').parent('.div-input-checkbox-checkbox').addClass('div-input-checkbox-checked');
        }
        if ($('input.radios-payment:checked').length) {
            $('input.radios-payment:checked').parent('.div-input-checkbox-radio').addClass('div-input-radio-selected');
        }
        if ($('input.radios-shipping:checked').length) {
            $('input.radios-shipping:checked').parent('.div-input-checkbox-radio').addClass('div-input-radio-selected');
        }
        
        // gift wrap items
        $('.giftwrapview-singleitem .div-input-checkbox-radio').click(function(){
            if ($(this).attr('id').indexOf('-off') != -1) {
                $(this).parents('.left:first').next('.right').find('.price').hide();
                $(this).parents('.left:first').next('.right').find('.price-zero').fadeIn();
            }
            else {
                $(this).parents('.left:first').next('.right').find('.price-zero').hide();
                $(this).parents('.left:first').next('.right').find('.price').fadeIn();
            }
        });
        $('.giftwrapview-singleitem').each(function(){
            if ($(this).find('input:checked:first').attr('id').indexOf('-on') > 0) {
                $(this).find('.price-zero').hide();
                $(this).find('.price').fadeIn();
            }
        });
        
        // gift card items
        $('.giftcard-col').click(function(){
            var cls = $(this).attr('class');
            var pos = cls.substr(cls.length - 2);
            if (pos == '-1') {
                $('#giftwrap-cardcontainer').find('.price').hide();
                $('#giftwrap-cardcontainer').find('.price-zero').fadeIn();
            }
            else {
                $('#giftwrap-cardcontainer').find('.price-zero, .price').hide();
                $('#giftwrap-cardcontainer').find('.price' + pos).fadeIn();
            }
            var radioBoxEl = $(this).find('.div-input-checkbox-radio');
            if (radioBoxEl) {
                Strenesse.Forms.selectRadiobox(radioBoxEl);
            }
            return false;
        });
        $('#giftwrap-cardcontainer input:checked').each(function(){
            $('#giftwrap-cardcontainer').find('.price-zero, .price').hide();
            var cls = $(this).parents('.giftcard-col:first').attr('class');
            var pos = cls.substr(cls.length - 2);
            if (pos == '-1') {
                $('#giftwrap-cardcontainer').find('.price').hide();
                $('#giftwrap-cardcontainer').find('.price-zero').fadeIn();
            }
            else {
                $('#giftwrap-cardcontainer').find('.price-zero, .price').hide();
                $('#giftwrap-cardcontainer').find('.price' + pos).fadeIn();
            }
            var radioBoxEl = $(this).parent('.div-input-checkbox-radio');
            if (radioBoxEl) {
                Strenesse.Forms.selectRadiobox(radioBoxEl);
            }
        });
        
        // giftcertificate input
        $('input#giftcertificate').focus(function(){
            var formRow = $(this).parents('.left:first');
            if (formRow.hasClass('form-row-error')) {
                formRow.addClass('form-row-focus-error');
            }
            else {
                formRow.addClass('form-row-focus');
            }
            $('input#giftcertificate-submitbutton').css('visibility', 'hidden');
        });
        $('input#giftcertificate').blur(function(){
            var formRow = $(this).parents('.left:first');
            formRow.removeClass('form-row-focus-error');
            formRow.removeClass('form-row-focus');
            $('input#giftcertificate-submitbutton').css('visibility', 'visible');
        });
    },
    
    selectCheckbox: function(checkBoxDiv){
        var isSelected = (checkBoxDiv.attr('class').indexOf('div-input-checkbox-checked') != -1);
        var checkBox = checkBoxDiv.find('input:checkbox');
        if (!isSelected) {
            checkBoxDiv.addClass('div-input-checkbox-checked');
            checkBox.attr('checked', true);
        }
        else {
            checkBoxDiv.removeClass('div-input-checkbox-checked');
            checkBox.attr('checked', false);
        }
    },
    
    selectRadiobox: function(radioel){
        var isSelected = (radioel.attr('class').indexOf('div-input-radio-selected') != -1);
        if (!isSelected) {
            var counterPart = radioel.attr('id');
            if (counterPart.indexOf('-off') != '-1') {
                counterPart = counterPart.substr(0, counterPart.length - 3) + 'on';
                counterPart = $('#' + counterPart);
            }
            else 
                if (counterPart.indexOf('-on') != '-1') {
                    counterPart = counterPart.substr(0, counterPart.length - 2) + 'off';
                    counterPart = $('#' + counterPart);
                }
                else {
                    var radioGroup = radioel.find('input').attr('name');
                    counterPart = $('input[name=' + radioGroup + ']').parents('.div-input-checkbox-radio');
                }
            counterPart.removeClass('div-input-radio-selected');
            counterPart.find('input').attr('checked', false);
            radioel.addClass('div-input-radio-selected');
        }
        radioel.find('input').attr('checked', true);
    }
};

Strenesse.Products = {
    init: function(){
    
        // used for now to hide all items by default
        //$('.productlist-item-mouseover').removeClass('productlist-item-mouseover');
        
        // Productoverview: mouseover bei .productlist-item: .productlist-item-inner mit zusätzlicher Klasse
        // .productlist-item-mouseover versehen; bei MouseOut Klasse wieder entfernen (blendet Farbauswahl und Favoriten-Stern-Sachen ein und aus)
        // show the details of a product when hovering
        /*
         $('.productlist-item').mouseenter(function(){
         $(this).addClass('productlist-item-mouseover');
         });
         $('.productlist-item').mouseleave(function(){
         $(this).removeClass('productlist-item-mouseover');
         });
         */
        $('.productlist-item').each(function(){
            var productItem = $(this);
            var productId = productItem.attr('id');
            
            // add handlers to modify the "colors"
            productItem.find('.productlist-singleicon').mouseenter(function(){
                var imageId = $(this).attr('id');
                if (imageId) {
                    imageId = imageId.substring(0, imageId.length - 5);
                    productItem.find('.productlist-item-singleimage').hide();
                    $('#' + imageId).show();
                    
                    productItem.find('.active').removeClass('active');
                    $(this).find('.productlist-singleicon-link').children(':first').addClass('active');
                }
            });
            
            // add handlers to make the whole black box on the bottom clickable
            var lnk = productItem.find('a:first');
            var detailBox = productItem.find('.productlist-item-details');
            detailBox.click(function(){
                window.location.href = lnk.attr('href');
            });
            detailBox.css('cursor', 'pointer');
        });
        
        if ($('#productlist-reset-selection').length > 0) {
            var selTest = 0;
            $('select :selected').each(function(i, selected){
                if ($(selected).val() && $(selected).val() != 'none' && $(selected).val() != 'asc' && $(selected).val() != 'desc') {
                    selTest = 1;
                }
            });
            if (selTest == 0) {
                $('#productlist-reset-selection').css('display', 'none');
            }
        }
        
        $('#productlist-reset-selection').click(function(){
            $('#_filterlist').find('select').each(function(i, el){
                $(this).find('option:first').attr('selected', 'selected').parent('select');
            });
            $('#_filterlist').submit();
        });
        
        // PRODUCT DETAILS
        
        // reload the page when a different size is selected
        $('select#size').change(function(){
            location.href = $(this).val();
        });
        
        // Smooth-Scrolling with Complete-the-Look
        $('.pd-link-completethelook').click(function(){
            Strenesse.Products.scrollTo('completethelook-area');
            return false;
        });
        
        $('#pd-link-tocart').click(function(){
            Strenesse.displayMessageBox('message-confirm-tocart');
            var url = $('#form-product-details').attr('action');
            var data = $('#form-product-details').serializeArray();
            $.post(url, data, function(xhr){
                // get the updated basket info from the 301 redirect / HTML response
                var res = xhr.substr(xhr.indexOf('id="menu-cart-link"') + 20, 100);
                res = res.substr(0, res.indexOf('</a>'));
                $('#menu-cart-link').empty().append(res);
            }, 'html');
            return false;
        });
        
        $('#pd-link-tocart-not-possible').click(function(){
            Strenesse.displayMessageBox('message-confirm-tocart-failed');
            return false;
        });
        
        $('#pd-link-careinfo').click(function(){
            Strenesse.displayMessageBox('message-product-careinfo');
            return false;
        });
        
        $('#pd-link-availability').click(function(){
            Strenesse.displayMessageBox('message-availability');
            return false;
        });
        
        $('#pd-link-infotext').click(function(){
            Strenesse.displayMessageBox('message-product-infotext');
            return false;
        });
        
        $('.pd-link-tipafriend').click(function(){
        	Strenesse.displayMessageBox('message-form-tipafriend');
            return false;
        });
        
        $('.pd-link-reorder').click(function(){
            Strenesse.displayMessageBox('message-form-reorder');
            return false;
        });
        
        $('#pd-link-notification').click(function(){
            Strenesse.displayMessageBox('message-form-notification');
            return false;
        });
        
        $('.wkb-availability-popup').click(function(){
            Strenesse.basketShowDelivery();
            return false;
        });
        
        $('#basket_availability .arrowBack').click(function(){
            Strenesse.basketHideDelivery();
            return false;
        });
        
        $('#form-tipafriend-submit').click(function(){
            var formFilled = true;
            $('#tipafriend-senderemail, #tipafriend-receiveremail').each(function(){
                var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                var address = $(this).val();
                if (reg.test(address) == false) {
                    formFilled = false;
                    $(this).parents('.form-row').addClass('form-row-error');
                }
                else {
                    $(this).parents('.form-row').removeClass('form-row-error');
                }
            });
            $('#tipafriend-sendername, #tipafriend-receivername').each(function(){
                if (!$(this).val().length) {
                    $(this).parents('.form-row').addClass('form-row-error');
                    formFilled = false;
                }
                else {
                    $(this).parents('.form-row').removeClass('form-row-error');
                }
            });
            if (!formFilled) {
                $('#form-tipafriend').find('.error').show();
                return false;
            }
            else {
                $('#form-tipafriend').find('.error').hide();
                var url = $('#form-tipafriend').attr('action');
                var data = $('#form-tipafriend').serializeArray();
                $.post(url, data, function(xhr){
                    Strenesse.displayMessageBox('message-confirm-tipafriend');
                }, 'html');
                $('#message-form-tipafriend').hide();
            }
        });
        
        $('#form-reorder-submit').click(function(){
            //$('#form-reorder').submit();
            
            var formFilled = true;
            $('#reorder-email').each(function(){
                var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                var address = $(this).val();
                if (reg.test(address) == false) {
                    formFilled = false;
                    $(this).parents('.form-row').addClass('form-row-error');
                }
                else {
                    $(this).parents('.form-row').removeClass('form-row-error');
                }
            });
            if (!formFilled) {
                $('#form-reorder').find('.error').show();
                return false;
            }
            else {
                $('#form-reorder').find('.error').hide();
                var url = $('#form-reorder').attr('action');
                var data = $('#form-reorder').serializeArray();
                $.post(url, data, function(xhr){
                    Strenesse.displayMessageBox('message-confirm-reorder');
                }, 'html');
                $('#message-form-reorder').hide();
            }
            
        });
        
        $('#form-notification-submit').click(function(){
            var formFilled = true;
            $('#notification-email').each(function(){
                var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                var address = $(this).val();
                if (reg.test(address) == false) {
                    formFilled = false;
                    $(this).parents('.form-row').addClass('form-row-error');
                }
                else {
                    $(this).parents('.form-row').removeClass('form-row-error');
                }
            });
            if (!formFilled) {
                $('#form-notification').find('.error').show();
                return false;
            }
            else {
                $('#form-notification').find('.error').hide();
                var url = $('#form-notification').attr('action');
                var data = $('#form-notification').serializeArray();
                $.post(url, data, function(xhr){
                    Strenesse.displayMessageBox('message-confirm-notification');
                }, 'html');
                $('#message-form-notification').hide();
            }
            
        });
        
        //Bei Klick bei den Farbteilen und bei den Ansichten, jeweils das gesamte BG-Image austauschen. Zu ladende Bilder sollten vorher auch schon in #picture-container geladen und ausgeblendet werden, damit die Höhe angepasst werden kann. Zu Testzwecken sind da verschiedene Hintergrundbilder drin im Produktdetails-Page-Template.
        //Bei Klick dann auf .details-icon-link a die Klasse active setzen, damit der Pfeil am Rand eingeblendet wird.
        $('#details-row-pictures .details-icon').click(function(){
            var iconId = $(this).attr('id');
            
            if (iconId) {
            
                if (iconId.substr(iconId.length - 2) === '01') {
                
                    $('#product-reorder-button').css({
                        display: 'block'
                    });
                    
                }
                else {
                
                    $('#product-reorder-button').css({
                        display: 'none'
                    });
                    
                }
                
                var imageId = 'detail-' + iconId.substr(iconId.length - 2);
                $(this).find('.details-icon-link').children(':first').addClass('loading');
                if (Strenesse.Products.isZoomOpen() && Strenesse.Products.hasZoomImage(imageId)) {
                    var zoomId = 'zoom-' + iconId.substr(iconId.length - 2);
                    var keys = $('#content-area-container').data('lastBackgrounds') || new Array();
                    keys.push(imageId);
                    $('#content-area-container').data('lastBackgrounds', keys);
                    Strenesse.loadBackgroundImage(zoomId, function(){
                        var detailEl = $('#' + iconId);
                        detailEl.parent().find('a.active').removeClass('active');
                        detailEl.parent().find('a.loading').removeClass('loading');
                        detailEl.find('.details-icon-link').children(':first').addClass('active');
                    });
                }
                else {
                    Strenesse.Products.closeZoom();
                    Strenesse.loadBackgroundImage(imageId, function(){
                        var detailEl = $('#' + iconId);
                        detailEl.parent().find('a.active').removeClass('active');
                        detailEl.parent().find('a.loading').removeClass('loading');
                        detailEl.find('.details-icon-link').children(':first').addClass('active');
                    });
                    if (Strenesse.Products.hasZoomImage(imageId)) {
                        Strenesse.Products.enableZoomPossibility();
                    }
                    else {
                        Strenesse.Products.disableZoomPossibility();
                    }
                }
            }
            return false;
        });
        
        if (Strenesse.Products.hasZoomImage('default')) {
            Strenesse.Products.enableZoomPossibility();
        }
        else {
            Strenesse.Products.disableZoomPossibility();
        }
        
        Strenesse.Products.initZoomCursor();
        Strenesse.Products.initOrderCursor();
        Strenesse.Products.initColorCursor();
        Strenesse.Products.initSoldoutCursor();
        
    },
    
    scrollTo: function(area){
        $('body').scrollTo($('#' + area), {
            axis: 'y',
            duration: 700,
            easing: 'swing'
        });
    },
    
    initZoomCursor: function(){
    
        if (Strenesse.Products.hasZoomImage('detail-01')) {
            Strenesse.Products.enableZoomPossibility();
        }
        else {
            Strenesse.Products.disableZoomPossibility();
        }
        
        // Klick auf Zoom-Ansicht öffnen (#link-open-zoom):
        if ($('#link-open-zoom').length) {
        
            $('#link-open-zoom').click(function(evt){
                Strenesse.Products.openZoom();
                evt.stopImmediatePropagation();
                return false;
            });
            $('#link-close-zoom, #close-zoom').click(function(evt){
                Strenesse.Products.closeZoom();
                evt.stopImmediatePropagation();
                return false;
            });
            
            
            // show the cursor icon to open
            /*layer for mouse-cursor-div to open/close zoom-view
             this layer should be visible only when mouse is over #content-area but not over #menu, #product-detail or #close-zoom
             #zoom-cursor contains open- and close-texts with different texts for open and close
             #zoom-cursor will be moved and turned on/off via JS
             */
            $('#zoom-click-area').mousemove(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.showZoomCursor(evt);
                }
            });
            $('#zoom-click-area').mouseleave(function(evt){
                Strenesse.Products.hideZoomCursor(evt);
            });
            $('#zoom-click-area').click(function(evt){
                if ($('#zoom-cursor').css('display') == 'block') {
                    if ($('#zoom-cursor-open').css('display') == 'block') {
                        Strenesse.Products.openZoom();
                    }
                    else 
                        if ($('#zoom-cursor-close').css('display') == 'block') {
                            Strenesse.Products.closeZoom();
                        }
                    return false;
                }
            });
            $('#menu, #product-details, #close-zoom, #logo, .message-popup').live('mousemove', function(evt){
                Strenesse.Products.hideZoomCursor();
                evt.stopImmediatePropagation();
                return false;
            });
        }
    },
    
    
    showZoomCursor: function(evt){
        if ($('#zoom-cursor').css('display') != 'block') {
            $('#zoom-cursor').fadeIn('fast');
            if (jQuery.browser.mozilla && navigator.userAgent.indexOf('Macintosh') != -1) {
                $('body').css('cursor', 'pointer');
                $('#zoom-cursor p').css('background-image', 'none');
            }
            else {
                $('body').css('cursor', 'url("/out/strenesse/src/css/img/zoom-plus.cur"), url("/out/strenesse/src/css/img/zoom-plus.cur"), pointer');
            }
        }
        
        var offsetX = ($('body').width() / 2) - 250;
        
        $('#zoom-cursor').css({
            'left': (evt.pageX + 12) - offsetX + 'px',
            'top': (evt.pageY + 12) + 'px'
        });
    },
    
    hideZoomCursor: function(){
        if ($('#zoom-cursor').css('display') == 'block') {
            $('#zoom-cursor').fadeOut('fast');
            $('body').css('cursor', 'default');
        }
    },
    
    /*
     *	set #menu to display:none;;
     *	set #close-zoom to display:block;
     *	change the image-placeholder in #picture-container to display:block; visibility:hidden for the productimage and to display:none; for the normal backgroundimage. This is to adjust the height of the page if necessary (e. g. much higher product-detail-image)
     *	change the background-image for #content-area-container to the productimage we want to see
     *	set #link-open-zoom to display:none; and #link-close-zoom to display:block;
     */
    openZoom: function(){
        $('#content-area-container').data('zoomIsOpen', true);
        $('#menu').hide();
        $('#close-zoom, #close-zoom-inner').show();
        if ($.browser.msie && parseInt($.browser.version) < 8) {
            $('#zoom-click-area').css({
                width: "750px",
                marginLeft: "-300px",
                marginTop: "50px"
            });
        }
        else {
            $('#zoom-click-area').css({
                width: "750px",
                marginLeft: "-50px",
                marginTop: "50px"
            });
        }
        
        var currentOpenedId = $('#content-area-container').data('lastBackgrounds');
        currentOpenedId = $(currentOpenedId).get(currentOpenedId.length - 1);
        if (currentOpenedId == 'default') {
            currentOpenedId = 'detail-01';
        }
        currentOpenedId = currentOpenedId.replace(/detail/, 'zoom');
        Strenesse.loadBackgroundImage(currentOpenedId);
        $('#link-open-zoom').hide();
        $('#link-close-zoom').show();
        $('#zoom-cursor-open').hide();
        $('#zoom-cursor-close').show();
        if (jQuery.browser.mozilla && navigator.userAgent.indexOf('mac') != -1) {
            $('body').css('cursor', 'pointer');
        }
        else {
            $('body').css('cursor', "url('/out/strenesse/src/css/img/zoom-minus.cur'), url('/out/strenesse/src/css/img/zoom-minus.cur'), pointer");
        }
    },
    
    isZoomOpen: function(){
        return ($('#content-area-container').data('zoomIsOpen') == true);
    },
    
    closeZoom: function(){
        if (this.isZoomOpen()) {
            if ($.browser.msie && parseInt($.browser.version) < 8) {
                $('#zoom-click-area').css({
                    width: "400px",
                    marginLeft: "0px",
                    marginTop: "0px"
                });
            }
            else {
                $('#zoom-click-area').css({
                    width: "400px",
                    marginLeft: "300px",
                    marginTop: "0px"
                });
            }
            $('#content-area-container').data('zoomIsOpen', false);
            $('#menu').show();
            $('#close-zoom').hide();
            Strenesse.loadBackgroundImage('last');
            $('#link-open-zoom').show();
            $('#link-close-zoom').hide();
            $('#zoom-cursor-open').show();
            $('#zoom-cursor-close').hide();
            if (jQuery.browser.mozilla && navigator.userAgent.indexOf('mac') != -1) {
                $('body').css('cursor', 'pointer');
            }
            else {
                $('body').css('cursor', "url('img/zoom-plus.cur'), url('css/img/zoom-plus.cur'), pointer");
            }
        }
    },
    
    // checks if the currently selected pic has a zoom counterpart
    hasZoomImage: function(itemId){
        if (!itemId) {
            var itemId = $('#content-area-container').data('lastBackgrounds');
            
            itemId = $(itemId).get(itemId.length - 1);
            if (itemId == 'default') {
                itemId = 'detail-01';
            }
        }
        itemId = itemId.replace(/detail/, 'zoom');
        
        var imgDetails = Strenesse.Images[itemId];
        if (imgDetails) {
            return !(imgDetails.src.indexOf('nopic.jpg') != -1 || imgDetails.src == '');
        }
        else {
            return false;
        }
        
    },
    
    enableZoomPossibility: function(){
        //if (!$('#message-confirm-towatchlist:visible')) {
            $('#zoom-click-area').show();
            //$('#link-open-zoom').css('visibility', 'visible');
            $('#link-open-zoom').css('display', 'block');
            $('#details-row-pictures .iconlist').css('padding-bottom', '5px');
            $('#content-area-container').data('zoomAllowed', true);
        //}
    },
    
    disableZoomPossibility: function(){
        $('#zoom-click-area').hide();
        //$('#link-open-zoom').css('visibility', 'hidden');
        $('#link-open-zoom').css('display', 'none');
        $('#details-row-pictures .iconlist').css('padding-bottom', '0px');
        $('#content-area-container').data('zoomAllowed', false);
        $('body').css('cursor', 'default');
    },
    
    isZoomAvailable: function(){
        return ($('#content-area-container').data('zoomAllowed'));
    },
    
    /*** order cursor functions ***/
    initOrderCursor: function(){
        if ($('#stc-navlayer-center').length) {
            $('#stc-navlayer-center').mousemove(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.showOrderCursor(evt);
                }
            });
            $('#stc-navlayer-center').mouseleave(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.hideOrderCursor(evt);
                }
            });
            $('#stc-navlayer-center').click(function(evt){
                Strenesse.Products.scrollTo('stc-area');
                return false;
            });
        }
    },
    
    showOrderCursor: function(evt){
        var offsetX = ($('body').width() / 2) - 250;
        if ($('#order-cursor').css('display') != 'block') {
            $('#order-cursor').fadeIn('fast');
        }
        
        $('#order-cursor').css({
            'left': (evt.pageX + 12) - offsetX + 'px',
            'top': (evt.pageY + 12) + 'px'
        });
    },
    
    hideOrderCursor: function(){
        if ($('#order-cursor').css('display') == 'block') {
            window.setTimeout(function(){
                $('#order-cursor').fadeOut('fast');
            }, 1000);
        }
    },
    
    /*** color cursor functions ***/
    initColorCursor: function(){
        if ($('.details-icon-link', $('#details-row-colors')).length) {
            $('.details-icon-link', $('#details-row-colors')).mousemove(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.showColorCursor(evt, this);
                }
            });
            $('.details-icon-link', $('#details-row-colors')).mouseleave(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.hideColorCursor(evt);
                }
            });
        }
    },
    
    showColorCursor: function(evt, target){
        if ($('#color-cursor').css('display') != 'block') {
            var color = $(target).children('a').children('img').attr('alt');
            $('#color-cursor').children('#color-cursor-inner').children('p').children('a').text(color);
            $('#color-cursor').css('display', 'block');
        }
        
        
        var offsetX = ($('body').width() / 2) - 250;
        
        $('#color-cursor').css({
            'left': (evt.pageX + 12) - offsetX + 'px',
            'top': (evt.pageY - 30 + 12) + 'px'
        });
    },
    
    hideColorCursor: function(){
        if ($('#color-cursor').css('display') == 'block') {
            $('#color-cursor').css('display', 'none');
        }
    },
    
    /*** color cursor functions ***/
    initSoldoutCursor: function(){
        if ($('#soldout-cursor').length) 
            $('#stc-navlayer-center').unbind('click');
        if ($('#stc-navlayer-center').length) {
            $('#stc-navlayer-center').mousemove(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.showSoldoutCursor(evt, this);
                }
            });
            $('#stc-navlayer-center').mouseleave(function(evt){
                if (!$('div.message-popup:visible').length) {
                    Strenesse.Products.hideSoldoutCursor(evt);
                }
            });
        }
    },
    
    showSoldoutCursor: function(evt, target){
        if ($('#soldout-cursor').css('display') != 'block') {
            $('#soldout-cursor').css('display', 'block');
        }
        /*  EDIT dazi: hier sollte wohl ne abfrage nach fenstergroesse usw kommen
         * 				hab die mal deaktiviert, weil sie nicht ging.
         */
        /*
         if (evt.pageX > 630) {
         xPos = evt.pageX - 213;
         //console.log("offset="+evt.pageX);
         }
         else {
         xPos = evt.pageX - 12;
         //console.log("offset="+evt.pageX);
         }*/
        var offsetX = ($('body').width() / 2) - 250;
        $('#soldout-cursor').css({
            'left': (evt.pageX + 12) - offsetX + 'px',
            'top': (evt.pageY + 12) + 'px'
        });
    },
    
    hideSoldoutCursor: function(){
        if ($('#soldout-cursor').css('display') == 'block') {
            $('#soldout-cursor').css('display', 'none');
        }
    }
    
};

Strenesse.WM = {
    init: function(){
    
        if ($('#wm-prv').length !== 0) {
        
            $('#content-area-container').css({
                backgroundRepeat: 'repeat-y'
            });
            
            //set opacity of hover images
            $('div.wm-prv-size1').children('img').not('.default').not('map').css({
                opacity: 0
            });
            $('div.wm-prv-size2').children('img').not('.default').not('map').css({
                opacity: 0
            });
            
            $('div.wm-prv-txt').children('a').css({
                color: '#999999'
            });
            
            $('div.wm-prv-txt').children('a').children('img').css({
                opacity: 0.6
            });
            
            //image map mouseenter
            $('map').children('area').mouseenter(function(){
            
                //define targets
                var parent = $(this).parent().parent();
                var target = $(this).attr('id');
                
                Strenesse.WM.fadeIn(parent, target);
                
            });
            
            //image map mouse leave
            $('map').mouseleave(function(){
            
                //define targets
                var parent = $(this).parent();
                
                Strenesse.WM.fadeOut(parent);
                
            });
            
            //image map mouseenter
            $('div.wm-prv-txt').children('a').mouseenter(function(){
            
                //define targets
                var parent = $(this).parent().parent();
                var targetTemp = $(this).attr('class');
                var target;
                if (targetTemp - length === 8) {
                    target = 'img' + targetTemp.substring(3, 8);
                }
                else {
                    target = 'img' + targetTemp.substring(3, 7);
                }
                Strenesse.WM.fadeIn(parent, target);
                
            });
            
            //image map mouse leave
            $('div.wm-prv-txt').children('a').mouseleave(function(){
            
                //define targets
                var parent = $(this).parent().parent();
                
                Strenesse.WM.fadeOut(parent);
                
            });
            
        }
        
        if ($('#wm-buch').length !== 0) {
        
        }
        
    },
    
    fadeIn: function(parent, target){
        if ($(parent).children('img.on').length !== 0) {
        
            //stop current animation
            $(parent).children('img.hover').stop();
            $(parent).children('div.wm-prv-txt').children('a').stop();
            $(parent).children('div.wm-prv-txt').children('a').children('img').stop();
            
            //check if image mouse over is already highlighted
            var imgOnSrc = $(parent).children('img.on').attr('src');
            if (imgOnSrc.indexOf(target) === -1) {
            
                $(parent).children('img.on').addClass('off').removeClass('on');
            }
        }
        
        //fade out text
        $('div.wm-prv-txt').children('a').css({
            color: '#999999'
        });
        
        $('div.wm-prv-txt').children('a').children('img').css({
            opacity: 0.6
        });
        
        //fade in text to hightlight
        var targetTextTemp = target.substring(3);
        var targetText = 'txt' + targetTextTemp;
        
        $('div.wm-prv-txt').children('a.' + targetText).css({
            color: '#ffffff'
        });
        
        $('div.wm-prv-txt').children('a.' + targetText).children('img').css({
            opacity: 1
        });
        
        //fade in image
        $(parent).children('img.hover[src*=' + target + ']').addClass('on').animate({
            opacity: 1
        }, {
            duration: 300,
            complete: function(){
            
                //hide other images                        
                $(parent).children('img.off').css({
                    opacity: 0
                }).removeClass('off');
                
            }
        });
    },
    
    fadeOut: function(parent){
    
        //stop current animation
        $(parent).children('img.hover').stop();
        $(parent).children('div.wm-prv-txt').children('a').stop();
        
        //fade out text
        $('div.wm-prv-txt').children('a').css({
            color: '#999999'
        });
        
        $('div.wm-prv-txt').children('a').children('img').css({
            opacity: 0.6
        });
        
        //fade out image
        $(parent).children('img.hover').animate({
            opacity: 0
        }, {
            duration: 500,
            complete: function(){
            
                $(this).removeClass('on');
                $(this).removeClass('off');
                
            }
        });
        
    },
    
    popup: function(lan){
    
        var winUrl = '/wm/tnb_' + lan + '.html';
        var winTarget = 'StrenesseInfo';
        var winProperties = 'width=500,height=500,left=0,top=0,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes';
        window.open(winUrl, winTarget, winProperties);
        
    }
    
};

$(document).ready(function(){

    if ($.browser.msie && parseInt($.browser.version) < 7) {
        if (strlang == "de") {
            $("body").html('<div class="ie6Bg"></div><div class="ie6Content"><h1>Warnung!</h1><p>F&uuml;r ein optimales Shopping-Erlebnis im Strenesse Online Shop, empfehlen wir Ihnen ein Upgrade auf einen modernen Browser durchzuf&uuml;hren.  Moderne Browser bieten Ihnen mehr Sicherheit beim Surfen und k&ouml;nnen Webseiten deutlich schneller verarbeiten. <br /><br /><a href="http://www.microsoft.com/germany/windows/internet-explorer/default.aspx" target="_blank">Download Internet Explorer</a><br /><a href="http://www.mozilla-europe.org/de/firefox/" target="_blank">Download Firefox</a></p></div>');
        }
        else {
            $("body").html('<div class="ie6Bg"></div><div class="ie6Content"><h1>Warning!</h1><p>For an optimal shopping experience in the Strenesse Online Shop, we recommend you to upgrade to a modern Browser. Current Browser offers you much more security and fast browsing. <br /><br /><a href="http://www.microsoft.com/germany/windows/internet-explorer/default.aspx" target="_blank">Download Internet Explorer</a><br /><a href="http://www.mozilla-europe.org/de/firefox/" target="_blank">Download Firefox</a></p></div>');
        }
    }
    else {
        Strenesse.init();
        Strenesse.Forms.init();
        Strenesse.Products.init();
        Strenesse.WM.init();
    }
    
    /* versandkosten werden auf der übersichtsseite nicth ausgewiesen, wenn der userr nicht eingeloggt. 
     * workaround über JS
     */
    if ($('#sumbox-shipping').length > 0) {
        var shipping_price = $('#sumbox-shipping').text().substr(0, $('#sumbox-shipping').text().length - 2);
        if (shipping_price == '0,00') {
            $('#sumbox-shipping').text('4,90 €');
        }
    }
    
    if($('#advent01').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_01.jpg)');
    }
    
    if($('#advent01-en').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_01_en.jpg)');
    }
    
    if($('#advent02').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_02.jpg)');
    }
    
    if($('#advent02-en').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_02_en.jpg)');
    }
    
    if($('#advent03').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_03.jpg)');
    }
    
    if($('#advent03-en').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_03_en.jpg)');
    }
    
    if($('#advent04').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_04.jpg)');
    }
    
    if($('#advent04-en').length > 0) {
    	$('#content-area-container.area-container').css('background-image','url(http://strenesse.com/out/strenesse/src/images/AdventsLiebling_04_en.jpg)');
    }
    
    /*
    if($('#strteaserstart2012')) {
    	$('#menu').css('position', 'relative');
    	$('#startpage-text').css('position', 'relative');
    	$('.product-teaser.plinestart-teaser').css('position', 'absolute');
    	$('.product-teaser.plinestart-teaser').css('top', '73px');
    	$('#content-area-container').css('height', '800px');
    }
    */
    
    if($('#messages.stc-messages').length !== 0) {
    	$('#content-area-container').height('800px');
    }
    
    if ($.browser.msie && parseInt($.browser.version) == 7) {
    	$('.product-teaser.plinestart-teaser').css('top', '25px');
    }
    
    if (/iPad/.test(navigator.userAgent||navigator.vendor||window.opera))
    	$('select option[disabled="disabled"]').remove();
});

