// JavaScript Document

function fadeOut(fadeDIV, opacity, requesting_page) {
	
	
	if (document.getElementById) {
		theDIV = document.getElementById(fadeDIV);
		// fade out exisinting content
		if (opacity > 0) {
			opacity -= 10;
			setOpacity(theDIV, opacity);
			//window.setTimeout("fadeOut('"+fadeDIV+"',"+opacity+")", 20);
			window.setTimeout("fadeOut('"+fadeDIV+"',"+opacity+",'"+requesting_page+"')", 30);
		}
	}
	// if fade out complete swap cotent and fade in
	if (opacity <= 0) {	
		if (requesting_page == 'portfolio_1') {
		replaceContent(fadeDIV,'portfolio_1.php');
		}
		if (requesting_page == 'portfolio_2') {
		replaceContent(fadeDIV,'portfolio_2.php');
		}	
		if (requesting_page == 'contact') {
		replaceContent(fadeDIV,'contact.php');
		}	
		fadeIn(fadeDIV,0);
	}
}

function fadeIn(fadeDIV, opacity) {
	if (document.getElementById) {
		theDIV = document.getElementById(fadeDIV);
		if (opacity < 100) {
			opacity += 10;
			setOpacity(theDIV, opacity);
			window.setTimeout("fadeIn('"+fadeDIV+"',"+opacity+")", 20);
		}
	}
}

function setOpacity(obj, 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;
}



// Just used to test swapping the DIV content. Feel free to replace with your script.

function replaceContent(targetDiv,SourceURL) {
	//store the current contents of targetDiv
	var existingContent = document.getElementById(targetDiv).innerHTML;
	// check browser type and create appropraite object
	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") {
		http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		http = new XMLHttpRequest();
	}
	// load the named document
	http.open("GET", SourceURL);
	//when the new content has loaded
	http.onreadystatechange = function() {
		if(http.readyState == 4) {
			var newContent = http.responseText;
			// replace existing content of targetDIV
			if(existingContent != newContent) {
				document.getElementById(targetDiv).innerHTML = newContent;
			}
		}
	}
	http.send(null);
}
