$(document).ready(
	function(){
	$('.class-folder-slideshow ul').cycle({ 
		fx:     'fade', 
		speed:  300, 
		timeout: 5000, 
		next:   '#next', 
		prev:   '#prev', 
		cleartype:  1
    });
	$('.class-folder-slideshow ul a').append("<div class='magnifier'></div>").fancybox({overlayOpacity: 0.5, titleShow: false});

	$('div.class-modulo-ultimas-ediciones ul').cycle({
		fx:     'fade',
		speed:  800,
		timeout: 6000,
		height: '214px',
		cleartype:  1
    });

	$('.class-folder-slide ul').cycle({
		fx:     'fade',
		speed:  400,
		timeout: 10000,
		next:   '.class-folder-slide .next',
		prev:   '.class-folder-slide .prev',
		cleartype:  1
    });

	$("div.galleryslide").galleryslide();

	$('#slideshow-nota ul').cycle({
		fx: 'fade',
		speed: 300,
		timeout: 5000,
		next: '#slideshow-nota .next',
		prev: '#slideshow-nota .prev',
		cleartype:  1
	});
	$('#slideshow-nota ul a').append("<div class='magnifier'></div>").fancybox({overlayOpacity: 0.5, titleShow:false});
	if($('#slideshow-nota ul li').length == 1) $('#slideshow-nota').addClass('nonav');
});

function toggleSlideshow(selector,me){
   if(me.className=="pause"){
      $(selector).cycle("pause");
      me.className="resume";
   } else {
      $(selector).cycle("resume");
      me.className="pause";
   }
}

/* function filterProvincia(id){
  $("#provincia-trash").append($("#provincia option"));
  $("#provincia").append("<option></option>");
  $("#provincia").append($("#provincia-trash option[@pais="+id+"]"));
  if($("#provincia").get(0)) $("#provincia").get(0).selectedIndex=0;
  if($("#provincia").get(0)) $("#provincia").get(0).selectedIndex = $("#provincia option[selected='selected']").prevAll().length;
}
function filterCiudad(id){
  $("#ciudad-trash").append($("#ciudad option"));
  $("#ciudad").append("<option></option>");
  $("#ciudad").append($("#ciudad-trash option[@provincia="+id+"]"));
  if($("#ciudad").get(0)) $("#ciudad").get(0).selectedIndex=0;
  if($("#ciudad").get(0)) $("#ciudad").get(0).selectedIndex = $("#ciudad option[selected='selected']").prevAll().length;
}
function filterBarrio(id){
  $("#barrio-trash").append($("#barrio option"));
  $("#barrio").append("<option></option>");
  $("#barrio").append($("#barrio-trash option[@ciudad="+id+"]"));
  if($("#barrio").get(0)) $("#barrio").get(0).selectedIndex=0;
  if($("#barrio").get(0)) $("#barrio").get(0).selectedIndex = $("#barrio option[selected='selected']").prevAll().length;
}
*/
$(document).ready(function(){
   var clones = {};
   clones.provincia = $("#provincia").clone();
   clones.ciudad = $("#ciudad").clone();
   clones.barrio = $("#barrio").clone();

   $("#pais").change(function(){
      $("#provincia,#ciudad,#barrio").empty();
      var pais = $(this).val();
      if(!pais) return;
      clones.provincia.find("option[rel='*'], option[rel='"+pais+"']").each(function(){
         $("#provincia").append($(this).clone());
      });
   });
   $("#provincia").change(function(){
      $("#ciudad,#barrio").empty();
      var provincia = $(this).val();
      if(!provincia) return;
      clones.ciudad.find("option[rel='*'], option[rel='"+provincia+"']").each(function(){
         $("#ciudad").append($(this).clone());
      });
   });
   $("#ciudad").change(function(){
      $("#barrio").empty();
      var ciudad = $(this).val();
      if(!ciudad) return;
      clones.barrio.find("option[rel='*'], option[rel='"+ciudad+"']").each(function(){
         $("#barrio").append($(this).clone());
      });
   });
   $("#pais,#provincia,#ciudad").trigger("change");
});

function cambiarCanal(canal,offset){
   if(!offset) offset=0;
   var h = $("#canal-actual").height() || 60;
   $("#canal-actual").height(h).html("<div class='cargando'><img src='/design/artealdia_com/images/cargando.gif' /><br>Cargando...</div>");
   $.get(canal+"/(offset)/"+offset,function(data){
      $("#canal-actual").height('auto').html(data);
   });
}
function elegirCanal(canal, it){
   cambiarCanal(canal, 0);
   $(it).parent().children().removeClass('selected');
   $(it).addClass('selected');
}

Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
}

$(document).ready(function(){
         $("#calendar").datepicker({
                                changeMonth: false,
                                changeYear: false,
                                dayNames: ['Domingo','Lunes','Martes','Miercoles','Jueves','Viernes','Sabado'],
                                dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sa'],
                                monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
                                onSelect: function(dateText){
                                   $('#estado').append("<option value='"+dateText+"'>"+dateText+"</option>");
				   $('#estado').get(0).selectedIndex=$('#estado').get(0).options.length-1;
                                   $('#form_agenda').submit();
                                },
                                prevText: '&laquo;',
                                nextText: '&raquo;',
                                dateFormat: 'dd/mm/yy' });
});

$(document).ready(function(){

   $('.content-view-full > .class-product .more .thumb').click(function(){
      $('.content-view-full > .class-product .left .attribute-image').hide();
      $('.content-view-full > .class-product .more .thumb').removeClass('selected');
      $('#'+$(this).attr('image')).show();
      $(this).addClass('selected');
   }); 
   $('.content-view-full > .class-product .left .thumb:first').trigger('click');

   $('.content-view-full > .class-product .wrapper .attribute-image a').fancybox({overlayOpacity: 0.5, titleShow:false });

   $('.content-view-full .class-folder-store .slide').cycle({
                                                    fx:     'fade',
                                                    speed:  300,
                                                    timeout: 5000,
                                                    pager: '.slide-wrapper .nav',
                                                    cleartype:  1
                                                    });

   $('.shop-register select[name=Country]').change(function(){
      if($(this).val()=='Argentina'){
         $('.shop-register .prov_otros').attr('disabled','disabled').hide();
         $('.shop-register .prov_argentina').removeAttr('disabled').show();
      } else {
         $('.shop-register .prov_otros').removeAttr('disabled').val('').show();
         $('.shop-register .prov_argentina').attr('disabled','disabled').hide();
      }
   }).trigger('change');

   $('.shop-register select[name=MedioDePago]').change(function(){
      if($(this).val()=='efectivo'){
         $('.shop-register select[name=FormaDeEnvio] option[value=correo]').attr('disabled','disabled');
         $('.shop-register select[name=FormaDeEnvio] option[value=correo]').next().attr('selected','selected');
      } else {
         $('.shop-register select[name=FormaDeEnvio] option[value=correo]').removeAttr('disabled');
      }
   }).trigger('change');

   $('.content-view-full .class-product .attribute-opciones a').fancybox({overlayOpacity: 0.5, titleShow:false });

   $('.shop-basket input[name=CheckoutButton], .shop-basket input[name=StoreChangesButton]').click(function(event){
      $('.nostock').remove();
      $('.shop-basket input[max]').each(function(){
         if($(this).val() > $(this).attr('max')){
            alert("Hay un producto que no tiene stock suficiente.");
            $(this).after('<div class="nostock">No hay stock suficiente para m&aacute;s de '+$(this).attr('max')+' item'+($(this).attr('max')>1?'s':'')+'</div>');
            event.preventDefault();
         }
      });
   });
});

