window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};

jQuery(document).ready(function($){
  
  var ie_lt_8 = $.browser.msie && $.browser.version.substr(0,1) < 8;
  
  //grosser verticaler slider
  var full_slide = $('.fce_keyvisual_full_slide');
  if(full_slide.length){
    
  var keyvisual_elements = full_slide.find('.fce-kv-element').unwrap().parent();
    var keyvisual_animated_controls = $('<div id="keyvisual_animated_controls"><div id="keyvisual_animated_nav" /></div>').appendTo(full_slide.parent());

    keyvisual_elements.cycle({
      fx: 'scrollVert',
      sync: 1,
      speed: 1000,
      timeout: 5000,
      delay: 200,
      easing: 'easeInOutExpo',
      pager:  '#keyvisual_animated_nav'
    });
    
    
    var keyvisual_on_off = $('<a class="on-off">Pause</a>').prependTo(keyvisual_animated_controls);
    keyvisual_on_off.toggle(
      function(){
        keyvisual_on_off.text('Start').addClass('paused');
        keyvisual_elements.cycle('pause');

      },
      function(){
        keyvisual_on_off.text('Pause').removeClass('paused');
        keyvisual_elements.cycle('resume');
      }
    );  
    
  }
  
  
  var side_slide = $('.mod-horz-slide');
  if(side_slide.length){
      
      
    var shadow = $('<a>', {'class':'mod-horz-slide-shadow'}).appendTo(side_slide);
    
    side_slide.find('.slide').unwrap();
    
    var side_slide_cycle = side_slide.find('.mod-horz-slide-slides').cycle({
      fx: 'scrollHorz',
      sync: 1,
      speed: 400,
      timeout: 5000,
      delay: 200,
      easing: 'easeInOutExpo',
      after: function(){
        shadow.attr({
          'href' : $(this).attr('href'),
          'title' : $(this).attr('title')
        });
      }
    });
    
    var nav = $('<div>', {'class':'mod-horz-slide-nav', 'html':'<a class="prev" href="#">Zurück</a><a class="next" href="#">Nächster</a>'}).appendTo(side_slide);
    
    nav.find('.prev').click(function(){ side_slide_cycle.cycle('prev'); return false; });
    nav.find('.next').click(function(){ side_slide_cycle.cycle('next'); return false; });
    
  }  
  
  $('.fce_tabbed').tabbed();
  $('.fce_horizontal_nav_slide').h_nav_slider();
  $('.slide_container').brandslider();

  $('.auftragsauskunft .form_helper').click(function(el){
    $.fancybox({
      type:'iframe',
      href: 'http://hardeck.de/service/auftragsauskunft/popup/',
      width: 520,
      height: '75%',
      autoScale: false,
      transitionIn: 'none',
      transitionOut: 'none'
    });
    el.preventDefault();
  });
  
  // Kuechenplaner
  
   var ddkps = $('.page-727 #c3868 img, .page-727 #c3878 img, .page-727 #c3868 h2, .page-727 #c3869 img, .3dkp-jq');

   if ($.browser.flash == true){
    ddkps.css('cursor', 'pointer').click(function(){
      $(this).removeAttr("target");
      $.fancybox({
        type:'iframe',
        href: 'http://www.hardeck.de/fileadmin/templates/hardeck/grafik/3d_kuechenplaner/kuechenplaner_frame_4_jquery.html',
        width: '90%',
        height: 830,
        autoScale: true,
        scrolling: 'no',
        transitionIn: 'elastic',
        transitionOut: 'elastic'
      });
    });
  }else{
    ddkps.css('cursor', 'pointer').click(function(){
      $(this).removeAttr("target");
      alert("Für diese Anwendung muss Flash eingeschaltet sein!");
    });
  }
    
  openLightbox = function(form) {
    var error = false;
    if($('#contract').val().length != 6) {
      $('#contract').css('backgroundColor', '#FDA2A4');
      error = true;
    }
    if($('#pin').val().length < 4) {
      $('#pin').css('backgroundColor', '#FDA2A4');
      error = true;
    }
    if(!error) {
      $('#contract').css('backgroundColor', '#eee');
      $('#pin').css('backgroundColor', '#eee');
      $.fancybox({
        'width'        : 520,
        'height'      : '75%',
        'autoScale'      : false,
        'transitionIn'    : 'none',
        'transitionOut'    : 'none',
        'type'        : 'iframe',
        'href'        : ''
      });
      return true;
    }
    return false;
  }

  $('a[rel^="lightbox"]').fancybox({
                   
    'transitionIn':'elastic',
    'transitionOut':'elastic',
    'speedIn':400, 
    'speedOut':200
  });
  
  $('.welcome-lightbox').each(function(){
    var root = $(this), childs = root.find('img'), imgs = [], intv;
    
    if(!childs.length){
      return;
    }
    
    // make an array
    childs.each(function(){
      child = $(this);
      img = {
        'href': child.attr('src'),
        'title': child.attr('alt')
      }
      imgs.push(img);
    });
    
    $.fancybox(imgs, {
      'transitionIn': 'fade',
      'transitionOut': 'none',
      'type': 'image',
      'cyclic':  true,
      'overlayColor': '#076e9b',
      'onClosed': function(){
        clearInterval(intv);
      }
    });
    
    intv = setInterval(function(){
      $.fancybox.next();
    }, 3000);
    
  });
  


  $('.socialbar').find('li a.rewrite').each(function() {
    var newhref = $(this).attr('href').replace('http%3A%2F%2Fwww.hardeck.de',encodeURIComponent(location.href)).replace('M%C3%96BEL+HARDECK', encodeURIComponent(document.title));
    $(this).attr({href : newhref});
  });

  $('#btn-share').hover(function(){
    off = $(this).offset();
    $('#sharer').css({top : off.top-40, left : off.left-30}).fadeIn().mouseleave(function(el){
      $('#sharer').fadeOut();
    })
  });

  if ($.browser.flash == false){
    var links2 = $('a[href*="HARDECK-Prospekte/Moebel-Prospekt"],a[href*="HARDI-Prospekte/HARDI-Moebel-Prospekt"],a[href*="DEPO-Prospekte/DEPO-Moebel-Prospekt"]');
    console.log(links2);
    links2.attr('href', $('#prospekt_text p a').first().attr('href'));
  }

});

jQuery.fn.cycle.transitions.keyvisual_zoom = function($cont, $slides, opts) {
  opts.before.push(function(curr, next, opts) {
    jQuery.fn.cycle.commonReset(curr,next,opts,false,false,true);
    opts.cssBefore.top = 290;
    opts.cssBefore.left = 270;
    opts.cssBefore.width = 1;
    opts.cssBefore.height = 1;
    opts.animIn     = { top: 0, left: 0, width: next.cycleW, height: next.cycleH };
    opts.animOut   = { width: 0, height: 0, top: 290, left: 270 };
  });
  
  opts.cssFirst = { top:0, left: 0 };
  opts.cssBefore = { width: 0, height: 0 };
};
