/////////////////////////////////////////////////////////////////////////

///// http://blog.firetree.net/2005/07/04/javascript-find-position/
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosYOld(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function findPosY(obj) {
	yPos = obj.offsetTop;
	tempEl = obj.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}



////////////////////// Swap-a-roo /////////////////
function swapimg (theimg, theonum, thennum) {
	var swaptmp;

	if ( (theimg) && (theimg.src) )
	{
		swaptmp = theimg.src;
		//alert("No - " + theonum + "/" + thennum + "..." + swaptmp);
		theimg.src = swaptmp.replace(theonum + ".png", thennum + ".png");
	}else{

	}
}


function swapback(theimg, theonum, thennum) {
	//alert("No2");
	var swaptmp;

	if ( (theimg) && (theimg.style) && (theimg.style.background)  )
	{
		swaptmp = theimg.style.background;
		//alert("No - " + theonum + "/" + thennum + "..." + swaptmp);
		theimg.style.background=swaptmp.replace(theonum + ".png", thennum + ".png");
	}else{

	}
}

function swapcache (theclass) {
	if ( (theimg) && (theimg.style) && (theimg.style.background) && (theimg.style.background.length > 1) && (theimg.style.background != "blank.gif") )
	{
		theimg.style.background=theimg.style.background.replace(theonum + ".png", thennum + ".png");
	}
}



///// Check for missing images ... Preload SWAP images for "xxxx_single1.png" //////////
function failsafeImg(){
	var badImg = new Image();
	badImg.src = 'blank.gif';
	var imageArray1=new Array();
	var imageArray2=new Array();
	var imgtot;

	imgtot = document.images.length;
	imgtot = -1;

	for(var fi=0;fi<imgtot;fi++)
	{
		if ( document.images[fi].src.indexOf("app") > 0 )
		{
			imageArray1[fi]=new Image();
			imageArray1[fi].src = document.images[fi].src;
		}else if ( ( document.images[fi].src.indexOf("ingle1") > 0 ) || ( document.images[fi].src.indexOf("utton") > 0 ) )
		{

			imageArray2[fi] = new Image();
			imageArray2[fi].src = document.images[fi].src.replace("1.png", "2.png");
			//alert (imageArray2[fi].src + " =-= " + imageArray2[fi].width );
		}
	}
	for(var fi=0;fi<imgtot;fi++)
	{
	    //if (imageArray1[fi].complete) 
	    if ( document.images[fi].src.indexOf("app") > 0 )
	    {
		//alert(document.images[fi].src + " / " + cpyImg.width);
		if ( (!imageArray1[fi].width) ||  (imageArray1[fi].width < 1 ) || (imageArray1[fi].width == 28 ) || (imageArray1[fi].height == 19 ) ) //IE's red X is 28px. Opera's replacement tag is 19px high.
		{
			//alert(document.images[fi].src + " -- " + imageArray1[fi].width);
			document.images[fi].src = badImg.src;
		            //document.images[fi].style.visibility = "hidden";
		            //document.images[fi].style.display = "none";
		}
	    }
	}
}


function IsImageOk(img) {

    //if ( img.src.indexOf("app3") > 0 )
    //{
	//alert(" ... " + img.src + " .... " + img.type + " .... " + img.width );
	//alert(" ... " + img.src + " .... " + img.width );
    //}

    //IE's red X is 28px. IE7 is 38px. Chrome is 18px
    if ( (!img.width) ||  (img.width < 1 ) || (img.width == 38 ) || (img.width == 28 ) || (img.width == 18 ) || (img.height == 19 ) )
    {
        return false;
    }

    // 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.
    try
    {
    	if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
	        return false;
	    }
    }
	catch (e)
	{
		idontcare = true;
	}

    // No other way of checking: assume it's ok.
    return true;
}


function failsafeImg2()
{
	var chkthisimg;

	if (document.domain.indexOf("store.") >= 1) return;
	if (document.domain.indexOf("secure.") >= 1) return;

	//  alert("failsafeImg2");
	var badImg = new Image();
	badImg.src = 'blank.gif';
	for (var fi = 0; fi < document.images.length; fi++)
	{
	    chkthisimg = false;
	    if ( document.images[fi].src.indexOf("_app") > 0 ) chkthisimg = true;	//XXX_app1.png
	    if ( document.images[fi].src.indexOf("_dia") > 0 ) chkthisimg = true;	//XXX_dia.png
	    if ( chkthisimg )
	    {
        	if ( !IsImageOk(document.images[fi]) )
		{
		    //alert(" ... " + document.images[fi].src + " .... " + document.images[fi].width );
		    document.images[fi].title = "X";
		    document.images[fi].src = badImg.src;
	            document.images[fi].style.visibility = "hidden";
	            document.images[fi].style.display = "none";
	        }else{
			if ( document.images[fi].width && ((document.images[fi].width == 2) && (document.images[fi].height == 1)))
			{
				//Blank APP images -- 2010-12-18
    				//document.images[fi].title = ".";
	            		document.images[fi].style.visibility = "hidden";
	            		document.images[fi].style.display = "none";
			}else{
		            document.images[fi].style.visibility = "visible";
		            //document.images[fi].style.display = "inline";
			}
		}
	    }
	}
}


function Wait4it(){

}


function moveSZimg(){
	//Move Sizechart IMG
	//if( (thise = document.getElementById("sizechart")) && (thisi = document.getElementById("sizeimg")) )




	if( (thise = document.getElementById("SZCHARTID")) && (thisi = document.getElementById("sizeimg")) )
	{
   		 setTimeout("moveSZimg2(thise,thisi)",100 );
   		 setTimeout("moveSZimg2(thise,thisi)",1000 );
  		 setTimeout("moveSZimg2(thise,thisi)",5000 );
	}

}

function moveSZimg2(thise,thisi){
	//alert("YES!");
	//thise = document.getElementById("SZCHARTID");
	//thisi = document.getElementById("sizeimg");
	thisy = findPosY(thise);
	if (thisy >= 150)
	{
		if ((thisi.width) && (thisi.width >= 40))
		{
			movelft = (thisi.width + 45);
			movelft = movelft + "";
		}else{
			movelft = "195";
		}

		thisyt = (thisy - 165) ;
		if( document.getElementById("IE6MSG")  )
		{
			if (thisyt < 1000) { thisyt = 1000; }
		}

		if (thisyt < 850) { thisyt = 850; }
		thisyt = thisyt + "px";
		//thisyt = (thisy - 155) + "px";
		//thisyt = (thisy) + "px";

		thisi.style.top = thisyt;
		thisi.style.left = "-" + movelft + "px";

	}
}


//////////////////////////////////////////////////////




//////////////////////////////////////////////////////


