$(function(){
	$('a[href][rel*=external]').each(function(i){this.target = "_blank";});
});

$(function(){
	$(".fancyboxImg").fancybox({'overlayShow': true});
	$('#rotator').cycle({fx:'fade', speed:2000, timeout: 5000});
});

$(function(){
	$('.top-text .item-text-short').expander({
    	slicePoint:       200,  // default is 100
	    expandText:         '[read more]', // default is 'read more...'
	    collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
    	userCollapseText: '[collapse]'  // default is '[collapse expanded text]'
	});
	$('.top-text .item-text-full').expander({
    	slicePoint:       200,  // default is 100
	    expandText:         '[read more]', // default is 'read more...'
	    collapseTimer:    0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
    	userCollapseText: '[collapse]'  // default is '[collapse expanded text]'
	});
	 
});



$(function(){
	$("#wines").tablesorter({
		headers: { 
            // assign the secound column (we start counting zero) 
            0: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            },
            7: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }
    }
	}); 
	
	
	var customMainNav = $('#customMainNav').html();
	$('#menu-box ul:first li:first').after(customMainNav);
	$('#customMainNav').remove();
	
	
	$('#menu-bottom-block ul:first li:first').after(customMainNav);
});



/* simple cart */
$(function(){
  $('#unselect-all').bind('click', function(){

    $('.product-select').each(function(){
        $(this).removeClass('selected');
        $(this).html('select');
    })

    $.ajax({
      type: "GET",
      url: "/index/clearCart/"
    });


  })

  $('.product-select').bind('click', function() {
      var id = $(this).attr('id').split('product-select-')[1];
      var action = '';
      if($(this).hasClass('selected')) {
        //unselect
        $(this).removeClass('selected');
        $(this).html('select');
        action = 'remove';

      }else{
        //select
        $(this).addClass('selected');
        $(this).html('unselect');
        action = 'add';
    }
    
    $.ajax({
      type: "GET",
      url: "/index/editCart/?do="+action+"&id="+id,
      success: function(msg){
        console.log(msg);

      }
    });


   });
});

/*
 * load select en unselected
 */
$(function(){
  $.ajax({
      type: "GET",
      url: "/index/getCart/",
      success: function(data){
      	if(data){
       	 JSON.parse(data, function (key, value){
          	if($('#product-select-'+value).length != 0){
             $('#product-select-'+value).addClass('selected');
             $('#product-select-'+value).html('unselect');
          	}
        	})
        }
       }
  });
});