//var arrImgs = ["imgPromo.jpg"];
//var arrLigas = ["http://promociones.liverpool.com.mx/promociones/promo_atg.jsp?ID=2151"];
//var index = 0;

$(document).ready(function(){
	/*****************************************************************************************/
	// Obtenemos la posicion del logo de liverpool, todo sera relativo a este elemento
	var o = $('#d_logo').offset();
	var l = $('#h3').offset();
	
	//	Insertamos dentro de uno de los divs flotantes el codigo para la imagen, es html dentro de comillas
	$('#d_float1').html("<a href='http://www.fashionfest.com.mx' target='_blank' onclick=\"javascript:pageTracker._trackPageview('/homE/fashionFest2/2010');\"><img src='/web/images/fashonFest6.gif' border='0'/></a>");
	//	Y lo colocamos en la posicion deseada en x:left y y:top de acuerdo a la posicion del logo
	//	Por ejemplo:
	//	A 20 pixeles de la posicion del logo en y
	$('#d_float1').css("top", l.top-140);
	//	A 50 pixeles de la posicion del logo en x
	$('#d_float1').css("left", o.left+170);

        //  Reposicionamos en el resize de la ventana
        $(window).bind('resize', function(){
           o = $('#d_logo').offset();
		   l = $('#h3').offset();
           $('#d_float1').css("top", l.top-140);
           $('#d_float1').css("left", o.left+173);
        });
		$('#d_float2').text('');
	
	//Si queremos un swf, entonces hacemos primero el html del objeto, es decir:
	//var swf = "<object height='120' width='145' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'>";
	//swf += "<param value='/web/images/febrero.swf' name='movie'/>";
	//swf += "<embed height='120' width='145' src='/web/images/febrero.swf' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'/>";
	//swf += "</object>";
	
	//	Y lo colocamos en el segundo div flotante
	//$('#d_float2').html(swf);
	//	Y lo posicionamos
	//$('#d_float2').css("top", l.top-125);
	//$('#d_float2').css("left", o.left+193);
	//$('#d_float2').text('.');
	 //  Reposicionamos en el resize de la ventana
        //$(window).bind('resize', function(){
           // o = $('#d_logo').offset();
			//l = $('#h3').offset();
           // $('#d_float2').css("top", l.top-125);
          // $('#d_float2').css("left", o.left+193);
         // });

	/*****************************************************************************************/

    if($('#h3').html()!=null)
        $("#h3").load("/web/lib/specialSections.html");
    
    //$('#1L10000 a').css("border-left","1px solid #fff");
	//$('#1L10000 a, #1L10002 a').css("border-right","1px solid #fff");
    $('#1L10000 a').css("font-size","9px");
    $('#1L10006 a, #1LLineaBlanca a').css("width","115px");


    $($($('.generic_link')[0]).children('a')[2]).attr("href","http://www.liverpool.com.mx/shopping/store/shop.jsp?location=almacenes&flashFile=/web/flash/directorio/index.swf&siteLocation=flash");
	//$('#promoSection a').attr("href","http://promociones.liverpool.com.mx/promociones/promo_atg.jsp?ID=2161");
	//setTimeout(rotateImgs, 0001);
	
	//	Cambios a estilos "fijos" en el header
	$('#d_services div').css("padding", "0 0 0 5px");
	$($('#h2 div')[0]).css("width", "63%");
	$($('#h2 div')[1]).css("width", "12%");
	$($('#h2 div')[2]).css("width", "25%");
	
	$('#1L10005 a, #1L10008 a').css("background","#e8e9ea");
	$('#1L10005 a, #1L10008 a').mouseover(function(){
		$(this).css("background","#d2d3d5");
    }).mouseout(function(){
        $(this).css("background","#e8e9ea");
    });
	
	var nombre = $('#d_userdata div').html();
	var a = nombre.split("|");
	if(a[0].indexOf("Si no eres")>0){
		var b = a[0].split("Si no eres");
		$('#d_userdata div').html(b[0]+"&nbsp;|&nbsp;"+a[1]);
		$('#d_userdata div').append("&nbsp;&nbsp;");
	}
	
    /*
    $('.itemnumshoppingcarr').each(function(){
        if($(this).children('ul').length>0){
            var txt = $(this).find('li').html();
            var t = $(this).parents('table').get(0);
            var c = $(t).parent();
            $(t).remove();
            $(c).html("<div class='error'>"+txt+"</div>");
        }
    });
    */
    var options={
        zoomWidth: 150,
        zoomHeight: 150,
        showEffect:'show',
        hideEffect:'fadeout',
        fadeoutSpeed: 'slow',
        title :true,
        showPreload: false
    }
    if($(".zooml").html()!=null)
        $(".zooml").jqzoom(options);

    if($(".simpledialog").html()!=null){
        $('.simpledialog').simpleDialog({
            opacity: 0.3,
            duration: 500,
            closeLabel: 'cerrar',
            showCaption: true,
            showCloseLabel: true,
            useTitleAttr: true,
            open: function(event){
                if($('select').html()!=null)
                    $('select').hide();
            },
            close: function(event, target){
                if($('select').html()!=null)
                    $('select').show();
            }
        });
    }

    //init();
});

//function rotateImgs(){
	//$('#promoSection img').attr("src","/web/images/"+arrImgs[index]);
	//$('#promoSection a').attr("href",arrLigas[index]);
	//index++;
	//if(index>=arrImgs.length)
		index = 0;
	//setTimeout(rotateImgs, 0001);
//}

function IsImageOk(img){
    //// During the onload event, IE correctly identifies any images that
    //// weren't downloaded as not complete. Others should too. Gecko-based
    //// browsers act like NS4 in that they report this incorrectly.
    if(!img.complete){
        return false;
    }
    //// However, they do have two very useful properties: naturalWidth and
    //// naturalHeight. These give the true size of the image. If it failed
    //// to load, either of these should be zero.
    if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0){
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}

function init(){
    for(var i = 0; i < document.images.length; i++){
        if(!IsImageOk(document.images[i])){
            if(document.images[i].src.lastIndexOf("/web/images/products/")>0){
                if(document.images[i].src.lastIndexOf("es_MX")>0){
                    if(document.images[i].src.lastIndexOf("lg")>0)
                        document.images[i].src =     "/web/images/products/es_MX/lg/productImageNotAvailable.jpg";
                    else
                        document.images[i].src =     "/web/images/products/es_MX/sm/productImageNotAvailable.jpg";
                }else{
                    if(document.images[i].src.lastIndexOf("lg")>0)
                        document.images[i].src = "/web/images/products/en_US/sm/productImageNotAvailable.jpg";
                    else
                        document.images[i].src = "/web/images/products/en_US/sm/productImageNotAvailable.jpg";
                }
            }
        }
    }
}