function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function popUp(url,w,h) {
   newWin = window.open(url,'_blank','width='+w+',height='+h+',menubar=no,scrollbars=1,status=yes,resizable=yes');
   newWin.focus();
}

/* Start image rollover */
var actImgTag;
var selImgTag;
var clsRoll;
var imgList;
var images;
var activeImages;
var inactiveImages;

// UIR (Unobtrusive Image Rollover) v2.0.1-20060309
if (document.getElementById) {
   function initUIR() {
      //actImgTag = "_on";
      actImgTag = "";
      selImgTag = "_sel";
      clsRoll = "roll";

      imgList = '';
      var images = document.getElementsByTagName('img');
   
      for (var i=0; i<images.length; i++) {
         if (eval('/' + clsRoll + '/').test(images[i].className)) {
            imgList += images[i].src + ",";
            setEvents(images[i]);
         }
      }
      
      if (imgList != '') {
         imgList = imgList.substring(0, imgList.length-1);
         preload(imgList.split(","));
      }
   }
   
   function setEvents(element) {
      element.parentNode.onmouseover = function() { roll(this); }
      element.parentNode.onmouseout = function() { roll(this); }
      element.parentNode.onfocus = function() { roll(this); }
      element.parentNode.onblur = function() { roll(this); }
   }
   
   function preload(imgList) {
      activeImages = new Array(imgList.length);
      inactiveImages = new Array(imgList.length);
      
      for (var i=0; i<imgList.length; i++) {
         activeImages[i] = new Image();
         activeImages[i].src = getBaseName(imgList[i]) + actImgTag + getExt(imgList[i]);
         inactiveImages[i] = new Image();
         inactiveImages[i].src = getBaseName(imgList[i]) + getExt(imgList[i]);
      }
   }
   
   function getBaseName(filename) {
      if (eval('/'+actImgTag+'\./').test(filename)) filename = filename.replace(actImgTag+'.', '.');
      if (eval('/'+selImgTag+'\./').test(filename)) filename = filename.replace(selImgTag+'.', '.');
      return filename.substring(0, filename.lastIndexOf('.'));
   }
   
   function getExt(filename) {
      return filename.substring(filename.lastIndexOf('.'), filename.length);
   }
   
   function getImage(imageName, isActive) {
      (isActive==0) ? images = inactiveImages : images = activeImages;
      for (var i=0; i<images.length; i++) {
         if (getBaseName(imageName) == getBaseName(images[i].src)) {
            return images[i];
            break;
         }
      }
      return [];
   }
   
   function roll(element) {
      var src, newSrc;
      var node, currNode;
      
      for (var i=0; i<element.childNodes.length; i++) {
         currNode = element.childNodes[i];
         if (currNode.nodeType==1 && /img/i.test(currNode.nodeName)) {
            node = i;
            break;
         }
      }
      src = element.childNodes[node].src;
      if (!(eval('/'+selImgTag+'\./').test(src))) {
         newSrc = getImage(src,!(eval('/'+actImgTag+'\./').test(src))).src;
      }
      if (!(typeof(newSrc)=='undefined')) element.childNodes[node].src = newSrc;
   }

   addLoadEvent(initUIR);
} // (C) 2005 Emanuele Rodriguez @ TangentDigital (http://www.tangent.es)

/* End image rollover */



/****************************************************
 ** 'Carrusel' continuous scroller v1.0.1.20070628 **
 **                                                **
 **     Tested browser compatibility:              **
 **                Internet Explorer 6.0 (Win)     **
 **                Internet Explorer 7.0 (Win)     **
 **                Firefox 2.0 (Win/Mac)           **
 **                Safari 3.02 (Win/Mac)           **
 **                Opera 9.21 (Win)                **
 **                                                **
 ** (C) 2007 Emanuele Rodriguez <erodri@gmail.com> **
 ****************************************************/
var timerScroll='';
var timerLoad='';
var defScrollStep=0.5;
var bImagesLoaded=false;

var scrollPos=0;
var scLength=0;
var elemId='';
var elemLength=0;

function initScroll(eid){
	elemId=eid;
	scLength=document.getElementById(eid).parentNode.offsetWidth;

	waitImgLoad();
}

// check that images are loaded
function waitImgLoad() {
	var oContainer = document.getElementById(elemId);
	var aImages = oContainer.getElementsByTagName('img');
	var iWidth = 0;
	var bImgLoaded = false;

	for (i = 0; i < aImages.length; i++) {
		if (!aImages[i].complete) {
			// wait some more
			bImgLoaded = false;
			timerLoad = setTimeout("waitImgLoad()", 1000);
			break;
		}
		bImgLoaded = true;
	}
	if (bImgLoaded) {
		clearTimeout(timerLoad);
		elemLength=getImagesWidth(elemId);
		bImagesLoaded = true;
		setupScroller(elemId, elemLength, scLength);
	}
}

function setupScroller(sContainer, iWidth, iVisibleWidth) {
	var oCurrNode, aClones, oClone;

	var iNumElem = 0;
	var iPosElem = 0;
	var iImgWidth = 0;

	var oContainer = document.getElementById(sContainer);
	var iNumElem = oContainer.childNodes.length;

	// setup array to hold cloned elements
	var aClones = new Array(iNumElem);

	for (i = 0; i < iNumElem; i++) {
		oCurrNode = oContainer.childNodes[i];
		if (oCurrNode.nodeType == 1) {
			if ((oCurrNode.tagName == 'IMG') || (oCurrNode.tagName == 'A')) {
				// warning: if the images have not yet been loaded in the page, getWidth returns 0
				if (iImgWidth < iVisibleWidth) {
					oClone = oCurrNode.cloneNode(true);
					aClones[iPosElem] = oClone;
					iImgWidth = iImgWidth + getWidth(oCurrNode);
					iPosElem++;
				}
			}
		}
	}
	for (i = 0; i < iPosElem; i++) {
		oContainer.appendChild(aClones[i]);
	}
	//note: doesn't work on Safari 2.x
	var iTotWidth = iWidth + iImgWidth;
	if (iTotWidth > 0) oContainer.style.width = iTotWidth + 'px';
}

function scrollIt(bToRight, scrollStep) {
	if (bImagesLoaded) {
		clearTimeout(timerScroll);
		if (!(scrollStep > 0)) scrollStep = defScrollStep;
		if (document.getElementById(elemId)) {
			if (bToRight) {
				// moving right
				if (scrollPos<=-parseInt(elemLength)) scrollPos = 0;
				scrollPos-=scrollStep;
			} else {
				// moving left
				if (scrollPos>0) scrollPos = -parseInt(elemLength);
				scrollPos+=scrollStep;
			}
			document.getElementById(elemId).style.marginLeft=scrollPos+'px';
			timerScroll=setTimeout("scrollIt("+bToRight+","+scrollStep+")",10);
		}
	}
}

function stopScroll(){
	clearTimeout(timerScroll);
}

function getImagesWidth(sContainer) {
	var oContainer = document.getElementById(sContainer);
	var aImages = oContainer.getElementsByTagName('img');
	var iWidth = 0;

	for (i = 0; i < aImages.length; i++) {
		iWidth = iWidth + aImages[i].width;
	}
	return iWidth;
}

function getWidth(oNode) {
	var iWidth = 0;

	if (oNode.tagName == 'IMG') iWidth = iWidth + oNode.width;
	else if (oNode.childNodes.length > 0) {
		for (j = 0; j < oNode.childNodes.length; j++) {
			oCurrChild = oNode.childNodes[j];
			if (oCurrChild.tagName == 'IMG') iWidth = iWidth + oCurrChild.width;
		}
	}
	return iWidth;
}

/* End image scroller */


/* Start image shaker */

function shakeElem(elemId){
	Effect.Shake(elemId);
	setTimeout("shakeElem('"+elemId+"')",2000);
}

/* End image shaker */


/* Start homeLoop */

var timerHomeLoop;
var timerElem1on;
var timerElem1off;
var timerElem2on;
var timerElem2off;
var timerElem3on;
var timerElem3off;
var timerElem4on;
var timerElem4off;
var defDelay=1250;
var nextShown=1;
var startFrom=1;
var showLoop=true;
//var isLoopRunning=false;

function homeLoop(){
	var delay=0;
	var elemId='';
	if (showLoop) {
		for (i=startFrom; i<=4; i++) {
			elemId='roll'+i;
			eval("timerElem"+i+"on  = setTimeout(\"showHomeElem('roll"+i+"')\", (delay=delay+defDelay))");
			eval("timerElem"+i+"off = setTimeout(\"hideHomeElem('roll"+i+"')\", (delay+defDelay))");
		}
		startFrom=1;
		timerHomeLoop=setTimeout("homeLoop();", delay);
	}
   //homeBannersLoop();
}

function homeBannersLoop(){
   var delay=0;
   setTimeout("Effect.Pulsate('banner1')", defDelay);
   setTimeout("Effect.Pulsate('banner2')", 3*defDelay);
   setTimeout("homeBannersLoop()", 5*defDelay);
}

function stopHomeLoop(){
	showLoop=false;
	for (i=1; i<=4; i++) {
		eval("clearTimeout(timerElem"+i+"on)");
		eval("clearTimeout(timerElem"+i+"off)");
	}
	clearTimeout(timerHomeLoop);
}

function hideHomeLoop(){
	stopHomeLoop();
	var elemId='';
	for (i=1; i<=4; i++) {
		elemId='roll'+i;
		document.getElementById(elemId).style.display='none';
	}
}

function showHomeLoop(){
//alert('showHomeLoop');
	showLoop=true;
	startFrom=nextShown;
	homeLoop();
}

var actImgTag = "_on";
var baseImgName = "images/home_photo_";
var imgExt = ".gif";

function showElem(elemBase, num) {
	//document.getElementById('img1').src='images/home_photo_1a_on.gif';
	var elemId = elemBase + num;
	var newImg = baseImgName + num + actImgTag + imgExt;
	document.getElementById(elemId).src = newImg;
}

function hideElem(elemBase, num) {
	//document.getElementById('img1').src='images/home_photo_1a.gif';
	var elemId = elemBase + num;
	var newImg = baseImgName + num + imgExt;
	document.getElementById(elemId).src = newImg;
}

function showHomeElem(elemId){
	if (showLoop) {
		Effect.Appear(elemId, { duration:1.0, from:0 });
	}
}

function hideHomeElem(elemId){
	if (showLoop) {
		Effect.Fade(elemId, { duration:1.0, from:1 });
		setNextShown(elemId);
	}
}

function setNextShown(elemId) {
	var currShownElem = parseInt(elemId.replace('roll',''));
	var nextShownElem = currShownElem + 1;
	if (nextShownElem > 4) nextShownElem = 1;
	nextShown = nextShownElem;
}

/* End homeLoop */

/* Start typewriter effect */

var text='';
var delay=50;
var currentChar=1;
var destination="[none]";

function type() {
	if (document.getElementById) {
		var dest=document.getElementById(destination);
		if (dest) {
			dest.style.color='#000';
			dest.innerHTML=text.substr(0, currentChar);
			currentChar++;
			if (currentChar>text.length) {
				// DONE - FADE IN LOGO + START SCROLL
				Effect.Appear('plogo', { duration:3.0, from:0.25 });
				setTimeout("scrollIt(true, 0.5)", 3000);
			} else {
				setTimeout("type()", delay);
			}
		}
	}
}

function startTyping(textParam, delayParam, destinationParam) {
	text=textParam;
	delay=delayParam;
	currentChar=1;
	destination=destinationParam;
	type();
}

/* End typewriter effect */
