/*
	Filename         : default.js
	Last modified by : Mark Thomas
	Created          : 11 April 2003 17:09:31
	Last Updated     : 11 April 2003 17:16:13
	Comments         : 
*/

/***********************************************************
	Events
************************************************************/

function init(){
	if(!document.getElementById)
		return;
	if(document.getElementById("wrapperHome")){
		homepageAnimation();
		homeWrapperSize();
		window.onresize = homeWrapperSize;
	}
	animateInputs();
	};

function homeWrapperSize(){
	if(!document.documentElement.clientHeight){
		document.getElementById("wrapperHome").style.height = document.body.clientHeight + "px";
	}else{
		document.getElementById("wrapperHome").style.height = document.documentElement.clientHeight + "px";
	};
};

/***********************************************************
	
************************************************************/


function homepageAnimation(){
	oQuote 		= new oDhtml("quote", "", 1);
	oClickHere 	= new oDhtml("clickHere","",1);
	oBannerClip	= new oDhtml("bannerClip")
	oBanner2 	= new oDhtml("aniBanner2", "bannerClip");
	oBanner1 	= new oDhtml("aniBanner1", "bannerClip");
	oQuote.setVisible(1);
	oClickHere.setVisible(1);
	oQuote.setOpacity(0);
	oClickHere.setOpacity(0);
	setTimeout("oQuote.fade(1, 1000);", 2000);
	setTimeout("oClickHere.fade(1, 1000);", 3000);
	setTimeout("showBullets(0, document.getElementById(\"main\").getElementsByTagName(\"LI\").length);", 1000);

	if(!brow.mac){
		window.oAniBanner = new animatedBanner(0, 148, 782, 70, "banner");
		setTimeout("window.oAniBanner.stop()", 10000)
	};
	oBannerClip.setProperties(0, 148, 770, 70);
	oBannerClip.clipTo(35, 770, 35, 0);
	oBanner1.setClass("aniBanner");
	oBanner2.setClass("aniBanner");
	oBanner1.write("<nobr>" + document.getElementById("imageBanner").innerHTML + "</nobr>");
	oBanner2.write("<nobr>" + document.getElementById("imageBanner").innerHTML + "</nobr>");
	document.getElementById("imageBanner").style.visibility = "hidden";
	oBanner1.setVisible(1);
	oBanner2.setVisible(1);
	oBanner1.resizeTo(782, 70);
	oBanner2.resizeTo(782, 70);
	oBanner2.moveTo(770, 0);
	setInterval("aniBanner()", 50);
	bannerClipOpen();

};

function makeChildOpake(objName){
	obj = document.getElementById(objName)
	for(var i=0; i<this.obj.childNodes.length; i++){
		this.obj.childNodes[i].firstChild.className = "halfOpacity";
	}
}

function bannerClipOpen(){
	oBannerClip.clipTo(oBannerClip.clip[0] - 2, 770, oBannerClip.clip[2] + 2, 0);
	if(oBannerClip.clip[2] < 70)
		setTimeout("bannerClipOpen()", 50);
};

function aniBanner(){
	var direction = (mouseX > 385) ? -1 : 1;
	direction += parseInt((385 - mouseX) / 200);
	if(oBanner1.x < -770) oBanner1.moveTo(770, 0);
	if(oBanner2.x < -770) oBanner2.moveTo(770, 0);
	if(oBanner1.x > 770) oBanner1.moveTo(-770, 0);
	if(oBanner2.x > 770) oBanner2.moveTo(-770, 0);
	oBanner1.moveBy(direction, 0);
	oBanner2.moveBy(direction, 0);
};

function showBullets(n, nMax){
	if(n == nMax)
		return;
	document.getElementById("main").getElementsByTagName("LI")[nMax - n - 1].style.display = "block";
	setTimeout("showBullets(" + (n+1) + ", " + nMax + ")", 70);
};


proto.fade = function(mode, time){
	clearInterval(this.fadetimer);
	this.fadetimer = setInterval('document.dhtml["'+this.id+'"].fadeStep(' + mode + ')', time/10);
};
proto.fadeStep = function(mode){
	if((this.opacity == 10 && !mode) || (this.opacity == 90 && mode))
		clearInterval(this.fadetimer);
	inc = (mode) ? 10 : - 10;
	this.setOpacity(this.opacity + inc);
};

function animatedBanner(x, y, w, h, id){
	this.x 		= x;
	this.y 		= y;
	this.w		= w;
	this.h		= h;
	this.id		= id;
	this.nLines	= 10;
	this.aLines	= [];
	for(var i=0; i<this.nLines; i++){
		var o = this.aLines[i] = new oDhtml("bannerLine" + this.id + i);
		var nWidth = rand(2, 30);
		o.setProperties(-20, this.y, nWidth, this.h, 'visible', '#FFFFFF');
		o.css.fontSize = this.h;
		if(!brow.ie)
			o.write("&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />");
		o.clipTo(0, nWidth, this.h, 0);
		o.widget = this;
		o.interval = rand(1500, 3000);
		o.slideTimer = setInterval('document.dhtml["'+o.id+'"].randomSlide()', o.interval);
		o.setOpacity(rand(10, 40));
	};
};

function rand(nMin, nMax){
	return  Math.round(Math.random() * (nMax - nMin)) + nMin;
};


animatedBanner.prototype.stop = function(){
	for(var i=0; i<this.nLines; i++){
		clearInterval(this.aLines[i].slideTimer);
	};
	oAniBanner.hideLines();
};

animatedBanner.prototype.hideLines = function(){
	for(var i=0; i<this.nLines; i++){
		this.aLines[i].setVisible(0);
	};
};

proto.randomSlide = function(){
	var x = this.widget.x;
	var y = this.widget.y;
	var w = this.widget.w;
	this.slideTo(rand(x, x+w), y, this.interval);
};
/***********************************************************
	Form stuff
************************************************************/

function searchSubmit(){
	if(document.getElementById("fQuery").value == "")
		return false;
	return true;
};

function validateEmail(src) {
	var regex = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
	if(!regex.test(src)){
		alert("Please supply a valid email address");
		return false;
	};
	return true;
};

var aColours = (String(location.search) == "") ? new Array("#EEEFFF", "#F5F5FF", "#fff") : new Array("#fff","#F5F5FF", "#EEEFFF");


function animateInputs(){
	var aForm = [] 
	var aInput = document.getElementsByTagName("INPUT")
	for(var i=0; i<aInput.length; i++){
		if(aInput[i].type == "text" || aInput[i].type == "password"){
			aInput[i].onfocus = function focused(){
				animateBackground(this.id, 0, 1);
			}
			aInput[i].onblur = function focused(){
				animateBackground(this.id, 1, 0);
			};
		};
	};
	var aTextarea = document.getElementsByTagName("TEXTAREA")
	for(i=0; i<aTextarea.length; i++){
		aTextarea[i].onfocus = function focused(){
			animateBackground(this.id, 0, 1);
		}
		aTextarea[i].onblur = function focused(){
			animateBackground(this.id, 1, 0);
		};
	};
};

function animateBackground(nId, nInc, bFocus){
	document.getElementById(nId).style.backgroundColor = (bFocus) ? aColours[nInc] : aColours[aColours.length - nInc - 1];
	if(nInc++ < aColours.length - 1)
		setTimeout("animateBackground('" + nId + "', " + nInc +", " + bFocus +")", 50);
};

function validate(){
	if(validForm("fName", "", "please enter your name", "fEmail", "email", "please enter your email address", "fComments", "", "please enter your comments"))
		return true;
	return false;
};



/***********************************************************
	
************************************************************/