function var_dump(data,addwhitespace,safety,level) {
        var rtrn = '';
        var dt,it,spaces = '';
        if(!level) {level = 1;}
        for(var i=0; i<level; i++) {
           spaces += '   ';
        }//end for i<level
        if(typeof(data) != 'object') {
           dt = data;
           if(typeof(data) == 'string') {
              if(addwhitespace == 'html') {
                 dt = dt.replace(/&/g,'&amp;');
                 dt = dt.replace(/>/g,'&gt;');
                 dt = dt.replace(/</g,'&lt;');
              }//end if addwhitespace == html
              dt = dt.replace(/\"/g,'\"');
              dt = '"' + dt + '"';
           }//end if typeof == string
           if(typeof(data) == 'function' && addwhitespace) {
              dt = new String(dt).replace(/\n/g,"\n"+spaces);
              if(addwhitespace == 'html') {
                 dt = dt.replace(/&/g,'&amp;');
                 dt = dt.replace(/>/g,'&gt;');
                 dt = dt.replace(/</g,'&lt;');
              }//end if addwhitespace == html
           }//end if typeof == function
           if(typeof(data) == 'undefined') {
              dt = 'undefined';
           }//end if typeof == undefined
           if(addwhitespace == 'html') {
              if(typeof(dt) != 'string') {
                 dt = new String(dt);
              }//end typeof != string
              dt = dt.replace(/ /g,"&nbsp;").replace(/\n/g,"<br>");
           }//end if addwhitespace == html
           return dt;
        }//end if typeof != object && != array
        for (var x in data) {
           if(safety && (level > safety)) {
              dt = '*RECURSION*';
           } else {
              try {
                 dt = var_dump(data[x],addwhitespace,safety,level+1);
              } catch (e) {continue;}
           }//end if-else level > safety
           it = var_dump(x,addwhitespace,safety,level+1);
           rtrn += it + ':' + dt + ',';
           if(addwhitespace) {
              rtrn += '\n'+spaces;
           }//end if addwhitespace
        }//end for...in
        if(addwhitespace) {
           rtrn = '{\n' + spaces + rtrn.substr(0,rtrn.length-(2+(level*3))) + '\n' + spaces.substr(0,spaces.length-3) + '}';
        } else {
           rtrn = '{' + rtrn.substr(0,rtrn.length-1) + '}';
        }//end if-else addwhitespace
        if(addwhitespace == 'html') {
           rtrn = rtrn.replace(/ /g,"&nbsp;").replace(/\n/g,"<br>");
        }//end if addwhitespace == html
        return rtrn;
     }//end function var_dump
     
     
formatPrice = function(iIn)
{
    return numberFormat(iIn, 2, ',', '.');
}

function numberFormat( number, laenge, sep, th_sep )
{
    number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
    str_number = number+"";
    arr_int = str_number.split(".");
    if(!arr_int[0]) arr_int[0] = "0";
    if(!arr_int[1]) arr_int[1] = "";
    if(arr_int[1].length < laenge)
    {
        nachkomma = arr_int[1];
        for(i=arr_int[1].length+1; i <= laenge; i++){   nachkomma += "0";   }
        arr_int[1] = nachkomma;
    }
    if(th_sep != "" && arr_int[0].length > 3)
    {
        Begriff = arr_int[0];
        arr_int[0] = "";
        for(j = 3; j < Begriff.length ; j+=3)
        {
            Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
            arr_int[0] = th_sep + Extrakt + arr_int[0] + "";
        }
        str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
        arr_int[0] = str_first + arr_int[0];
    }
    return arr_int[0]+sep+arr_int[1];
}

startApp = function()
{
    // ie hovermenu
    if (document.all)
    {
        $('#navInternational, #navMain li')
        .mouseover(function(){this.className += " over";})
        .mouseout(function(){this.className = this.className.replace(" over", "");});
    }
    
    // configurator
    if($("#configurator").length)
    {
        updateConfiguratorResult();
    }
    $("#configurator").glider({iMinHeight: $('#configuratorImgContainer').height()}).find('input').click(function()
    {
        updateConfiguratorResult();
    });
    $("a.send").fancybox({callbackOnStart: getConfiguratorDataSend, frameWidth: 520, frameHeight: 500, overlayOpacity: 0.1, hideOnContentClick: false});
    $("a.order").fancybox({callbackOnStart: getConfiguratorDataOrder, frameWidth: 520, frameHeight: 530, overlayOpacity: 0.1, hideOnContentClick: false});
    
    // buttons
    $('button').wrapInner('<span><span></span></span>');
    $('a.button').wrapInner("<span></span>");
    
    // forms
    $('form#f').submit(function()
    {
        if (this.bSubmitted)
        {
            return false;
        }
        else
        {
            this.bSubmitted = true;
            $(this).find(":submit,:image").addClass('disabled');
            return true;
        }
    });
    
    // imgload // safari
    $('<img />').attr('src', ("https:" == document.location.protocol ? sSslBaseUrl : sBaseUrl) + 'images/bgButtonsBlueDisabled.gif');
    $('<img />').attr('src', ("https:" == document.location.protocol ? sSslBaseUrl : sBaseUrl) + 'images/bgButtonsDisabled.gif');
    
    // blank
    $('a.blank').click(function()
    {
        window.open(this.href);
        return false;
    });
    
    // gallery
    $('.gallery').gallery();
    
    // bikes
    $("#bikes").glider();
    
    // ff links without borders
    $('a').focus(function(){if(this.blur)this.blur();});
    
    // newsticker startseite
    $('#newsPanel').each(function()
    {
        $oTicker = $(this);
        $oTickerContent = $oTicker.find('.scrollContent');
        var iWidth = $oTicker.find('.content').innerWidth(true);
        var iCountNews = $oTickerContent.width(iWidth).find('li').css({opacity: 0.01}).width(iWidth).length - 1;
        var bAnimationRunning = false;
        var iAnimationSpeed = 1000;
        var iCurrentPosition = 0;
        $oTickerContent.find('li:nth-child(' + (iCurrentPosition + 1) + ')').fadeTo(iAnimationSpeed, 1);
        function next()
        {
            if(bAnimationRunning)
            {
                return;
            }
            
            iCurrentPosition ++;
            bAnimationRunning = true;
            if(iCurrentPosition > iCountNews)
            {
                iCurrentPosition = 0;
            }
            $oTickerContent.animate(
                { left: (-iCurrentPosition * iWidth) + 'px' }, 
                iAnimationSpeed, 
                "easeInOutCirc",
                function()
                {
                    bAnimationRunning = false;
                }
            );
            $oTickerContent.find('li:nth-child(' + iCurrentPosition + ')').fadeTo(iAnimationSpeed, 0.01);
            $oTickerContent.find('li:nth-child(' + (iCurrentPosition + 1) + ')').fadeTo(iAnimationSpeed, 1);
        }
        setInterval(next, 7000);
        
        return $oTicker;
    });

    // ie png fix
    $.ifixpng(sBaseUrl + 'images/blank.gif');
    $('body, #footer, #header, #newsPanel').not('#popup, #popup #footer, #popup #header').ifixpng();
}

getConfiguratorData = function()
{
    var aConfiguratorDetails = [];
    $('input:checked').each(function()
    {
        var sName = $(this).attr('name');
        var fTmpData = 'a[' + sName + ']' + (sName.indexOf('optional') != -1 ? '[]' : '') + '=' + $(this).val();
        aConfiguratorDetails.push(fTmpData);
    });
    return '&amp;' + sSessionQSA + aConfiguratorDetails.join('&amp;');    
}

getConfiguratorDataSend = function()
{
    this.itemArray = [{href: sSendLink + getConfiguratorData()}];
}

getConfiguratorDataOrder = function()
{
    this.itemArray = [{href: sOrderLink + getConfiguratorData()}];
}

updateConfiguratorResult = function()
{
    var fPrice = fConfiguratorPrice;
    var aConfiguratorDetails = [];
    var aConfiguratorImagesToCreate = [sBackGroundImageUrl];
    var aThumbnailImagesToCreate = [];
    var aThumbnailDataToCreate = [];
    $('input:checked').each(function()
    {
        var sValue = $(this).val();
        var sName = $(this).attr('name')
        
        // price
        var fTmpPrice = oConfiguratorData[sName][sValue]['fPrice'];
        fPrice += fTmpPrice;
        
        // descr
        sTmpDescr = $(this).parent().parent().parent().find('h3').text();
        sTmpDescr = sTmpDescr + ': ' + oConfiguratorData[sName][sValue]['sDescr'];
        if(fTmpPrice)
        {
            sTmpDescr = sTmpDescr + ' <span class="price">(' + formatPrice(fTmpPrice) + ' €)</span>';
        }
        aConfiguratorDetails.push(sTmpDescr);
        
        // img
        if(oConfiguratorData[sName][sValue]['sImage'])
        {
            aConfiguratorImagesToCreate.push(oConfiguratorData[sName][sValue]['sImage']);
        }
        
        // thumbs & popups
        if(oConfiguratorData[sName][sValue]['sImagePopup'])
        {
            aThumbnailDataToCreate.push(
            {
                'thumb': oConfiguratorData[sName][sValue]['sImageThumb'],
                'popup': oConfiguratorData[sName][sValue]['sImagePopup'],
                'descr': $(this).parent().parent().parent().parent().find('h1').text() + ' ' + sTmpDescr
            });
            aThumbnailImagesToCreate.push(oConfiguratorData[sName][sValue]['sImagePopup']);
        }
    });
    
    // check currently displayed images
    // fade out & remove all images we dont need anymore
    $('#configuratorImg img').each(function()
    {
        var sSrc = $(this).attr('src');
        if($.inArray(sSrc, aConfiguratorImagesToCreate) == -1)
        {
            $(this).fadeOut(300, function()
            {
                $(this).remove();
            });
        }
    });
    
    // create all images to display & fade in
    // make sure to create in right order
    var iZIndex = 1;
    var aLoadingIndicators = [];
    $(aConfiguratorImagesToCreate).each(function()
    {
        var bInstantFadeIn = true;
        oJImage = $('#configuratorImg').find('img[src="' + this + '"]');
        if(oJImage.length == 0)
        {
            // create img
            var oNewImg = new Image();
            oNewImg.src = this;
            oJImage = $(oNewImg).addClass('configuratorImg').css({display: 'none'});
            
            // image loaded? if not, create indicator
            if(!isImageLoaded(oNewImg))
            {
                aLoadingIndicators[this] = $('<img />')
                    .attr('src', sBaseUrl + 'images/blank.gif')
                    .addClass('configuratorImg')
                    .addClass('indicator')
                    .css({display: 'block', zIndex: 200});
                $('#configuratorImg').append(aLoadingIndicators[this]);
                
                bInstantFadeIn = false;
                oJImage.load(function()
                {
                    aLoadingIndicators[$(this).attr('src')].remove();
                    $(this).fadeIn(300);
                });
            }
            
            // append to container
            $('#configuratorImg').append(oJImage);
        }
        
        // assign zIndex and fade in if necessary
        oJImage.css({zIndex: iZIndex++});
        if(bInstantFadeIn)
        {
            oJImage.fadeIn(300);
        }
    });
    
    // blank gif on top
    $('#configuratorImg').append(
        $('<img />')
            .attr('src', sBaseUrl + 'images/blank.gif')
            .addClass('configuratorImg')
            .css({display: 'block', zIndex: iZIndex++})
    );
    
    // check currently displayed thumbnails
    // fade out & remove all images we dont need anymore
    $('#thumbList a').each(function()
    {
        var oThis = $(this)
        var sSrc = oThis.attr('href');
        if($.inArray(sSrc, aThumbnailImagesToCreate) == -1)
        {
            $('#thumbList a').fadeOut(100, function()
            {
                $(oThis).remove();
            });
        }
    });

    // create all thumbnails to display & fade in
    var aThumbsLoading = [];
    var bThumbCreated = false;
    $(aThumbnailDataToCreate).each(function(iCount, oObject)
    {
        if(typeof(oObject.thumb) == 'undefined')
        {
            return;
        }

        oJImageLink = $('#thumbList').find('a[href*="' + oObject.popup + '"]');
        if(oJImageLink.length == 0)
        {
            // create img
            aThumbsLoading.push(iCount);
            bThumbCreated = true;
            var oJImage = $('<img />').attr('src', oObject.thumb).css({display: 'none'}).load(function()
            {
                $(this).fadeIn(200, function()
                {
                    aThumbsLoading.pop();
                    if(aThumbsLoading.length == 0)
                    {
                        $('#thumbList a').fadeIn(200);
                    }
                });
            });

            // append to container
            sTopDescr = $(this).parent().parent().parent().parent().find('h1').text();
            oJImageLink = $('<a></a>')
                .attr('href', oObject.popup)
                .attr('title', oObject.descr.replace('<span class="price">', '').replace('</span>', ''))
                .css({display: 'none'})
                .append(oJImage)
                .fancybox({'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad'})
            $('#thumbList').append(oJImageLink);
        }
    });
    
    // fade in
    if(aThumbnailImagesToCreate.length && !bThumbCreated)
    {
        $('#thumbList a').fadeIn(200);
    }
    
    // price & description
    $('.totalAmount').text(formatPrice(fPrice));
    $('#resultDetails').html('<ul><li>' + sTitle + ' <span class="price">(' + formatPrice(fConfiguratorPrice) + ' €)</span></li><li>' + aConfiguratorDetails.join('</li><li>') + '</li></ul>');

    // pngfix
    $.ifixpng(sBaseUrl + 'images/blank.gif');
    $('.configuratorImg').ifixpng();
}


isImageLoaded = function (img)
{
    if (!img.complete)
    {
        return false;
    }

    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0)
    {
        return false;
    }

    return true;
}

initFancyBox = function ()
{
    // allg
    $(".popupImg").fancybox({'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad'});
    $('.popupLink').each(function()
    {
        if (this.href.indexOf('?') != -1)
        {
            this.href += '&media=popup';
        }
        else
        {
            this.href += '?media=popup';
        }    
    }).fancybox({frameWidth: 800, frameHeight: 540, overlayShow: true, overlayOpacity: 0.01, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad'});
}

roundCorners = function ()
{
    $('.textContent img:not(.bikeTab img, .gallery img), .bikeTab').addClass('roundCornersContainer').addClass('autoclear');
    $('.roundCornersContainer').wrap('<div class="roundCorners"><div class="leftTop"></div></div>');
    $('.roundCorners')
        .append('<div class="rightTop"></div><div class="leftBottom"></div>')
        .each(function()
        {
            $(this).addClass($(this).find('.roundCornersContainer').attr('class'))
        }
    );

    $('.roundCorners img').removeAttr('align').css({'float': 'none'});    
}

if (top != self && window.location.search.indexOf('popup') == -1)
{
    top.location = self.location;
}

$(document).ready(function()
{
    roundCorners();
    initFancyBox();
    startApp();
});