
/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

/*
 * Aux functions
 */

//IE Browser test
var IE = document.all?true:false;

// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
	){
		var strText = this;
		var intIndexOfMatch = strText.indexOf( strTarget );
 
		// Keep looping while an instance of the target string
		// still exists in the string.
		while (intIndexOfMatch != -1){
			// Relace out the current instance.
			strText = strText.replace( strTarget, strSubString )
 
			// Get the index of any next matching substring.
			intIndexOfMatch = strText.indexOf( strTarget );
		}
 
		// Return the updated string with ALL the target strings
		// replaced out with the new substring.
		return( strText );
}

 /** @return true if is a string */
 function isString(object) {
      return typeof object == "string";
 }

function eventPush(obj, event, handler) {
  var handlerwrapper = function(e) {	
	if( !e ) {
	    //if the browser did not pass the event information to the
	    //function, we will have to obtain it from the event register
	    if( window.event ) {
	      //Internet Explorer
	      e = window.event;
	    } else {
	      //total failure, we have no way of referencing the event
	      return;
	    }
	 }
	if (IE)	{
		//alert(this.event.srcElement);
		handler(this.event.srcElement,e);
	} else {
		handler(this,e);
	}
  }
  if (obj.addEventListener) {
    obj.addEventListener(event, handlerwrapper, false);
  } else if (obj.attachEvent) {
    obj.attachEvent('on'+event, handlerwrapper);
  }
}

function eventPushInsideiFrame(obj, event, handler) {
  var handlerwrapper = function(e) {	
	if( !e ) {
	    //if the browser did not pass the event information to the
	    //function, we will have to obtain it from the event register
	    if( window.event ) {
	      //Internet Explorer
	      e = window.event;
	    } else {
	      //total failure, we have no way of referencing the event
	      return;
	    }
	 }
	if (IE)	{
		handler(e);
	} else {
		handler(e);
	}
  }

  if (obj.addEventListener) {
    obj.addEventListener(event, handlerwrapper, false);
  } else if (obj.attachEvent) {
    obj.attachEvent('on'+event, handlerwrapper);
  }
}

function max(n1,n2) {
	if (n1>n2) return n1; else return n2;
}
function min(n1,n2) {
	if (n1<n2) return n1; else return n2;
}

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes";
var iframestoresize=[];
var iframeswidthtoresize=[];

var FF=navigator.userAgent.indexOf("Firefox") > -1;
var SF=navigator.userAgent.indexOf("Safari") > -1;
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraWidth=FF? 10 : 0;
var SFextraHeight=SF? 1 : 0;
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 18 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
var IEextraWidth=0;
//FFextraHeight = 0;


function resizeCaller() {
	var dyniframe=new Array()
	for (i=0; i<iframestoresize.length; i++){
		//alert(iframestoresize[i]);	
		if (document.getElementById)
			resizeIframeHeight(iframestoresize[i])
			//reveal iframe for lower end browsers? (see var above):
		if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframestoresize[i]] : 					
			document.getElementById(iframestoresize[i])
			tempobj.style.display="block"
		}
	}
	for (i=0; i<iframeswidthtoresize.length; i++){
		if (document.getElementById)
			resizeIframeWidth(iframeswidthtoresize[i])
			//reveal iframe for lower end browsers? (see var above):
		if ((document.all || document.getElementById) && iframehide=="no"){
			var tempobj=document.all? document.all[iframeswidthtoresize[i]] : 					
			document.getElementById(iframestoresize[i])
			tempobj.style.display="block"
		}
	}

}

function resizeIframeHeight(frameid){
	var currentfr=document.getElementById(frameid)
	//alert("resizeIframeHeight : " + frameid + " : " + currentfr);
	var initialheight = 0;
	currentfr.height=initialheight;
	if (currentfr && !window.opera){
		if(currentfr.style.display!='inline') {
			currentfr.style.display="block"
		}
		currentfr.style.visibility="visible";
		if (currentfr.contentDocument && !(currentfr.contentDocument.body.offsetHeight==undefined)) { //ns6 syntax 
			var height;
			var offsetHeight = currentfr.contentDocument.body.offsetHeight;
			if (offsetHeight==0 || offsetHeight == initialheight ) {
				height = currentfr.contentDocument.body.scrollHeight;  
			} else {
				height = currentfr.contentDocument.body.offsetHeight; 
			}
			//alert(currentfr.contentDocument.body.offsetHeight);
				if(height==150)
				{   
					//150 is default value and can therefore not trusted
					//call mininumheight function if it is defined
					//and once the iframe has been completely loaded
					var minimumheight = currentfr.contentDocument.minimumHeight;
					//alert('minimumheight fie : ' + minimumheight);
					if (!(minimumheight==undefined)) { 
						height = minimumheight();
						//alert('minimumheight : ' + height);
						currentfr.height = height;
					} else {
						eventPushInsideiFrame(currentfr,"load", function() {
							//alert('inside frame');
							var minimumheight = currentfr.contentDocument.minimumHeight;
							//alert('minimumheight fie : ' + minimumheight);
							if (!(minimumheight==undefined)) { 
								height = minimumheight();
								//alert('minimumheight : ' + height);
							}
							currentfr.height = height;
						});
					}
				} else {
					currentfr.height = height+FFextraHeight+SFextraHeight;
					if(document.iFrameResized!=undefined) document.iFrameResized(currentfr);
				}
		}
		else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
		    //alert(currentfr.id + " : " + (currentfr.Document.body.scrollHeight) + ":" + currentfr.Document.body.offsetHeight + ":" + currentfr.Document.body.clientHeight );
            scrollHeightOverflow(frameid, 0);
		    if (currentfr.Document.body.innerHTML=="") 
		        currentfr.height = 0
		    else {
			    currentfr.height = currentfr.Document.body.scrollHeight;
			    //alert(currentfr.id + " : " + (currentfr.height)  );
			}        
        }
		//alert(currentfr.id + " : " + (currentfr.height)  );	
        
		//alert(currentfr.id + " : " + (currentfr.contentDocument.body.scrollHeight) + ":" + currentfr.contentDocument.body.offsetHeight + ":" + currentfr.contentDocument.body.clientHeight + ":" + currentfr.contentDocument.body.innerHeight + ":" + currentfr.contentDocument.height + ":"+currentfr.contentDocument.documentElement.clientHeight  );	

		/*if (currentfr.addEventListener)
			currentfr.addEventListener("load", readjustIframe, false)
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			currentfr.attachEvent("onload", readjustIframe)
		}*/
	}
}

function scrollHeightOverflow(frameid, counter) {
    var currentfr=document.getElementById(frameid)
    if (currentfr.Document.body.scrollHeight > 100000) {
            if (currentfr.isLoaded) {
                currentfr.height = currentfr.Document.body.scrollHeight;
            } else {
                if (counter> 10)
                    alert("ERROR:document.isLoaded is not set by iframe")
                else
                    setTimeout("scrollHeightOverflow('" + frameid + "', " + (counter+1) + ")", 200)
            }
   } else {
       currentfr.height = currentfr.Document.body.scrollHeight;
   }
}

function resizeIframeWidth(frameid){
	//alert(frameid);	
	var currentfr=document.getElementById(frameid);
	if (currentfr && !window.opera){
		//alert(currentfr.id);	
		if(currentfr.style.display!='inline') {
			currentfr.style.display="block"
		}
		currentfr.style.visibility="visible";
		if (currentfr.contentDocument && !(currentfr.contentDocument.body.scrollWidth==undefined)) { //ns6 syntax 
			currentfr.width = currentfr.contentDocument.body.scrollWidth+FFextraWidth; 
			//alert(currentfr.width);
			
	        docObj = currentfr.contentDocument.getElementById("measurable_content");
			if(docObj != null) {
				var width = null;
				docObj = currentfr.contentDocument.defaultView.getComputedStyle(docObj, "");
				if(docObj!=null) {
	        		width = docObj.getPropertyValue("width");
	        		width = width.split('px');
	        		width = parseInt(width[0]);
				}
				if(width == null || isNaN(width)) { width = docObj.scrollWidth+FFextraWidth }
				//alert(width+FFextraWidth);
				currentfr.width = width+FFextraWidth; 
			}
			
			//alert(currentfr.width);
			//setTimeout('alert(document.getElementById("'+ frameid + '").contentDocument.getElementById("measurable_content"))',500);
			var minimumwidth = currentfr.contentDocument.minimumWidth;
			if (!(minimumwidth==undefined)) { 
				currentfr.width = minimumwidth(parseInt(currentfr.width));
				//alert('minimumwidth : ' + currentfr.width);
			} else {
				//maybe frame is still loading
				eventPushInsideiFrame(currentfr,"load", function() {
					//with computation cannot be trusted
					//call mininumheight function if it is defined
					//and once the iframe has been completely loaded
					var minimumwidth = currentfr.contentDocument.minimumWidth;
					if (!(minimumwidth==undefined)) { 
						currentfr.width = minimumwidth(parseInt(currentfr.width));
						//alert('minimumheight : ' + height);
					}
				});
			}
			//alert(currentfr.id + " : " + (currentfr.contentDocument.body.scrollWidth) + ":" + currentfr.contentDocument.body.offsetWidth  );	
		}
		else if (currentfr.Document && currentfr.Document.body.scrollWidth) { //ie5+ syntax
		    if (currentfr.Document.body.innerHTML=="") 
		        currentfr.width = 0
		    else {
			  	//currentfr.width = currentfr.Document.body.scrollWidth+IEextraWidth;        
				var oBody = currentfr.Document.body;
				currentfr.width = oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth);
				
				docObj = currentfr.Document.getElementById("measurable_content");
				if(docObj != null) {
		        	var width = docObj.offsetWidth;
		        	width = parseInt(width);
					//alert(width+FFextraWidth);
					currentfr.width = width+IEextraWidth; 
				}
		        
				
			}
			//alert(currentfr.id + " : " + (currentfr.Document.body.scrollWidth) + ":" + currentfr.Document.body.offsetWidth  );	

        }
		//alert(iframeswidthtoresize[i]);	
        
		/*if (currentfr.addEventListener)
			currentfr.addEventListener("load", readjustIframe, false)
		else if (currentfr.attachEvent){
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			currentfr.attachEvent("onload", readjustIframe)
		}*/
	}
}



function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot)
		resizeIframe(iframeroot.id);
}

function refreshparentframe() {
	if(window != top) {
		//alert('refreshing ' + window.parent.location + ' with ' + window.location.pathname);
		//there is another parent iframe
		if (window.parent.refreshframe != undefined) {
			window.parent.refreshframe( window.parent.findIFrame(window.location.pathname) );
		}	
	} else {
		//alert("there is no other parent frame ");
	}
}
function findIFrame(iframesrc) {
	iframesrc = iframesrc.replaceAll(" ", "%20");
	var iframes = document.getElementsByTagName("iframe");
	
	//alert(iframes[0].src.substring(iframes[0].src.length -iframesrc.length ) == iframesrc);
	//alert(iframesrc.substring(iframesrc.length -iframes[0].src.length ) == iframes[0].src);
	for(var i=0;i<iframes.length;i++) {
		//alert(iframes[i].src + " == " + iframesrc);

		//exit for loop when src of iframe ends with given iframesrc
		if (iframes[i].src.length > iframesrc.length) {
			//src of frame is a full path
			if (iframes[i].src.substring(iframes[i].src.length -iframesrc.length ) == iframesrc) return iframes[i];
		} else {
			//src of frame is not a full path
			if (iframesrc.substring(iframesrc.length -iframes[i].src.length ) == iframes[i].src) return iframes[i];
		}
	}
	return null;
}	
function refreshframe(iframe) {
	//alert('refreshing sizing of ' + iframe.id);
	resizeIframeHeight(iframe.id); 
	
	//alert(iframe.height);
	refreshparentframe()
}

function iframeToResize(iframe) {
	if (isString(iframe)) {
		//iframe is a simple string
    	iframestoresize[iframestoresize.length] = iframe;
	} else {
		//iframe is a dom element
    	iframestoresize[iframestoresize.length] = iframe.id;		
	}
}
function iframeHeightToResize(iframe) {
	if (isString(iframe)) {
		//iframe is a simple string
    	iframestoresize[iframestoresize.length] = iframe;
	} else {
		//iframe is a dom element
    	iframestoresize[iframestoresize.length] = iframe.id;		
	}
}
function iframeWidthToResize(iframe) {
	//alert("iframeWidthToResize " + iframe);
	if (isString(iframe)) {
		//iframe is a simple string
    	iframeswidthtoresize[iframeswidthtoresize.length] = iframe;
	} else {
		//iframe is a dom element
    	iframeswidthtoresize[iframeswidthtoresize.length] = iframe.id;		
	}
}


function makeIFramesResizable() {
	var loadediframes = 0;	
	for(var i=0;i<iframestoresize.length;i++)  {
		var iframe = document.getElementById(iframestoresize[i]);

		eventPush(iframe,'load',
		function(src) { 
			var iframeid;
			if(src.id == undefined) {
				//in ie this is bound to the window and not the iframe
				iframeid = window.event.srcElement.id
			} else {
				//this is bound to an iframe
				iframeid = src.id
			}
			//alert('Resizing Iframe height of ' + iframeid);
			resizeIframeHeight( iframeid ); 
			//alert(iframeid);
			loadediframes++;
			if (loadediframes == iframestoresize.length) {
				//all frames have been loaded, refresh the parent
				refreshparentframe(); 
			}
		});
	}
}

function showIFrame(iframe) {
	if(!iframe.shown) {
		eventPush(iframe,'load',
		function(src) { 
			var iframeid;
			if(src.id == undefined) {
				//in ie this is bound to the window and not the iframe
				iframeid = window.event.srcElement.id
			} else {
				//this is bound to an iframe
				iframeid = src.id
			}
			resizeIframeHeight( iframeid ); 
			//alert(iframeid);
			refreshparentframe(); 
		});
		iframe.src=pictures[fotosindex];
		iframe.shown=true;
	}
}

 

function loadintoIframe(iframe, url){
	if (iframe.src == undefined)
		iframe.location=url
	else
	    iframe.src = url
}

if (window.addEventListener)
	window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
	window.attachEvent("onload", resizeCaller)
else
	window.onload=resizeCaller

//contruct an iframe inside div
//this will automatically retrieve and set the name of iframe as well
function constructTargetableIFrame(srcvar,indiv,frameborder) {
    var width = "100%";
    var name = eval("window._" + srcvar + "name");
    var iframeid = "i" + srcvar;
    var src = eval("window." + srcvar);
    if (name == undefined) name = "none";
    indiv.innerHTML = '<iframe name="' + name + '" id="' + iframeid + '" scrolling="no" allowtransparency="true" background-color="transparent" marginwidth="0" marginheight="0" frameborder="' + frameborder + '" vspace="0" hspace="0" style="overflow:visible;width:' + width +  '"></iframe>'
    var iframe = document.getElementById(iframeid);
    return iframe;
}

function iframedoc(iframe) {
	if (iframe.contentDocument) { 
		return iframe.contentDocument; 
	}
	else {
		return iframe.Document
	}
}

/**
 * Public UI functions
 **/
//argument is optional
function propagateClick(originatingiframe) {
	if(window != top) {
		//alert('refreshing ' + window.parent.location + ' with ' + window.location.pathname);
		//there is another parent iframe
		//alert(window.parent.document.onChildClick);
		var childiframe = window.parent.findIFrame(window.location.pathname)
		if(originatingiframe==undefined || originatingiframe==null) {
			//if no originating iframe exists, 
			//then the orginator is the current child 
			originatingiframe = childiframe
		}
		if (window.parent.document.onChildClick != undefined) {
			window.parent.document.onChildClick( childiframe, originatingiframe);
		} else {
			window.parent.propagateClick(originatingiframe);
		}	
	} else {
		//alert("there is no other parent frame ");
	}	
}
function propagateSiblingClick(iframe) {
	if (isString(iframe)) iframe = document.getElementById(iframe);
		
	var doc = iDocument(iframe);
	if(doc.onSiblingClick) { doc.onSiblingClick() }
}
function setDisplayNone(obj) {
	obj.style.display='none';		
	refreshparentframe();
}
function setDisplayBlock(obj) {
	obj.style.display='block';
	if (obj.isEmpty) { 
		obj.fill();
		obj.isEmpty=false;
	} else {
		refreshparentframe();
	}
}
function toggleDisplay(obj) {
	if(obj.style.display=='none') {
		setDisplayBlock(obj);	
	}
	else {
		setDisplayNone(obj);
	}
}
function parseID(str) {
	var parts = str.split("_");	
	return {id: parts[0], index: parseInt(parts[parts.length-1]) };
}
function iDocument(iframe) {
	if (iframe.contentDocument) 
		return iframe.contentDocument;
	else
		return iframe.Document;
}
//default parameters = { resizeHeight: true; resizeWidth: false; width: 100%; putIn: null; name:nil; overflow:true}
function createIFrame(itemname, parameters) {
	var withstyle="";
	var cssClass="";
	var srcTag="";
	var nameTag="";
	var cssFloat="";
	var showBorder="frameborder='0'";
	if(parameters != undefined) {
		if(parameters.resizeWidth != true) {
			withstyle="width:100%;"
		}	
		if(parameters.cssClass != undefined) {
			cssClass="class='" + parameters.cssClass + "'";
		}	
		if(parameters.src != undefined) {
			srcTag="src='" + parameters.src + "'";
		}	
		if(parameters.name != undefined) {
			//alert("window._" + parameters.name + "name");
			var name = eval("window._" + parameters.name + "name");
			nameTag="name='" + name + "'";
		}
		if((parameters.overflow == undefined) || !parameters.overflow ) {
			cssOverflow="overflow:no;";
		} else {
			cssOverflow="overflow:visible;";
		}
		cssFloat="float:left;";
		if(parameters.float != undefined) {
			cssFloat="float:" + parameters.float + ";";
		}
		if(parameters.resizeHeight != false || parameters.resizeWidth != undefined) cssDisplay="visibility:hidden;"; else cssDisplay="visibility:visible;";
		if(parameters.display != undefined) {
			cssDisplay="display:" + parameters.display + ";";
		}	
		if(parameters.showBorder) {
			showBorder="frameborder=1";
		}
	}	
	var htmlcode = '<iframe ' + nameTag + ' id="' + itemname +  '" ' + cssClass + ' scrolling="no"  allowtransparency="true" background-color="transparent"  marginwidth="0" marginheight="0" ' + showBorder + ' vspace="0" hspace="0" style="' + cssDisplay + cssFloat + cssOverflow + withstyle + '"' + srcTag + ' ></iframe>';
	//alert(htmlcode);
	if(parameters != undefined) {
		if(parameters.resizeHeight != false) {
			iframeHeightToResize(itemname);
		}
		if(parameters.resizeWidth == true) {
			iframeWidthToResize(itemname);
		}
		if(parameters.putIn != undefined) {
			//alert(parameters.target);
			parameters.putIn.innerHTML = htmlcode;
		}
	}
	return htmlcode;
}
//default parameters = { resizeHeight: true; resizeWidth: false; width: 100%; putIn: null; name:nil; overflow:true}
function createIFrames(itemname, parameters) {
	var htmlcode = "";
	if(parameters != undefined) {
		if(parameters.src != undefined) { 
			var htmlarray = createIFrameList(itemname,parameters);
			for(var i=0;i<htmlarray.length;i++) {
				htmlcode += htmlarray[i];
			}
			if(parameters.putIn != undefined) {
				//alert(parameters.target);
				parameters.putIn.innerHTML = htmlcode;
			}

		}
	}
	return htmlcode
}

//default parameters = { resizeHeight: true; resizeWidth: false; width: 100%; putIn: null; name:nil; overflow:true}
function createIFrameList(itemname, parameters) {
	var withstyle="";
	var cssClass="";
	var nameTag="";
	var cssOverflow;
	if(parameters != undefined) {
		if(parameters.resizeWidth != true) {
			withstyle="width:100%;"
		}	
		if(parameters.cssClass != undefined) {
			cssClass="class='" + parameters.cssClass + "'";
		}
		if((parameters.overflow == undefined) || !parameters.overflow ) {
			cssOverflow="overflow:no;";
		} else {
			cssOverflow="overflow:visible;";
		}
		cssFloat="float:left;";
		if(parameters.float != undefined) {
			cssFloat="float:" + parameters.float + ";";
		}
		if(parameters.resizeHeight != false || parameters.resizeWidth != undefined) cssDisplay="visibility:hidden;"; else cssDisplay="visibility:visible;";
		cssDisplay="display:block;";
		if(parameters.display != undefined) {
			cssDisplay="display:" + parameters.display + ";";
		}	
	}	
	var htmlcode = new Array();
	if(parameters != undefined) {
		if(parameters.src != undefined) { 
			
		for(var i=0;i<parameters.src.length;i++)  { 
			var srcTag="";
			srcTag="src='" + parameters.src[i] + "'";
			
			htmlcode[htmlcode.length] = '<iframe id="' + itemname + i +  '" ' + cssClass + ' scrolling="no" allowtransparency="true" background-color="transparent"  marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" style="' + cssDisplay +cssFloat + cssOverflow + withstyle + '" ' + srcTag + ' ></iframe>';

			if(parameters.resizeHeight != false) {
				iframeHeightToResize(itemname + i);
			}
			if(parameters.resizeWidth == true) {
				iframeWidthToResize(itemname + i);
			}
		}

		//alert(htmlcode);

		
		}
	}
	
	//alert(htmlcode);

	return htmlcode;


}

