$(document).ready(function() { 
  
  // Events "carousel"
  $("#home-events ul").cycle({
    slideExpr: 'li',
    continuous: 1,
    fx: 'scrollLeft',
    next: '#home-events-carousel-arrow',
    height: 174,
    pause: true,
    speed: 4000,
    timeout: 1000, 
    animOut: {  
        opacity: 0  
    }
  });
  
  // Tools "carousel"
  $("#home-products").cycle({
    delay: 1000,
    // fx: 'scrollLeft',
    next: '.products-arrow',
    pause: true,
    speed: 3000,
    timeout: 4000, 
    animOut: {  
        opacity: 0
    }
  });
  
  $(".home-looks").cycle({
    fx: 'scrollLeft',
    delay: 1000,
    pause: true,
    speed: 2000,
    timeout: 2000, 
    animOut: {  
        opacity: 0
    },
    fit: true
  });  
  
  $("#photos").cycle({
    fit:true,
    width:411,
    height:262
  });
  
  // Homa main slider
  $("#slides").cycle({
    height: 338,
    pager: "#slider-pager"
  }); 
  
  // Global fancybox
  $("a.fancybox").fancybox({
		'hideOnContentClick': true
	});
	     
  // Global jQZoom
	$('a.jqzoom').jqzoom({position:'left', preloadImages: true, preloadText : 'Cargando Zoom'})
	$(".zoomPad").each(function(index) {
	  var imgWidth = $(this).children('img').attr('width');
	  $(this).css('width', imgWidth);
	});
	
  // Show zoom icon
	$("#looks .look a").hover(function() {
	 $(this).children('span').show();
	}, function() {
	 $(this).children('span').hide();
	});
	
  // Add and Remove to PDF 
  function hideOrShowCart(data) {
    if (data == 0) {
      $("#pdf-cart").hide();
    } else {
      $("#pdf-cart").show();
    };
  }
  
  $("form.add-to-pdf").submit(function() {
    var $form = $(this),
        form_data = $form.serialize();                        
    
    $.post($(this).attr('action') + '&ajax=true', form_data, function(data) {
      $form.children('.add-it').attr('src', template_dir + '/images/added-to-pdf.png');
      $form.siblings('.remove-from-pdf').show();
      $("#pdf-count").html(data);
      hideOrShowCart(data)
    });
    
    return false;
  });
  
  $("form.remove-from-pdf").submit(function() {
    var $form = $(this),
        form_data = $form.serialize();                        
    
    $.post($(this).attr('action') + '&ajax=true', form_data, function(data) {
      $form.children('.remove-it').remove();
      $form.siblings('.add-to-pdf').children('.add-it').attr('src', template_dir + '/images/add-to-pdf.png');
      $("#pdf-count").html(data);
      hideOrShowCart(data)
      
    });
    
    return false;
  }); 
  
  //  Tool Tip for PDF
  $(".add-it").qtip({
     content: {
        attr: 'title'
     },
     position: {
       my: 'top center'
     }
  });
  
  //  Catalog
  $(".products-per-page select").change(function() {
    var value = $(this).val(),
    old_query = $('input#old_query').val();
    $(this).parent("form").attr("action", "?per-page="+value+'&query='+old_query).submit();
  });
  
});


Cufon.replace('.cufon, h3', { fontFamily: 'GothamRnd', hover: true });
Cufon.replace('.cufon-two, h1, .service ul li', { fontFamily: 'Gotham', hover: true });
