

startApp = function()
{       
    // forms
    if(!$.browser.msie)
    {
        $('form.cform')
        .find(":submit")
        .replaceWith("<button id=\"sendbutton\" name=\"sendbutton\">Senden</button>")
        .end()
        .submit(function()
        {
            $(this)
                .find(":submit,:image")
                .addClass('disabled')
                .end()
                .submit(function()
                {
                    return false;
                })
            ;
        });
    }

   
    // ff links without borders
    $('a').focus(function(){if(this.blur)this.blur();});    
    
    // ext links
    if(!document.all)
    {
        $("a:parent:not(#header a):not(.popupImg):not(.popupLink):not([href^=#]):not([href^=javascript]):not([href^=mailto]):not([href^=" + sBaseUrl + "])").not(":has(img)").click(function()
        {
            window.open(this.href);
            return false;
        }).attr('title', 'Externer Link, öffnet ein neues Fenster').addClass('external');
    }
        
    // add. blank links
    $('a.blank').click(function()
    {
        window.open(this.href);
        return false;
    });
    
    // images & links
    $('.singleArticle a[href*="' + document.location.href.replace(sBaseUrl, '').replace(document.location.hash, '').replace(window.location.search, '') + '"]:has(img)').hide();
    $('.singleArticle a[href$=".jpg"]:has(img)').addClass('popupImg');
    $('.postList a[href$=".jpg"]:has(img)').hide();
    $('.postList a[href*="/attachment/"]').each(function()
    {
        sHref = $(this).attr('href');
        $(this).attr('href', sHref.substr(0, sHref.indexOf("/attachment/")));
    });

    // smooth scroll
    $('a[href*=#]').click(function()
    {
        if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'') && location.hostname==this.hostname && this.hash.replace(/#/,''))
        {
            var hash=this.hash;
            var target=$(hash).offset().top;
            $("html:not(:animated),body:not(:animated)").animate({ scrollTop: target }, 500, 'swing', function() { /* location.hash=hash; */ });
            return false;
        }
    });
    
    // search
    // $('form.searchform .searchsubmit').val('');
    populateElement('.searchform input[name=s]', 'Suche im Blog ...');
    populateElement('#email', 'Email-Adresse');

    // category accordion
    $('.widget_categories a').each(function()
    {
        $(this).attr('href', $(this).attr('href').replace('./', ''));
    });
    $('.widget_categories ul ul:has(ul) a').addClass('head');
    $('.widget_categories ul ul').find('ul a').removeClass('head').end().each(function()
    {
        $(this).Accordion(
        {
            active: 'a.selected',
            header: 'a.head',
            alwaysOpen: false,
            animated: true,
            showSpeed: 300,
            hideSpeed: 300
        });
    });
    
    
    // vermietung
    $('#vermietung').css('display', 'none').each(function()
    {
        var self = this;
        $.get(sTemplateUrl + 'ajax/vermietung', {}, function(data)
        {
            $(self).html(data).fadeIn(10, function()
            {
                $("#detailNavi")
                    .glider({iMinHeight: 50})
                    .find('.section a')
                    .bind('mousedown', function()
                    {
                        this.href += ('&n=' + Math.round(Math.random() * 1000000000));
                    })
                    .fancybox(
                    {
                        /* callbackOnShow: setupCalendars,  */hideOnContentClick: false, padding: 0, origIsParent: true,
                        frameWidth: 900, frameHeight: 525, zoomSpeedIn: 400, zoomSpeedOut: 300, 
                        zoomOpacity: true, overlayShow: false, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' 
                    });
            });
        }); 
    });
    
    // team
    $('#team').css('display', 'none').each(function()
    {
        var self = this;
        $.get(sTemplateUrl + 'ajax/team?dontcache=1', {}, function(data)
        {
            $(self).html(data).fadeIn(10, function()
            {
                $("#team a.team").fancybox(
                {
                    hideOnContentClick: false, padding: 0, origIsParent: true,
                    frameWidth: 850, frameHeight: 525, zoomSpeedIn: 400, zoomSpeedOut: 300, 
                    zoomOpacity: true, overlayShow: false, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' 
                });
                
                $.ifixpng(sTemplateUrl + 'images/blank.gif');
                $("#team a.team img, #team .row").ifixpng();
                $(document.location.hash.replace('#', '#teamMember')).trigger('click');
            });
        }); 
    });
    
    $('#postHeader').each(function()
    {
        $oTicker = $(this);
        $oTickerContent = $oTicker.find('.scrollContent');
        var iWidth = $oTicker.innerWidth(true);
        var iDescrWidth = $oTicker.find('span.descr').width();
        sHeadlineWidth = $oTickerContent.find('span.headline').each(function()
        {
            oThis = $(this);
            var oDiv = $("<div class=\"headline\"></div>").hide().css({
                "position": "absolute",
                "width": "auto",
                "white-space": "nowrap",
                "overflow": "visible"
            }).text(oThis.text());
    		oThis.after(oDiv);
            if(oDiv.width() < iDescrWidth)
            {
                oThis.after('<br />');
            }
            oDiv.remove();
        });
        
        
        //alert($oTicker.innerWidth())
        var iCountNews = $oTickerContent.width(iWidth).find('li')/* .css({opacity: 0.01}) */.width(iWidth).length - 1;
        var bAnimationRunning = false;
        var iAnimationSpeed = 1500;
        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, 
                "easeInOutQuart",
                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;
    });
    
    // tooltips
    $('a.tooltip[href][title]').qtip(
    {
        content: 
        {
            text: false
        },
        style: { 
            padding: 5,
            background: '#ffffff',
            color: '#547387',
            border: {
                width: 2,
                radius: 3,
                color: '#e4170e'
            },
            tip: 'topLeft'
        }
    });
        
    // buttons
    $('button').wrapInner('<span><span></span></span>');
    $('a.button').wrapInner("<span></span>");
  
    // ie png fix
    if($.browser.msie && $.browser.version < 7)
    {
        sBgImg = $('.searchsubmit').css('backgroundImage').replace(/"/g, '').replace('url(', '').replace(')', '');
        $('.searchsubmit').attr('src', sBgImg).css('backgroundImage', 'none')/*.attr('type', 'image') */;
        $.ifixpng(sTemplateUrl + 'images/blank.gif');
        $('a.external, #header, .searchsubmit, .scrollContent .bg').ifixpng(sTemplateUrl + 'images/blank.gif');
    }
}

populateElement = function (selector, defvalue)
{
    $(selector).each(function()
    {
        if($.trim(this.value) == "")
        {
            this.value = defvalue;
        }
    }).focus(function()
    {
        if(this.value == defvalue)
        {
            this.value = "";
        }
    }).blur(function()
    {
        if($.trim(this.value) == "")
        {
            this.value = defvalue;
        }
    });
}
 
roundImgCorners = function ()
{
    //return;
    $('#content img:not(.popupImg img, form img, #postHeader img, .userInfo img, .wp-smiley):visible, .popupImg, .cform:not(.roundCornersContainer .cform)').addClass('roundCornersContainer').addClass('autoclear');
    $('.userInfo span.avatar, .userInfo a:has(img)').addClass('roundCornersContainer');
    $('.roundCornersContainer').wrap('<span class="roundCorners"><span class="leftTop"></span></span>');
    $('.roundCorners')
        .append('<span class="rightTop"></span><span class="leftBottom"></span>')
        .each(function()
        {
            $(this).addClass($(this).find('.roundCornersContainer').attr('class'));
            $(this).addClass($(this).find('.roundCornersContainer img').attr('class'));
            //$(this).attr('style', $(this).find('.roundCornersContainer').attr('style'));
        }
    );

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


initFancyBox = function ()
{
    // allg
    $("#travelPopupLink").fancybox({ padding: 0, zoomSpeedIn: 400, zoomSpeedOut: 300, zoomOpacity: true, overlayShow: false, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' });
    $(".popupImg").fancybox({ padding: 0, zoomSpeedIn: 400, zoomSpeedOut: 300, zoomOpacity: true, overlayShow: false, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' });
    $(".gallery a").attr('rel', 'img').fancybox({ padding: 0, zoomSpeedIn: 400, zoomSpeedOut: 300, zoomOpacity: true, overlayShow: false, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' });
    $('.popupLink').addClass('iframe').each(function()
    {
        if (this.href.indexOf('?') != -1)
        {
            this.href += '&media=popup';
        }
        else
        {
            this.href += '?media=popup';
        }    
    }).fancybox({ padding: 0, zoomSpeedIn: 400, zoomSpeedOut: 300, frameWidth: 900, frameHeight: 600, overlayShow: false, overlayOpacity: 0.01, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' });
    $('a.popupLinkTeam').each(function()
    {
        if (this.href.indexOf('?') != -1)
        {
            this.href += '&media=popup';
        }
        else
        {
            this.href += '?media=popup';
        }    
    }).fancybox({ padding: 0, zoomSpeedIn: 400, zoomSpeedOut: 300, frameWidth: 800, frameHeight: 540, overlayShow: false, overlayOpacity: 0.01, 'easingIn': 'easeOutQuad', 'easingOut': 'easeOutQuad' });
}

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

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






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
