var mainLinkArr_2;
function photofader2(nm, mainDiv, imgArr, linkArr){
	this.name		= nm;
	this.imgArr = imgArr;
	this.curImg = 0;
	this.curDiv = 1;
	mainLinkArr_2 = linkArr;
	var mainDv = document.getElementById(mainDiv);
	
	document.pfObj_2 = this;
	
	document.write("<style type='text/css'>\n");
	document.write("#pf_photo1_2 img { visibility:hidden; }\n");
	document.write("#pf_photo1_2 { position:absolute; z-index: 1; }\n");
	document.write("#pf_photo2_2 { position:absolute; z-index: 0; }\n");
	document.write("</style>");
	
	this.initImages_2 = function() {
		document.write("<scr");
		document.write("ipt type='text/javascript'>\n");
		for(var i=0; i<this.imgArr.length; i++){
			document.write("var img"+i+" = new Image();\n");
			document.write("img"+i+".src = '"+ this.imgArr[i] +"';\n");			
		}
		document.write("document.pfObj_2.start_2();\n");
		document.write("</scr");
		document.write("ipt>\n");
		
	} 
	
	this.start_2 = function(){
		var hldr1 = "pf_photo1_2";
		var hldr2 = "pf_photo2_2";
		
		var dv1 = document.createElement("div");
				dv1.id = "pf_photo1_2";
				loc = "document.location='"+mainLinkArr_2[0]+"'";
				dv1.innerHTML = '<img src="'+ imgArr[0] +'" onclick="'+loc+'" style="cursor:pointer;" />';
		var dv2 = document.createElement("div");
				dv2.id = "pf_photo2_2";
		
		mainDv.appendChild(dv1);
		mainDv.appendChild(dv2);
		
	  image1 = document.getElementById(hldr1).childNodes[0];
		
	  setOpacity_2(image1, 0);
	  image1.style.visibility = 'visible';
	  fadeIn_2(hldr1,0);
	}
	
	this.initImages_2();
}
	
function setOpacity_2(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn_2(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId).childNodes[0];
    if (opacity < 100) {
			speed_2 = (speed_2 < 2)?2:speed_2;
      setOpacity_2(obj, opacity);
			opacityDif = Math.ceil((100-opacity)/speed_2);
			opacity += opacityDif;
      //opacity += 2;
      window.setTimeout("fadeIn_2('"+objId+"',"+opacity+")", 100);
    }
		else
			setTimeout("swapImages_2()",delay_2*1000);
  }
}

function swapImages_2(){
	// find out which 
	if(document.pfObj_2.curImg == document.pfObj_2.imgArr.length-1)
		document.pfObj_2.curImg = 0;
	else 
		++document.pfObj_2.curImg;

	// now get the div to hld the new image
	var dvName	= (document.pfObj_2.curDiv == 1)?"pf_photo2_2":"pf_photo1_2";
	var eDivName		= (document.pfObj_2.curDiv == 1)?"pf_photo1_2":"pf_photo2_2";
	document.pfObj_2.curDiv = (document.pfObj_2.curDiv == 1)?2:1;
	
	var tgtDiv = document.getElementById(dvName);
	var eDiv = document.getElementById(eDivName);

	
	loc = "document.location='"+mainLinkArr_2[document.pfObj_2.curImg]+"'";
	
	// now fill the target div
	tgtDiv.innerHTML = '<img src="'+ document.pfObj_2.imgArr[document.pfObj_2.curImg] +'" style="visibility:hidden; cursor:pointer;" onclick="'+loc+'" />';
	
	//move the divs around in z-index
	eDiv.style.zIndex = 0;
	tgtDiv.style.zIndex = 1;
	
	// And finally fade in the image
	
  var img = tgtDiv.childNodes[0];
	
  setOpacity_2(img, 0);
  img.style.visibility = 'visible';
  fadeIn_2(tgtDiv.id,0);
}

