// global js brandmeyer-markenberatung

// cufon for headlines
Cufon.replace('.upfrontcontentright .teaser h3', { hover: true });
Cufon.replace('h1, h2, h3, h4, p.singlecopylarge');

$(document).ready(function(){

// animate scroll top
  $('.backtotop').click(function(){
    $('html, body').animate({scrollTop:0}, 500);
    return false;
  });

  $('.toplink span').hide();
  $('.toplink a').hover(function(){
    $('.toplink a span').fadeIn(200);
  },
  function(){
    $('.toplink a span').fadeOut(200);
  });

// homepage
  $('.upfrontcontentright a.projectthumb img').hover(function(){
    $(this).stop().animate({'opacity': .8}, 200);
  },
  function(){
    $(this).stop().animate({'opacity': 1}, 200);
  });

  $('.upfrontcontentright .teaser:last').addClass('last');

  // splash
  $('#splash').meerkat({
    background: '#bc2715',
    height: '100%',
    width: '100%',
    position: 'bottom',
    dontShowAgain: '#enter',
    animationIn: 'none',
    animationOut: 'fade',
    animationSpeed: 500,
    timer: 2,
    dontShowAgainAuto: true,
    cookieExpires: 1,
    removeCookie: '.reset'
  });

// referenzen scroll to ...
  $('#refsubnav ul li a').anchorScroll();

// company show/hide moreinfo
  $('p#showmoreinfo a').click(function(){
    $('#moreinfo').slideDown(200);
    $('p#showmoreinfo').hide();
    return false;
  });

  $('p#hidemoreinfo a').click(function(){
    $('#moreinfo').slideUp(200);
    $('p#showmoreinfo').show();
    return false;
  });

// publications
  $('#press table tr:even').addClass('even');

// blaetterkatalog popupWindow
  $('.cataloguewindow').popupWindow({
    width: 1000,
    height: 900,
    top: 50,
    left: 50,
    centerScreen: 1
  });

// layout fixes - no dotted outline on hover, focus

  $('a img').parent().css('border','none');

  $('a').focus(function() {
      $(this).blur();
  });

  $('.branche:last').addClass('last');

  $('body#projects .listing .projectteaser:nth-child(3n)').css('margin-right','0');    
  
  $.each($('.projectsingleright'), function(index, value) {
      var centerright = $(value);
      var left = centerright.find('.projectsinglecenterleft');
      var right = centerright.find('.projectsinglecenterright');

      if (left.length && !left.children().length && right.length && !right.children().length) {
        var centerleft = centerright.prev('.projectsingleleft'); 
        centerright.hide(); 
        centerleft.hide(); 
      }
  });
  
});

// additional plugins ------------------------------------------------

// anchorScroll
(function($){
    $.fn.anchorScroll = function(options) {
        var defaults = {
            speed: 800,
            fx: "jswing"
        };
        //var version =  "1.0";
        var options = $.extend(defaults, options);
        return $(this).each(function(){
            var element = this;


            $(element).click(function (event) {

                var locationHref = window.location.href;
                var elementClick = $(element).attr("href");

                var destination = $(elementClick).offset().top;

                $("html,body").animate({ scrollTop: destination}, options.speed,  options.fx);

                //Stop links default events
                event.preventDefault();
                return false;
            })
        })
    }
})(jQuery);

// meerkat 1.3
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}('4.1Y.1k({8:5(1E){9 1r={v:\'g\',E:m,k:\'1n\',y:\'w%\',h:\'1u\',U:\'.U\',13:\'#1P-u\',1s:T,18:\'g\',R:m,P:\'Z\',x:\'Z\',K:\'1J\',Q:0,1a:\'.1a\',f:0,1I:5(){},l:m};9 3=4.1k(1r,1E);7(4.1U.1S){3.P=3.P;3.x=3.x}p{3.P=\'Z\';3.x=\'Z\'}7(3.R===m){3.R=3.18}3.f=3.f*1c;7(3.l!=m){3.l=3.l*1c}5 I(F,1D,1d){7(1d){9 12=1M 1N();12.1O(12.1Q()+(1d*24*1w*1w*1c));9 10="; 10="+12.1L()}p{9 10=""}q.1m=F+"="+1D+10+"; 1R=/"}5 1v(F){9 19=F+"=";9 1b=q.1m.1K(\';\');1X(9 i=0;i<1b.S;i++){9 c=1b[i];1W(c.1V(0)===\' \')c=c.1q(1,c.S);7(c.1T(19)===0)t c.1q(19.S,c.S)}t m}5 1o(F){I(F,"",-1)}4(3.1a).D(5(){1o(\'8\')});t e.23(5(){9 16=4(e);7(1v(\'8\')!="X"){3.1I.2l(e);5 O(11,H){9 j=4(\'#8-d\');7(H==="B"){7(3.h==="1e"||3.h==="1f"){9 14=\'y\'}p{9 14=\'k\'}}p{9 14="E"}9 A={};A[14]=11;7(11==="u"){7(H!=="g"){7(3.f>0){4(j).a().f(3.f).W(A,3.K,3.P)}p{4(j).a().W(A,3.K,3.P)}}p 7((H==="g")&&(3.f>0)){4(j).a().f(3.f).u(0)}p{4(j).u()}4(16).u(0)}7(11==="a"){7(H!=="g"){7(3.l!==m){4(j).f(3.l).W(A,3.K,3.x,5(){4(e).o();7(3.1s===2k){I(\'8\',\'X\',3.Q)}})}4(3.U).D(5(){4(j).1t().W(A,3.K,3.x,5(){4(e).o()});t T});4(3.13).D(5(){4(j).1t().W(A,3.K,3.x,5(){4(e).o()});I(\'8\',\'X\',3.Q);t T})}p 7((H==="g")&&(3.l!==m)){4(j).f(3.l).a(0).N(5(){4(e).o()})}p{4(3.U).D(5(){4(j).a().N(5(){4(e).o()});t T});4(3.13).D(5(){4(j).a().N(5(){4(e).o()});I(\'8\',\'X\',3.Q);t T})}}}4(\'1y, n\').b({\'2h\':\'0\',\'k\':\'w%\'});4(16).d(\'<s 15="8-d"><s 15="8-r"></s></s>\');4(\'#8-d\').b({\'h\':\'2i\',\'z-17\':\'2n\',\'y\':3.y,\'k\':3.k}).b(3.h,"0");4(\'#8-r\').b({\'v\':3.v,\'k\':3.k});7(3.h==="1e"||3.h==="1f"){4(\'#8-d\').b("1i",0)}7(3.E!=m){4("#8-d").2o(\'<s 2s="E-1j"></s>\');4(\'#8-r\').b({\'v\':\'2q\',\'z-17\':\'2\',\'h\':\'2t\'});4(".E-1j").b({\'h\':\'1g\',\'1i\':\'0\',\'k\':\'w%\',\'y\':\'w%\',\'v\':3.v,"E":3.E})}7(4.1l.2g&&4.1l.2f<=6){4(\'#8-d\').b({\'h\':\'1g\',\'1u\':\'-26\',\'z-17\':\'0\'});7(4(\'#V-Y-r\').S==0){4(\'n\').22().20(5(17){t 4(e).1Z(\'15\')!=\'8-d\'}).21(\'<s 15="V-Y-r"></s>\');4(\'1y, n\').b({\'k\':\'w%\',\'y\':\'w%\',\'1z\':\'28\'});4(\'#V-Y-r\').b({\'1z\':\'1n\',\'y\':\'w%\',\'k\':\'w%\',\'h\':\'1g\'});9 C=q.n.G.2d+" ";C+=q.n.G.2e+" ";C+=q.n.G.2c+" ";C+=q.n.G.2b+" ";C+=q.n.G.29+" ";C+=q.n.G.2a;4("n").b({\'v\':\'g\'});4("#V-Y-r").b({\'v\':C})}9 1h=q.2r(\'V-Y-r\');7((1h.27<1h.25)&&(3.h!=\'1e\')){4(\'#8-d\').b({\'1f\':\'2p\'})}}1H(3.18){M"B":O("u","B");J;M"L":O("u","L");J;M"g":O("u","g");J;1x:1B(\'1C 18 1p 1A 1G "B", "L", 1F "g"\')}1H(3.R){M"B":O("a","B");J;M"L":O("a","L");J;M"g":7(3.l!=m){4(\'#8-d\').f(3.l).a(0).N(5(){4(e).o()})}4(3.U).D(5(){4(\'#8-d\').a().N(5(){4(e).o()})});4(3.13).D(5(){4(\'#8-d\').a().N(5(){4(e).o()});I(\'8\',\'X\',3.Q)});J;1x:1B(\'1C R 1p 1A 1G "B", "L", 1F "g"\')}}p{4(16).a()}})},o:5(){4(\'#8-d\').2j(4(\'#8-r\').2m().a())}});',62,154,'|||settings|jQuery|function||if|meerkat|var|hide|css||wrap|this|delay|none|position||meerkatWrap|height|timer|null|body|destroyMeerkat|else|document|container|div|return|show|background|100|easingOut|width||animationProperty|slide|bgProperties|click|opacity|name|currentStyle|fadeOrSlide|createCookie|break|animationSpeed|fade|case|queue|animateMeerkat|easingIn|cookieExpires|animationOut|length|false|close|ie6|animate|dontshow|content|swing|expires|showOrHide|date|dontShowAgain|animationType|id|element|index|animationIn|nameEQ|removeCookie|ca|1000|days|left|right|absolute|ie6ContentContainer|top|layer|extend|browser|cookie|auto|eraseCookie|option|substring|defaults|dontShowAgainAuto|stop|bottom|readCookie|60|default|html|overflow|only|alert|The|value|options|or|accepts|switch|onMeerkatShow|normal|split|toGMTString|new|Date|setTime|dont|getTime|path|def|indexOf|easing|charAt|while|for|fn|attr|filter|wrapAll|children|each||scrollHeight|1px|clientHeight|hidden|backgroundPositionX|backgroundPositionY|backgroundAttachment|backgroundRepeat|backgroundColor|backgroundImage|version|msie|margin|fixed|replaceWith|true|call|contents|10000|prepend|17px|transparent|getElementById|class|relative'.split('|'),0,{}))

// img zoom http://andreaslagerkvist.com/jquery/image-zoom/
jQuery.fn.imageZoom=function(conf){var config=jQuery.extend({speed:200,dontFadeIn:0,hideClicked:0,imageMargin:15,className:'jquery-image-zoom',loading:'laden...'},conf);config.doubleSpeed=config.speed/4; return this.click(function(e){var clickedElement=jQuery(e.target);var clickedLink=clickedElement.is('a')?clickedElement:clickedElement.parents('a');clickedLink=(clickedLink&&clickedLink.is('a')&&clickedLink.attr('href').search(/(.*)\.(jpg|jpeg|gif|png|bmp|tif|tiff)$/gi)!=-1)?clickedLink:false;var clickedImg=(clickedLink&&clickedLink.find('img').length)?clickedLink.find('img'):false;if(clickedLink){clickedLink.oldText=clickedLink.text();clickedLink.setLoadingImg=function(){if(clickedImg){clickedImg.css({opacity:'0.5'})}else{clickedLink.text(config.loading)}};clickedLink.setNotLoadingImg=function(){if(clickedImg){clickedImg.css({opacity:'1'})}else{clickedLink.text(clickedLink.oldText)}};var displayImgSrc=clickedLink.attr('href');if(jQuery('div.'+config.className+' img[src="'+displayImgSrc+'"]').length){return false}var preloadOnload=function(){clickedLink.setNotLoadingImg();var dimElement=clickedImg?clickedImg:clickedLink;var hideClicked=clickedImg?config.hideClicked:0;var offset=dimElement.offset();var imgzoomBefore={width:dimElement.outerWidth(),height:dimElement.outerHeight(),left:offset.left,top:offset.top};var imgzoom=jQuery('<div><img src="'+displayImgSrc+'" alt="" /></div>').css('position','absolute').appendTo(document.body);var imgzoomAfter={width:imgzoom.outerWidth(),height:imgzoom.outerHeight()};var windowDim={width:jQuery(window).width(),height:jQuery(window).height()};if(imgzoomAfter.width>(windowDim.width-config.imageMargin*2)){var nWidth=windowDim.width-config.imageMargin*2;imgzoomAfter.height=(nWidth/imgzoomAfter.width)*imgzoomAfter.height;imgzoomAfter.width=nWidth}if(imgzoomAfter.height>(windowDim.height-config.imageMargin*2)){var nHeight=windowDim.height-config.imageMargin*2;imgzoomAfter.width=(nHeight/imgzoomAfter.height)*imgzoomAfter.width;imgzoomAfter.height=nHeight}imgzoomAfter.left=(windowDim.width-imgzoomAfter.width)/2+jQuery(window).scrollLeft();imgzoomAfter.top=(windowDim.height-imgzoomAfter.height)/2+jQuery(window).scrollTop();var closeButton=jQuery('<a href="#">Close</a>').appendTo(imgzoom).hide();if(hideClicked){clickedLink.css('visibility','hidden')}imgzoom.addClass(config.className).css(imgzoomBefore).animate(imgzoomAfter,config.speed,function(){closeButton.fadeIn(config.doubleSpeed)});var hideImgzoom=function(){closeButton.fadeOut(config.doubleSpeed,function(){imgzoom.animate(imgzoomBefore,config.speed,function(){clickedLink.css('visibility','visible');imgzoom.remove()})});return false};imgzoom.click(hideImgzoom);closeButton.click(hideImgzoom)};var preload=new Image();preload.src=displayImgSrc;if(preload.complete){preloadOnload()}else{clickedLink.setLoadingImg();preload.onload=preloadOnload}return false}})};$(document).keydown(function(e){if(e.keyCode==27){$('div.jquery-image-zoom a').click()}});

// popup window
(function($){
  $.fn.popupWindow = function(instanceSettings){

    return this.each(function(){

    $(this).click(function(){

    $.fn.popupWindow.defaultSettings = {
      centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
      centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
      height:500, // sets the height in pixels of the window.
      left:0, // left position when the window appears.
      location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
      menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
      resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
      scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
      status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
      width:500, // sets the width in pixels of the window.
      windowName:null, // name of window set from the name attribute of the element that invokes the click
      windowURL:null, // url used for the popup
      top:0, // top position when the window appears.
      toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
    };

    settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});

    var windowFeatures =    'height=' + settings.height +
                ',width=' + settings.width +
                ',toolbar=' + settings.toolbar +
                ',scrollbars=' + settings.scrollbars +
                ',status=' + settings.status +
                ',resizable=' + settings.resizable +
                ',location=' + settings.location +
                ',menuBar=' + settings.menubar;

        settings.windowName = this.name || settings.windowName;
        settings.windowURL = this.href || settings.windowURL;
        var centeredY,centeredX;

        if(settings.centerBrowser){

          if ($.browser.msie) {//hacked together for IE browsers
            centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
            centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
          }else{
            centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
            centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
          }
          window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
        }else if(settings.centerScreen){
          centeredY = (screen.height - settings.height)/2;
          centeredX = (screen.width - settings.width)/2;
          window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
        }else{
          window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();
        }
        return false;
      });

    });
  };
})(jQuery);

