/* 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Title : Global Scripts
Author : Jeetendra Chandragiri
URL : http://www.fyfeasia.com/

Description : Various functions for usability and presentation.

Created : October 1, 2005
Modified : November 15, 2005

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/


/* 
------------------------------------------------------------------------------
Browser Window functions
------------------------------------------------------------------------------ */

function loadExternalURL(urlToLoad) {
	var travelConfirmation=false;
   	travelConfirmation = confirm('You have selected a link to a third party web site, over which FyfeAsia.com has no control.\nDo you wish to continue?');
	if (travelConfirmation) {
		window.location = urlToLoad;
	}
}

function getCurrentSection() {
		pageloc1 = unescape(window.location.protocol);
		pageloc2 = unescape(window.location.host);		
		pagelocMask = pageloc1 + "//" + pageloc2 + "/";
		csIndexEnd = unescape(window.location.href).indexOf("/", pagelocMask.length);
		if(csIndexEnd!=-1){
			cs = unescape(window.location.href).substring(pagelocMask.length, csIndexEnd);
		} else {
			cs = "Home";
		}
		return cs;
}

function addListener( obj, type, fn ){ 
   if (obj.addEventListener){ 
	  obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
	  obj["e"+type+fn] = fn; 
	  obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
	  obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
} 

function getBrowserWidth() {	
	if(window.innerWidth) {
		return window.innerWidth;
	}  
    else if(document.documentElement && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;
	}
    else if(document.body) {
		return document.body.clientWidth;
	}      
	return 0;
}

function initializeLayout(){
	var browserWidth = getBrowserWidth();
	if (browserWidth > 992){
		changeLayout("normal");
	} else {
		changeLayout("compact");
	}
}

function finalizeLayout() {
	setTextSize();
	if(typeof sIFR == "function" && !sIFR.UA.bIsIEMac){
		/* 
		Note: This is an undesirable workaround.
		sIFR should inherit colors from the CSS stylesheet!
		*/
		currentSection=getCurrentSection();
		if(currentSection=="Corporate_Profile" || currentSection=="Contact_Us" || currentSection=="Terms_Of_Use"){
			csNormalColor='#009ed9'; csDarkColor='#006e98'; csLightColor = '#bfeeff'; csMedColor = '#80dcff';
		} else if(currentSection=="Services_Offered"){
			csNormalColor='#858bc6'; csDarkColor='#5d618b'; csLightColor = '#eaecff'; csMedColor = '#d5d9ff';
		} else if(currentSection=="Tyfo_Systems"){
			csNormalColor='#ff9900'; csDarkColor='#b36b00'; csLightColor = '#ffe6bf'; csMedColor = '#ffcc80';
		} else if(currentSection=="Research_And_Development"){
			csNormalColor='#dbab00'; csDarkColor='#997800'; csLightColor = '#fff1bf'; csMedColor = '#ffe380';
		} else if(currentSection=="Project_Briefs"){
			csNormalColor='#6f9900'; csDarkColor='#6f9900'; csLightColor = '#edffbf'; csMedColor = '#dcff80';
		} else if(currentSection=="Resources"){
			csNormalColor='#535353'; csDarkColor='#535353'; csLightColor = '#ffbfee'; csMedColor = '#ff80dc';
		} else {
			csNormalColor='#009ed9'; csDarkColor='#006e98'; csLightColor = '#bfeeff'; csMedColor = '#b180ff';
		}
		sIFR.replaceElement("h1", named({sFlashSrc: "/assets/titles/v6/headingRegular.swf", sColor: csNormalColor, sWmode: "transparent"}));
		sIFR.replaceElement("h2", named({sFlashSrc: "/assets/titles/v6/headingRegular.swf", sColor: csDarkColor, sWmode: "transparent"}));
		sIFR.replaceElement("p.pbtitle", named({sFlashSrc: "/assets/titles/v6/headingMedium.swf", sColor: csDarkColor, sWmode: "transparent"}));
	};		
	if(document.getElementById('tabsContent')) {
		Element.cleanWhitespace('tabsContent');		
		initTabsContent();
	}
}

var exists;
var allStretch;

function initTabsContent() {
		var tccDivs = document.getElementsByClassName("tabsContent-container");
		allStretch = new fx.MultiFadeSize(tccDivs, {duration: 400});

		items = document.getElementsByClassName("tabsContent-title");
		for (i = 0; i < items.length; i++){
			var tcTitle = items[i];
			div = tcTitle.nextSibling;
			tcTitle.title = tcTitle.className.replace("tabsContent-title ", "") + " (click to expand)";

			if (window.location.href.indexOf(tcTitle.title) < 0) {
				allStretch.hide(div, 'height');
				if (exists != true) exists = false;
			}
			else exists = true;

			tcTitle.onclick = function(){
				allStretch.showThisHideOpen(this.nextSibling, 100, 'height');
			}
		}
		if (exists == false) {
			$('tabsContent').childNodes[1].fs.toggle('height');	
		}
}

/* 
------------------------------------------------------------------------------
Style functions
------------------------------------------------------------------------------ */

function changeLayout(description){
   var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
	// First disable both
	if(a.getAttribute("title") == "normal" || a.getAttribute("title") == "compact"){a.disabled = true;}
	// Now enable the selected layout
	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") == description){a.disabled = false;}
   }
}

function changeTextSize(description){
   var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
	// First disable both
	if(a.getAttribute("title") == "regular" || a.getAttribute("title") == "large"){a.disabled = true;}
	// Now enable the selected size
	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") == description){a.disabled = false;}
   }
}

function showDiv(divName) {
	thisDiv = document.getElementById(divName);
	if (thisDiv) {
			thisDiv.style.display = "block";
	}
}

function hideDiv(divName) {
	thisDiv = document.getElementById(divName);
	if (thisDiv) {
			thisDiv.style.display = "none";
	}
}

function toggleStyleSheet(thisone, thatone) {
	  var i, a, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
	      if(a.getAttribute("title") == thisone) a.disabled = false;
		  else if(a.getAttribute("title") == thatone) a.disabled = true;
	    }
	  }
}

function searchFocus() {
	queryString = document.getElementById("queryString");
	queryString.className = 'inputHover';
	if(queryString.value == 'enter keyword(s)') {
		queryString.value = '';
	}
}

function searchBlur() {
	queryString = document.getElementById("queryString");
	queryString.className = 'inputNormal';
	if(queryString.value == '') {
		queryString.value = 'enter keyword(s)';
	}
}

function setTextSize() {
	if (getCookie('fatextsize') == 'large') {
		var largeClass = ' class="tsLargeActive"';
		var regularClass = ' class="tsRegular"';
		changeTextSize("large");
	}
	else {
		var largeClass = ' class="tsLarge"';
		var regularClass = ' class="tsRegularActive"';
		changeTextSize("regular");
	}	
	
	var cookiesite = "." + location.hostname;
	var str = '<em>Text Size: </em><a href="#"' + regularClass + ' onclick="deleteCookie(\'fatextsize\', \'/\', \'' + cookiesite + '\'); setTextSize();"><em>Regular</em></a><em> | </em>'	
	+ '<a href="#"' + largeClass + ' onclick="setCookie(\'fatextsize\', \'large\', 365, \'/\', \'' + cookiesite + '\'); setTextSize();"><em>Large</em></a>';
	document.getElementById('optionsRow2').innerHTML = str;
}


	function calloutCaptionFlyouts() {
		cvrc1Height = new fx.Height('calloutVarRightCaption1',{duration:400});
	}
	
	function showCaption(textToShow,whichCaption){
		if(document.getElementById(whichCaption)) {
			document.getElementById(whichCaption).innerHTML = textToShow;
		}
	}

	function hideCaption(whichCaption){
		if(document.getElementById(whichCaption)) {
			document.getElementById(whichCaption).innerHTML = "";
		}
	}


/* 
------------------------------------------------------------------------------
Cookie functions
------------------------------------------------------------------------------ */


function setCookie(name, value, expires, path, domain, secure)
{

	if (expires) {
		var expireDate = new Date();
		expireDate.setTime(expireDate.getTime() + 3600000*24*expires);
	}
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expireDate.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/*
------------------------------------------------------------------------------
Library: AHAH
------------------------------------------------------------------------------*/

function showhide(url,target) {
    // native XMLHttpRequest object
	if(document.getElementById(target).innerHTML== "") {
		document.getElementById(target).innerHTML = 'Loading... Please Wait.';
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = function() {jahDone(target);};
			req.open("GET", url, true);
			req.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = function() {jahDone(target);};
				req.open("GET", url, true);
				req.send();
			}
		}
	} else {
		document.getElementById(target).innerHTML = "";
	}
}    

function jah(url,target) {
// native XMLHttpRequest object
	document.getElementById(target).innerHTML = 'Loading... Please Wait.';
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = function() {jahDone(target);};
		req.open("GET", url, true);
		req.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = function() {jahDone(target);};
			req.open("GET", url, true);
			req.send();
		}
	}
} 

function jahDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML="System Error:\n" +
                req.statusText;
        }
    }
}

/* 
------------------------------------------------------------------------------
Library: Lightbox
------------------------------------------------------------------------------ */

var loadingImage = '/assets/images/loading.gif';		

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
//
function getPageSize(){
	
	var xScroll, yScroll;

	if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}


//
// addSuffix()
// Uses current date and time to append a number to the image name.
// Only does this if browser is Opera. This forces Opera to download the image again.
// If Opera had pulled the image from cache, the image onload function would not get triggered.
//
function addSuffix() {
//	if(window.opera){
		var currentDate = new Date();
		var suffix = currentDate.getTime();
		suffix = '?' + suffix;
//	} else {
// suffix = '';
//	}
	
	return suffix;
}




//
// showLightbox()
// Preloads images. Pleaces new image in lightbox then centers and displays.
//
function showLightbox(objLink)
{
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 40 - objLoadingImage.width) / 2) + 'px');
	}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// preload image
	imgPreload = new Image();
	imgPreload.src = objLink.href + addSuffix();
	
	imgPreload.onload=function(){

		objImage.src = objLink.href;

		// center lightbox
		objLightbox.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - imgPreload.height) / 2) + 'px');
		objLightbox.style.left = (((arrayPageSize[0] - 40 - imgPreload.width) / 2) + 'px');

		// A small pause between the image loading and displaying is required with IE,
		// this prevents the previous image displaying for a short burst causing flicker.
		// I know I know.. browser detection is bad, but what else can I do???
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			temp = navigator.appVersion.split("MSIE");
			version = parseFloat(temp[1]);
			pause(250);
		}

		objLightbox.style.display = 'block';

		return false;

	}

}





//
// hideLightbox()
//
function hideLightbox()
{
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');

	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
}




//
// initLightbox()
// Function runs on window load, going through link tags looking for rel="lightbox".
// These links receive onclick events that enable the lightbox display for their targets.
// The function also inserts html markup at the top of the page which will be used as a
// container for the overlay pattern and the inline image.
//
function initLightbox()
{
	
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");

	// loop through all anchor tags
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox")){
			anchor.onclick = function () {showLightbox(this); return false;}
		}
	}

	// the rest of this code inserts html at the top of the page that looks like this:
	//
	// <div id="overlay"><a href="#" onclick="hideLightbox(); return false;"><img id="loadingImage" /></a></div>
	// <div id="lightbox">
	//		<a href="#" onclick="hideLightbox(); return false;"><img /></a>
	// </div>
	
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// preload and create loader image
	var imgPreloader = new Image();
	imgPreloader.src = loadingImage + addSuffix();
	
	// if loader image found, create link to hide lightbox and create loadingimage
	imgPreloader.onload=function(){
		//alert("opera!");
		var objLoadingImageLink = document.createElement("a");
		objLoadingImageLink.setAttribute('href','#');
		objLoadingImageLink.onclick = function () {hideLightbox(); return false;}
		objOverlay.appendChild(objLoadingImageLink);
		
		var objLoadingImage = document.createElement("img");
		objLoadingImage.src = loadingImage;
		objLoadingImage.setAttribute('id','loadingImage');
		objLoadingImage.style.position = 'absolute';
		objLoadingImage.style.zIndex = '150';
		objLoadingImageLink.appendChild(objLoadingImage);

		imgPreloader.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

		return false;
	}


	// create lightbox div, same note about styles as above
	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	// create link
	var objLink = document.createElement("a");
	objLink.setAttribute('href','#');
	objLink.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink);
	
	// create image
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink.appendChild(objImage);
}




//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}




addLoadEvent(initLightbox);	// run initLightbox onLoad


/* 
------------------------------------------------------------------------------
Library: Prototype
------------------------------------------------------------------------------ */

/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/


//note: this is a stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    return __method.apply(object, arguments);
  }
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

//-------------------------

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  
  return elements;
}

//-------------------------

if (!window.Element) {
  var Element = new Object();
}

Object.extend(Element, {
  remove: function(element) {
    element = $(element);
    element.parentNode.removeChild(element);
  },

  hasClassName: function(element, className) {
    element = $(element);
    if (!element)
      return;
    var a = element.className.split(' ');
    for (var i = 0; i < a.length; i++) {
      if (a[i] == className)
        return true;
    }
    return false;
  },

  addClassName: function(element, className) {
    element = $(element);
    Element.removeClassName(element, className);
    element.className += ' ' + className;
  },
  
  removeClassName: function(element, className) {
    element = $(element);
    if (!element)
      return;
    var newClassName = '';
    var a = element.className.split(' ');
    for (var i = 0; i < a.length; i++) {
      if (a[i] != className) {
        if (i > 0)
          newClassName += ' ';
        newClassName += a[i];
      }
    }
    element.className = newClassName;
  },
  
  // removes whitespace-only text node children
  cleanWhitespace: function(element) {
    element = $(element);
    for (var i = 0; i < element.childNodes.length; i++) {
      var node = element.childNodes[i];
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
        Element.remove(node);
    }
  }
});

/* 
------------------------------------------------------------------------------
Library: Moo.fx
------------------------------------------------------------------------------ */

/*
moo.fx, simple effects library built with prototype.js (http://prototype.conio.net).
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE.
for more info (http://moofx.mad4milk.net).
10/24/2005
v(1.0.2)
*/

//base
var fx = new Object();
fx.Base = function(){};
fx.Base.prototype = {
	setOptions: function(options) {
	this.options = {
		duration: 500,
		onComplete: ''
	}
	Object.extend(this.options, options || {});
	},

	go: function() {
		this.duration = this.options.duration;
		this.startTime = (new Date).getTime();
		this.timer = setInterval (this.step.bind(this), 13);
	},

	step: function() {
		var time  = (new Date).getTime();
		var Tpos   = (time - this.startTime) / (this.duration);
		if (time >= this.duration+this.startTime) {
			this.now = this.to;
			clearInterval (this.timer);
			this.timer = null;
			if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
		}
		else {
			this.now = ((-Math.cos(Tpos*Math.PI)/2) + 0.5) * (this.to-this.from) + this.from;
			//this time-position, sinoidal transition thing is from script.aculo.us
		}
		this.increase();
	},

	custom: function(from, to) {
		if (this.timer != null) return;
		this.from = from;
		this.to = to;
		this.go();
	},

	hide: function() {
		this.now = 0;
		this.increase();
	},

	clearTimer: function() {
		clearInterval(this.timer);
		this.timer = null;
	}
}

//stretchers
fx.Layout = Class.create();
fx.Layout.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.el.style.overflow = "hidden";
		this.el.iniWidth = this.el.offsetWidth;
		this.el.iniHeight = this.el.offsetHeight;
		this.setOptions(options);
	}
});

fx.Height = Class.create();
Object.extend(Object.extend(fx.Height.prototype, fx.Layout.prototype), {	
	increase: function() {
		this.el.style.height = this.now + "px";
	},

	toggle: function() {
		if (this.el.offsetHeight > 0) this.custom(this.el.offsetHeight, 0);
		else this.custom(0, this.el.scrollHeight);
	}
});

fx.Width = Class.create();
Object.extend(Object.extend(fx.Width.prototype, fx.Layout.prototype), {	
	increase: function() {
		this.el.style.width = this.now + "px";
	},

	toggle: function(){
		if (this.el.offsetWidth > 0) this.custom(this.el.offsetWidth, 0);
		else this.custom(0, this.el.iniWidth);
	}
});

//fader
fx.Opacity = Class.create();
fx.Opacity.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.now = 1;
		this.increase();
		this.setOptions(options);
	},

	increase: function() {
		if (this.now == 1) this.now = 0.9999;
		if (this.now > 0 && this.el.style.visibility == "hidden") this.el.style.visibility = "visible";
		if (this.now == 0) this.el.style.visibility = "hidden";
		if (window.ActiveXObject) this.el.style.filter = "alpha(opacity=" + this.now*100 + ")";
		this.el.style.opacity = this.now;
	},

	toggle: function() {
		if (this.now > 0) this.custom(1, 0);
		else this.custom(0, 1);
	}
});

/* 
------------------------------------------------------------------------------
Library: Moo.fx pack
------------------------------------------------------------------------------ */

/*
moo.fx pack, effects extensions for moo.fx.
by Valerio Proietti (http://mad4milk.net) MIT-style LICENSE
for more info visit (http://moofx.mad4milk.net).
11/01/2005
v1.0.31
*/

//text size modify, works with ems only
fx.Text = Class.create();
fx.Text.prototype = Object.extend(new fx.Base(), {
	initialize: function(el, options) {
		this.el = $(el);
		this.setOptions(options);
	},

	increase: function() {
		this.el.style.fontSize = this.now + "em";
	}
});

//composition effect, calls Width and Height alltogheter
fx.Resize = Class.create();
fx.Resize.prototype = {
	initialize: function(el, options) {
		this.h = new fx.Height(el, options); 
		if (options) options.onComplete = null;
		this.w = new fx.Width(el, options);
		this.el = $(el);
	},

	toggle: function(){
		this.h.toggle();
		this.w.toggle();
	},

	modify: function(hto, wto) {
		this.h.custom(this.el.offsetHeight, this.el.offsetHeight + hto);
		this.w.custom(this.el.offsetWidth, this.el.offsetWidth + wto);
	},

	custom: function(hto, wto) {
		this.h.custom(this.el.offsetHeight, hto);
		this.w.custom(this.el.offsetWidth, wto);
	},

	hide: function(){
		this.h.hide();
		this.w.hide();
	}
}

//composition effect, calls Opacity and (Width and/or Height) alltogheter
fx.FadeSize = Class.create();
fx.FadeSize.prototype = {
	initialize: function(el, options) {
		this.el = $(el);
		this.el.o = new fx.Opacity(el, options);
		if (options) options.onComplete = null;
		this.el.h = new fx.Height(el, options);
		this.el.w = new fx.Width(el, options);
	},

	toggle: function() {
		this.el.o.toggle();
		for (var i = 0; i < arguments.length; i++) {
			if (arguments[i] == 'height') this.el.h.toggle();
			if (arguments[i] == 'width') this.el.w.toggle();
		}
	},

	hide: function(){
		this.el.o.hide();
		for (var i = 0; i < arguments.length; i++) {
			if (arguments[i] == 'height') this.el.h.hide();
			if (arguments[i] == 'width') this.el.w.hide();
		}
	}
}

//intended to work with arrays.
var Multi = new Object();
Multi = function(){};
Multi.prototype = {
	initialize: function(elements, options){
		this.options = options;
		this.el = this.getElementsFromArray(elements);
		for (i=0;i<this.el.length;i++){
			this.effect(this.el[i]);
		}
	},

	getElementsFromArray: function(array) {
		var elements = new Array();
		for (i=0;i<array.length;i++) { 
			elements.push($(array[i])); 
		}
		return elements;
	}
}

//Fadesize with arrays
fx.MultiFadeSize = Class.create();
fx.MultiFadeSize.prototype = Object.extend(new Multi(), {
	effect: function(el){
		el.fs = new fx.FadeSize(el, this.options);
	},

	showThisHideOpen: function(el, delay, mode){
		for (i=0;i<this.el.length;i++){
			if (this.el[i].offsetHeight > 0 && this.el[i] != el && this.el[i].h.timer == null && el.h.timer == null){
				this.el[i].fs.toggle(mode);
				setTimeout(function(){el.fs.toggle(mode);}.bind(el), delay);
			}
		}
	},

	hide: function(el, mode){
		el.fs.hide(mode);
	}
});

var Remember = new Object();
Remember = function(){};
Remember.prototype = {
	initialize: function(el, options){
		this.el = $(el);
		this.days = 365;
		this.options = options;
		this.effect();
		var cookie = this.readCookie();
		if (cookie) {
			this.fx.now = cookie;
			this.fx.increase();
		}
	},

	//cookie functions based on code by ALA author Peter-Paul Koch
	setCookie: function(value) {
		var date = new Date();
		date.setTime(date.getTime()+(this.days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		document.cookie = this.el+this.prefix+"="+value+expires+"; path=/";
	},

	readCookie: function() {
		var nameEQ = this.el+this.prefix + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
}

fx.RememberHeight = Class.create();
fx.RememberHeight.prototype = Object.extend(new Remember(), {
	effect: function(){
		this.fx = new fx.Height(this.el, this.options);
		this.prefix = 'height';
	},
	
	toggle: function(){
		if (this.el.offsetHeight == 0) this.setCookie(this.el.scrollHeight);
		else this.setCookie(0);
		this.fx.toggle();
	},

	custom: function(from, to){
		if (this.fx.now != to) {
			this.setCookie(to);
			this.fx.custom(from, to);
		}
	},
	
	resize: function(to){
		this.setCookie(this.el.offsetHeight+to);
		this.fx.custom(this.el.offsetHeight,this.el.offsetHeight+to);
	},

	hide: function(){
		this.fx.hide();
	}
});

fx.RememberText = Class.create();
fx.RememberText.prototype = Object.extend(new Remember(), {
	effect: function(){
		this.fx = new fx.Text(this.el, this.options);
		this.prefix = 'text';
	},
	
	custom: function(from, to){
		if (this.fx.now != to) {
			this.setCookie(to);
			this.fx.custom(from, to);
		}
	}
});

ParseClassNames = Class.create();
ParseClassNames.prototype = {
	initialize: function(options){
		var babies = document.getElementsByTagName('*') || document.all;
		for (var i = 0; i < babies.length; i++) {
			var el = babies[i];
			//attach the effect, from the classNames;
			var effects = this.getEffects(el);
			for (var j = 0; j < effects.length; j++) {
				if (j == 1 && options) options.onComplete = null;
				el[effects[j]+"fx"] = new fx[effects[j]](el, options);
			}
			//execute methods, from rel
			if (el.rel) {
				el.crel = el.rel.split(' ');
				if (el.crel[0].indexOf("fx_") > -1) {
					var event = el.crel[0].replace('fx_', '');
					var tocompute = this.getEffects($(el.crel[1]));
					el["on"+event] = function(){
						for (var f = 0; f < tocompute.length; f++) {
							$(this.crel[1])[tocompute[f]+"fx"][this.crel[2] || "toggle"](this.crel[3] || null, this.crel[4] || null);
						}
					}
				}
			}
		}
	},

	getEffects: function(el){
		var effects = new Array();
		var css = el.className.split(' ');
		for (var i = 0; i < css.length; i++) {
			if (css[i].indexOf('fx_') > -1) {
				var effect = css[i].replace('fx_', '');
				effects.push(effect);
			}
		}
		return effects;
	}
}

/*
------------------------------------------------------------------------------
XHTML-compliant Flash embedding.
------------------------------------------------------------------------------ */

FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;

	this.version = ver || 7; // default to 7
	this.align = "top"; // default to top
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.altTxt = "Please <a href='http://www.macromedia.com/go/getflashplayer'>upgrade your Flash Player</a>.";
	this.bypassTxt = "<p>Already have Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	this.params = new Object();
	this.variables = new Object();
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'best'); // default to best
	this.doDetect = getQueryParamValue('detectflash');
}

FlashObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}

FlashObject.prototype.getParams = function() {
    return this.params;
}

FlashObject.prototype.getParam = function(name) {
    return this.params[name];
}

FlashObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}

FlashObject.prototype.getVariable = function(name) {
    return this.variables[name];
}

FlashObject.prototype.getVariables = function() {
    return this.variables;
}

FlashObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    }
    return flashHTML;	
}


FlashObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}

FlashObject.prototype.write = function(elementId) {

	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}		
}

function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
	   			flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	
	if (getFlashVersion() >= ver) {
		return true;
	} else {
		return false;
	}
}

// get value of querystring param
function getQueryParamValue(param) {
	var q = document.location.search;
	var detectIndex = q.indexOf(param);
	var endIndex = (q.indexOf("&", detectIndex) != -1) ? q.indexOf("&", detectIndex) : q.length;
	if(q.length > 1 && detectIndex != -1) {
		return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
	} else {
		return "";
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
	}
}

/* 
------------------------------------------------------------------------------
Inject functions at run-time
------------------------------------------------------------------------------ */

//Run initiateLayout function when page loads and when it resizes.
addListener(window, 'resize', initializeLayout);