//some useful global variables
var locHREF = window.location.href;
var locSRCH = window.location.search;

//encapsulating functionality inside an object
var coral = {
    settings: {
        theTooltip: '<div id="theTooltip"><div id="theTooltipTop"></div><div id="theTooltipContent"><!-- --></div><div id="theTooltipBottom"></div></div>',
        theOverlay: '<div id="theOverlay"><!-- --></div>'
    },
    methods: {
        test: function () {
            //console.log('Test!');
        },
        setTitleOnExternalLink: function (extLinkText) {
            $(this).attr('title', extLinkText + ' ' + $(this).attr('title'));
        },
        checkForElem: function (elem) {
            if (!elem.size()) {
                return false;
            }
            else {
                return true;
            }
        },
        appendTooltip: function () {
            $('body').prepend(coral.settings.theTooltip);
        },
        showTooltip: function (elem, content) {
            $('#theTooltipContent')
			.empty()
			.append(content);

            var theTooltipHeight = $('#theTooltip').height();

            var offset = elem.offset();
            var xPos = offset.left;
            var yPos = offset.top - theTooltipHeight;

            //console.log(xPos, $(window).width());

            //if the tooltip is gouing to be outside the window (right)
            //@ToDo: expand the check to cover more situations and encapsule it in a function
            if (xPos + $('#theTooltip').width() > $(window).width()) {
                xPos = $(window).width() - $('#theTooltip').width() + 20;
            }

            $('#theTooltip')
				.css(
					{
					    left: xPos - 40,
					    top: yPos
					}
				)
				.show();
        },
        hideTooltip: function () {

            $('#theTooltip').hide();

            $('#theTooltipContent')
				.empty()
				.text('<!-- -->');
        },
        //check url for a matching string 
        checkURL: function (url, str, matching) {
            if (url.toLowerCase().match(str.toLowerCase())) {
                matching = true;
            }
            return matching;
        },
        //check url for a parameter
        checkURLForParams: function (param) {
            if (locSRCH) {
                var $URLParams = locHREF.split('?')[1];
                var $URLParamsArr = $URLParams.split('&');
                var $URLParamsArrLen = $URLParamsArr.length;
                var $URLParamsKeys = new Array();
                var $URLParamsVals = new Array();

                for (var i = 0; i < $URLParamsArrLen; i++) {
                    // push keys and values into their own arrays
                    $URLParamsKeys.push($URLParamsArr[i].split('=')[0]);
                    $URLParamsVals.push($URLParamsArr[i].split('=')[1]);
                }
                if (typeof ($URLParams) != 'undefined') {
                    //$('body').append('<p>Keys: '+$URLParamsKeys+'<br />Values: '+$URLParamsVals+'</p>');
                    // execute check for certain parameters (strings)
                    for (var i = 0; i < $URLParamsArrLen; i++) {
                        if ($URLParamsKeys[i].match(param)) {
                            return ($URLParamsVals[i]);
                        }
                        else {
                            return "undefined";
                        }
                    }
                }
            }
        },
        handlePrintLinks: function () {
            $('.doPrint').click(
				function () {
				    window.print();
				}
			);
        },
        initializeCarousels: function () {
            $('.carousel').each(function () {
                var carouselPages = $(this).children('li').size();
                $(this).next('.carouselPagination').find('.carouselPages').append('/ ' + carouselPages);

                //initiate a preloader if necessary
                //@see: http://www.egrappler.com/jquery-image-preload-plugin-smart-preloader/				
                if (($(this).hasClass('bigCarousel') && $(this).hasClass('preload')) || ($(this).hasClass('medCarousel') && $(this).hasClass('preload'))) {
                    var carouselElem = $(this).parents('div[class$="CarouselContainer"]');
                    var carouselElemId = carouselElem.attr('id');
                    var imgPath = '/assets-dynamic/gfx/content/' + carouselElemId + '/';
                    var imageSlides = [];

                    for (var cnt = 0; cnt < carouselPages; cnt++) {
                        imageSlides.push(imgPath + $(this).find('.slide:eq(' + cnt + ')').attr('id') + '.png');
                    }

                    $(document).smartpreload(
						{
						    carouselElemId: carouselElemId,
						    images: imageSlides,
						    oneachimageload: function (src) {
						        var delim = src.lastIndexOf('/') + 1;
						        var slideId = src.substr(delim).split('.')[0];
						        $('#' + slideId).css('background-image', 'url(' + src + ')');
						    },
						    onloadall: function (carouselElemId) {
						        $('#' + this.carouselElemId).find('.carouselPagination .left,.carouselPagination .right,.carouselPagination.pager').show();

						        $('#' + this.carouselElemId).find('.carousel').carouFredSel({
						            items: 1,
						            effect: "swing",
						            direction: "left",
						            auto: {
						                play: true,
						                pauseOnHover: true,
						                pauseDuration: 6000
						            },
						            prev: '#' + this.carouselElemId + ' .carouselPagination .prev',
						            next: '#' + this.carouselElemId + ' .carouselPagination .next',
						            pagination: {
						                container: '#' + this.carouselElemId + ' .carouselPagination .pager',
						                anchorBuilder: function (nr) {
						                    return "<li><span>" + nr + "</span></li>";
						                }
						            },
						            scroll: {
						                onBefore: function () { },
						                onAfter: function () { }
						            },
						            circular: true
						        });

						        if ($('#' + this.carouselElemId).attr('class').match('medCarousel')) {
						            console.log('med carousel pager');
						            var pager = $('#' + this.carouselElemId).find('.pager');
						            var pagerW = pager.width();
						            var carouselW = $('#' + this.carouselElemId).width();

						            pager.css({
						                'left': carouselW / 2 - pagerW / 2 + 'px'
						            });
						        }
						    }
						}
					);
                }
            });

            var newsPages = $('#newsCarouselHome .carousel li').size();
            $('#newsCarouselHome .carouselPagination .carouselPager .carouselPages').text('/' + newsPages);

            $('#newsCarouselHomeInner').find('.carousel').carouFredSel({
                items: 1,
                effect: "swing",
                direction: "left",
                height: "auto",
                auto: {
                    play: true,
                    pauseOnHover: true,
                    pauseDuration: 6000
                },
                prev: '#newsCarouselHome .carouselPagination .prev',
                next: '#newsCarouselHome .carouselPagination .next',
                scroll: {
                    onBefore: function () { },
                    onAfter: function () { }
                },
                circular: true,
                pagination: {
                    container: "#newsCarouselHome .carouselPagination .carouselPager .carouselPage",
                    anchorBuilder: function (nr) {
                        return "<span>" + nr + "</span>";
                    }
                }
            });
            var cHeight = $('#newsCarouselHome .carousel').outerHeight();
            $('#newsCarouselHome .carousel li').find('.newsText').height(cHeight - 20);
            $('#newsCarouselHome .carousel li').find('.newsImage').height(cHeight);

            $('#bottleCarouselHomeInner').find('.carousel').carouFredSel({
                items: 1,
                effect: "swing",
                direction: "left",
                auto: {
                    play: false,
                    pauseOnHover: true,
                    pauseDuration: 3000
                },
                prev: '#bottleCarouselHome .carouselPagination .prev',
                next: '#bottleCarouselHome .carouselPagination .next',
                scroll: {
                    onBefore: function () { },
                    onAfter: function () { }
                },
                circular: true
            });

            $('#carouselUeberCoralAwards').find('.carousel').carouFredSel({
                items: 1,
                effect: "swing",
                direction: "left",
                auto: {
                    play: true,
                    pauseOnHover: true,
                    pauseDuration: 3000
                },
                prev: '#carouselUeberCoralAwards .carouselPagination .prev',
                next: '#carouselUeberCoralAwards .carouselPagination .next',
                pagination: {
                    container: '#carouselUeberCoralAwards .carouselPagination .pager',
                    anchorBuilder: function (nr) {
                        return "<li>" + nr + "</li>";
                    }
                },
                scroll: {
                    onBefore: function () { },
                    onAfter: function () { }
                },
                circular: true
            });
        },
        initializeBottleRotators: function () {
            $('.bottleRotator').each(
				function () {
				    var flashContainer = $(this);
				    var flashContainerId = flashContainer.attr('id');
				    var flashPath = '/assets/flash/bottleRotator/';
				    var xmlPath = '/assets/flash/' + flashContainerId + '/';
				    if ((culture === "de-CH") || (culture === "fr-CH")) {
				        xmlPath = '/assets/flash/' + flashContainerId + '/' + culture + '/';
				    }
				    var flashId = flashContainerId + 'Flash';
				    var alternativeContent = flashContainer.find('.flashcontainerAlt');
				    alternativeContent.attr('id', flashId + 'Container');

				    var flashW = flashContainer.attr('width');
				    var flashH = flashContainer.attr('height');

				    //swfobject call
				    var flashvars = {};
				    var params = {
				        allowFullScreen: false,
				        allowScriptAccess: 'sameDomain',
				        wmode: 'transparent'
				    };
				    var attributes = {
				        id: flashId
				    };

				    function outputStatus(e) {
				        //alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
				        if (e.success === false) {
				            $('#installFlash').show();
				        }
				    }

				    swfobject.embedSWF(flashPath + "main.swf?xmlPath=" + xmlPath + 'config.xml', flashId + 'Container', flashW, flashH, "9.0.0", false, flashvars, params, attributes, outputStatus);
				}
				);
        },
        initializeBottleRotatorOnHome: function () {
            var flashContainer = $('#bottleCarouselHome');
            var flashContainerId = flashContainer.attr('id');

            var alternativeContent = flashContainerId;
            var flashId = flashContainerId + 'Flash';
            var flashPath = '/assets/flash/' + flashContainerId + '/';
            var xmlPath = flashPath + 'xml/';
            if ((culture === "de-CH") || (culture === "fr-CH")) {
                xmlPath = '/assets/flash/' + flashContainerId + '/' + culture + '/xml/';
            }

            var flashW = flashContainer.attr('width');
            var flashH = flashContainer.attr('height');

            //swfobject call
            var flashvars = {};
            var params = {
                allowFullScreen: false,
                allowScriptAccess: 'sameDomain',
                wmode: 'transparent'
            };
            var attributes = {
                id: flashId
            };

            function outputStatus(e) {
                //alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
                if (e.success === false) {
                    $('#installFlash').show();
                }
            }

            swfobject.embedSWF(flashPath + "main.swf?xmlPath=" + xmlPath + 'config.xml', alternativeContent, flashW, flashH, "9.0.0", false, flashvars, params, attributes, outputStatus);
        },
        initializeTimeline: function () {
            var flashContainer = $('#historieTimelinePlayer');
            var flashContainerId = flashContainer.attr('id');

            var alternativeContent = flashContainerId;
            var flashId = flashContainerId + 'Flash';
            var flashPath = '/assets/flash/' + flashContainerId + '/';
            var xmlPath = flashPath + 'xml/';
            if (culture !== "de-DE") {
                xmlPath = flashPath + culture + '/xml/';
            }
            var skinPath = flashPath;

            var flashW = flashContainer.attr('width');
            var flashH = flashContainer.attr('height');

            //swfobject call
            var flashvars = {};
            var params = {
                allowFullScreen: false,
                allowScriptAccess: 'sameDomain',
                wmode: 'transparent'
            };
            var attributes = {
                id: flashId
            };

            function outputStatus(e) {
                //alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
                if (e.success === false) {
                    $('#installFlash').show();
                }
            }

            swfobject.embedSWF(flashPath + "main.swf?xmlPath=" + xmlPath + "config.xml&skinPath=" + skinPath + "playerskin.swf", alternativeContent, flashW, flashH, "9.0.0", false, flashvars, params, attributes, outputStatus);
        },
        initializeCurrentTrends: function () {
            var flashContainer = $('#currentTrends');
            var flashContainerId = flashContainer.attr('id');

            var alternativeContent = flashContainerId;
            var flashId = flashContainerId + 'Flash';
            var flashPath = '/assets/flash/' + flashContainerId + '/';
            var xmlPath = flashPath + 'xml/';
            if (culture === "de-CH") {
                flashPath = '/assets/flash/' + flashContainerId + '/' + culture + '/';
                xmlPath = '/assets/flash/' + flashContainerId + '/' + culture + '/xml/';
            }
            if ((culture === "fr-CH") && (coral.methods.checkURL(locHREF, '/fr/') === true)) {
                flashPath = '../../assets/flash/' + flashContainerId + '/' + culture + '/';
                xmlPath = '../../assets/flash/' + flashContainerId + '/' + culture + '/xml/';
            }

            var flashW = flashContainer.attr('width');
            var flashH = flashContainer.attr('height');

            //swfobject call
            var flashvars = {};
            var params = {
                allowFullScreen: false,
                allowScriptAccess: 'sameDomain',
                wmode: 'transparent'
            };
            var attributes = {
                id: flashId
            };

            function outputStatus(e) {
                //alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
                if (e.success === false) {
                    $('#installFlash').show();
                    coral.methods.initializeCurrentTrendsFallback(); //if flash fails, try the javascript fallback
                }
            }

            swfobject.embedSWF(flashPath + "main.swf?xmlPath=" + xmlPath + 'config.xml', alternativeContent, flashW, flashH, "9.0.0", false, flashvars, params, attributes, outputStatus);
        },

        initializeCurrentTrendsFallback: function () {
            var recentTrend = this;
            var intro = $('.oneLook:eq(0)');
            var firstLook = $('.oneLook:eq(1)');
            var firstLookText = firstLook.find('.firstLook').text();
            var looks = ($('.oneLook').size()) - 1; //intro does not count as one "look"

            this.updateCurrentLookIndex = function (index) {
                $('.navigation .is').text(index);
            }

            //initial settings
            //firstLook.show();
            var currentLookIndex = 1;
            //$('.isIntro .navigation .firstLook').text(firstLookText);
            recentTrend.updateCurrentLookIndex(currentLookIndex);
            $('.navigation .of').text(looks);
            $('.oneLook.isLook').hide();
            intro.addClass('activeTrend');

            //@ToDo: add a better animation
            this.showLookPage = function (index) {
                $('.oneLook').not('.oneLook:eq(' + index + ')').hide();
                $('.oneLook:eq(' + index + ')').fadeIn(350, function () {
                    $('.oneLook').removeClass('activeTrend');
                    $(this).addClass('activeTrend');
                });
            }

            $('.backToIntro').click(function () {
                recentTrend.showLookPage(0);
                recentTrend.updateCurrentLookIndex(1);
            });
            $('.firstLook').click(function () {
                recentTrend.showLookPage(1);
                recentTrend.updateCurrentLookIndex(1);
            });

            $('.navigation.look').find('.prev').click(function () {
                if (currentLookIndex === 1) {
                    currentLookIndex = 1;
                    recentTrend.showLookPage(currentLookIndex - 1);
                }
                else {
                    currentLookIndex--;
                    recentTrend.showLookPage(currentLookIndex);
                }
                recentTrend.updateCurrentLookIndex(currentLookIndex);

            });
            $('.navigation.look').find('.next').click(function () {
                currentLookIndex++;
                recentTrend.updateCurrentLookIndex(currentLookIndex);
                recentTrend.showLookPage(currentLookIndex);
            });

            $('.oneLook:last').find('.navigation.look').find('.next').remove();
        },
        setUpVideoplayer: function () {
            // Add VideoJS to all video tags on the page when the DOM is ready
            VideoJS.setupAllWhenReady(
				{
				    controlsBelow: false, // Display control bar below video instead of in front of
				    controlsHiding: true, // Hide controls when mouse is not over the video
				    //defaultVolume: 0.85, // Will be overridden by user's last volume if available
				    flashVersion: 9, // Required flash version for fallback
				    linksHiding: true // Hide download links when video is supported
				}
			);
        },
        washingConsultant: function () {
            //initally hide the last two steps and all buttons
            $('#step2,#step3').hide();
            $('#washingConsultantForm fieldset div.accordion-bottom button').hide();

            $('#tabForStep1').find('a.washingTab').addClass('activeTab');
            $('#tabForStep2').find('a.washingTab').addClass('inactiveTab');
            $('#tabForStep3').find('a.washingTab').addClass('inactiveTab');


            //button functionality
            $('#washingConsultantForm #step1 div.accordion-bottom button').bind('click', function () {
                $('#tabForStep1').find('a.washingTab').removeClass('activeTab');
                $('#tabForStep2').find('a.washingTab').removeClass('inactiveTab').addClass('activeTab');

                $('#step1').hide();
                $('#step2').show();
            });
            $('#washingConsultantForm #step2 div.accordion-bottom button').bind('click', function () {
                $('#tabForStep1').find('a.washingTab').removeClass('activeTab');
                $('#tabForStep2').find('a.washingTab').removeClass('inactiveTab').removeClass('activeTab');
                $('#tabForStep3').find('a.washingTab').removeClass('inactiveTab').addClass('activeTab');

                $('#step1').hide();
                $('#step2').hide();
                $('#step3').show();
            });

            //washing tabs functionality
            $('a.washingTab').not('#washingTabSingle a.washingTab').click(
				function (e) {
				    e.preventDefault();

				    if (!$(this).hasClass('inactiveTab')) {
				        $('#washingConsultantForm fieldset').hide();
				        var targetStep = $(this).attr('href');
				        $(targetStep).show();
				    }
				}
			);

            //Coral washing consultant
            //step 1
            var washingCategorySelector = $('.washingCategory ul li .washingSymbol');

            function markAsSelected() {
                $(this).parents('.washingCategory').find('.washingSymbol').removeClass('selected');
                $(this).addClass('selected');

                var actClass = $(this).attr('class')

                $(this).parents('.washingCategory').prev('.accordion-head').find('a.washingSymbol').removeAttr('class').addClass(actClass).addClass('selectionMade');

                checkStep1Ready();
            }

            washingCategorySelector.each(
				function () {
				    var content = '<p><strong>' + $(this).attr("title") + '</strong><br />' + $(this).text() + '</p>';

				    $(this)
					.click(markAsSelected)
					.hover(
						function () {
						    coral.methods.showTooltip($(this), content);
						},
						function () {
						    coral.methods.hideTooltip();
						}
					);
				}
			);

            //handle buttons and washing tabs
            var step1ReadyIndicators = $('#step1 div.accordion-head a.washingSymbol');

            function checkStep1Ready() {
                if ($('#Waschen a.washingSymbol').hasClass('selectionMade')) {
                    $('#washingConsultantForm #step1 div.accordion-bottom button').show();
                    $('#washingConsultantForm #step1 .stepDescHint').hide();
                }
                else {
                    $('#washingConsultantForm #step1 div.accordion-bottom button').hide();
                    $('#washingConsultantForm #step1 .stepDescHint').show();
                }
                /*
                if(step1ReadyIndicators.isTrueForAll(".selectionMade")){
                $('#washingConsultantForm #step1 div.accordion-bottom button').show();
                }
                else {
                $('#washingConsultantForm #step1 div.accordion-bottom button').hide();
                }
                */
            }

            //step 2
            var fabricSelector = $('#washingConsultant #step2 label');
            var availableFabricSlots = $('#washingConsultant #step2 label').size() - 3;
            var activeFabrics = 0;

            //console.log('activeFabrics: ' + activeFabrics);
            //console.log('availableFabricSlots: ' + availableFabricSlots);

            function toggleFabrics(fabric) {
                if (fabric.hasClass('unavailable')) {
                    //fabric cannot be clicked
                }
                else if (fabric.hasClass('activeFabric')) {
                    activeFabrics--;
                    availableFabricSlots++;

                    //console.log('activeFabrics: ' + activeFabrics);
                    //console.log('availableFabricSlots: ' + availableFabricSlots);


                    fabric.removeClass('activeFabric');

                    $('#washingConsultant #step2 label').removeClass('unavailable');
                }
                else {
                    activeFabrics++;
                    availableFabricSlots--;

                    //console.log('activeFabrics off: ' + activeFabrics);
                    //console.log('availableFabricSlots off: ' + availableFabricSlots);


                    fabric.addClass('activeFabric');

                    if (availableFabricSlots === 0) {
                        $('#washingConsultant #step2 label').not('.activeFabric').addClass('unavailable');
                    }
                }
                checkStep2Ready();
            }

            fabricSelector.each(
				function () {
				    $(this).bind('click', function () {
				        var fabric = $(this);
				        toggleFabrics(fabric);
				    });
				}
			);

            //handle buttons and washing tabs
            var step2ReadyIndicators = fabricSelector;

            function checkStep2Ready() {
                if (step2ReadyIndicators.hasClass('activeFabric')) {
                    $('#washingConsultantForm #step2 div.accordion-bottom button').show();
                }
                else {
                    //
                }
            }

            //step 3
            var stainSelector = $('#washingConsultant #step3 label');

            function toggleStains(stain) {
                stainSelector.removeClass('activeStain');
                stain.addClass('activeStain');

                checkStep3Ready();
            }

            stainSelector.each(
				function () {
				    $(this).bind('click', function () {
				        var stain = $(this);
				        toggleStains(stain);
				    });
				}
			);

            //handle buttons and washing tabs
            var step3ReadyIndicators = stainSelector;

            function checkStep3Ready() {
                $('#washingConsultantForm #step3 div.accordion-bottom button').show();
            }
        },
        styleInterview: function () {
            $('#theInterview').hide();

            $('#toInterviewFlag').click(function () {
                $('#theInterview_startpage').hide();
                $('#theInterview').show();

                return false;
            });


            var recentInterviewPart = this;
            var currentInterviewPartIndex = 1;

            var interviewParts = $('.interviewPart').size();

            this.updateInterviewPartIndex = function (index) {
                $('.navigation .is').text(index);
            }
            $('.navigation .of').text(interviewParts);
            recentInterviewPart.updateInterviewPartIndex(currentInterviewPartIndex);

            $('.interviewPart').not('.interviewPart:first').hide();
            recentInterviewPart.updateInterviewPartIndex(1);
            $('.interviewPart:first').addClass('activeInterviewPart');

            //@ToDo: add a better animation
            this.showInterviewPart = function (index) {
                $('.interviewPart').not('.interviewPart:eq(' + index + ')').fadeOut(350);
                $('.interviewPart:eq(' + index + ')').fadeIn(350, function () {
                    $('.interviewPart').removeClass('activeInterviewPart');
                    $(this).addClass('activeInterviewPart')
                });
            }

            $('.navigation').find('.prev').click(function () {
                currentInterviewPartIndex--;
                recentInterviewPart.updateInterviewPartIndex(currentInterviewPartIndex);
                recentInterviewPart.showInterviewPart(currentInterviewPartIndex - 1);
            });
            $('.navigation').find('.next').click(function () {
                currentInterviewPartIndex++;
                recentInterviewPart.updateInterviewPartIndex(currentInterviewPartIndex);
                recentInterviewPart.showInterviewPart(currentInterviewPartIndex - 1);
            });

            $('.interviewPart:last').find('.navigation').find('.next').remove();
            $('.interviewPart:first').find('.navigation').find('.prev').css('visibility', 'hidden');
        },
        initializeAccordions: function () {
            function toggleAccordionElemShow() {
                $(this).next('.accordion-content').show();
                $(this).find('h3').addClass('nextElemOpen');
            }
            function toggleAccordionElemHide() {
                $(this).next('.accordion-content').hide();
                $(this).find('h3').removeClass('nextElemOpen');
            }
            $('.accordion-content').hide();
            $('.accordion-head').toggle(
				toggleAccordionElemShow,
				toggleAccordionElemHide
			);
        },
        cleanrightTeaser: function () {
            var flashContainer = $('#cleanrightTeaser');
            var flashContainerId = flashContainer.attr('id');

            var alternativeContent = flashContainerId;
            var flashId = flashContainerId + 'Flash';
            var flashPath = '/assets/flash/teaser/';

            var flashW = flashContainer.attr('width');
            var flashH = flashContainer.attr('height');

            //swfobject call
            var flashvars = {};
            var params = {
                allowFullScreen: false,
                allowScriptAccess: 'sameDomain',
                wmode: 'transparent'
            };
            var attributes = {
                id: flashId
            };

            function outputStatus(e) {
                //alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
                if (e.success === false) {
                    $('#installFlash').show();
                }
            }

            swfobject.embedSWF(flashPath + flashContainerId + ".swf", alternativeContent, flashW, flashH, "9.0.0", false, flashvars, params, attributes, outputStatus);
        },
        careTakingInfos: function () {
            var triggers = $('div#rightContentInner div.tabsNavigationWrapper div[id*="List"] ul li a');

            $('div#rightContentInner ol[id*="Infos"] > li').not('li:first').hide();

            function showHideCareTakingInfo(elem) {
                triggers.removeClass('selectedElem');
                $('div#rightContentInner ol[id*="Infos"] > li').hide();
                $(elem).show();
            }

            //coming from an URL like '/Waschtipps/Waschsymbole#Polyester' links directly to the target article
            //useful for newsletters, etc;
            (function showHideCareTakingInfoFromURL() {
                if (coral.methods.checkURL(locHREF, '#') === true) {

                    var cnt = triggers.size();
                    for (var i = 0; i < cnt; i++) {
                        var trigger = triggers[i];
                        var elem = $(trigger).attr('href');

                        if (coral.methods.checkURL(locHREF, elem) === true) {
                            showHideCareTakingInfo(elem);
                            $('div#rightContentInner div.tabsNavigationWrapper div[id*="List"] ul li a[href="' + elem + '"]').addClass('selectedElem');
                            break;
                        }
                        else {
                            continue;
                        }
                    }
                }
            })();

            triggers.each(
				function () {
				    $(this).bind('click', function (e) {
				        var elem = $(this).attr('href');
				        e.preventDefault();

				        showHideCareTakingInfo(elem);
				        $(this).addClass('selectedElem');
				    });
				});
        },
        siteutilities: function () {
            var unileverGroupLink = $('#linkUnileverGroup');
            var unileverGroupLayer = $('#unileverBrands');

            var captchaHelpLayerTrigger1 = $('#captchaHelpLayerTrigger1');
            var captchaHelpLayerTrigger2 = $('#captchaHelpLayerTrigger2');
            var codeHelp = $('#codeHelp');

            var legalContactLink = $('#legalcontactlayerlink');
            var legalContactLayer = $('#emailDatenschutz');

            var newsletterRaffleTBGLink = $('a[href="#TBGNewsletterGewinnspiel"]');
            var newsletterRaffleTBGLayer = $('#TBGNewsletterGewinnspiel');

            var close = $('a[href="#close"]');
            close.bind('click', function () {
                coral.methods.hideOverlay();
            }
			);
            unileverGroupLink.bind('click', function (e) {
                e.preventDefault();
                coral.methods.showLayer(unileverGroupLayer);
            });
            captchaHelpLayerTrigger1.bind('click', function (e) {
                e.preventDefault();
                coral.methods.showLayer(codeHelp);
            });
            captchaHelpLayerTrigger2.bind('click', function (e) {
                e.preventDefault();
                coral.methods.showLayer(codeHelp);
            });
            legalContactLink.bind('click', function (e) {
                e.preventDefault();
                coral.methods.showLayer(legalContactLayer);
            });
            newsletterRaffleTBGLink.bind('click', function (e) {
                e.preventDefault();
                coral.methods.showLayer(newsletterRaffleTBGLayer);
            });
        },
        showLayer: function (layer) {
            var dimensions = {
                winW: $(window).width(),   // returns height of browser viewport
                winH: $(window).height(),   // returns height of browser viewport

                docW: $(document).width(), // returns height of HTML document
                docH: $(document).height(), // returns height of HTML document

                centerWinX: $(window).width() / 2,
                centerDocX: $(document).width() / 2,
                centerWinY: $(window).height() / 2,
                centerDocY: $(document).height() / 2
            }
            var layerDimensions = {
                layerW: layer.width(),
                layerH: layer.height()
            }
            coral.methods.showOverlay(dimensions, layerDimensions);

            layer.css(
				{
				    left: (dimensions.centerWinX - layerDimensions.layerW / 2),
				    top: dimensions.centerWinY - layerDimensions.layerH / 2
				}
			);

            layer
				.show()
				.focus();
        },
        hideLayer: function () {
            $('.layer').hide();
        },
        insertInstallFlashBadge: function () {
            var flashBadge = $('#installFlash');
            $('#rightContentInner').append(flashBadge);
        },
        showOverlay: function (dimensions) {
            if (coral.methods.checkForElem($('#theOverlay')) === true) {
                $('#theOverlay').css(
					{
					    width: dimensions.winW,
					    height: dimensions.docH
					}
				).show();
            }
            else {
                $('body').prepend(coral.settings.theOverlay);
                $('#theOverlay').css(
					{
					    width: dimensions.winW,
					    height: dimensions.docH
					}
				).show();
            }
            $('#theOverlay').bind('click', function () {
                coral.methods.hideOverlay();
            }
			);
        },
        hideOverlay: function () {
            $('#theOverlay').hide();
            coral.methods.hideLayer();
        },
        AjaxForm: function () {
            selector = 'form.ajaxRequest',
			userId = $('body').attr('data-userhash'),
			init = function () {
			    var _this = this;
			    $(this.selector).each(function (index) {
			        $(this).attr('id', 'ajaxRequest_' + index);
			        _this.formObserve($(this).attr('id'));
			    });
			},
			formObserve = function (id) {
			    var _this = this;
			    var form = $('#' + id);
			    form.submit(function () {
			        if (form.serialize() != "") {
			            $.ajax({
			                url: form.attr('action') + "?userId=" + _this.userId,
			                data: form.serialize(),
			                type: form.attr('method'),
			                cache: false,
			                success: function (data) {
			                    form.replaceWith(data);
			                    _this.init();
			                }
			            });
			        }
			        return false;
			    });
			}
            init();
        },
        handleNoIEBar: function () {
            var noiebar = $('#activebar-container');
            var noiebarClose = $('#activebar-container-close');

            noiebar.hover(
				function () {
				    noiebarClose.addClass('hover');
				},
				function () {
				    noiebarClose.removeClass('hover');
				}
			);
            noiebarClose.hover(
				function () {
				    $(this).addClass('hover');
				    noiebar.addClass('hover');
				},
				function () {
				    $(this).removeClass('hover');
				    noiebar.removeClass('hover');
				}
			);

            noiebarClose.click(
				function () {
				    noiebar.hide();
				    $(this).hide();

				    $('html').removeClass('noiebar');
				}
			);

            if (coral.methods.checkURL(locHREF, 'Browserupdate') === true) {
                noiebar.hide();
                noiebarClose.hide();
                $('html').removeClass('noiebar');
            }
        },
        rating: function () {
            //
        }
    },
    initialize: function () {	
        if ($('form.ajaxRequest').length) {
            this.methods.AjaxForm();
        }
        this.methods.insertInstallFlashBadge();
        this.methods.handlePrintLinks();

        this.methods.initializeCarousels();
        this.methods.initializeBottleRotators();
        this.methods.initializeAccordions();

        this.methods.handleNoIEBar();
        this.methods.appendTooltip();

        if ((this.methods.checkURL(locHREF, 'TV-Spot') === true) || (this.methods.checkURL(locHREF, 'Fashion-Week') === true)) {
            this.methods.setUpVideoplayer();
        }
        if (this.methods.checkURL(locHREF, 'Style-Interview') === true) {
            this.methods.styleInterview();
        }
        if ($('body').hasClass('home')) {
            //this.methods.initializeBottleRotatorOnHome();
        }
        if (this.methods.checkURL(locHREF, 'Waschberater') === true) {
            this.methods.washingConsultant();
        }
        if ((this.methods.checkURL(locHREF, 'cleanright') === true) && (culture !== 'fr-CH')) {
            this.methods.cleanrightTeaser();
        }
        if ((this.methods.checkURL(locHREF, 'Waschsymbole') === true) || (this.methods.checkURL(locHREF, 'Pflegesymbole') === true)) {
            this.methods.careTakingInfos();
        }
        if ((this.methods.checkURL(locHREF, 'SiteUtilities') === true) || (this.methods.checkURL(locHREF, 'CoralAktuell/Geld-Zuruck-Garantie') === true)) {
            this.methods.siteutilities();
        }
        if (this.methods.checkURL(locHREF, 'Historie') === true) {
            this.methods.initializeTimeline();
        }
        if ((this.methods.checkURL(locHREF, 'FashionTrends') === true) && (this.methods.checkURL(locHREF, 'Aktuelle-Trends') === true)) {
            this.methods.initializeCurrentTrends();
        }
    }
}

//call methods of the coral object
jQuery(function($) { 
		coral.initialize();
});
