var BASIC_URL = '/';
var URL = BASIC_URL;

//function slide() {
/*var news = $('#news');
  var newsWidth = news.width();  
  var ul = $('ul', news);
  var ulWidth = ul.outerWidth(); 
  var li = $('li:first', ul);
  var liWidth = li.outerWidth();
    
  var pxSpeed = 25000/ulWidth;
  
  ul.animate({ left: -liWidth }, liWidth*pxSpeed, 'linear', function () {    
    ul.append(li);
    ul.css('left', 0);
    
    slide();
  });*/
  
  
/*var ul = $('#news ul');
  var width = ul.width();
  var left = parseInt(ul.css('left'), 10);
  ul.css('left', left-1);  
  
  var li = $('li:first', ul);
  if (li.width() <= -left) {    
    ul.append(li);
    ul.css('left', left+li.width());
  }
  
  //if ($('#news').width() - left >= ul.width()) {    
  //  var lis = $('li', ul).clone();
  //  ul.append(lis);
  //}   
  
  setTimeout("slide()", 20); */
//}

$(function () {
  
  if ($('body').hasClass('dealer-page')) {
    URL = '/dealer.php/'+ $('body').attr('id').split('-')[1] +'/';
  }
  
  var addToWishlist = function (id) {
    $.post(BASIC_URL +'merkliste/auf', {
      id: id
    });
    
    var count = parseInt($('#wishlist-count').text(), 10);
    $('#wishlist-count').text(count+1);
    alert('Das Produkt wurde auf die Merkliste hinzugefügt');
  };
  
  /**
   * Preload images
   */
  var menuActive = $('#menu ul li a.active');
  var menuBg = [];
  $('#menu ul li a').each(function () {
    var bg = $(this).addClass('active').css('background-image');    
    var path = bg.match(/url\(\"(.*?)\"\)/);
    if (path !== null) {
      menuBg.push(path[1]);
    }    
    $(this).removeClass('active');    
  });
  menuActive.addClass('active');  
  
  $.preloadImages(menuBg);
  
  /**
   * Gallery
   */
  $("a[rel^='gallery']").prettyPhoto({
    theme:'officebase',
    showTitle: false
  });

  /**
   * Search
   */
  $('#search').focus(function () {
    if ($(this).val() === 'Suche' || $(this).val() === '') {
      $(this).val('').removeClass('placeholder');
    }
  }).blur(function () {    
    if ($(this).val() === 'Suche' || $(this).val() === '') {
      $(this).val('Suche').addClass('placeholder');
    }
  }).blur();
  
  /**
   * Menu
   */
  var active = false;
  $('#menu li').mouseenter(function () {
    var submenu = $('.submenu, .submenu-arrow', this);
    if (submenu.length === 0) {
      return true;
    }
    
    $(this).css('z-index', 1003);
    $('body').prepend('<div id="overlay"></div>');
    submenu.show();
    
    if ($('a:first', this).hasClass('active') === true) {
      active = $('a:first', this).attr('href');
    } else {
      $('a:first', this).addClass('active');
    }    
  }).mouseleave(function () {
    var submenu = $('.submenu, .submenu-arrow', this);
    if (submenu.length === 0) {
      return true;
    }
    
    submenu.hide();
    $('#overlay').remove();
    
    if (active !== $('a:first', this).attr('href')) {
      $('a:first', this).removeClass('active');
    }    
  }).find('a:first').click(function () {
    var submenu = $(this).siblings('.submenu, .submenu-arrow');
    if (submenu.length === 0 || submenu.is(':hidden') === false) {
      return true;
    }
    
    if (submenu.is(':hidden')) {
      $(this).parent().mouseenter();
    } else {
      $(this).parent().mouseleave();
    }
  });
    
    
  /**
   * News
   */
  
  /*var mycarousel_initCallback = function (carousel) {
    $('.jcarousel-control a').bind('click', function() {
      $(this).siblings().removeClass('active');
      $(this).addClass('active');
      carousel.scroll($.jcarousel.intval($(this).text()));
      return false;
    });
  };*/

  var newsSlide = function () {

    var news = $('#news'); 
    var ul = $('ul', news);
    var ulWidth = ul.outerWidth(); 
    var li = $('li:first', ul);
    var liWidth = li.outerWidth();
    
    var pxSpeed = parseInt(35000/ulWidth, 10);
  
    ul.animate({
      left: -liWidth
    }, liWidth*pxSpeed, 'linear', function () {    
      ul.append(li);
      ul.css('left', 0);      
    
      newsSlide();
    });
    
  };
  
  if ($('#news ul li').length > 0) {
    /*$('#news ul').cycle({
      fx: 'scrollLeft',          
      containerResize: 0,
      continuous: 1, 
      speed: 8000
    });*/
        
    var lis = $('#news ul li');
    $('#news ul').append(lis); // inline-block additional margin fix
    
    $(window).load(function () {
      $('#news ul').append(lis); // IE bug fix
      newsSlide();  
    });    
  
  /*$('#news').jcarousel({
      auto: 2,
      scroll: 1,
      wrap: 'last',
      initCallback: mycarousel_initCallback,        
      itemVisibleInCallback: {            
        onAfterAnimation:  function (carousel, li, index, state) {      
          var length = $('.jcarousel-control a').length;
          while (index > length) {
            index -= length;
          }        
          $('.jcarousel-control a').removeClass('active');        
          $('.jcarousel-control a:nth('+ (index-1) +')').addClass('active');
        }
      },
      buttonNextHTML: null,
      buttonPrevHTML: null
    });*/
  }
  
  
  
  /**
   * Product groups
   */
  
  $('.filter .categories select, .filter .more select, .filter .dealers-filter select').change(function () {
    if ($(this).val() !== '') {
      $(this).parent().addClass('active');
    } else {
      $(this).parent().removeClass('active');
    }
    
    if ($('#content').attr('class').match(/productGroup/)) {
      var path = URL +'produktgruppen';
      if ($('#filter-group').val() !== '') {
        path = path +'/'+ $('#filter-group').val();
      }
      if ($('#filter-group2').val() !== '' && $(this).attr('id') !== 'filter-group') {
        path = path +'/'+ $('#filter-group2').val();
      }
      if ($('#filter-group3').val() !== '' && $(this).attr('id') !== 'filter-group' && $(this).attr('id') !== 'filter-group2') {
        path = path +'/'+ $('#filter-group3').val();
      }
      if ($('#filter-material').val() !== '' && $(this).attr('id') !== 'filter-group' && $(this).attr('id') !== 'filter-group2' && $(this).attr('id') !== 'filter-group3') {
        path = path +'?material='+ $('#filter-material').val();
      }
      if ($('#filter-application').val() !== '' && $(this).attr('id') !== 'filter-group' && $(this).attr('id') !== 'filter-group2' && $(this).attr('id') !== 'filter-group3') {
        if ($('#filter-material').val() !== '') {
          path = path +'&';
        } else {
          path = path +'?';
        }
        path = path + 'application='+ $('#filter-application').val();
      }
      
      $('#list').html('<div class="loader"></div>');
      
      location = path;
    } else if ($(this).attr('id') === 'dealers-filter-group') {
      
      if ($(this).val() === '') {
        $('#dealers-filter-brand option').show();
      } else {
        $('#dealers-filter-brand option').hide();
        $('#dealers-filter-brand').prepend('<option value="" selected="selected">Loading...</option>');
                  
        $.get(URL +'produktgruppen/'+ $(this).val() +'/marken', function (json) {
          $('#dealers-filter-brand option:first').attr('selected', false).remove();
                            
          $('#dealers-filter-brand option').each(function () {
            if ($.inArray($(this).val(), json) > -1) {
              $(this).show();
            }
          });
          
          $('#dealers-filter-brand option:first').show();
        }, 'json');
      }                  
    }
  });
  
  $('.sort').change(function () {
    if ($('#content').attr('class').match(/productGroup/)) {
      var path = URL +'produktgruppen/'+ $('#filter-group').val();
      if ($('#filter-group2').val() !== '') {
        path = path +'/'+ $('#filter-group2').val();
      }
      if ($('#filter-group3').val() !== '') {
        path = path +'/'+ $('#filter-group3').val();
      }
      
      path = path +'?';     
      if ($('#filter-material').val() !== '') {
        path = path +'material='+ $('#filter-material').val() +'&';
      }
      if ($('#filter-application').val() !== '') {
        path = path +'application='+ $('#filter-application').val() +'&';
      }
      
      path = path +'sort='+ $(this).val();
      
      $('#list').html('<div class="loader"></div>');
      
      location = path;
    }
  });
  
  $('#filter-showMore').click(function () {
    $('.filter .more').show();
    $(this).remove();
  });
       
  /* PRODUCT DETAIL PRODUCT
   * 
  $('#list #products a, #family a').click(function (e) {
    e.preventDefault();
    
    var a = $(this);
    
    $('body').prepend('<div id="product-overlay" class="transparent"></div>');
    $('#product-overlay').after('<div id="product-popup"></div>');    
    
    var popup = $('#product-popup');    
    var top = a.offset().top - (popup.outerHeight()-a.height())/2;        
    if (top < 0) {
      top = 0;
    } else if (top + popup.outerHeight() > $(document).height()) {
      top = $(document).height() - popup.outerHeight();
    }
    var left = a.offset().left - (popup.outerWidth()-a.width())/2;
    if (left < 0) {
      left = 0;
    } else if (left + popup.outerWidth() > $(document).width()) {
      left = $(document).width() - popup.outerWidth();
    }
    
    popup.css({
      top: top,
      left: left
    });
    
    var name = $('img', a).attr('alt');
    if (!name) {
      name = '';
    }
    var img = $('img', a).attr('src');
    if (img) {
      img = img.match(/(.*)\/thumbnails\/([a-zA-Z0-9_\-]*)\/(.*)/);    
    }
    
    var shortName = name;
    if (shortName.length > 20) {
      shortName = shortName.substr(0, 20) +'...';
    }
    
    html = '<div class="heading"><a href="'+ a.attr('href') +'">'+ shortName +'</a></div>';
    if ($('#content').hasClass('wishlist') === false && $('#content').hasClass('planner') === false) {
      html += '<a class="right button light merkliste add-to-wishlist">Auf die Merkliste</a>';
    }    
    html += '<div class="clr"></div>\n\
    <div class="img">';
    if (img) {
      html = html +'<a href="'+ a.attr('href') +'"><img src="'+ img[1] +'/thumbnails/productPopup/'+ img[3] +'" alt="'+ name +'" /></a>';
    }
    html = html +'</div>\n\
    <div class="loader"></div>';
    
    popup.html(html);
    
    var path = 'produktPopup';
    if ($('#content').attr('class').match(/planner/)) {
      path = 'planungPopup';
    }
    
    var id = a.attr('id').split('-')[1];  
    
    $('#product-popup .add-to-wishlist').click(function (e) {
      e.preventDefault();
      
      addToWishlist(id);
      
      return false;
    });
                  
    $.get(URL + path +'/'+ id, function (html) {
      popup.find('.loader').remove();
      popup.find('.img').after(html);
    });
    
    popup.click(function () {
      location = a.attr('href');
    });
    
    return false;
  });
   */
  
  $('#product-overlay').live('click', function () {
    $(this).remove();
    $('#product-popup').remove();
  });
  
  $(window).keyup(function (e) {
    if (e.keyCode == 27) { 
      if ($('#product-overlay').length > 0) {
        $('#product-overlay').click();
      }
    } 
  });
  
  
  /**
   * Product
   */
  
  var clickedOn = null;
  
  $('#product #productImg, #product-references .img').live('mouseenter', function () {
    var block = $(this);    
    var more = $('#product .moreImages a');
    if ($('#product-references').length > 0) {
      more = $('#product-references .moreImages a');
    }
    if ($('img', block).length > 0 && more.length > 1) {      
      var offset = block.offset();
      var center = offset.left + block.width()/2;
                              
      $(document).mousemove(function (e) {                       
        var img = $("img", block);
        var imgTop = img.position().top;
        var navPossition = (block.width() - img.width())/2;      
        var navHeightBasic = img.height()/2;
        var navHeight = navHeightBasic+10;
        var navPadding = navHeightBasic-10;        
        
        if (e.clientX < center || clickedOn === 'prev') {
          if ($("a.prev", block).length === 0) {            
            block.prepend('<a class="prev"></a>');
            $("a.next", block).remove();
          }
          $("a.prev", block).css({
            top: imgTop, 
            'left': navPossition,
            'height': navHeight,
            'padding-top': navPadding
          });            
        } else {
          if ($("a.next", block).length === 0) {
            block.prepend('<a class="next"></a>');            
            $("a.prev", block).remove();
          }
          $("a.next", block).css({
            top: imgTop, 
            'right': navPossition,
            'height': navHeight,
            'padding-top': navPadding
          });
        }
        
        clickedOn = null;
      });                
    }
  }).live('mouseleave', function () {    
    $('a', this).remove();
    $(document).unbind('mousemove');
  });
  
  $('#product #productImg a, #product-references .img a').live('click', function (e) {
    var all = $('#product .moreImages a');
    if ($('#product-references').length > 0) {
      all = $('#product-references .moreImages a');
    }
    var a = null;
    if ($(this).hasClass('prev')) {
      a = $('#product .moreImages a.active').prev('a');    
      if ($('#product-references').length > 0) {
        a = $('#product-references .moreImages a.active').prev('a');    
      }
      if (a.length === 0) {
        a = all.last();
      }
      clickedOn = 'prev';
    } else {
      a = $('#product .moreImages a.active').next('a');      
      if ($('#product-references').length > 0) {
        a = $('#product-references .moreImages a.active').next('a');    
      }
      if (a.length === 0) {
        a = all.first();
      }
      clickedOn = 'next';
    }    
    
    a.click();    
    var img = $('#product #productImg');
    if ($('#product-references').length > 0) {
      img = $('#product-references .img');
    }
    img.mouseleave();
  });
  
  $('#product .moreImages a, #product-references .moreImages a').live('click', function (e) {
    e.preventDefault();
    
    var key = $(this).prevAll().length;
    $(this).siblings().removeClass('active');
    $(this).addClass('active');
    
    var img = $('img', this).attr('src').match(/(.*)\/thumbnails\/([a-zA-Z0-9_\-]*)\/(.*)/);      
    
    var block = $('#product .img:first');
    if ($('#product-references').length > 0) {
      block = $('#product-references .img');
    }
    $('img', block).remove();
    block.addClass('loading');
    
    block.append('<img src="'+ img[1] +'/thumbnails/productBig/'+ img[3] +'" alt="" />');
    if ($('#product-references').length > 0) {
      $("div[id^='reference-description-']").hide();
      $('#reference-description-'+ key).show();
    }
    
    $('img', block).load(function () {
      block.removeClass('loading');    
      $(document).mousemove();
    });        
    
    return false;
  });
  
  $("#open-popup-catalog, .open-popup-catalog, #open-popup-documents, #open-popup-offer, #open-popup-pricelist, #open-popup-cad, #open-popup-send, .open-newsletter, .mail").click(function (e) {
    e.preventDefault();
    
    var a = $(this);
    var type = a.attr('id').split('-');
    type = type[type.length-1];
    if (a.hasClass('mail')) {
      type = 'mail'
    }
    
    var path = BASIC_URL +'produktAnforden';
    if (type === 'mail') {
      var company = parseInt(a.attr('id').split('-')[1], 10);
      path = path +'?type=mail&company='+ company;
    } else if (type === 'catalog' || a.hasClass('open-popup-catalog')) {
      path = path +'?type=katalog';
    } else if (type === 'documents') {
      path = path +'?type=unterlagen';
    } else if (type === 'offer') {
      path = path +'?type=angebot';
    } else if (type === 'pricelist') {
      path = path +'?type=preisliste';
    } else if (type === 'cad') {
      path = path +'?type=cad';
    } else if (type === 'send') {
      if ($('body').hasClass('dealer-page')) {
        path = BASIC_URL +'produktSenden?link='+ window.parent.location;
      } else {
        path = BASIC_URL +'produktSenden?link='+ window.location;
      }      
    } else {
      if (a.hasClass('open-newsletter')) {
        type = 'newsletter';
        path = BASIC_URL +'newsletter';
      }      
    }
    
    
    $('body').prepend('<div id="overlay" class="black"></div>');
    $('#overlay').after('<div id="popup"></div>');    
    
    var popup = $('#popup');            
                    
    $(window).resize(function () {
      popup.css({
        top: ($(window).height() - popup.outerHeight())/2,
        left: ($(window).width() - popup.outerWidth())/2
      });
    }).resize();
    
    popup.addClass('loading');
            
    $.get(path, function (html) {
      popup.html(html);
      popup.removeClass('loading');
      
      $('.button', popup).click(function () {
        var empty = false;
        $('.required input, .required textarea', popup).each(function () {
          if ($(this).val() === '') {
            empty = true;
            return;
          }
        });
        
        if (empty === true) {
          alert('Sie haben nicht alle Pflichtfelder ausgefüllt!');
          return false;
        }
        
        $(this).after('<div class="loader right"></div>');        
        
        var data = {};
        
        if (type === 'mail') {
          data['company'] = company;
        } else {
          if (type !== 'newsletter' && $('#product').length > 0) {
            data['product'] = parseInt($('#product').attr('class').split('id-')[1], 10);
          }
          if (a.hasClass('open-popup-catalog')) {
            data['brand'] = parseInt(a.attr('id').split('-')[1], 10);
          }        
        }      
        
        if ($('body').hasClass('dealer-page')) {
          data['dealer'] = $('body').attr('id').split('-')[1];
        }
        
        $('input, textarea', popup).each(function () { 
          data[$(this).attr('name')] = $(this).val();
        });                
        
        $.post(path, data, function (response) {          
          $('.loader', popup).remove();
          
          if(response === '')
          {            
            if (type === 'newsletter') {
              alert('Sie haben den Newsletter abonniert');
            } else {
              alert('Ihre Nachricht wurde gesendet');
            }
            $('#popup .close').click();
          }
          else
          {
            alert(response);
          }          
        });
      });
    });
            
    return false;
  });
  
  $('#overlay, #popup .close').live('click', function () {
    $('#overlay, #popup').remove();    
  });
  
  $(window).keyup(function (e) {
    if (e.keyCode == 27) { 
      if ($('#overlay').length > 0) {
        $('#overlay').click();
      }
    }   
  });
  
  $('#open-references').click(function () {
    //$('#references a:first').click();
    
    $('body').prepend('<div id="overlay" class="black"></div>');
    $('#overlay').after('<div id="popup"></div>');    
    
    var popup = $('#popup');            
    popup.css({
      width: 450, 
      'min-height': 450
    });
                    
    $(window).resize(function () {
      popup.css({
        top: ($(window).height() - popup.outerHeight())/2,
        left: ($(window).width() - popup.outerWidth())/2
      });
    }).resize();
    
    popup.addClass('loading');
            
    $.get(BASIC_URL +'produktReferenzen/'+ parseInt($('#product').attr('class').split('id-')[1], 10), function (html) {
      popup.html(html);
      popup.removeClass('loading');
    });
  });
  
  $('#print').click(function () {
    window.print();
  });
      
  $('#product .add-to-wishlist').click(function () {
    var id = parseInt($('#product').attr('class').split('id-')[1], 10);
    addToWishlist(id);
  });
  
  /**
 * Dealers
 */

  $("input[name='plz-ort']").keyup(function () {
    if ($(this).val() !== '') {
      $("input[name='umkreis']").attr('checked', false);
      $('#umkreis-5').attr('checked', true);
    }
  }).change(function () {    
    if (isNaN(parseInt($(this).val().substr(0,1), 10)) === false) {
      alert('Bitte wählen Sie eine Ortschaft');
      return false;
    }
    return true;
  });

  if ($('#dealers-map').length > 0) {        
    var latlng = new google.maps.LatLng(46.818188, 8.227512);
    var myOptions = {
      zoom: 7,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("dealers-map"), myOptions);
    
    var geocoder = new google.maps.Geocoder();
    var address = $("input[name='plz-ort']").val() +', Europe';
    var distance = parseInt($("input[name='umkreis']:checked").val(), 10);        
    var zoom = 12;
    if (distance === 50) {
      zoom = 8;
    } else if (distance === 30) {
      zoom = 8;
    } else if (distance === 20) {
      zoom = 9;
    } else if (distance === 10) {
      zoom = 10;
    } else if (distance === 5) {
      zoom = 11;
    } else if (isNaN(distance)) {
      zoom = 7;
    }     
    
    geocoder.geocode( {
      'address': address
    }, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        map.setZoom(zoom);
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
    
    $('#sponsors li').each(function () {
      var li = $(this);
      var position = li.attr('id').split('-');
      latlng = new google.maps.LatLng(position[1], position[2]);
      var marker = new google.maps.Marker({
        map: map,        
        position: latlng
      });
      
      google.maps.event.addListener(marker, 'click', function () {       
        $.scrollTo(li, 500, {
          onAfter: function () {
            if ($('.detail', li).is(':hidden')) {
              li.click();
            }
            var origcolor = $('h1:first').css('color');
            var rgb = origcolor.substr(4).split(',');
            var amount = 0.6;
            var r = parseInt(parseInt(rgb[0], 10) + 255*amount, 10);
            if (r > 255) {
              r = 255;
            }
            var g = parseInt(parseInt(rgb[1], 10) + 255*amount, 10);
            if (g > 255) {
              g = 255;
            }
            var b = parseInt(parseInt(rgb[2], 10) + 255*amount, 10);
            if (b > 255) {
              b = 255;
            }
            var color = 'rgb('+ r +', '+ g +', '+ b +')';
            console.log(color);
            li.effect('highlight', {
              color: color
            }, 2000);
          }
        });        
      });
    });
    
  }
      
  $('#dealers li, .companies.list li').click(function () {    
    var href = $('a:first', this).attr('href');
    var detail = $('.detail', this);

    if (detail.is(':hidden')) {      
      detail.slideDown(400, function () {
        detail.css('display', 'block');
      });
      $('.icon', this).removeClass('show').addClass('hide');
      
      if (href !== undefined) {
        location = href;
      }      
    } else {            
      detail.slideUp('fast', function () {
        detail.css('display', 'none');
      });
      $('.icon', this).removeClass('hide').addClass('show');
      
      if (href !== undefined) {
        location = '#/';
      }
    }        
  });
  
  var hash = window.location.hash;
  if (hash) {
    if ($("#dealers a[href='"+ hash +"']").length > 0) {
      $("#dealers a[href='"+ hash +"']").parent().click();
    }
  }
  
  $('#dealers-suche').click(function() {
    $('#list').html('<div class="loader"></div>');     
  });
  
  
  /**
 * Brands
 */
  
 
  $('.filter .alphabet input').change(function () {   
    if ($('#content').attr('class').match(/brands/)) {
      var path = URL +'marken';
      if ($("input[name='filter-alphabet']:checked").val() !== '') {
        path = path +'?filter='+ $("input[name='filter-alphabet']:checked").val();
      }      
      
      $('#list').html('<div class="loader"></div>');
      
      location = path;
    } else if ($('#content').attr('class').match(/designers/)) {
      var path = URL +'designer';
      if ($("input[name='filter-alphabet']:checked").val() !== '') {
        path = path +'?filter='+ $("input[name='filter-alphabet']:checked").val();
      }      
      
      $('#list').html('<div class="loader"></div>');
      
      location = path;
    } else if ($('#content').attr('class').match(/planning/)) {
      var path = URL +'planung';
      if ($("input[name='filter-alphabet']:checked").val() !== '') {
        path = path +'?filter='+ $("input[name='filter-alphabet']:checked").val();
      }      
      
      $('#list').html('<div class="loader"></div>');
      
      location = path;
    } else if ($('#content').attr('class').match(/productIndex/)) {
      var path = URL +'produkteindex';
      if ($("input[name='filter-alphabet']:checked").val() !== '') {
        path = path +'?filter='+ $("input[name='filter-alphabet']:checked").val();
      }      
      
      $('#list').html('<div class="loader"></div>');
      
      location = path;
    }
  });
  
  $('#sponsors:not(.dealers) li').click(function () {
    location = $('a:first', this).attr('href');
  });
  
  
      
  $('#brands li .icon').click(function () {
    ;
    var detail = $(this).siblings('.detail');

    if (detail.is(':hidden')) {      
      detail.slideDown(400, function () {
        detail.css('display', 'block');
      });
      $(this).removeClass('show').addClass('hide');      
    } else {            
      detail.slideUp('fast', function () {
        detail.css('display', 'none');
      });
      $(this).removeClass('hide').addClass('show');      
    }        
  });
  
  
  /**
 * Designers
 */
    
  $('#designers li').click(function () {
    location = $('a:first', this).attr('href');
  });
  
  
  /**
 * Planning
 */
    
  $('#planners li').click(function () {
    location = $('a:first', this).attr('href');
  });
  
    
  /**
 * Wishlist
 */
  
  $('.wishlist-delete').click(function () {
    $.post(BASIC_URL +'merkliste/loschen');
        
    $('#wishlist-count').text('0');        
    $('#content.wishlist .container-content').text('Die Merkliste ist leer.');
    
    alert('Die merkliste wurde gelöscht');
  });
  
  
  $('.back').click(function (e) {
    e.preventDefault();
    
    history.back();
    
    return false;
  });
  
  
});
