/*******************************************************************************
Author:      PLY
Project:     PLY Domain Website
File:        ply.js
Created:     July 2006
Purpose:     Defines and initializes primary functions and data for PLY 
             JavaScript library.
*******************************************************************************/
/* DEFINE GLOBAL VARIABLES AND ARRAYS */
var rollovers = new Array(); // For product display images

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof oldonload != "function") {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
//addLoadEvent(initializeAjax);

window.addEvent('domready', function() {
	// Determine if page is blog or not
	var url = window.location + "";

	if (url.indexOf('blog') != -1)
	{
		initMenu();
	}
	else
	{
		// Original init function
		initializeAjax();
	}
});

// GLOBAL VARIABLES
var panel = false;
var page = false;

/*******************************************************************************
Section:     Global Functions
Purpose:     Defines common functions used throughout the PLY domain website.
*******************************************************************************/
/* FUNCTION DEFINITIONS */
// Adds or apends class to element
function addClass(element,new_class) {
	// Determine current class and adjust if necessary
	var old_class = element.className;
	if (old_class.indexOf(" " + new_class) == -1) {
		element.className = element.className ? element.className + " " + new_class : new_class;
		return true;
	} else {
		return false;
	}
}

// Removes class from element
function removeClass(element,new_class) {
	// Determine current class and adjust if necessary
	var old_class = element.className;
	var i = old_class.indexOf(" " + new_class);
	if (i != -1) {
		var old_length = old_class.length;
		var new_length = new_class.length;
		var first = old_class.substring(0,i);
		var last = old_class.substring(i+new_length+1,old_length);
		element.className = first + last;
		return true;
	} else {
		return false;
	}
}

// Preload images
function preloadImages(image_array,main_folder) {
	// Define variables
	var first_folder = null;
	// Preload images for each in images array
	for (var i = 0; i < image_array.length; i++) {
		// Grab image object and src attribute
		var src = image_array[i].getAttribute("src");
		// Separate src attribute
		var separator = ".";
		var src_split = src.split(separator);
		// Grab position, path and suffix
		var length = src_split.length;
		var path = src_split[length-2].toLowerCase();
		if (path == "on") {
			path = src_split[length-3].toLowerCase();
		}
		var suffix = "." + src_split[length-1].toLowerCase();
		// Grab folder and filename
		separator = "/";
		var path_split = path.split(separator);
		length = path_split.length;
		var folder = path_split[length-2];
		var name = path_split[length-1];

		// If not main_folder is passed, assign empty string to first_folder
		if (main_folder) {
			first_folder = main_folder + "/";
		} else {
			first_folder = "";
		}
		
		// Check if rollover array exists for image set; if not, create
		if (!rollovers[folder]) {
			rollovers[folder] = new Array();
		}

		// Load images
		rollovers[folder][name] = new Image();
		rollovers[folder][name].src = "/ply/_images/" + first_folder + folder + "/" + name + suffix;
		rollovers[folder][name + ".mo"] = new Image();
		rollovers[folder][name + ".mo"].src = "/ply/_images/" + first_folder + folder + "/" + name + ".mo" + suffix;
	}
}

// Turns image on
function imageOn(image) {
		var array = rollovers;
		var old_src = image.getAttribute("src");
		
		// Grab src attribute
		var src = image.getAttribute("src");
		// Separate src attribute
		var separator = ".";
		var src_split = src.split(separator);
		var length = src_split.length;
		
		// Grab path.  If image is "on," grab correct path.
		var path = src_split[length-2].toLowerCase();
		if (path == "mo") {
			path = src_split[length-3].toLowerCase();
		}
		
		// Grab folder filename
		separator = "/";
		var path_split = path.split(separator);
		length = path_split.length;
		var folder = path_split[length-2];
		var name = path_split[length-1];
		
		// Set new source
		var new_src = array[folder][name + ".mo"].src;
		if (new_src != old_src) {
			image.setAttribute("src",new_src);
		}
}

// Turns image off
function imageOff(image) {
		var array = rollovers;
		var old_src = image.getAttribute("src");
		
		// Grab src attribute
		var src = image.getAttribute("src");
		// Separate src attribute
		var separator = ".";
		var src_split = src.split(separator);
		var length = src_split.length;
		
		// Grab path.  If image is "on," grab correct path.
		var path = src_split[length-2].toLowerCase();
		if (path == "mo") {
			path = src_split[length-3].toLowerCase();
		}
		
		// Grab folder and filename
		separator = "/";
		var path_split = path.split(separator);
		length = path_split.length;
		var folder = path_split[length-2];
		var name = path_split[length-1];
		
		// Set new source
		var new_src = array[folder][name].src;
		if (new_src != old_src) {
			image.setAttribute("src",new_src);
		}
}

/* Animation functions */
/*
		t = time
		b = beginning position
		c = change in position
		d = duration
*/
function easeIn(t,b,c,d) {
	return c*t*t/(d*d) + b;
}
function easeOut(t,b,c,d) {
	return -c*t*t/(d*d) + 2*c*t/d + b;
}
function easeInOut(t,b,c,d) {
		if (t < d/2) return 2*c*t*t/(d*d) + b;
		var ts = t - d/2;
		return -2*c*ts*ts/(d*d) + 2*c*ts/d + c/2 + b;
}

/*******************************************************************************
Section:     Dynamic Loading of ActiveX/Object Controls
Purpose:     Manages Flash object replacement.
*******************************************************************************/
/**
 * SWFObject v1.4.2: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a,_b){if(!document.getElementById){return;}this.DETECT_KEY=_b?_b:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(c){this.addParam("bgcolor",c);}var q=_8?_8:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",_7);this.setAttribute("doExpressInstall",false);var _d=(_9)?_9:window.location;this.setAttribute("xiRedirectUrl",_d);this.setAttribute("redirectUrl","");if(_a){this.setAttribute("redirectUrl",_a);}};deconcept.SWFObject.prototype={setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16.push(key+"="+_18[key]);}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=key+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}return _23;};deconcept.PlayerVersion=function(_27){this.major=_27[0]!=null?parseInt(_27[0]):0;this.minor=_27[1]!=null?parseInt(_27[1]):0;this.rev=_27[2]!=null?parseInt(_27[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_29){var q=document.location.search||document.location.hash;if(q){var _2b=q.substring(1).split("&");for(var i=0;i<_2b.length;i++){if(_2b[i].substring(0,_2b[i].indexOf("="))==_29){return _2b[i].substring((_2b[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2d=document.getElementsByTagName("OBJECT");for(var i=0;i<_2d.length;i++){_2d[i].style.display="none";for(var x in _2d[i]){if(typeof _2d[i][x]=="function"){_2d[i][x]=null;}}}};if(typeof window.onunload=="function"){var oldunload=window.onunload;window.onunload=function(){deconcept.SWFObjectUtil.cleanupSWFs();oldunload();};}else{window.onunload=deconcept.SWFObjectUtil.cleanupSWFs;}if(Array.prototype.push==null){Array.prototype.push=function(_30){this[this.length]=_30;return this.length;};}

var getQueryParamValue=deconcept.util.getRequestParameter;
var FlashObject=deconcept.SWFObject; // for legacy support
var SWFObject=deconcept.SWFObject;


/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
	return document[movieName]
	}
}

// This function checks browser against list of unsupported; returns true if browser is supported
function supportedBrowser() {
	// Define deciding variable
	var isSupported = true;
	// Test if mozilla based browser
	if (navigator.appCodeName == "Mozilla") {
		// Detect Safari
		if (navigator.vendor == "Apple Computer, Inc.") {
			isSupported = false;
		}
		// Detect pre-1.0 Firefox
		if (navigator.userAgent.indexOf("Firefox")!=-1){
			var versionindex=navigator.userAgent.indexOf("Firefox")+8
			if (parseInt(navigator.userAgent.charAt(versionindex))>=1) {
				isSupported = true;
			} else {
				isSupported = false;
			}
		}
	}
	// Return value of isSupported
	if (isSupported == true) {
		return true;
	} else {
		return false;
	}
}

// This function checks browser against list of unsupported; returns true if browser is supported
function supportedBrowserFlash() {
	// Define deciding variable
	var isSupported = true;
	// Test if mozilla based browser
	if (navigator.appCodeName == "Mozilla") {
		// Detect pre-1.3 Safari
		if (navigator.userAgent.indexOf("Safari")!=-1){
			var versionindex=navigator.userAgent.indexOf("Safari")+7
			var version=navigator.userAgent.substring(versionindex,navigator.userAgent.length)
			if (parseFloat(version)>=312) {
				isSupported = true;
			} else {
				isSupported = false;
			}
		}
		// Detect pre-1.0 Firefox
		if (navigator.userAgent.indexOf("Firefox")!=-1){
			var versionindex=navigator.userAgent.indexOf("Firefox")+8
			if (parseInt(navigator.userAgent.charAt(versionindex))>=1) {
				isSupported = true;
			} else {
				isSupported = false;
			}
		}
	}
	// Return value of isSupported
	if (isSupported == true) {
		return true;
	} else {
		return false;
	}
}

/*******************************************************************************
Section:     Init Functions
Purpose:     Initializes various features of the site
*******************************************************************************/
function initMenu()
{
	// Init Menu
	if($('mainmenu'))
	{
		MainMenu = new SlideList($E('ul', 'mainmenu'), {transition: Fx.Transitions.linear, duration: 200});
	}
}

/*******************************************************************************
Section:     XMLHttpRequest
Purpose:     Initializes XMLHttpRequest object(s)
*******************************************************************************/
function initializeAjax(section,panel,page) {
	// Object detection
	if (!document.getElementById) return true; // Follow link
		
	// Determine current page
	var url = window.location.href;
	var seperator = url.indexOf("#");
	var url_seperator = url.substring((seperator + 1),url.length);
	if (typeof section != "string") {
		section = url_seperator;
		if (url_seperator == url) {
			section = 'home-page';
		}
	}
	
	if (typeof panel != "number") {
		panel = false;
	}
	if (typeof page != "number") {
		page = false;
	}
	
	//Re-style page if on a section with shorter background copy 
	var intro = document.getElementById('intro');
	if (section=='the-work'||section=='contact-ply') {
		intro.className='compact';
	} else {
		intro.className = '';
	}
	
	// Test if going to a new section and show transition
	if (page == false && typeof page != "number") {
		var details = document.getElementById("details");
		var transitionElement = document.getElementById("animation");
		if ((null != details)&&(null != transitionElement)) { //If both elements exist on the page
			startTransition(details,transitionElement,250,475);
		}
	}

	if (supportedBrowser()) {	
		new_url = url.substring(0,seperator);
		new_url = new_url + "#" + section;
		window.location.href = new_url;
	}
		
	// Set background based on current section
	var content = document.getElementById("content");
	content.className = section;
	
	// Set Flash navigation to proper state
	//if (section == "home-page") {
		/* Call a function registered as callPlayBall in the SWF named mymovie. */
		// Only call if function exists (if Flash is loaded)
		//if (getMovieName("mymovie").callNavOff) {
			//getMovieName("mymovie").callNavOff(); 
		//}
	//}
	
	// Set navigation to proper state
	var menu = document.getElementById('mainmenu');
	var menulis = menu.getElementsByTagName('li');

	// Get menu item for current page
	var currentMenuItem = null;
	if (section == 'home-page')
	{
		currentMenuItem = document.getElementById('menu_home');
	}
	else if (section == 'the-work')
	{
		currentMenuItem = document.getElementById('menu_work');
	}
	else if (section == 'the-company')
	{
		currentMenuItem = document.getElementById('menu_company');
	}
	else if (section == 'contact-ply')
	{
		currentMenuItem = document.getElementById('menu_contact');
	}

	for (var i = 0; i < menulis.length; i++)
	{
		menulis[i].className = "";
	}
	currentMenuItem.className = "current";
	
	// Init Menu
	initMenu();
	
	var requester = getXMLHttpRequestObject();

	// Initialize connection
	try {	
		requester.open("GET","default.php?timestamp=" + new Date().getTime() + "&section=" + section + "&panel=" + panel + "&page=" + page,true);
	} catch (error) {
		window.location = "upgrade.html";
	}
	// Attach event handler for loading complete event
	requester.onreadystatechange = function() {
		if (requester.readyState == 4) {
			if (requester.status == 200 || requester.status == 304) {
				processData(requester); // Document request complete
			} else {
				failure(requester); // Document request failed
			}
		}
		return true;
	};
	// Send request
	requester.send(null);
}

function sendEmailRequest(theForm) {
	if (validateForm(theForm)) {
		var contactControl = document.getElementById("contactControl");
		var transitionElement = document.getElementById("animation");
		startTransition(contactControl,transitionElement,310,535);
		
		// create email requester object
		var emailXMLHttpObj = getXMLHttpRequestObject();
		// open socket connection
		emailXMLHttpObj.open('POST','_scripts/sendmail.php',true);
		// set form http header
		emailXMLHttpObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		// get form values and send http request
		emailXMLHttpObj.send(getFormValues(theForm));
		emailXMLHttpObj.onreadystatechange = function() {
			emailStatusChecker(emailXMLHttpObj);
		}
		
		endTransition(contactControl,transitionElement,40);
	} else {
		return false;
	}
}

function getXMLHttpRequestObject() {
    var xmlobj;
    // check for existing requests
    if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){
        xmlobj.abort();
    }
    try{
        // instantiate object for Mozilla, Nestcape, etc.
        xmlobj=new XMLHttpRequest();
    }
    catch(e){
        try{
            // instantiate object for Internet Explorer
            xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e){
            // Ajax is not supported by the browser
            xmlobj=null;
            return false;
        }
    }
    return xmlobj;
}

function processData(requester) {
	// Grab objects and define variables and arrays
	var text = requester.responseText;
	
	var details = document.getElementById("details");
	var transitionElement = document.getElementById("animation");
	
	details.innerHTML = text;
	
	endTransition(details,transitionElement, 20);
					
	prepareDetails();
}

var timer = 0;

function startTransition(element,transitionElement,top,left) {

		timer = 0;

		element.style.visibility = "hidden";
		transitionElement.style.top = top + "px";
		transitionElement.style.left = left + "px";
		transitionElement.style.visibility = "visible";

}
	
function endTransition(element,transitionElement,time) {
		
		// Check if timeout exists and stop
		if (transitionTimeout) {
			clearTimeout(transitionTimeout);
		}
		
		timer = timer+1;

		if (timer >= time) {
			
			element.style.visibility = "visible";
			transitionElement.style.visibility = "hidden";
			
			// reset timer
			timer = 0;
		} else {
		
			var repeat = function() {
				endTransition(element,transitionElement,time);
			}
			
			var transitionTimeout = setTimeout(repeat,40);
			
		}

}

function emailStatusChecker(emailXMLHttpObj) {
	// if mail request is completed
	if (emailXMLHttpObj.readyState == 4) {
		if (emailXMLHttpObj.status == 200) {
			// if status == 200 display server response
			displayServerResponse(emailXMLHttpObj,"contactControl");
		} else {
			alert('Failed to get response: '+emailXMLHttpObj.statusText);
		}
	}
}

function displayServerResponse(httpObj,container_name) {
	if (!document.getElementById) return false;
	if (!document.getElementById(container_name)) return false;

	var container = document.getElementById(container_name);

	var response = httpObj.responseText;
	
	container.innerHTML = response;
}

function getFormValues(fobj){
    var str='';
    for(var i=0;i< fobj.elements.length;i++){
        str+=fobj.elements[i].name+'='+ escape(fobj.elements[i].value)+'&';
    }
    str=str.substr(0,(str.length-1));
    return str;
}

function link(target) {
	// Change "_blank" to something like "newWindow" to load all links in the same new window
	var newWindow = window.open(target, '_blank');
	newWindow.focus();
	return false;
}
/*******************************************************************************
Section:     Contact PLY Form Validation
Purpose:     General form validation.
*******************************************************************************/
function validateForm(theForm) {
 if (theForm.name.value == "") {
		alert("Please enter a value for the \"Name\" field.");
		theForm.name.focus();
		return false;
	}

	if (theForm.email.value == "") {	
		alert("Please enter a value for the \"Email\" field.");
		theForm.email.focus();
		return false;
	}
	
// test if valid email address, must have @ and .
	var checkEmail = "@.";
	var checkStr = theForm.email.value;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++) {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkEmail.length;  j++) {
			if (ch == checkEmail.charAt(j) && ch == "@")
			EmailAt = true;
			if (ch == checkEmail.charAt(j) && ch == ".")
			EmailPeriod = true;
			if (EmailAt && EmailPeriod)
			break;
			if (j == checkEmail.length)
			break;
		}
		// if both the @ and . were in the string
		if (EmailAt && EmailPeriod) {
			EmailValid = true
			break;
		}
	}
	if (!EmailValid) {
		alert("Please enter a valid email address (e.g. address@domain.com)");
		theForm.email.focus();
		return false;
	}
	return true;
}
/*******************************************************************************
Section:     Details
Purpose:     Defines common functions used throughout the Details section.
*******************************************************************************/
function prepareDetails() {
	// Object detection
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.body.scrollHeight) return true; //Follow link
	// Grab objects and define variables
	var details = document.getElementById("details");
	var detailsdivs = details.getElementsByTagName("div");
	
	for (var i = 0; i < detailsdivs.length; i++) {
		if (detailsdivs[i].className.indexOf("section") != -1) {

			// Define starting attributes				
			if (detailsdivs[i].className.indexOf(" on") != -1)	{
				detailsdivs[i].style.height = "323px";
			} else {
				detailsdivs[i].style.height = "23px";
			}
						
			// Grab rollover elements
			var detailsanchors = detailsdivs[i].getElementsByTagName("a");
			for (var ii = 0; ii < detailsanchors.length; ii++) {
				if (detailsanchors[ii].className.indexOf("rollover") != -1) {
				
				// Create rollover image array
				rollovers[rollovers.length] = detailsanchors[ii].firstChild;
				
				// Assign event handlers
				/*
					detailsanchors[ii].onmouseover = function() {
						return imageOn(this.firstChild);
					}
					detailsanchors[ii].onmouseout = function() {
						return imageOff(this.firstChild);
					}
				*/
				}
			}
			
			detailsdivs[i].onclick = function() {
				this.getElementsByTagName("a")[0].blur();
				return toggleDetails(this,detailsdivs);
			};
		}
	}
	
	//preloadImages(rollovers);
}

function toggleDetails(element,family) {
	// Object detection
	if (!Math) return true; // Follow link

	for (var i = 0; i < family.length; i++) {
		if (family[i].className.indexOf("section") != -1 && family[i] != element) {
			family[i].begin = parseInt(family[i].style.height);
			family[i].finish = 23;
			family[i].change = family[i].finish - family[i].begin;
			family[i].opacity_begin = 100;
			family[i].opacity_finish = 0;
			family[i].opacity_change = family[i].opacity_finish - family[i].opacity_begin;
			family[i].duration = 7;
			family[i].time = 0;
		}
	}
	element.begin = parseInt(element.style.height);
	element.finish = 323;
	element.change = element.finish - element.begin;
	element.opacity_begin = 0;
	element.opacity_finish = 100;
	element.opacity_change = element.opacity_finish - element.opacity_begin;
	element.duration = 12;
	element.time = 0;

	addClass(element,"on");
	
	animateDetails(element,family);
	
	return false;
}

function animateDetails(element,family) {
	// Define variables
	var movement = false;
	
	for (var i = 0; i < family.length; i++) {
		// Clear timeout if necessary
		if (family[i].timeout) {
			clearTimeout(family[i].timeout);
		}
		if (family[i].className.indexOf("section") != -1 && family[i] != element) {
			var f = family[i];
			// Run until time equals duration
			if (f.time <= f.duration && f.begin != f.finish) {
				// Shrink height of all non-active divs
				f.height = easeInOut(f.time++,f.begin,f.change,f.duration);
				f.style.height = Math.ceil(f.height) + "px";
				// Adjust opacity of non-active content table
				f.content = f.getElementsByTagName("table")[0];
				f.opacity = easeIn(f.time,f.opacity_begin,f.opacity_change,f.duration);
				f.content.style.filter = "alpha(opacity=" + f.opacity + ")"; // For IE
				f.content.style.KhtmlOpacity = (f.opacity / 100); // For Safari/KHTML
				// Keep opacity at 0.99 for mozilla
				f.content.style.opacity = f.opacity > f.opacity_finish ? (f.opacity / 100) : (f.opacity_finish / 100);
				f.content.style.MozOpacity = f.opacity > f.opacity_finish ? (f.opacity / 100) : (f.opacity_finish / 100);
				// If on last loop, turn element off
				if (f.time == f.duration) {
					// Turn element off
					removeClass(f,"on");
				}
					
				movement = true;
			} else {
				// Turn element off
				removeClass(f,"on");
			}
		}
	}
	var e = element;
	// Run until time equals duration
	if (e.time <= e.duration && e.begin != e.finish) {
		// Adjust height of section div
		e.height = easeInOut(e.time++,e.begin,e.change,e.duration);
		e.style.height = Math.ceil(e.height) + "px";
		// Adjust opacity of content table
		e.content = e.getElementsByTagName("table")[0];
		e.opacity = easeIn(e.time,e.opacity_begin,e.opacity_change,e.duration);
		e.content.style.filter = "alpha(opacity=" + e.opacity + ")"; // For IE
		e.content.style.KhtmlOpacity = (e.opacity / 100); // For Safari/KHTML
		// Keep opacity at 0.99 for mozilla
		e.content.style.opacity = e.opacity < e.opacity_finish ? (e.opacity / 100) : (e.opacity_finish / 100);
		e.content.style.MozOpacity = e.opacity < e.opacity_finish ? (e.opacity / 100) : (e.opacity_finish / 100);
	
		movement = true;
	}
	
	// Recursion
	if (movement) {
		var repeat = function() {
			animateDetails(element,family);
		};
		element.timeout = setTimeout(repeat,40);
	}
	return movement;
}

/*******************************************************************************
Section:     Pop-up
Purpose:     Pop-up live examples from work section.
*******************************************************************************/

function popWindow(url){  
	window.open(url, 'window', 'toolbar=yes,location=yes,statusbar=yes,menubar=yes,scrollbars=yes,resizable=yes');
}