$(function() {

  if ($('#products_id').val() == '') 
  {
    $('#productinfo .sidebar div.block form').hide();
  }

  // events on product sizes
  $('.productSizes').click(function() {

    // reset the products_id input field
    $('#products_id').val($(this).attr('id'));
    $('#productinfo .sidebar div.block form').show();

    // get all boxes borders back to default
    $('.productSizes').each(function() {
      $(this).css({
        'border-color': '#ccc',
        'border-left' : 'none',
        'background-color' : '#fff',
        'color' : '#666'
      });
    });

    // set selected box border
    $(this).css({
      'border': '1px solid #000',
      'background-color' : '#A8C557',
      'color' : '#fff'
    });

//    $('#your_choice #color').html('-');
//    $('#your_choice #size').html($(this).attr('id'));
//    $('#fill_it_in_here').html('');
//    
//    $('#fill_it_in_here').append('<span id="loadergif" style="font-weight:bold;"><img src="/templates/notanshop/images/ajax-loader.gif" border="0" alt="" align="absmiddle" /> &nbsp; Vent...</span>');
//
//    // make the ajax call to get the colors available for the chosen size
//    $.getJSON('ajax.php?action=getColors&pID=' + $(this).attr('rel') + '&pSize=' + $(this).attr('id'),
//      function(data) {
//        $('#loadergif').remove();
//        $.each(data, function(prodID, output) {
//
//          var color = output.color.split(',');
//
//          $('#fill_it_in_here').append('<div ' + (output.quantity < 1 ? 'title="Farven ' + color[0] +' er ikke på lager, og kan derfor ikke vælges"' : 'title="Farve: ' + color[0] + '"') + ' style="color:' + (output.quantity > 0 ? '#666;cursor:pointer;' : '#aaa;' ) + 'float:left;width:13px;height:13px;margin-left:6px;margin-bottom:6px;padding:3px;border:1px solid #ccc;background-color:' + color[1] + '" class="productColors ' + (output.quantity > 0 ? 'stock' : 'out') + '" rel="' + color[0] + '" id="' + output.p_id + '">&nbsp;</div>');
//        });
//
//        $('#fill_it_in_here').append('<br style="clear:both;" />');
//
//        // events on product colors
//        $('.productColors').click(function() {
//          if ($(this).hasClass('stock'))
//          {
//            $('#your_choice #color').html($(this).attr('rel'));
//            $('#products_id').val($(this).attr('id'));
//            $('.productColors').each(function() {
//              $(this).css({'border-color': '#ccc'})
//            });
//            $(this).css({'border-color': '#6F8239'})
//
//          }
//        });
//
//      }
//    );
//
//    // show the color box if size is chosen
//    if ($('#product_colors').css('display') == 'none')
//    {
//      $('#product_colors').show();
//    }
  });

  $('#submit').click(function() {
    if ($('#products_id').val() == '')
    {
      alert('Du skal huske at vælge farve og størrelse.');
      return false;
    }
    return true;
  });

  $('#searchfield').focus(function() {
    if (this.value == 'Søg...')
    {
      this.value = '';
    }
    $(this).css({color: '#000'});
  });

  $('#searchfield').blur(function() {
    if (this.value == '')
    {
      this.value = 'Søg...';
      $(this).css({color: '#aaa'});
    }
    else
    {
      $(this).css({color: '#000'});
    }
  });

  $('#submitsearch').click(function() {
    if ($('#searchfield').val() != 'Søg...')
    {
      $('quick_find').submit();
    }
    else
      {
        return false;
      }
  });

  $('div.catview').corner({
    tl: { radius: 16 },
    tr: false,
    bl: false,
    br: { radius: 16 },
    antiAlias: true,
    autoPad: true
  });

  $('.sidebar div.block h3').corner({
    tl : {radius:10},
    tr : {radius:10},
    bl : false,
    br : false,
    antiAlias: true,
    autoPad: true
  });

  $('a[rel=lightbox]').lightBox({
    imageLoading  : '/templates/notanshop/images/loading.gif',
    imageBtnClose : '/templates/notanshop/images/close.gif',
    imageBtnPrev  : '/templates/notanshop/images/prev.gif',
    imageBtnNext  : '/templates/notanshop/images/next.gif',
    imageBlank    : '/templates/notanshop/images/blank.gif',
    txtImage      : 'Billede',
    txtOf         : 'ud af'
  });


  // manufactures cycle
  $('.cycle-cloud').cycle({
    'fx' : 'fade'
  });
});
