function mycarousel_itemVisibleOutCallbackBeforeAnimation(carousel, item, idx, state) { jQuery('img', item).fadeOut('slow');};
function mycarousel_itemVisibleInCallbackBeforeAnimation(carousel, item, idx, state) {
if (state == 'init')
return;
jQuery('img', item).fadeIn('slow');
};

$(function() {
	
	
	//windows modal
	$('.wdialog').palacioPopup();
	
	/* agregar la clase "lastElement" a los ultimos elementos de los LI en los resultados */
	$('#results.lista ul li:nth-child(4n)').addClass('lastElement');
	$('#results.tabs ul li:nth-child(4n)').addClass('lastElement');
	$('#results.col2 ul li:odd').addClass('lastElement');
	$('#results.cols3 ul li:nth-child(3n)').addClass('lastElement');
	
	/* the main menu */
	$('#mainMenu ul li:last-child').addClass('last');
	var combos = $('#resultadosPanel select, .combos');
	$('#mainMenu > ul > li').hover(function(){
		var el = $(this);
		el.addClass('selected');
		$('#'+el.attr('id')+'_sub').css({display:'block'});
		if($.browser.msie && ($.browser.version == "6.0")){
			combos.css('visibility','hidden');
		}
	},function(){
		var el = $(this);
		el.removeClass('selected');
		$('#'+$(this).attr('id')+'_sub').css('display','none');
		if($.browser.msie && ($.browser.version == "6.0")){
			combos.css('visibility','visible');
		}
	});
	
	/* for the footer menu */
	$('#footer .links ul.fmenu > li:last-child').addClass('last');
	$('#footer .links ul.fmenu li.title').hover(function(){
		var el = $(this);
		el.addClass('selected');
		el.find('ul').css('display','block');
	},function(){
		var el = $(this);
		el.removeClass('selected');
		el.find('ul').css('display','none');
	});
	
	/* the main slider */
    $('#mainSlider').jcarousel({
        scroll: 1,
		auto:10,
		//easing:'easeOutBack',
		animation: 2000,
		initCallback: CarouselPalacio.init,
		itemVisibleInCallback: {onBeforeAnimation: CarouselPalacio.lastItem}
    });
	
	/* the sub slider */
	$('#subSlider').jcarousel({
        scroll: 1
	});
	
	/* banners en sliders */
	$('#sliderTop').jcarousel({
        scroll: 1,
		animation: 2000,
		//easing:'easeOutCubic',
		auto:10,
		wrap: 'last',
		itemVisibleInCallback: {
            onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation
            
        },
        itemVisibleOutCallback: {
            onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation
            
        }
	});
	
	/******************************** for the search boxes */
	$('#searchBox').focus(function(){
		if(this.value == 'Encuentra lo que necesitas en El Palacio de Hierro') {this.value = '';}
	});
	$('#searchBox').blur(function(){
		if(this.value == ''){this.value = 'Encuentra lo que necesitas en El Palacio de Hierro';}
	});
	$('#tuEmail').focus(function(){
		if(this.value == 'Tu email') {this.value = '';}
	});
	$('#tuEmail').blur(function(){
		if(this.value == ''){this.value = 'Tu email';}
	});
	
	/******************************** for the fast nav in the subpage */
	$('#subhome .fastNav').each(function(){
		var item = $(this);
		var list = item.find('ul');
		item.find('h2').click(function(){
			var txt = $(this).find('a');
			if(item.hasClass('fastNav_closed')){
				item.removeClass('fastNav_closed');
			}else{
				item.addClass('fastNav_closed');
			}
			return false;
		});
	});
	
	/* over lista dos columnas */
	$("#results ul li a").bigTarget({hoverClass:'mouse_over'});
	$("#results table.table_default tbody tr td.precio a").bigTarget({hoverClass:'mouse_over',clickZone : 'tr:eq(0)'});
	 
	if($.browser.msie){
		$('#results.col2 ul li:last-child').css('border','none');
	}
	
	/* detalle producto mas imagenes */
	var imgs = $('#detail .pics img:not(.selected)');
	imgs.css('opacity',.6)
	imgs.hover(function(){
		var el = $(this);
		el.css('opacity',1.0);
	},function(){
		var el = $(this);
		el.css('opacity',.6);
	});
	
	//para acomodar último elemento en filas
	$('#detail .product .combos div:last').addClass('lastElement');
	
	//para centrar imágenes	
	$('#results ul li .picFrame img').each(function(){
	var img = $(this);
	var image = new Image();
	img.load(function(){	
	img.css({left: ((img.parent().width()-img.width())/2)+"px",top: ((img.parent().height()-img.height())/2) +"px" ,position:"relative"}); }).attr('src',img.attr('src'));
 	});
	
	//hover en tablas
	$(".table_default tr").hover(function(){ $(this).addClass("tableHover");}, function(){$(this).removeClass("tableHover");});
	
	//función para el zoom en el detalle
	$("#detailImage a.zoom").click(function(){
  	var src = $("#detailImage a.zoom").attr("href");
  	$("#detailImage").zoom({image:src});    
  	return false;
 	});	

	$(document).pngFix(); 
});
