$("html").removeClass("JSoff").addClass("JSon");

/* teaser rotation */
var countTeaser;
var currentTeaser = 0;



/**
 * delete the dashed border by clicken on a link (type3 fuction)
 */
function blurLink(i){
    i.blur();
}


/**
 * show Text in the BlogNavi on mouse-over
 */
(function($){
    $.fn.showBlogNaviText = function(){
        $(".sitenavi a").hover(function(){
            $('.navitext').html($(this).html());
        }, function(){
            $('.navitext').html('');
        });
    }
}(jQuery));


/**
 * show shopSubMenu in shop navi
 */
(function($){
    var naviTimer = null;
    var childInputIsBlur = true;
    $.fn.showSubMenu = function(){

        $('.quicknavi li a.topiclink, .pressNavi li a.topiclink').click(function(){
            var checkElement = $(this).next();

            // hide submenu
            if ((checkElement.is('.submenu')) && (checkElement.is(':visible'))) {
                clearTimeout(naviTimer);
                checkElement.parent().removeClass("hi");
                checkElement.fadeOut('fast');
                return false;
            }
            // show submenu
            if ((checkElement.is('.submenu')) && (!checkElement.is(':visible'))) {
                $(this).parent().find('.submenu').hover(function(){
                    clearTimeout(naviTimer);
                }, function(){
                    clearTimeout(naviTimer);
                });

                clearTimeout(naviTimer);
                $('.quicknavi .submenu:visible, .pressNavi .submenu:visible').fadeOut('slow');
                $('.quicknavi .submenu:visible, .pressNavi .submenu:visible').parent().removeClass("hi");

                checkElement.fadeIn('slow');
                checkElement.parent().addClass("hi");
                $(this).parent().find('.submenu').hover(function(){
                    clearTimeout(naviTimer);
                }, function(){
                    naviTimer = setTimeout(function(){
                        checkElement.parent().removeClass("hi");
                        checkElement.fadeOut('fast');
                        return false;
                    }, 2000);
                });

                return false;
            } //is.submenu
        });
    }
}(jQuery));


/**
 * show shopSubMenu in shop navi
 */
(function($){
    var naviTimer = null;
    var childInputIsBlur = true;
    $.fn.showShopSubMenu = function(){
        $('.shopnavi').find('.submenu').hover(function(){
            clearTimeout(naviTimer);
        }, function(){
            naviTimer = setTimeout(function(){
                $('.submenu').parent().removeClass("hi");
                $('.submenu').fadeOut('fast');
                return false;
            }, 2000);
        });
        $('.shopnavi li.node a').bind('click', function(){
            var checkElement = $(this).next();

            // hide submenu
            if ((checkElement.is('.submenu')) && (checkElement.is(':visible'))) {
                clearTimeout(naviTimer);
                checkElement.parent().removeClass("hi");
                checkElement.fadeOut('fast');
                return false;
            }
            // show submenu
            if (($(this).parent().is('.node')) && (!checkElement.is(':visible'))) {

                $(this).parent().find('.submenu').hover(function(){
                    clearTimeout(naviTimer);
                }, function(){
                    clearTimeout(naviTimer);
                });

                clearTimeout(naviTimer);
                $('.shopnavi .submenu:visible').fadeOut('slow');
                $('.shopnavi .submenu:visible').parent().removeClass("hi");

                // get menu from generated page
                var currentPath = window.location.href.split('/', 3);
                var host = currentPath[2];
                var href = $(this).attr('href');
                var link = (href.indexOf("http") == -1) ? 'http://' + host + '/' + href : href;
                $.ajax({
                    url: link,
                    type: 'GET',
                    async: false,
                    error: function(){
                    },
                    success: function(data){
                        $('.shopnaviwrapper').html($(data).find(".shopnaviwrapper").html());
                        $('.shopnavi').showShopSubMenu();
                        if ($('#teamContainer').length > 0) {
                            $('.shopnavi').subMenuLinkTeam();
                        }
                        else {
                            $('.shopnavi').subMenuLink();
                        }
                    }
                });
                return false;
            } //is.submenu
        });
    }
}(jQuery));


/**
 * links in submenu of shop navi
 */
(function($){
    $.fn.subMenuLink = function(){
        $('.shopnavi .bgVignetteMiddle ul li a').bind('click', function(event){
            event.preventDefault();
            var label = $(this).text();
            // fade out any submenues while requesting new menu
            $('.shopnavi .submenu:visible').fadeOut('slow');
            $('.shopnavi .submenu:visible').parent().removeClass("hi");
            // get menu from generated page and content where available
            var currentPath = window.location.href.split('/');
            var host = currentPath[2];
            var href = $(this).attr('href');
            var link = (href.indexOf("http") == -1) ? 'http://' + host + '/' + href : href;
            $.ajax({
                url: link,
                type: 'GET',
                dataType: 'html',
                async: false,
                error: function(){
                },
                success: function(data){
                    $('.shopnaviwrapper').html($(data).find(".shopnaviwrapper").html());
                    document.title = $(data).find('span.pagetitle').text();
                    var result = $(data).find("#endnode").html();
                    if (result) {
                        $(".vignetteBoxes").children().fadeOut("fast", function(){
                            $(".vignetteBoxes").children().remove();
                            $(".vignetteBoxes").append(result).children().hide().fadeIn("fast");
                            $('.gmlink').css('display', 'block').attr('href', '#metaMap');
                            $("#map_canvas").children().remove();
                            /*$('.street-address').each(function(e){
                             if ($(this).children().length > 1) {
                             $(this).parent().parent().find('.gmlink').hide();
                             }
                             });*/
                            $('.gmlink').nyroModal({
                                bgColor: '#fff',
                                padding: 15,
                                windowResize: false,
                                showTransition: false,
                                endShowContent: function(){
                                initLoader(this.from);
                                if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
                                    $("#nyroModalFull").css("top", $(window).scrollTop());
                                    $(window).bind('scroll', function(){
                                        $("#nyroModalFull").css("top", $(window).scrollTop());
                                    });
                                }
                            }
                            });
                        });
                        var slideshowData = $(data).find(".slideSources").children();
                        var slideSources = [];
                        slideshowData.each(function(i){
                            slideSources[i] = $(this).attr('src');
                        });
                        if (slideSources.length > 1) {
                            $(".srImg").slideshow({
                                slideImages: slideSources
                            });
                        }
                        if (_gaq._getAsyncTracker) pageTracker = _gaq._getAsyncTracker('')
                        if (pageTracker) pageTracker._trackPageview(link);
                    }
                    $('.shopnavi').showShopSubMenu();
                    $('.shopnavi').subMenuLink();

                }
            });

            return false;
        });
    }
}(jQuery));


/**
 * links in submenu of team navi
 */
(function($){
    $.fn.subMenuLinkTeam = function(){
        $('.shopnavi .bgVignetteMiddle ul li a').bind('click', function(event){
            event.preventDefault();
            var label = $(this).text();
            // fade out any submenues while requesting new menu
            $('.shopnavi .submenu:visible').fadeOut('slow');
            $('.shopnavi .submenu:visible').parent().removeClass("hi");
            // get menu from generated page and content where available
            var currentPath = window.location.href.split('/');
            var host = currentPath[2];
            var href = $(this).attr('href');
            var link = (href.indexOf("http") == -1) ? 'http://' + host + '/' + href : href;
            $.ajax({
                url: link,
                type: 'GET',
                dataType: 'html',
                async: false,
                error: function(){
                },
                success: function(data){
                    $('.shopnaviwrapper').html($(data).find(".shopnaviwrapper").html());
                    document.title = $(data).find('span.pagetitle').text();
                    var result = $(data).find(".endnode").html();
                    if (result) {
                        $("#teamContainer").children().fadeOut("fast", function(){
                            $("#teamContainer").children().remove();
                            $("#teamContainer").append(result).children().hide().fadeIn("fast");
//                          $(".teamTiles div").setTeamTiles().scaleTileImages();
                            $(".teamTiles div").setTeamTiles();
                        });
                        if (_gaq._getAsyncTracker) pageTracker = _gaq._getAsyncTracker('')
                        if (pageTracker) pageTracker._trackPageview(link);
                    }
                    $('.shopnavi').showShopSubMenu();
                    $('.shopnavi').subMenuLinkTeam();

                }
            });

            return false;
        });
    }
}(jQuery));




/**
 * updates tiles after using the category filter
 */
(function($){
    $.fn.updateCollectionTiles = function(){
        return this.each(function(i){
            $(this).bind('click', function(e){
                $(".topiclink").addClass("actual");
                var link = $(this).attr("href");
                var label = $(this).text();
                $.ajax({
                    url: link,
                    type: 'GET',
                    dataType: 'html',
                    timeout: 3000,
                    error: function(){
                    },
                    success: function(data){
                        var newData = ($('<div>' + data + '</div>').find('.collectionTiles'));
                        $(".collectionTiles").children().fadeOut("fast", function(){
                            $(".collectionTiles").children().remove();
                            $(newData.html()).appendTo(".collectionTiles");
                            $(".collectionTiles div").setPriority();
                            $(".collectionTiles div").scaleTileImages();
                            $(".quicknavi .close").show();
                            $("#topiclink").text("\"" + label + "\"");
                        });
                    }
                });
                return false;
            });
        });
    }
}(jQuery));




/**
 * updates stage and stagecontrols when clicking products
 */
(function($){
    $.fn.updateStage = function(){
        return this.each(function(i){
            $(this).bind('click', function(e){
                if (!$(this).hasClass("active")) {
                    var $this = $(this);
                    var link = $(this).attr("href");
                    $(".stage").children().hide();
                    $(".stageArea .stage").children().remove();
                    $(".stageArea .stage").append($("<div class='loader'><div></div></div>"));
                    $.ajax({
                        url: link,
                        type: 'GET',
                        dataType: 'html',
                        async: false,
                        error: function(){
                        },
                        complete: function(xmlHttp, status){
                        },
                        success: function(data, status){
                        	var newData = ($('<div>' + data + '</div>').find('.stage').first());
                        	// play collection
                        	var customize = ($('<div>' + data + '</div>').find('.customize'));
	                        $(".customize").children().remove();
	                        $(".customize").append(customize.html()).children().hide().fadeIn("fast");
	                        $(".customize .colorWrapper a").updatePreviewAndStage();
                            if (newData.length > 0) {
                                $this.parents(".stageControls").children("div").children("a").removeClass("active");
                                $(".stageControls div a").removeClass("active");
                                $this.addClass("active");
                                setHash($this.attr("href"));
                                setPageParameters($(data).find('span.pagetitle').text(), link);

                                $(".stage").children().fadeOut("fast", function(){
                                    if (newData.children().length > 0) {
                                        $(".stageArea .stage").children().remove();
                                        $(".stageArea .stage").prepend(newData.children());
                                        $(".stage img").fadeIn();
                                        $(".stage span").fadeIn();
                                    }
                                });
								if (_gaq._getAsyncTracker) pageTracker = _gaq._getAsyncTracker('')
                        		if (pageTracker) pageTracker._trackPageview(link);
                            }
                            if ($('.property1').length > 0) {
                                $(".customize").css("min-height", "260px");
                            }
                            if ($('.property2').length > 0) {
                                $(".customize").css("min-height", "310px");
                            }
                            if ($('.property3').length > 0) {
                                $(".customize").css("min-height", "400px");
                            }
                            if ($('.property4').length > 0) {
                                $(".customize").css("min-height", "480px");
                            }
                            var colors = $('<div>' + data + '</div>').find('#color');
                            $("#color").children().remove();
                            $("#color").append(colors.html());
                            $("#color .colorWrapper a").updatePreviewAndStage();
                            $('.stage img').fadeIn();
                            $('.stage span').fadeIn();
                        }
                    });
                    return false;
                }
            });
        });
    }
}(jQuery));

/**
 * changes the stage image when clicking gallery pictures or pressimages
 */
(function($){
    $.fn.addImageToStage = function(){
        return this.each(function(i){
            $(this).bind('click', function(e){
                $this = $(this);
                if (!$this.hasClass("active")) {
                    $(".stageControls div a").removeClass("active");
                    $this.addClass("active");
                    if ($(".jquery-reel").length > 0) {
                        var stageImg = new Image();
                        $(stageImg).load(function(){
                            $(this).hide();
                            $(".stageArea .stage").children().remove();
                            $('<img/>', {
                               src: $this.attr("href")
                            }).appendTo('.stage').hide().fadeIn('fast');
                        }).attr("src", $this.attr("href"));
                    }
                    else {
                        $(".stage img").fadeOut("fast", function(){
                            $(".stage span").hide();
                            $(".stage img").attr("src", $this.attr("href")).fadeIn('fast');
                        });
                    }

					if (_gaq._getAsyncTracker) pageTracker = _gaq._getAsyncTracker('');


                    if ($this.hasClass('press')) {
                        if (pageTracker) pageTracker._trackEvent('Kollektion', 'Pressefreisteller', $this.children().attr('alt'));
                    }
                    else
                        if ($this.hasClass('reel')) {
                          if (pageTracker)  pageTracker._trackEvent('Kollektion', '360Grad', $this.children().attr('alt'));
                           }
                        else {
                        	if (pageTracker) pageTracker._trackEvent('Kollektion', 'Galerie', $this.children().attr('alt'));
                        }

                    return false;
                }
                else {
                    e.preventDefault();
                }
            });
        });
    }
}(jQuery));


/**
 * manage reel image for 360
 */
(function($){
    $.fn.addReelToStage = function(){
        return this.each(function(i){
            $(this).bind('click', function(e){
                $this = $(this);
                if (!$this.hasClass("active")) {
                    $(".stageControls div a").removeClass("active");
                    $this.addClass("active");
                    $(".stageArea .stage").children().remove();
                    $(".stageArea .stage").append($("<div class='loader'><div></div></div>"));
                    var reelImg = new Image();

                    $(reelImg).load(function(){
                        $.reel.instances= $(); // important clear reel instances
                        $(this).hide();
                        $(".stageArea .stage").children().remove();
                        $('<img/>', {
                            src: $this.attr("href"),
                            width: 715,
                            height: 472,
                            rel: $this.attr('rel')
                        }).appendTo('.stage').load(function(){
                            $(this).reel({
                                footage: 4,
                                frames: 32,
                                cw: true,
                                image: $this.attr('rel'),
                                suffix: ''
                            });
                        }).hide().fadeIn('fast');
                    }).attr('src', $this.attr('rel'));
                    return false;
                }
                else {
                    e.preventDefault();
                }
            });
        });
    }
}(jQuery));


/**
 * updates stage, stagecontrols, customize and moodboard when choosing a color
 */
(function($){
    $.fn.updatePreviewAndStage = function(){
        return this.each(function(i){
            $(this).hover(function(){
                this.oldTitle = $(this).parent().parent().parent().parent().find(".colorLabel").text();
                this.newTitle = $(this).attr("title");
                $(this).parent().parent().parent().parent().find(".colorLabel").text(this.newTitle);
                $(this).addClass("hover");
            }, function(){
                $(this).removeClass("hover");
                $(this).parent().parent().parent().parent().find(".colorLabel").text(this.oldTitle);
            });
            $(this).bind('click', function(e){
                if (!$(this).hasClass("active")) {
                    $(this).parents(".colorBlock").find(".colorWrapper").find("a").removeClass("active");
                    $(this).addClass("active");
                    setHash($(this).attr("href"));
                    var title = $(this).attr("title");
                    this.oldTitle = title;
                    $(this).parent().parent().parent().parent().find(".colorLabel").text(title);
                    var link = $(this).attr("href");
                    if ($(this).parents(".colorBlock").attr("id") != "color") {
                        var preview = $(this).attr("rel");
                        var image = $(this).parents(".colorBlock").attr("id");
                        $("." + image).fadeOut("fast", function(){
                            $(this).attr("src", preview).fadeIn("fast");
                        });
                    }

 					// propertytype: play collection
                    if ($("*[id^=propertytype]").length > 0 ) {
                    	$.ajax({
                            url: link,
                            type: 'GET',
                            dataType: 'html',
                            async: false,
                            error: function(){
                            },
                            success: function(data){
                                var stage = ($('<div>' + data + '</div>').find('.stage'));
                                var stageControls = ($('<div>' + data + '</div>').find('.stageControls'));
                                var plannerControls = ($('<div>' + data + '</div>').find('.plannerControls'));
                                var customize = ($('<div>' + data + '</div>').find('.customize'));
                                $(".customize").children().remove();
                                $(".customize").append(customize.html()).children().hide().fadeIn("fast");
                                $(".customize .colorWrapper a").updatePreviewAndStage();
                                setPageParameters($(data).find('span.pagetitle').text(), link);

                                // gallery or rotation is selected
                                if ($(".stageControls .gallery").prev("a.accordion").hasClass("active") || $(".stageControls .rotation").prev("a.accordion").hasClass("active")) {
                                    $(".plannerControls .products").remove();
                                    $(".stageControls .accordion").first().after(stageControls.children(".products"));
//                                    $(".products").first().children("a").randomizeOrder().scaleTileImages();
                                    setTimeout(function(){
                                        $(".products").first().hide(1, function(){
                                            $(".products").children("a.prod").updateStage();
                                            $(".products").children("a.press").addImageToStage();
                                            if ($(".stageControls .gallery").prev("a.accordion").hasClass("active")) {
                                                $(".gallery").children("a").first().click();
                                            }
                                            else {
                                                $(".rotation").children("a").first().click();
                                            }
                                        });
                                    }, 10);
                                }
                                // products are selected
                                else {
                                    $(".stage").children().first().fadeOut("fast", function(){
                                        $(".stageArea .stage").children().remove();
                                        $(".stageArea .stage").append(stage.html()).children().hide().fadeIn("fast");

                                    });
                                }
                            }
                        });
                    }

                    if ($(this).parents(".colorBlock").attr("id") == "color") {
                        /*if (!$(".stageControls .gallery").prev("a.accordion").hasClass("active")) {
                         $(".stage").children().hide();
                         $(".stageArea .stage").children().remove();
                         $(".stageArea .stage").append($("<div class='loader'><div></div></div>"));
                         }*/
                        $.ajax({
                            url: link,
                            type: 'GET',
                            dataType: 'html',
                            async: false,
                            error: function(){
                            },
                            success: function(data){
                                var stage = ($('<div>' + data + '</div>').find('.stage'));
                                var stageControls = ($('<div>' + data + '</div>').find('.stageControls'));
                                var customize = ($('<div>' + data + '</div>').find('.customize'));
                                $(".customize").children().remove();
                                $(".customize").append(customize.html()).children().hide().fadeIn("fast");
                                $(".customize .colorWrapper a").updatePreviewAndStage();
                                setPageParameters($(data).find('span.pagetitle').text(), link);

                                // gallery or rotation is selected
                                if ($(".stageControls .gallery").prev("a.accordion").hasClass("active") || $(".stageControls .rotation").prev("a.accordion").hasClass("active")) {
                                    $(".stageControls .products").remove();
                                    $(".stageControls .accordion").first().after(stageControls.children(".products"));
//                                    $(".products").first().children("a").randomizeOrder().scaleTileImages();
                                    setTimeout(function(){
                                        $(".products").first().hide(1, function(){
                                            $(".products").children("a.prod").updateStage();
                                            $(".products").children("a.press").addImageToStage();
                                            if ($(".stageControls .gallery").prev("a.accordion").hasClass("active")) {
                                                $(".gallery").children("a").first().click();
                                            }
                                            else {
                                                $(".rotation").children("a").first().click();
                                            }
                                        });
                                    }, 10);
                                }
                                // products are selected
                                else {
                                    $(".stage").children().first().fadeOut("fast", function(){
                                        $(".stageArea .stage").children().remove();
                                        $(".stageArea .stage").append(stage.html()).children().hide().fadeIn("fast");
                                        $('.stage span').fadeIn();

                                        $(".stageControls").children().fadeOut("fast", function(){
                                            $(".stageControls").children().remove();
                                            $(".stageControls").append(stageControls.html()).children().hide().fadeIn("fast");
//                                            $(".products").first().children("a").randomizeOrder().scaleTileImages();
                                            setTimeout(function(){
                                                $(".products").first().children("a.prod").updateStage().bind("click", function(e){
                                                    e.preventDefault();
                                                }).toggleProductImages();
                                                $(".products").first().children("a.press").addImageToStage().bind("click", function(e){
                                                    e.preventDefault();
                                                }).toggleProductImages();
                                                var ac = false;
                                                $(".products").first().children("a").each(function(){
                                                    if ($(this).hasClass("active"))
                                                        ac = true;
                                                });
                                                if (!ac)
                                                    $(".products").first().children("a").first().addClass("active");
                                            }, 100);
//                                          $(".gallery").first().children("a").randomizeOrder().scaleTileImages().addImageToStage().toggleGalleryImages();
//                                          $(".rotation").first().children("a").randomizeOrder().scaleTileImages().addReelToStage().toggleRotationImages();
                                            $(".gallery").first().children("a").addImageToStage().toggleGalleryImages();
                                            $(".rotation").first().children("a").addReelToStage().toggleRotationImages();
                                            if ($(".products").first().children("a").length == 0)
                                                $(".products").prev().css("background", "0 none");
                                            if ($(".gallery").first().children("a").length == 0)
                                                $(".gallery").prev().css("background", "0 none");
                                            if ($(".rotation").first().children("a").length == 0)
                                                $(".rotation").prev().css("background", "0 none");
                                            $(".accordion").slideBoxes();
                                            if ( $(".stageControls").hasClass("moreLink") ) {
                                            	$(this).moreLink();
                                            }
                                        });
                                    });
                                }
                            }
                        });
                    }
					if (_gaq._getAsyncTracker) pageTracker = _gaq._getAsyncTracker('')
                    if (pageTracker) pageTracker._trackEvent($('.stage span.producttext').text(), $(this).parents(".colorBlock").attr("id"), title);

                }
                return false;
            });

        });
    }
}(jQuery));

/**
 * shows more link in accordion (collection detailpage)
 */
(function($){
    $.fn.moreLink = function(){
		$(".accordion").removeClass("active");
		$(".gallery").css('display', 'block');
		$(".products").css('display', 'block');
		$(".stageControls").addClass("moreLink");
		var oldHeight = $(".products").height();
		$(".products").attr('rel', oldHeight);
	  if($(".products a").length > 6) {
	    $(".products a:nth-child(6)").nextAll("a").hide();;
			$(".products").append("<span class='prodToggle'>MORE</span>");
  		$(".products").css('height', '100px');
		}
		var oldHeight = $(".gallery").height();
		$(".gallery").attr('rel', oldHeight);
    if($(".gallery a").length > 6) {
  		$(".gallery a:nth-child(6)").nextAll("a").hide();
			$(".gallery").append("<span class='galToggle'>MORE</span>");
    	$(".gallery").css('height', '100px');
		}
		$("span.prodToggle").toggleProductImages();
		$("span.galToggle").toggleGalleryImages();
	}
}(jQuery));

/**
 * show color titles and update stage
 */
(function($){
    $.fn.updateTitlesAndStage = function(){
        return this.each(function(i){
            $(this).hover(function(){
                this.oldTitle = $(this).parent().parent().parent().parent().find(".colorLabel").text();
                this.newTitle = $(this).attr("title");
                $(this).parent().parent().parent().parent().find(".colorLabel").text(this.newTitle);
                $(this).addClass("hover");
            }, function(){
                $(this).removeClass("hover");
                $(this).parent().parent().parent().parent().find(".colorLabel").text(this.oldTitle);
            });
            $(this).bind('click', function(e){
                if (!$(this).hasClass("active")) {
                    $this = $(this);
                    $(this).parents(".colorBlock").find(".colorWrapper").find("a").removeClass("active");
                    $(this).addClass("active");
                    var title = $(this).attr("title");
                    this.oldTitle = title;
                    $(this).parent().parent().parent().parent().find(".colorLabel").text(title);
                    $(".stage img").fadeOut("fast", function(){
                        $(".stage img").attr("src", $this.attr("rel"));
                        $(".stage img").fadeIn("fast");
                    });
                }
                return false;
            });
        });
    }
}(jQuery));


/**
 * fade-in the page after loading
 */
(function($){
    $.fn.pageFadeIn = function(){
        $('#content').css({
            opacity: 0
        })
        $('#content').animate({
            opacity: 1
        }, 800);
    }
}(jQuery));

/**
 * Showrooms slideshow
 */
(function($){
    $.fn.slideshow = function(options){
        var opts = $.extend({
            slideKey: 1,
            slideDelay: 0
        }, options);

        window.clearTimeout(opts.slideDelay);

        function runSlideshow(slideKey){
            var slideImg = new Image();
            /*if (opts.slideDelay == 0) {
             clearTimeout(opts.slideDelay);
             }*/
            opts.slideDelay = setTimeout(function(){
                opts.slideDelay = 0;
                $(slideImg).load(function(){
                    $(this).hide();
                    $('.srImg img').fadeTo('slow', 0, function(){
                        $('.srImg img').remove();
                        $('.srImg').append($(slideImg));
                        $(slideImg).fadeTo('slow', 1);
                    });
                }).attr('src', opts.slideImages[slideKey]);
                slideKey++;
                if (slideKey == opts.slideImages.length) {
                    slideKey = 0;
                }
                runSlideshow(slideKey);
            }, 4000);
        }
        runSlideshow(opts.slideKey);
    }
}(jQuery));


/**
 * teaser rotation for webspecial teaser on startpage
 */
(function($){
    $.fn.initTeaserRotation = function(){
        countTeaser = $(".t8").hide().size();
        $(".t8:eq(" + currentTeaser + ")").show();
        if (countTeaser > 1)
            setInterval(rotateTeaser, 4000);
    }
})(jQuery);

/**
 * teaser rotation core function
 */
function rotateTeaser(){
    oldTeaser = currentTeaser % countTeaser;
    newTeaser = ++currentTeaser % countTeaser;
    $(".t8:eq(" + newTeaser + ")").fadeIn("slow", function(){
        $(".t8:eq(" + oldTeaser + ")").fadeOut("slow");
    });
}

/**
 * set the priority and direction of the tiles on the collection page
 */
(function($){
    $.fn.setPriority = function(){
        var z = 8000;
        var count = this.length;
        return this.each(function(i){
            var $this = $(this);
            $this.css('position', 'absolute').css("z-index", z);
            if ($this.prev().length != 0) {
                var posTop = (Math.floor(i / 4) * ($this.height() + 5)) + (Math.floor(i % 2) * 15);
                var posLeft = (Math.floor(i % 4) * ($this.width() + 5)) + (Math.floor(i % 8 / 4) * 17);
                $this.css("top", posTop).css("left", posLeft);
            }
            else {
                $this.css("left", 0).css("top", 0);
            }
            z--;
            if (i == count - 1)
                $this.parent().height($this.position().top + $this.height());
        });
    };
})(jQuery);

/**
 * preload collection category images
 */
(function ($) {
	$.preLoadCatImages = function(imageList,callback) {
		var pic = [], i, total, loaded = 0;
		if (typeof imageList != 'undefined') {
			if ($.isArray(imageList)) {
				total = imageList.length; // used later
					for (i=0; i < total; i++) {
						pic[i] = new Image();
						pic[i].onload = function() {
							loaded++; // should never hit a race condition due to JS's non-threaded nature
							if (loaded == total) {
								if ($.isFunction(callback)) {
									callback();
								}
							}
						};
						pic[i].src = imageList[i];
					}
			}
			else {
				pic[0] = new Image();
				pic[0].onload = function() {
					if ($.isFunction(callback)) {
						callback();
					}
				}
				pic[0].src = imageList;
			}
		}
		pic = undefined;
	};
})(jQuery);

/**
 * set the priority and direction of the tiles on the collection category page
 */
(function($){
    $.fn.setPriority2 = function(){
//      var z = 5000;
        var count = this.length;
        var zeile = 0;
        var position = 0;
        var posTopAdd = 0;
        if($("html").hasClass("ie7")) {
            this.each( function(i) {
                var $this = $(this);
                var minWidth = 0;
                $this.children('a').each( function(c) {
                    minWidth += $(this).width();
                });
                if (minWidth > 960) {
                    minWidth = 960;
                }
                $this.css({
                    minWidth: minWidth+'px'
                });
            });
        }

        return this.each(function(i){
            var $this = $(this);
            var posTop = $this.position().top;
            var posLeft = $this.position().left;
            position++;
            if(posLeft==0){
            	zeile++;
            	position=0;
            }
            if($("html").hasClass("ie7") && posTopAdd == 0 && posTop < 0) {
              posTopAdd = Math.abs(posTop);
            }
            posTop += posTopAdd;

            posTop += (position%1) * 10 + ((zeile-1)*12) ;
            posLeft += (position*15) + (0-(zeile%1)*10) ;
//          $this.css("z-index", z).css("left", posLeft).css("top", posTop);
            $this.css("left", posLeft).css("top", posTop).width($this.width()+1);
//          z--;
            if (i == count - 1)
                $this.parent().height(posTop+($this.height()));
        });
    };
})(jQuery);

/**
 * set the priority and direction of the images of the collection thumbs
 */
(function($){
    $.fn.randomizeOrder = function(){
        var z = 8000;
        var count = this.length;
        return this.each(function(i){
            var $this = $(this);
            $this.css('position', 'absolute').css("z-index", z);
            var posTop = 0;
            var posLeft = 0;
            if ($this.prev().length != 0) {
                posTop = Math.floor(i / 3) * $this.height() + Math.floor(i / 3) * 7;
                posLeft = Math.floor(i % 3) * $this.width() + Math.floor(i % 3) * 2;
                $this.css("top", posTop).css("left", posLeft);
                if (i > 2) {
                    posLeft = posLeft + 2;
                }
                if (i % 3 - 1 == 0)
                    $this.css("top", posTop + 7);
                if (i % 3 - 2 == 0)
                    $this.css("top", posTop + 14);
            }
            else {
                $this.css("left", 0).css("top", 0);
            }
            z--;
            if (i == count - 1) {
                $this.parent().height($this.position().top + $this.height());
            }
        });
    };
})(jQuery);

/**
 * set the priority and direction of the tiles on the "DEDON Team" page
 */
/*(function($){
    $.fn.setTeamTiles = function(){
        var z = 8000;
        var x = 2;
        var count = this.length;
        return this.each(function(i){
            var $this = $(this);
            $this.css('position', 'absolute').css("z-index", z);
            if ($this.prev().length != 0) {

                if (i % 5 == 0)
                    x = 3;

                var posTop = (Math.floor(i / 5) * ($this.height() + 30)) + (Math.floor(i % x) * 15) + (Math.floor(i % 6 / 5) * 10);
                var posLeft = (Math.floor(i % 5) * ($this.width() + 8)) + (Math.floor(i % 10 / 5) * 30);
                $this.css("top", posTop).css("left", posLeft);
            }
            else {
                $this.css("left", 0).css("top", 0);
            }
            z--;
            if (i == count - 1)
                $this.parent().height($this.position().top + $this.height());
        });
    };
})(jQuery);*/
(function($){
    $.fn.setTeamTiles = function(){
      return this.each(function(i){
        var pos = i+1;
        if (pos%5 == 0) {
          $(this).css({marginRight: 0});
        }
        /*$img = $(this).children('img:first');
        $img.newWidth = 225;
        $img.oldWidth = $img.width();
        $img.oldHeight = $img.height();
        $img.scaleFactor = $img.newWidth / $img.oldWidth;
        console.log($img.scaleFactor);
        $img.newHeight = Math.round($img.oldHeight*$img.scaleFactor);

        $(this).width($img.newWidth);
        $(this).height($img.newHeight);
        $img.width($img.newWidth);
        $img.height($img.newHeight);

        if (i+1 % 4 == 0) {
          $(this).css({marginRight: 0});
        }*/
      });
    };
})(jQuery);

/**
 * scale tile images on the collection page
 */
(function($){
    $.fn.scaleTileImages = function(){
        return this.each(function(i){
            var $this = $(this);
            $this.hover(function(e){
                if (!$this.hasClass("hover")) {
                    this.newMargin = -($this.width() / 100 * 2);
                    this.oldHeight = $this.height();
                    this.newHeight = this.oldHeight / 100 * 110;
                    this.oldWidth = $this.width();
                    this.newWidth = this.oldWidth / 100 * 110;
                    this.oldZindex = $this.css('z-index');
                    this.oldZindex2 = $this.parents("div").first().css('z-index');
                    $(this).addClass("hover");
                }
                $this.stop().animate({
                    marginLeft: this.newMargin,
                    marginTop: this.newMargin,
                    width: this.newWidth,
                    height: this.newHeight
                }, 150, function() {
//                	if (!$("#companyindex").length > 0) {
//                		$(this).children("a").children("img").attr('src', $this.children("a").attr("rel"));
//                	}
                });
                $this.css({
                    'z-index': '8000'
                });
//                if ($("#companyindex").length > 0)
//                    $this.parents("div").first().css({
//                        'z-index': '80'
//                    });
                if ($("#collectionContainer").length > 0)
                 	this.oldZindexTeaser = $this.parents("h2").first().css('z-index');
                    $this.parents("h2").first().css({
                        'z-index': '80'
                    });
            }, function(e){
                $this.css({
                    'z-index': this.oldZindex
                });
//                if ($("#companyindex").length > 0)
//                    $this.parents("div").first().css({
//                        'z-index': this.oldZindex2
//                    });
                if ($("#collectionContainer").length > 0)
                    $this.parents("h2").first().css({
                        'z-index': this.oldZindexTeaser
                    });
                if ($this != undefined)
                    $this.animate({
                        marginLeft: '0',
                        marginTop: '0',
                        width: this.oldWidth,
                        height: this.oldHeight
                    }, 150, function() {
                    	if (!$("#companyindex").length > 0) {
                    		$(this).children("a").children("img").attr('src', $this.children("a").children("span").attr("rel"));
                    	}
                    });
            });
        });
    };
}(jQuery));


/**
 * scale tile images on the collection category page
 */
(function($){
    $.fn.scaleCatTileImages = function(){
        return this.each(function(i){
            var $this = $(this);
            $this.hover(function(e){
                if (!$this.hasClass("hover")) {
                    this.newMargin = -5;
                    this.oldHeight = $this.height();
                    if (this.oldHeight == 130) {
                        this.newHeight = this.oldHeight / 100 * 110;
                    }
                    if (this.oldHeight == 135) {
                        this.newHeight = this.oldHeight / 100 * 110;
                    }
                    else {
                        this.newHeight = this.oldHeight / 100 * 107;
                    }

//                  this.oldWidth = $this.width();
                    this.oldWidth = $this.width() + 1;
                    this.newWidth = this.oldWidth / 100 * 105;
                    this.oldZindex = $this.css('z-index');


                    $(this).addClass("hover");
	                $this.stop().animate({
	                    marginLeft: this.newMargin,
	                    marginTop: this.newMargin,
	                    width: this.newWidth,
	                    height: this.newHeight
	                }, 150);

	                $this.children('a').children('img').each(function(){
	                	var obj = $(this);
	                	this.ow = $(this).width();
	                	this.oh = $(this).height();
	                	$(this).stop().animate({
	                        width: obj.width() / 100 * 104,
	                        height: obj.height() / 100 * 104
	                    }, 150, function() {
	                        $(this).addClass("hover");
	                    });
	                });
	                $this.css({
	                    'z-index': '8000'
	                });
                }
            }, function(e){
                $this.css({
                    'z-index': this.oldZindex
                });
                if ($this != undefined)
                    $this.children('a').children('img').each(function(){
                    	$(this).stop().animate({
                            width: this.ow,
                            height: this.oh
                        }, 150);
                    });

                    $this.animate({
                        marginLeft: '0',
                        marginTop: '0',
                        width: this.oldWidth,
                        height: this.oldHeight
                    }, 150, function() {
                        $(this).removeClass("hover");
                    });

            });
        });

    };
}(jQuery));


/**
 * scale tile images on the collection category page
 */
(function($){
    $.fn.scaleCatTileImagesMeasures = function(){
        return this.each(function(i){
            var $this = $(this);
            $this.hover(function(e){
                if (!$this.hasClass("hover")) {
                    this.oldZindex = $this.css('z-index');
                    $(this).addClass("hover");
                }
        		$(this).parent('a').children("img").attr('src', $this.parent("a").attr("rel"));


            }, function(e){
                $this.css({
                    'z-index': this.oldZindex
                });

                if ($this != undefined)
                        $(this).removeClass("hover");
        				$(this).parent('a').children("img").attr('src', $this.parent("a").children("span").attr("rel"));

            });
        });
    };
}(jQuery));




/**
 * toggle accordion
 */
(function($){
    $.fn.slideBoxes = function(){
        return this.each(function(i){
            if (!$(this).hasClass("active")) {
                $(this).next("div").hide();
            }
            $(this).click(function(e){
            	e.preventDefault();
                if (!$(this).hasClass("active")) {
                    $this = $(this);

                    if ($(".stageControls").hasClass("moreLink")) {
                    	var prods = $(".products");
                    	var gal = $(".gallery");
						var oldHeightProd = prods.attr("rel") + "px";
						prods.hide().css("height", oldHeightProd);
						var oldHeightGal = gal.attr("rel") + "px";
						gal.hide().css("height", oldHeightGal);
						if ($(".prodToggle").length > 0) {
							$(".prodToggle").hide();
							$(".products a:nth-child(6)").nextAll("a").show();
	            		}
						if ($(".galToggle").length > 0) {
							$(".galToggle").hide();
							$(".gallery a:nth-child(6)").nextAll("a").show();
	            		}
						$(".stageControls").removeClass("moreLink");
                    }

                    $(".accordion").next().slideUp("fast");
                    $(".accordion").removeClass("active");
                    $(this).next().delay(200).slideDown("slow", function(){
                        $this.next().children("a").first().click();
                        $(".gallery").css("visibility", "visible");
                        $(".products").css("visibility", "visible");
                    });
                    $(this).addClass("active");
                    if ($(this).next().hasClass("gallery")) {
                        $(".stage span").hide();
                    }
                }
                return false;
            });
        });
    };
}(jQuery));





function initMetaLayerScrollPane(oid){
    $(oid).jScrollPane({
        showArrows: true,
        arrowSize: 20,
        scrollbarWidth: 14,
        dragMinHeight: 14,
        scrollbarMargin: 20
    });
}

/* Social Media - Facebook / Twitter */

function connectFacebook(){
    $("#connectLogin").html('<div class="connectLoggedIn clear"><fb:profile-pic uid="loggedinuser" size="square" facebook-logo="true"></fb:profile-pic><ul><li><span><fb:name uid="loggedinuser" useyou="false" linked="false"></fb:name></span></li><li><a href="#" onclick="logoutFacebook(); return false;" class="logout">Log out</a></li></ul></div>');
    $("#connectLogin").removeClass("connectLogin");

    $('#li_commentauthor').html('<input type="hidden" name="tx_t3blog_pi1[blogList][facebookUser]" value="' + FB.Facebook.apiClient.get_session().uid + '" />');
    $('#li_commentauthoremail').html('');
    FB.XFBML.Host.parseDomTree();
}

function logoutFacebook(){
    FB.Connect.logout();
    $("#connectLogin").html('<p>Comment as guest or login below.</p><ul class="clear"><li><a href="#" onclick="FB.Connect.requireSession(); return false;" class="facebookConnect"><span>Connect with Facebook</span></a></li><li><a href="#" onclick="connectTwitter(); return false;" class="twitterConnect">Sign in with Twitter</a></li></ul>');
    $("#connectLogin").addClass("connectLogin");

    $('#li_commentauthor').html('<div class="clear"><input type="text" id="commentauthor" title="Name" class="text displace" name="tx_t3blog_pi1[blogList][commentauthor]" value="Name" /></div>');
    $('#li_commentauthoremail').html('<div class="clear"><input type="text" title="Email (will not be shown)" class="text displace" name="tx_t3blog_pi1[blogList][commentauthoremail]" value = "Email (will not be shown)" /></div>');
    FB.XFBML.Host.parseDomTree();
}

function connectTwitter(){
    var url = '/index.php?eID=twitterconnect&url=' + window.location;
    window.location = url;
}

function logoutTwitter(){
    $('#socialLogin').load('/index.php?eID=twitterlogout');
    $('#li_commentauthor').html('<div class="clear"><input type="text" id="commentauthor" title="Name" class="text displace" name="tx_t3blog_pi1[blogList][commentauthor]" value="Name" /></div>');
    $('#li_commentauthoremail').html('<div class="clear"><input type="text" title="Email (will not be shown)" class="text displace" name="tx_t3blog_pi1[blogList][commentauthoremail]" value = "Email (will not be shown)" /></div>');
}

function setPageParameters(title, link){
    document.title = title;
    $(".addthis_toolbox div a").attr("addthis:url", "http://www.dedon.de/" + link);
    $(".addthis_toolbox div a").attr("addthis:title", link);
    if (window.addthis) {
        window.addthis.ost = 0;
        window.addthis.ready();
    }
}

// Redirect the page if Hash is given
function redirectHash(){
    var hash = window.location.hash;
    if (hash) {
        hash = hash.substr(1);
        var path = window.location.pathname;
        var ext = path.substr(path.lastIndexOf('.'));
        path = path.substr(0, path.lastIndexOf('/'));
        path = path.substr(0, path.lastIndexOf('/') + 1);
        path = path + hash + ext;
        window.location.href = path;
    }
}

// Extract Hash from URL
function setHash(url){
    var path = url;
    path = path.substr(0, path.lastIndexOf('/'));
    path = path.substr(0, path.lastIndexOf('/'));
    window.location.hash = url.substr(path.length + 1, url.lastIndexOf('.') - (path.length + 1));
}

/* GoogleMaps for shops */
var apikey_dev = "ABQIAAAApy5xfn5SOY98AP3mOFGM4BRdDPip7q9ghW7JFjBZtK4pDnLLghQOvdPR7_Grmit-msuu6MQGM_PZtQ";
var apikey_prod = "ABQIAAAApy5xfn5SOY98AP3mOFGM4BRSBUIQ-Q0FHvVTyQzEZGWvUIy_YRSODLf8pYd6F-TFK00x-58m4J9U3Q";
var apikey = (window.location.href.indexOf("www.dedon.de") == -1) ? apikey_dev : apikey_prod;
var address;
var geolocation;

function initLoader(obj){
    var adr = $(obj).parents(".vcard").find(".adr");
    var arrAdr = new Array($(adr).children(".street-address").html(), $(adr).children(".postal-code").text(), $(adr).children(".locality").text(), $(adr).children(".country-name").text());
    address = $(obj).parents(".vcard").find(".fn.org").text() + '<br />' + arrAdr[0] + '<br />' + arrAdr[1] + ' ' + arrAdr[2];
    var geo = $(obj).parents(".vcard").find(".geo");
    if (geo.length > 0) {
        geolocation = $(geo).children(".latitude").text() + "," + $(geo).children(".longitude").text();
    }
    else {
        geolocation = arrAdr.join(' ');
    }
    var script = document.createElement("script");
    script.src = "http://maps.google.com/maps/api/js?sensor=false&key=" + apikey + "&callback=loadMaps";
    script.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(script);
}

function loadMaps(){
    geocoder = new google.maps.Geocoder();
    geocoder.geocode({
        'address': geolocation
    }, function(results, status){
        if (status == google.maps.GeocoderStatus.OK) {
            var myOptions = {
                zoom: 13,
                center: results[0].geometry.location,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
            var infowindow = new google.maps.InfoWindow({
                content: address
            });

            var marker = new google.maps.Marker({
                position: results[0].geometry.location,
                map: map
            });
            google.maps.event.addListener(marker, 'click', function(){
                infowindow.open(map, marker);
            });
            infowindow.open(map, marker);
        }
        else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
        	$("#map_canvas").replaceWith('<div id="map_canvas"><p>An error occurred. The address could not be found on Google Maps.</p></div>');
        }
    });
}

/**
 * newsletter subscription form
 */
(function($){
    $.fn.newsletterForm = function(){

        // --- behavior
        $('select[name=country]').change(function(){
        	if ( $(this).val() == "Vereinigte Staaten von Amerika" || $(this).val() == "United States of America" || $(this).val() == "�tats-Unis" || $(this).val() == "Stati Uniti d'America" || $(this).val() == "Estados Unidos" ) {
        			$('#selectstate').css('display', 'block');
        	}
        	else {
        		$('#selectstate').css('display', 'none');
        	}
        });
        $('.checkboxfake').css('display', 'block');
        $('.input-check').css('display', 'none');
        $('.checkboxfake').click(function(){
            if ($(this).hasClass("off")) {
                // radiobox behavior for checkboxgroup
                if ($(this).prev().attr('name') == 'newslettertype') {
                    $('input[name=newslettertype]').attr('checked', false);
                    $('input[name=newslettertype]').next().removeClass("on").addClass("off");
                }
                $(this).addClass("on").removeClass("off").prev().attr('checked', true);
            }
            else {
                $(this).addClass("off").removeClass("on").prev().attr('checked', false);
            }
        });
        $('.nlsubscr .input-text').toggleValue();

        // --- validation
        var action = $('.nlsubscr').attr('action');
        // custom method making the default values invalid
        jQuery.validator.addMethod("defaultInvalid", function(value, element){
            return value != element.defaultValue;
        }, "");
        jQuery.validator.messages.required = "";

        $(".nlsubscr").validate({
            invalidHandler: function(e, validator){
                var errors = validator.numberOfInvalids();
                if (errors) {
                    $("p.catalogintro").html($("span.errortext").text());
                    $("p.catalogintro").addClass('errormsg');
                }
            },
            errorPlacement: function(error, element){
            },
            submitHandler: function(form){
                var dataString = $(form).serialize();
                $.ajax({
                    type: 'POST',
                    url: action,
                    data: dataString,
                    success: function(data){
                        var result = $(data).find("#metaContent").html();
                        $("#nyroModalContent").children().fadeOut("fast", function(){
                            $("#nyroModalContent").children().remove();
                            $("#nyroModalContent").append(result).children().hide().fadeIn("fast");
                        });
                    }
                });
            }
        });
    }
}(jQuery));


/**
 * catalog order form
 */
(function($){
    $.fn.catalogForm = function(){
        // --- behavior
        $('select[name=country]').change(function(){
        	if ( $(this).val() == "Vereinigte Staaten von Amerika" || $(this).val() == "United States of America" || $(this).val() == "�tats-Unis" || $(this).val() == "Stati Uniti d'America" || $(this).val() == "Estados Unidos" ) {
        			$('#selectstate').css('display', 'block');
        	}
        	else {
        		$('#selectstate').css('display', 'none');
        	}
        });
        $('.checkboxfake').css('display', 'block');
        $('.input-check').css('display', 'none');
        if($('span.contract').length > 0){
        	$('input#catalog-arc').next().addClass("on").removeClass("off").prev().attr('checked', true);
        	$('.catalogcover img').attr('src', 'fileadmin/blogazine/html/_img/contract_catalog_cover.jpg');
        }
        $('.checkboxfake').click(function(){
            if ($(this).hasClass("off")) {
                // radiobox behavior for checkboxgroup
                if ($(this).prev().attr('name') == 'catalogtype') {
                    $('input[name=catalogtype]').attr('checked', false);
                    $('input[name=catalogtype]').next().removeClass("on").addClass("off");
                }
                $(this).addClass("on").removeClass("off").prev().attr('checked', true);
            }
            else {
                $(this).addClass("off").removeClass("on").prev().attr('checked', false);
            }
        });
        $('#ordercatalog .input-text').toggleValue();

        // --- validation
        var action = $('#ordercatalog').attr('action');
        var defaultPobox = $('#pobox').attr('value');
        // custom method making the default values invalid
        jQuery.validator.addMethod("defaultInvalid", function(value, element){
            return value != element.defaultValue;
        }, "");
        // custom method making street and number invalid if PO Box is not filled
        jQuery.validator.addMethod("adressInvalid", function(value, element){
            if ($("#pobox").val() == defaultPobox || $("#pobox").val() == '')
                return value != element.defaultValue;
            return true;
        }, "");
        jQuery.validator.messages.required = "";

        $("#ordercatalog").validate({
            invalidHandler: function(e, validator){
                var errors = validator.numberOfInvalids();
                if (errors) {
                    $("p.catalogintro").html($("span.errortext").text());
                    $("p.catalogintro").addClass('errormsg');
                }
            },
            errorPlacement: function(error, element){
            },
            submitHandler: function(form){
                var dataString = $(form).serialize();
                $.ajax({
                    type: 'POST',
                    url: action,
                    data: dataString,
                    success: function(data){
                        var result = $(data).find("#metaContent").html();
                        $("#nyroModalContent").children().fadeOut("fast", function(){
                            $("#nyroModalContent").children().remove();
                            $("#nyroModalContent").append(result).children().hide().fadeIn("fast");
                        });
                    }
                });
            }
        });
    }
}(jQuery));


/**
 * toggle defaulttext in input fields
 */
(function($){
    $.fn.toggleValue = function(){
        $(this).focus(function(){
            return $(this).each(function(){
                var defaultText = $(this).attr('title');
                if ($(this).val() == defaultText) {
                    $(this).val('');
                }
                $(this).blur(function(){
                    if ($.trim($(this).val()) == '') {
                        $(this).val(defaultText);
                    }
                });
            });
        });
    }
}(jQuery));

(function($){
    var cache = [];
    $.preLoadImages = function(){
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery);



$(window).load(function(){

	$(".collectionCatTiles .tileWrapper").setPriority2();
	$(".collectionCatTiles .tileWrapper").css("position", "absolute");
   	$(".collectionCatTiles .tileWrapper").scaleCatTileImages();
   	$(".collectionCatTiles .tileWrapper a img").scaleCatTileImagesMeasures();

    if($('#playGalleryImage img').length > 0){
	  	if (document.getElementById("galleryFadeImg").complete == true) {
	  		$('.loader').remove();
	  		$('#playGalleryImage img').first().fadeIn('fast', function(){
	  			$('.stage span').show();
	  			$('.stage img').first().show();
	  			$('#playGalleryImage').delay(5000).fadeOut(2000);
	  		});
		}
    }

}); //end (window).load

$(document).ready(function(){

	$(".stageControls").fadeIn('slow',function() {
		$(this).css("visibility", "visible");
	});

	// set first value to empty see: function initOverLabels()
	$('#tx-srfeuserregister-pi1-tx_dedonpressdb_projectsspecialisation option:first').val('');
	$('#tx-srfeuserregister-pi1-tx_dedonpressdb_contractsfocus option:first').val('');
	$('#tx-srfeuserregister-pi1-tx_dedonpressdb_jobtitle option:first').val('');

	// set document title on team pages
	$('#shopnavicontainer .shopnaviwrapper span.pagetitle').each( function(){
		if ($('#teamContainer')) document.title = $(this).text();
	});

    if ($("#tx-srfeuserregister-pi1-tx_dedonpressdb_acceptprivacy").attr('checked') == true) {
    	$("#tx-srfeuserregister-pi1-tx_dedonpressdb_acceptprivacy").parent().children(".checkboxfake").addClass("on").removeClass("off")
    }
    $("#tx-srfeuserregister-pi1-tx_dedonpressdb_acceptpurpose").attr('checked', true).parent().find("*").hide();
	$("#tx-srfeuserregister-pi1-email").keyup(function () {
	    var value = $(this).val();
	    $("#tx-srfeuserregister-pi1-username").val(value);
	  }).keyup();

	if($("#pressContainer.article").length > 0) {
		loadNextPage();
	}
	if ($("span.info a").length > 0) {
		$("span.info a").addClass("floatBoxPress").each(function(){
			var u = $(this).attr("href");
			$(this).attr("href", u + "#metaContent");
		});
	}

    if($('#playGalleryImage img').length > 0){
    	$('#playGalleryImage img').attr('id', 'galleryFadeImg');
    	$('.stage span').hide();
    	$('.stage img').hide();
    	$(".stageArea .stage").append($("<div class='loader'><div></div></div>"));
    	$('.loader').hide().delay(500).fadeIn('fast');
    } else {
    	$('.stage img').first().fadeIn('fast');
    	$('.stage span').first().fadeIn('fast');
    }


//	if ($(".imageTitle img").css('height','42px')) {
//	       $(".imageTitleWrapper").css("margin-top", "20px");
//	}
	if ($("#aboutContainer").length > 0) {
		$("a.readMoreToggle").toggleArticle();
	}
	/*
    if ($('#sitetools').length > 0 && !$('#pressContainer').length > 0) {
        $("#content").css("padding-top", "120px");
    }
    if ($('#pressContainer').length > 0 && $('#sitetools').length > 0) {
        $("#content").css("padding-top", "0px");
    }
    if ($('#pressContainer .collectionDetail').length > 0 && $('#sitetools').length > 0) {
        $("#content").css("padding-top", "0px");
    }
    if ($('#pressContainer').length > 0 && !$('#sitetools').length > 0) {
        $("#content").css("padding-top", "0px");
    }
    */
    if ($('.property2').length > 0) {
        $(".customize").css("min-height", "310px");
    }

    // todo: bezieht sich derzeit noch auf alle imageTitleWrapper
    if ($('.imageTitle a img').has('height="42"')) {
       $('.imageTitleWrapper').css("min-height", "57px");
    }

    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
    }
    else {
        // if (!$.browser.msie)
        //     $('#wrapper').pageFadeIn();
     	$('a.floatBox, a.floatBoxPress').each(function(i,el){

    				// Standard-Einstellungen
    		        var defaultWidth = 685;
    		        var defaultHeight = 398;

    		        var width = defaultWidth;
    		        var height = defaultHeight;

    		        // können über rel-Attribut im Link überschrieben werden, z.b. <a href='#' rel="width=300,height=400">
    		        var rel = $(el).attr('rel');
    		        $(el).removeAttr('rel');
    		        var relVar = [];
    		        var tmp;
    		        if (rel){
    		            rel = rel.split(',');
    		            for(var i = 0; i < rel.length; i++)
    		            {
    		                tmp = rel[i].split('=');
    		                relVar.push(tmp[0]);
    		                relVar[tmp[0]] = tmp[1];
    		            }

    		            if(relVar['height'])
    		                height = relVar['height'];
    		            if(relVar['width'])
    		                width = relVar['width'];
    		        }

		        $(el).nyroModal({
		            bgColor: '#fff',
		            width: width,
		            height: height,
		            padding: 15,
		            windowResize: false,
		            endShowContent: function(){
		        		if (height != defaultHeight) // bei abweichender Höhe
		        			$('#nyroModalWrapper #scrollerContent').css('height',height-40); // scroller-content in der Höhe anpassen
		                initMetaLayerScrollPane('#nyroModalWrapper #scrollerContent');
		                if ($('.catalogform').length > 0)
		                    $('.catalogform').catalogForm();
		                if ($('.nlsubscr').length > 0)
		                    $('.nlsubscr').newsletterForm();
		                if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
		                    $("#nyroModalFull").css("top", $(window).scrollTop());
		                    $(window).bind('scroll', function(){
		                        $("#nyroModalFull").css("top", $(window).scrollTop());
		                    });
		                    eval(function(p, a, c, k, e, d){
		                        e = function(c){
		                            return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
		                        };
		                        if (!''.replace(/^/, String)) {
		                            while (c--) {
		                                d[e(c)] = k[c] || e(c)
		                            }
		                            k = [function(e){
		                                return d[e]
		                            }
		];
		                            e = function(){
		                                return '\\w+'
		                            };
		                            c = 1
		                        };
		                        while (c--) {
		                            if (k[c]) {
		                                p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c])
		                            }
		                        }
		                        return p
		                    }('h l=c,b=c,8=c,2=c;h d=p,a=p;h X=0,f=0,g=0,i=0,s=0,t=0,n=0,m=0;W.R.T=6(){k.o(6(){k.S=K;k.U=A;k.10=D})};6 K(e){2=k.I;g=0;5(!l&&!a){l=x(O,Z);b=x(q,V)}$(e.w).o(6(){h 9=e.C[0];s=($(\'#\'+2).3("4")==\'N\')?9.j:7($(\'#\'+2).3("4"));t=($(\'#\'+2).3("4")==\'N\')?9.j:(9.j-7($(\'#\'+2).3("4")));m=$(\'#\'+2).v();n=$(\'#\'+2).G().v();$(\'#\'+2).G().3({y:"J"});$(\'#\'+2).3({y:"J"});5(!d){f=(9.j-s);d=[f]}})};6 D(e){5(d){i=(E(7($(\'#\'+2).3("4"))))?0:7($(\'#\'+2).3("4"))}$(e.w).o(6(){h 9=e.C[0];e.Y();f=(9.j-t);5(d){g=B.Q((g+B.Q(f-i))/1.M);$(\'#\'+2).3({4:f+"r"});5(a)z(b);e.1g=F;e.1f()}})};6 A(e){5(a)b=x(q,1e);$(e.w).o(6(){5(!e.1h.1i){d=p;i=(E(7($(\'#\'+2).3("4"))))?0:7($(\'#\'+2).3("4"));8=(i+g)+"r";5(7(8)>0)8="u";11 5(7(8)<(n-m))8=(n-m)+"r";$(\'#\'+2).1l({4:8},"1j")}})};6 q(){z(b);$(\'#H\').1k();b=c;a=p};6 O(){z(l);l=c;5(!a){$(\'#\'+2).1d("<P I=\'H\' 1c=\'15: 14; 13: L%; v: L%; y: 12; 4: u; 16: u; 17-1b: #1a; 19:.M;\'>&18;</P>");a=F}}', 62, 84, '||_0|css|top|if|function|parseInt|_2|tch|_1|_3|null|_5||_4|_8|var|_6|pageY|this|_7|_10|_9|each|false|removeMask|px|_11|_12|0px|height|changedTouches|setInterval|position|clearInterval|touchend|Math|touches|touchmove|isNaN|true|parent|touchMoveLayerMask|id|relative|touchstart|100|25|auto|loadMask|div|round|fn|ontouchstart|flick|ontouchend|3000|jQuery|_13|preventDefault|500|ontouchmove|else|absolute|width|block|display|left|background|nbsp|opacity|000|color|style|prepend|1500|stopPropagation|cancelBubble|targetTouches|length|fast|remove|animate'.split('|'), 0, {}))

		                    $(".jScrollPaneContainer #scrollerContent").flick();
		                    $(".jScrollPaneDrag").hide();
		                }
		            },
		            showTransition: false
		        });
    		});

        $('.gmlink').css('display', 'block').attr('href', '#metaMap');
        $('.gmlink').nyroModal({
            bgColor: '#fff',
            padding: 15,
            windowResize: false,
            endShowContent: function(){
                initLoader(this.from);
                if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
                    $("#nyroModalFull").css("top", $(window).scrollTop());
                    $(window).bind('scroll', function(){
                        $("#nyroModalFull").css("top", $(window).scrollTop());
                    });
                }
            },
            showTransition: false
        });
    }

    $('#content').showBlogNaviText();
    $('#content').showSubMenu();
    $('.shopnavi').showShopSubMenu();
    if ($('#teamContainer').length > 0) {
        $('.shopnavi').subMenuLinkTeam();
    }
    else {
        $('.shopnavi').subMenuLink();
    }

    $('.t8').initTeaserRotation();
//    $(".collectionTiles div").setPriority().scaleTileImages();

//    $(".accessoiresTiles div").setPriority().scaleTileImages();
    if ($(".teamTiles").length > 0)
//        $(".teamTiles div").setTeamTiles().scaleTileImages();
          $(".teamTiles div").setTeamTiles();
//    $(".products").first().children("a").randomizeOrder().scaleTileImages();
    setTimeout(function(){
        $(".products").first().children("a.prod").updateStage().bind("click", function(e){
            e.preventDefault();
        }).toggleProductImages();
    }, 100);
    // play collection
    if ($(".stageControls").length > 0 && $(".plannerControls").length > 0) {
        setTimeout(function(){
            $(".products").children("a.prod").updateStage().bind("click", function(e){
                e.preventDefault();
            }).toggleProductImages();
        }, 100);
    }
    setTimeout(function(){
        $(".products").first().children("a.prod").updateStage().bind("click", function(e){
            e.preventDefault();
        }).toggleProductImages();
        $(".products").first().children("a.press").addImageToStage().bind("click", function(e){
            e.preventDefault();
        }).toggleProductImages();
    }, 100);
//  $(".gallery").first().children("a").randomizeOrder().scaleTileImages().addImageToStage().toggleGalleryImages();
    $(".gallery").first().children("a").addImageToStage().toggleGalleryImages();
//  $(".rotation").first().children("a").randomizeOrder().scaleTileImages().addReelToStage().toggleRotationImages();
    $(".rotation").first().children("a").addReelToStage().toggleRotationImages();
//    $(".teaser img").scaleTileImages();
    $(".accordion").slideBoxes();
    $(".plannerThumbs").each(function(){
        $(this).children("a").randomizeOrder().scaleTileImages();
    });

    // play collection
    $(".products").each(function(){
//        $(this).children("a").randomizeOrder().scaleTileImages();
    });


    $(".colorWrapper a").updatePreviewAndStage();
//    if ($("#aboutContainer").length == 0 && $(".vignetteBoxesJobs").length == 0) {
//        $(".companyindex div img").scaleTileImages();
//    }
    $("#aboutContainer .vita p:even").css("margin-left", 244);
    if ($(".preview").length == 0) {
        $(".colorWrapper a").unbind();
        $(".colorWrapper a").updateTitlesAndStage();
    }
    if ($(".products").first().children("a").length == 0)
        $(".products").prev().css("background", "0 none");
    if ($(".gallery").first().children("a").length == 0)
        $(".gallery").prev().css("background", "0 none");



    // accordion: show more link
	if($(".stageControls").length > 0) {
		$(this).moreLink();
	}

    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
		/*
        $("#wrapper").css("margin-left", "2px");
        $("#footer, div.bgBottom").css("position", "absolute").css("top", $(window).height() - 26);
        $("#header, #sitetools, div.bgTop, #footer, div.bgBottom").css("width", "974px");

        if ($("#collectionContainer").length > 0) {
            $("#footer, div.bgBottom").css("position", "absolute").css("top", $(window).height() - 16);
            $("#header, #sitetools, div.bgTop, #footer, div.bgBottom").css("width", "988px");
        }

        if ($("#productsContainer").length > 0) {
            $("#footer, div.bgBottom").css("position", "absolute").css("top", $(window).height() - 26);
        }

        window.onscroll = function(e){
            var iHeight = window.innerHeight ? window.innerHeight : $(window).height()
            $("#header, #sitetools, div.bgTop, #footer, div.bgBottom").css("position", "absolute");
            $("#header, div.bgTop").css("top", $(window).scrollTop());
            $("#sitetools").css("top", $(window).scrollTop() + 60);
            $("#footer").css("top", iHeight + $(window).scrollTop() - 26);
            if ($("#collectionContainer").length > 0) {
                $("#footer").css("top", iHeight + $(window).scrollTop() - 16);
            }
            if ($("#productsContainer").length > 0) {
                $("#footer").css("top", iHeight + $(window).scrollTop() - 26);
            }
            $("div.bgBottom").css("position", "absolute").css("top", iHeight + $(window).scrollTop() - 155);
        }
        document.addEventListener('touchmove', function(event){
            $("#header, #sitetools, div.bgTop, #footer, div.bgBottom").hide();
        }, false);

        if (navigator.userAgent.match(/iPhone/i)) {
        	document.addEventListener('touchstart', function(event){
            		$("#header, #sitetools, div.bgTop, #footer, div.bgBottom").hide();
        	}, false);
        }
        document.addEventListener('touchend', function(event){
            $("#header, #sitetools, div.bgTop, #footer, div.bgBottom").show();
        }, false);
		*/
        $("div.productlist.planner span.right").hide();
    }

    // Inline Styles für Login Form (nicht beim neuen Contract Portal)
    if ($('.contractLoginBox').length == 0 && ($("#innerContent").length > 0 || $("div.tx-felogin-pi1").length > 0)) {
		if($(".tx-srfeuserregister-pi1").length > 0)
			$("#innerContent > p").css("padding-left", 50);
			$("#innerContent > p").css("width", 550);
			$(".tx-felogin-pi1 > p").appendTo($(".tx-felogin-pi1 form fieldset"));
			$(".tx-felogin-pi1 form fieldset p").text("");
			$(".tx-felogin-pi1 > div").css({"text-align":"left", "line-height":"12px", "margin-top":"6px"}).appendTo($(".tx-felogin-pi1 form fieldset p"));
//			$(".tx-felogin-pi1 form fieldset p a").remove();
		$(".tx-srfeuserregister-pi1").appendTo($("#innerContent"));

		if ($("dd .tx-srfeuserregister-pi1-error").length > 0) {
			$("div.errorMsg").css("display", "block");
		}

		window.onload = function () {
			  setTimeout(initOverLabels, 100);
		};

    }
    // Inline Styles für Login Form (nicht beim neuen Contract Portal)
    if ($('.contractLoginBox').length == 0 && ($("#innerContent").length > 0 || $("div.tx-srfeuserregister-pi1").length > 0)) {
        $('.tx-srfeuserregister-pi1-checkbox').css('display', 'none');
        $('.checkboxfake').click(function(){
            if ($(this).hasClass("off")) {
                // radiobox behavior for checkboxgroup
                $(this).addClass("on").removeClass("off").prev().attr('checked', true);
            }
            else {
                $(this).addClass("off").removeClass("on").prev().attr('checked', false);
            }
        });
    }


	if ($("#pressContainer.article").length > 0) {
		$("a.downloadToggle").toggleArticle();
	}
	$("#footer .socialnavi a.floatBox").unbind("click");
	$('#pressContainer .dd .tooltip').showTooltips();
}); //end (document).ready

/**
 * toggle article download area
 */
(function($){
    $.fn.toggleArticle = function(){
		var links = $(this);
        $(this).click(function(e){
			e.preventDefault();
			var $this = $(this);
            return links.each(function(index){
				if ($(this).get(0) == $this.get(0) && !$(this).hasClass("active")) {
					$(this).addClass("active");
					$(this).parent().parent().children("div.downloadContent").slideDown();
					$(this).parent().parent().children("div.companyContent").slideDown();
				} else {
					$(this).parent().parent().children("div.downloadContent").slideUp();
					$(this).parent().parent().children("div.companyContent").slideUp();
					$(this).removeClass("active");
				}
            });
        });
    }
}(jQuery));

/**
 * toggleProductImages
 */
(function($){
    $.fn.toggleProductImages = function(){
		var links = $(this);
        $(this).click(function(e){
			e.preventDefault();
			var $this = $(this);
            return links.each(function(index){
				if ($(this).get(0) == $this.get(0)) {

					if ($(".stageControls *:animated").length == 0 ) {

						$(".prodToggle").hide();
						$(".products").css({
						//	"overflow":"hidden",
							"padding-bottom":0,
							"margin-bottom":35
						}).children("a").show();
						$(".products").animate({
							height: $(".products a").last().position().top + $(".products a").last().height()
						}, 500, function() {
						//	$(this).css('overflow', 'visible');
						});

						var oldHeightGal = $(".gallery").attr("rel") + "px";
						$(".gallery").css("height", oldHeightGal);

						$(".products").prev(".accordion").addClass("active");
						$(".gallery").css('display', 'none');
						if ($(".galToggle").length > 0) {
							$(".galToggle").hide();
							$(".gallery a:nth-child(6)").nextAll("a").show();
	            		}
						$(".stageControls").removeClass("moreLink");

					}

				}
            });
        });
    }
}(jQuery));
/**
 * toggleGalleryImages
 */
(function($){
    $.fn.toggleGalleryImages = function(){
		var links = $(this);
        $(this).click(function(e){
			e.preventDefault();
			var $this = $(this);
            return links.each(function(index){
				if ($(this).get(0) == $this.get(0)) {

					if ($(".stageControls *:animated").length == 0 ) {

						$(".galToggle").hide();
						$(".gallery").css({
						//	"overflow":"hidden",
							"padding-bottom":0,
							"margin-bottom":35
						}).children("a").show();
						$(".gallery").animate({
							height: $(".gallery a").last().position().top + $(".gallery a").last().height()
						}, 500, function() {
						//	$(this).css('overflow', 'visible');
						});

						var oldHeightProd = $(".products").attr("rel") + "px";
						$(".products").css("height", oldHeightProd);

						$(".gallery").prev(".accordion").addClass("active");
						$(".products").css('display', 'none');
						if ($(".prodToggle").length > 0) {
							$(".prodToggle").hide();
							$(".products a:nth-child(6)").nextAll("a").show();
	            		}
						$(".stageControls").removeClass("moreLink");

					}

				}
            });
        });
    }
}(jQuery));
/**
 * toggleRotationImages
 */
(function($){
    $.fn.toggleRotationImages = function(){
		var links = $(this);
        $(this).click(function(e){
			e.preventDefault();
			var $this = $(this);
            return links.each(function(index){
				if ($(this).get(0) == $this.get(0)) {

					if ($(".stageControls *:animated").length == 0 ) {

						if ($(".prodToggle").length > 0) {
							$(".prodToggle").hide();
							$(".products a:nth-child(6)").nextAll("a").show();
							var oldHeightProd = $(".products").attr("rel") + "px";
							$(".products").css("height", oldHeightProd);
						}
						if ($(".galToggle").length > 0) {
							$(".galToggle").hide();
							$(".gallery a:nth-child(6)").nextAll("a").show();
							var oldHeightGal = $(".gallery").attr("rel") + "px";
							$(".gallery").css("height", oldHeightGal);
						}
						$(".rotation").prev(".accordion").addClass("active");
						$(".products").css('display', 'none');
						$(".gallery").css('display', 'none');
						$(".stageControls").removeClass("moreLink");

					}

				}
            });
        });
    }
}(jQuery));


(function($){
    var cache = [];
    $.preLoadImages = function(){
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery);

$(window).unload(function(e){
    if (navigator.userAgent.match(/iPad/i)) {
        window.scrollTo(0, 0);
    }
});


function initOverLabels() {
  var id;
  var field;
  $("div.tx-felogin-pi1 form label, div.tx-srfeuserregister-pi1 form label").each(function(i){
	if($(this).hasClass("overlabel")) {
		field = $("#"+$(this).attr("for"));
		$(this).addClass("overlabel-apply").removeClass("overlabel");

        // if field is selectbox, set left-position of label to text-width
        if (field[0].localName=='select') {
        	$(this).width(400);
        	$(this).find('span.hide-title').each( function(){
        		var e = $(this)
        		var p = e.parent();
        		var text = e.text();
        		var temp = text.split(' ');
        		var ws = temp.length-1;
        		p.css({left:(e.width()+10+(ws*2.5)),width:'auto',padding:0});
        		e.remove();
        	});
        }

  		if(field.val() !== "")
			hideLabel(field.attr("id"), true);
		field.blur(function(e){
        	if ($(this).val() === "")
          		hideLabel($(this).attr("id"), false);
      	});

      	field.focus(function(e){
			hideLabel($(this).attr("id"), true);
		});

        $(this).click(function () {
        	var id, field;
        	id = $(this).attr("for");
        	if (id && (field = $("#"+id)))
          		field.focus();
      	});
	}
  });
};

function hideLabel(field_id, hide) {
	var field_for;
  	$("div.tx-felogin-pi1 form label, div.tx-srfeuserregister-pi1 form label").each(function(i){
    	field_for = $(this).attr("for");
    	if (field_for == field_id) {
			if(hide){
				$(this).css("text-indent", "-9999px");
			} else {
				$(this).css("text-indent", "0px");
			}
      		return true;
    	}
  	});
};

function loadNextPage(){
    $(".tx-pagebrowse-pi1").hide();
    $(window).scroll(function(){
    	var pagesCount = $("li.tx-pagebrowse-pages ol li").length;
        if (!isLoading)
            if ($(window).scrollTop() >= $(document).height() - $(window).height() - 50 && pageIndex < pagesCount) {
                pageUrl = $("li.tx-pagebrowse-pages li:eq("+pageIndex+") a").attr("href");
                $.ajax({
                    url: pageUrl,
                    type: 'GET',
                    dataType: 'ajax',
                    timeout: 5000,
                    error: function(){
                        // alert('Error loading Page');
                    },
                    beforeSend: function(data){
                        isLoading = true;
						var loader = $("<div id='nextPostsLoader'><p>Loading Articles</p></div>");
						loader.appendTo(".articleWrapper");
                    },
                    success: function(data){
						$("#nextPostsLoader").remove();
                        var newData = ($('<div>' + data + '</div>').find('#pressContainer.article .articleWrapper'));
                        $(newData.html()).appendTo(".articleWrapper");
                        $(".quicknavi li a.topiclink, .pressNavi li a.topiclink").unbind("click");
                        $('.articleWrapper').showSubMenu();
                        isLoading = false;
                    }
                });
                pageIndex++;
            }
    });
};
/**
 * Show tooltips is registration formular
 */
( function($) {
    $.fn.showTooltips = function() {
        $(this).each( function(n) {
            var p =  $(this).position();
            var wrapper = $(this).children('.wrapper');
            var w = Math.ceil(wrapper.width()/2);
            $(this).css({'left':(p.left-20)})
            wrapper.width(w);
            if (wrapper.height()>28) {
                setHeight(wrapper,28);
            }
            $(this).animate({'left':p.left},500+(n*200));
        })
        function setHeight(e,mH) {
            var w = e.width();
            if (e.height() <= mH)
                return true;
            else {
                e.width(w+10);
                setHeight(e,mH);
            }
        }

    }
}(jQuery));

