// $Id: jVIT.js,v 1.2(Teeside) 2009/06/21 19:18:00 charlotteg Exp $

function jVITCustomLaunch(){
	

 	/* This function is customised for each site deployed to. This cuts down on the number of specific files required. */
 	
 	/* Define Paths First */
 	

 	SiteDomain = window.location.host
 	SiteURL = "http://" + SiteDomain;
 	SiteName = "The_Teeside_Website";
 	
 	Debug = false;

  	LightBoxIsReady();

	animationUtilityIsReady();

		anchors = document.getElementsByTagName('a');
		
			for(i=0; i<anchors.length;i++){
	
				if(anchors[i].getAttribute('href').match(/print\-page/)){
						
						addEvent(anchors[i],"click",printPage);
		
				}else if(anchors[i].getAttribute('href').match(/bookmark\-page/)){
						
						addEvent(anchors[i],"click",bookmarkPage);	
						
				}else if(anchors[i].getAttribute('href').match(/outbound/)){
				
						addEvent(anchors[i],"click",outboundLink);	
				
				}else if(anchors[i].getAttribute('href').match(/pdf/)){
				
						addEvent(anchors[i],"click",outboundLink);	
				
				}else if(anchors[i].getAttribute('href').match(/site_feedback/)){
				
						addEvent(anchors[i],"click",openProblemReportingForm);
				
				}

				
			};
			
  	
 	importJavascript("slideshow.js");
 	
 	
}

function SlideShowIsReady(){
	/* Specific Initialisation for Slideshow */

	slideshows["HomePage"] = new SlideShow;
	slideshows["HomePage"].init("school/slideshow-config-json.html","HomePage","animation");

}


function animationUtilityIsReady(){
	// this.init = function(StartVal,EndVal,Element,Attribute,Miliseconds,AnimationType,Mode,Fade,callback){

	report("animation utility loaded");
	
	var AnimationUtility = true;
	window.AnimationUtility = AnimationUtility;

}

function LightBoxIsReady(){
	/* Site Specific Setup for Lightbox */

   //report("lightbox script loaded");
	
	createLightBox("gallery-box");
	lightbox("gallery-box").init(
		  270 // width
		, 600 // height 
		, 50 // pixels from top
		, 80 // background opacity 0-100
		, /pop\.html\?t_widget_action=load/ //links which should trigger this lightbox
		, /t_widget_action=close/ //link in lightbox that closes it.
	);
	
	// Join is extra special lightbox, requires override of callback function
}

function jVITUtilityIsReady(){

	report("jVit utility script loaded");

}




var SiteSubDomain = "";
var SiteDomain = "";
var SiteURL = "";
var SiteName = "";
var Debug = false;


var jVIT = function () {
	var isIE = /*@cc_on!@*/false;
	var uniqueHandlerId = 0;
	var DOMLoaded = false;
	var DOMLoadTimer = null;
	var functionsToCall = [];
	var addedStrings = {};
	var execFunctions = function () {
		for (var i=0, il=functionsToCall.length; i<il; i++) {
			try {
				functionsToCall[i]();
			}
			catch (e) {
				
				alert(e);
				// Prevent possible reference errors
			}
		}
		functionsToCall = [];
	};
	var DOMHasLoaded = function () {
		if (DOMLoaded) {
			return;
		}
		DOMLoaded = true;
		execFunctions();
	};
	
	var XMLHttpFactories=[
	
		function(){
		
			return new XMLHttpRequest();
			
		},
		
		function(){
		
			return new ActiveXObject("Msxml2.XMLHTTP");
			
		},function(){
		
			return new ActiveXObject("Msxml3.XMLHTTP");
			
		},
		
		function(){
		
			return new ActiveXObject("Microsoft.XMLHTTP")
			
		}
		
	];
	
	return {
		init : function () {
			window.elm = window.elm || this.elm;
			window.elmsByClass = window.elmsByClass || this.elmsByClass;
			window.addClass = window.addClass || this.addClass;
			window.removeClass = window.removeClass || this.removeClass;
			window.addEvent = window.addEvent || this.addEvent;
			window.removeEvent = window.removeEvent || this.removeEvent;
			window.stopDefault = window.stopDefault || this.stopDefault;
			window.cancelBubbling = window.cancelBubbling || this.cancelBubbling;
			window.DOMReady = window.DOMReady || this.DOMReady;
			window.getCSSRule = window.getCSSRule || this.getCSSRule;
			window.createXMLHTTPObject = window.createXMLHTTPObject || this.createXMLHTTPObject;
			window.load = window.load || this.load;
			window.addBustCache = window.addBustCache || this.addBustCache;
			window.URLEncode = window.URLEncode || this.URLEncode;
			window.URLDecode = window.URLDecode || this.URLDecode;
			window.importJavascript = window.importJavascript || this.importJavascript;
			window.addDiv = window.addDiv || this.addDiv;
			window.getProfile = window.getProfile || this.getProfile;
			window.getXContent = window.getXContent || this.getXContent;
			window.getMetaValue = window.getMetaValue || this.getMetaValue;
			window.report = window.report || this.report;
			
			if (document.addEventListener) {
				document.addEventListener("DOMContentLoaded", DOMHasLoaded, false);
			}
			if (isIE) {
				if (document.getElementById) {
					document.write("<script id=\"ieScriptLoad\" defer src=\"//:\"><\/script>");
					document.getElementById("ieScriptLoad").onreadystatechange = function() {
						if (this.readyState === "complete") {
							DOMHasLoaded.call(this);
						}
					};
				}
			}
			if (/KHTML|WebKit|iCab/i.test(navigator.userAgent)) {
				DOMLoadTimer = setInterval(function () {
					if (/loaded|complete/i.test(document.readyState)) {
						DOMHasLoaded.call(this);
						clearInterval(DOMLoadTimer);
					}
				}, 10);
			}
			window.onload = DOMHasLoaded;
			
		},
		
		elm : function (id) {
			return document.getElementById(id);
		},
		
		report : function(string) {
		
			if(Debug){
		
				if(!elm("console")){
				
			
					elms = document.getElementsByTagName('body');
					CSSRules.add("#console","position: fixed; top:0px;z-index:2000;width:100%;overflow: auto;background: #000088;color:#FFFFFF;font-size:10px;font-family:courier;margin:0 auto;padding:0;")
					addDiv(elms[0],"console","<strong>Console</strong><br />");
					
					if(typeof AnimationUtility != 'undefined'){
					
						CSSRules.add("#console", "{height:0px;opacity:0}");
						createAnimation("grow-console");
						createAnimation("fade-in-console");
						animation("grow-console").init(0,100,elm("console"),"Height",1000,"decelerate","single","");
						animation("fade-in-console").init(0,50,elm("console"),"Alpha",1000,"decelerate","single","");
						animation("grow-console").start();
						animation("fade-in-console").start();
					
					}else{
					
						CSSRules.add("#console {height:100px;opacity:0.5}");
					
					}
					

					
					
				}
				
				var DateObj = new Date;
				elm("console").innerHTML+=DateObj.getHours()+":"+DateObj.getMinutes()+":"+DateObj.getMilliseconds()+" | "+string+"<br />";
			
			}
			
			
		
		},
		
		elmsByClass : function (className, tag, elm){
			if (document.getElementsByClassName) {
				this.elmsByClass = function (className, tag, elm) {
					elm = elm || document;
					var elements = elm.getElementsByClassName(className),
						nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
						returnElements = [],
						current;
					for(var i=0, il=elements.length; i<il; i+=1){
						current = elements[i];
						if(!nodeName || nodeName.test(current.nodeName)) {
							returnElements.push(current);
						}
					}
					return returnElements;
				};
			}
			else if (document.evaluate) {
				this.elmsByClass = function (className, tag, elm) {
					tag = tag || "*";
					elm = elm || document;
					var classes = className.split(" "),
						classesToCheck = "",
						xhtmlNamespace = "http://www.w3.org/1999/xhtml",
						namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
						returnElements = [],
						elements,
						node;
					for(var j=0, jl=classes.length; j<jl; j+=1){
						classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
					}
					try	{
						elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
					}
					catch (e) {
						elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
					}
					while ((node = elements.iterateNext())) {
						returnElements.push(node);
					}
					return returnElements;
				};
			}
			else {
				this.elmsByClass = function (className, tag, elm) {
					tag = tag || "*";
					elm = elm || document;
					var classes = className.split(" "),
						classesToCheck = [],
						elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
						current,
						returnElements = [],
						match;
					for(var k=0, kl=classes.length; k<kl; k+=1){
						classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
					}
					for(var l=0, ll=elements.length; l<ll; l+=1){
						current = elements[l];
						match = false;
						for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
							match = classesToCheck[m].test(current.className);
							if (!match) {
								break;
							}
						}
						if (match) {
							returnElements.push(current);
						}
					}
					return returnElements;
				};
			}
			return this.elmsByClass(className, tag, elm);
		},
		
		addClass : function (elm, className) {
			var currentClass = elm.className;
			if (!new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(currentClass)) {
				elm.className = currentClass + (currentClass.length? " " : "") + className;
			}
		},

		removeClass : function (elm, className) {
			var classToRemove = new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i");
			elm.className = elm.className.replace(classToRemove, function (match) {
				var retVal = "";
				if (new RegExp("^\\s+.*\\s+$").test(match)) {
					retVal = match.replace(/(\s+).+/, "$1");
				}
				return retVal;
			}).replace(/^\s+|\s+$/g, "");
		},
		
		addDiv : function (parent,newID, innerHTML, className){
		
			x = document.createElement('div');
			x.id = newID;
			x.innerHTML = innerHTML;
			if(className!=""){
				addClass(x,className);
			}
			parent.appendChild(x);
	

		},
		
		getXContent : function(){
			return getMetaValue("X-content");
		},
		
		getProfile : function(){
			return getMetaValue("X-profile");
		},
		
		getMetaValue : function(MetaName){
 			elements = document.getElementsByTagName('meta');
 			for(x in elements){
 				if(elements[x].name==MetaName){
 					return elements[x].getAttribute('content');
 				}
 			}
 			
 		},
		
		importJavascript: function(url){

			var fileref=document.createElement('script');
					
			fileref.setAttribute("type","text/javascript");
					
			fileref.setAttribute("src", SiteURL+"/javascript/"+url)
					
			if (typeof fileref!="undefined"){
		
				document.getElementsByTagName("head")[0].appendChild(fileref);
			
			}
			
		},
	
		getCSSRule: function(ruleName, deleteFlag) { 
		             
			ruleName=ruleName.toLowerCase();                      
			if (document.styleSheets) {                           
			  for (var i=0; i<document.styleSheets.length; i++) { 
				 var styleSheet=document.styleSheets[i];          
				 var ii=0;                                       
				 var cssRule=false;
				 if (styleSheet.cssRules) {                    
					cssRulez = styleSheet.cssRules;         
				 } else {                                      
					cssRulez = styleSheet.rules;            
				 }
				 var max_iterations = cssRulez.length;
				 do {                                             
					cssRule = cssRulez[ii];      
					if (cssRule)  {                              
					   if (cssRule.selectorText.toLowerCase()==ruleName) { 
						  if (deleteFlag=="delete") {             
							 if (styleSheet.cssRules) {           
								styleSheet.deleteRule(ii);        
							 } else {                             
								styleSheet.removeRule(ii);        
							 }                                    
							 return true;                         
						  } else {                                
							 return cssRule;                      
						  }                                       
					   }                                          
					}                                             
					ii++;                                         
				 } while((cssRule)&&(ii<max_iterations))                                
			  }                                                   
		   }                                                      
		   return false;                                          
		},	
		
		load: function(url,callback,DOMId,postData){
		
			report("AJAX Request Initalising: url:"+url+", callback:"+typeof(callback)+", DOMId:"+DOMId+", postData:"+postData);
		
			var req=createXMLHTTPObject();
			
			if(!req)return;
			
			var method=(postData)?"POST":"GET";
			
			req.open(method,addBustCache(url),true);
			
			//req.setRequestHeader('User-Agent','XMLHTTP/1.0');
			
			req.setRequestHeader("X-Requested-With", "XMLHttpRequest");

			if(postData){
				req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			}
			
			req.onreadystatechange=function(){
				
				
				if(req.readyState!=4){
				
					report("ReadyState:"+req.readyState+" (url:"+url+")");
					return;
					
				}
				
				if(req.status!=200&&req.status!=304&&req.status!=500){
					
					return;
					
				}
				
				report("ReadyState:"+req.readyState+" (url:"+url+")");

				callback(req,DOMId);
				
			}

			if(req.readyState==4){
			
				return;
				
			}
			
			req.send(postData);
			
		},
		
		addBustCache: function(url){

			var Temp = new Date();
	
			BustCache="bustcache=" + URLEncode(Temp.getTime());

			if(url.search(/\?/)==-1)
			{
				
				url = url+"?"+BustCache
			
				
			}else{
			
				url = url+"&"+BustCache
				
			}
		
			//url = SiteURL+"/"+url;
			
			return url;
		
		},
		
		URLEncode: function(clearString){
		
			var output='';
			
			var x=0;
			
			clearString=clearString.toString();
			
			var regex=/(^[a-zA-Z0-9_.]*)/;
			
			while(x<clearString.length){
			
				var match=regex.exec(clearString.substr(x));
				
				if(match!=null&&match.length>1&&match[1]!=''){
				
					output+=match[1];x+=match[1].length;
					
				}else{
				
					if(clearString[x]==' '){
						
						output+='+';
						
					}else{
					
						var charCode=clearString.charCodeAt(x);
						var hexVal=charCode.toString(16);
						output+='%'+(hexVal.length<2?'0':'')+hexVal.toUpperCase();
						
					}
				
					x++;
				
				}
				
			}
		
			return output;
		
		},
		
		URLDecode : function(url){

			var HEXCHARS = "0123456789ABCDEFabcdef";
			var encoded = url;
			var plaintext = "";
			var i = 0;
			
			while (i < encoded.length) {
			
				var ch = encoded.charAt(i);
			
				if (ch == "+") {
			
					plaintext += " ";
					i++;
			
				} else if (ch == "%") {
			
					if (i < (encoded.length-2)
						
						&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
						&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
						plaintext += unescape( encoded.substr(i,3) );
						i += 3;
					} else {
						alert( 'Bad escape combination near ...' + encoded.substr(i) );
						plaintext += "%[ERROR]";
						i++;
					}
				} else {
					
					plaintext += ch;
					i++;
				}
			} // while
			
			return plaintext;
		}, 
		
		addEvent : function (elm, evt, func) {
			if (document.addEventListener) {
				this.addEvent = function (elm, evt, func) {
					elm.addEventListener(evt, func, false);
				};
			}
			else {
				this.addEvent = function (elm, evt, func) {
					if (!elm.uniqueHandlerId) {
						elm.uniqueHandlerId = uniqueHandlerId++;
					}
					var alreadyExists = false;
					if (func.attachedElements && func.attachedElements[evt + elm.uniqueHandlerId]) {
						alreadyExists = true;
					}
					if (!alreadyExists) {
						if (!elm.events) {
							elm.events = {};
						}
						if (!elm.events[evt]) {
							elm.events[evt] = [];
							var existingEvent = elm["on" + evt];
							if (existingEvent) {
								elm.events[evt].push(existingEvent);
							}
						}
						elm.events[evt].push(func);
						elm["on" + evt] = jVIT.handleEvent;
						
						if (!func.attachedElements) {
							func.attachedElements = {};
						}
						func.attachedElements[evt + elm.uniqueHandlerId] = true;
					}
				};
			}
			return this.addEvent(elm, evt, func);
		},
		
		createXMLHTTPObject: function(){
		
			var xmlhttp=false;
			for(var i=0;i<XMLHttpFactories.length;i++){
			
				try{
				
					xmlhttp=XMLHttpFactories[i]();
				
				}catch(e){
				
					continue;
					
				}
				break;
				
			}
			return xmlhttp;
			
		},
		
		handleEvent : function (evt) {
			var currentEvt = evt || event;
			var currentTarget = currentEvt.target || currentEvt.srcElement || document;
			while (currentTarget.nodeType !== 1 && currentTarget.parentNode) {
				currentTarget = currentTarget.parentNode;
			}			
			currentEvt.eventTarget = currentTarget;
			var eventColl = this.events[currentEvt.type].slice(0);
			var eventCollLength = eventColl.length - 1;
			if (eventCollLength !== -1) {
				for (var i=0; i<eventCollLength; i++) {
					eventColl[i].call(this, currentEvt);
				}
				return eventColl[i].call(this, currentEvt);
			}
		},
		
		removeEvent : function (elm, evt, func) {
			if (document.addEventListener) {
				this.removeEvent = function (elm, evt, func) {
					elm.removeEventListener(evt, func, false);
				};
			}
			else {
				this.removeEvent = function (elm, evt, func) {
					if (elm.events) {
						var eventColl = elm.events[evt];
						if (eventColl) {
							for (var i=0; i<eventColl.length; i++) {
								if (eventColl[i] === func) {
									delete eventColl[i];
									eventColl.splice(i, 1);
								}
							}
						}
						func.attachedElements[evt + elm.uniqueHandlerId] = null;
					}
				};
			}
			return this.removeEvent(elm, evt, func);
		},
		
		stopDefault : function (evt) {
			evt.returnValue = false;
			if (evt.preventDefault) {
				evt.preventDefault();
			}
		},
		
		cancelBubbling : function (evt) {
			evt.cancelBubble = true;
			if (evt.stopPropagation) {
				evt.stopPropagation();
			}
		},
		
		
		
		DOMReady : function () {
			for (var i=0, il=arguments.length, funcRef; i<il; i++) {
				funcRef = arguments[i];
				if (!funcRef.DOMReady && !addedStrings[funcRef]) {
					if (typeof funcRef === "string") {
						addedStrings[funcRef] = true;
						funcRef = new Function(funcRef);
					}
					funcRef.DOMReady = true;
					functionsToCall.push(funcRef);
				}
			}
			if (DOMLoaded) {
				execFunctions();
			}
		}
	};
}();
jVIT.init();
DOMReady("jVITCustomLaunch()");

/* JSON Utility */
if (!this.JSON) {
    JSON = {};
}
(function () {

    function f(n) {
    
        return n < 10 ? '0' + n : n;
    }

    if (typeof Date.prototype.toJSON !== 'function') {

        Date.prototype.toJSON = function (key) {

            return this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z';
        };

        String.prototype.toJSON =
        Number.prototype.toJSON =
        Boolean.prototype.toJSON = function (key) {
            return this.valueOf();
        };
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


    function quote(string) {

        escapable.lastIndex = 0;
        return escapable.test(string) ?
            '"' + string.replace(escapable, function (a) {
                var c = meta[a];
                return typeof c === 'string' ? c :
                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
    }


    function str(key, holder) {

        var i,          
            k,          
            v,          
            length,
            mind = gap,
            partial,
            value = holder[key];

        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }

        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }

        switch (typeof value) {
        case 'string':
            return quote(value);

        case 'number':

            return isFinite(value) ? String(value) : 'null';

        case 'boolean':
        case 'null':

            return String(value);

        case 'object':

            if (!value) {
                return 'null';
            }

            gap += indent;
            partial = [];
            
            if (Object.prototype.toString.apply(value) === '[object Array]') {

                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }

                v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                            partial.join(',\n' + gap) + '\n' +
                                mind + ']' :
                          '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }

            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    k = rep[i];
                    if (typeof k === 'string') {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {

                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }

            v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                        mind + '}' : '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        }
    }

    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {

            var i;
            gap = '';
            indent = '';

            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }
                
            } else if (typeof space === 'string') {
                indent = space;
            }

            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                     typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }

            return str('', {'': value});
        };
    }

    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {

            var j;

            function walk(holder, key) {

                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }

            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }

            if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

                j = eval('(' + text + ')');

                return typeof reviver === 'function' ?
                    walk({'': j}, '') : j;
            }

            throw new SyntaxError('JSON.parse');
        };
    }
}());

/* CSS Classes Utility Helper */

var CSSRules = function() {

	var headElement = document.getElementsByTagName("head")[0],
	styleElement = document.createElement("style");
	styleElement.type = "text/css";
	headElement.appendChild(styleElement);
	
	var add = function() {
	
		if (styleElement.styleSheet) {
	
			return function(selector, rule) {
	
		    	if (styleElement.styleSheet.cssText == '') {
		
		     		styleElement.styleSheet.cssText = '';
		
		   		}
		
		   		styleElement.styleSheet.cssText += selector + " { " + rule + " }";
	
			}	
	
	  	} else {
	
	   		return function(selector, rule) {
	
	    		styleElement.appendChild(document.createTextNode(selector + " { " + rule + " }"));
	
	   		}
	
	 	}
	
	}();
	
	return {
	
	  add : add
	
	}

}();

var AnimationUtility = function(){


	return {
	
		init: function(){
			
			window.Animations = window.Animations || this.Animations;
			window.createAnimation = window.createAnimation || this.createAnimation;
			window.animation = window.animation || this.animation;
			window.quickAnimate = window.quickAnimate || this.quickAnimate;
			window.decelerate = window.decelerate  || this.decelerate ;
			window.accelerate = window.accelerate  || this.accelerate ;
			window.bubble = window.bubble  || this.bubble ;
			window.createCurve = window.createCurve || this.createCurve;
			window.B1 = window.B1 || this.B1;
			window.B2 = window.B2 || this.B2;
			window.B3 = window.B3 || this.B3;
			window.B4 = window.B4 || this.B4;
			window.getValueByPercent = window.getValueByPercent || this.getValueByPercent;
			window.cacheCurve = window.cacheCurve || this.cacheCurve;
			window.createLinearCurve = window.createLinearCurve || this.createLinearCurve;
			window.tick = window.tick || this.tick;
			window.rgbHexToArray = window.rgbHexToArray || this.rgbHexToArray;
			window.__globalDrawHandler = window.__globalDrawHandler || this.__globalDrawHandler;
			window.__globalTimeoutID = window.__globalTimeoutID || this.__globalTimeoutID;
	

			Animations = new Array;
			tick = 10;
			
			__globalTimeoutID = setTimeout("__globalDrawHandler()",0);
			
		},
		
		createAnimation : function(Identifier){
		
			Animations[Identifier] = new Animation();
			Animations[Identifier].ObjectHandle = Identifier;

		},
		
		animation : function(Identifier){
		
			if(Animations[Identifier]){
			
				return(Animations[Identifier]);
				
			}else{
				
				Animations[Identifier] = new Animation();
				Animations[Identifier].ObjectHandle = Identifier;
			
				return Animations[Identifier];
			
			}
			
		
		},
		
		quickAnimate: function(Identifier, StartVal,EndVal,Element,Attribute,Miliseconds,AnimationType,Mode,Fade,callback,callbackDelay){
		
			createAnimation(Identifier);
			animation(Identifier).init(StartVal,EndVal,Element,Attribute,Miliseconds,AnimationType,Mode,Fade,callback,callbackDelay);
			animation(Identifier).start();
		
		},
		
		decelerate: function(StartX,EndX){ 
		
			return {p1: EndX, p2: EndX, p3: EndX, p4: StartX};
		
		},
		
		accelerate: function(StartX,EndX){ 
		
			return {p1: EndX, p2: StartX, p3: StartX, p4: StartX};
		
		},
		
		bubble: function(StartX,EndX){ 
		
			return {p1: EndX, p2: EndX, p3: StartX, p4: StartX}; 
		
		},
				createLinearCurve: function(StartVal, EndVal){
		
			var ValueArray = new Array;
			var Difference = EndVal - StartVal;
			
			
			for(i=0;i<101;i++){
				ValueArray[i] = StartVal+Math.round(Difference * i / 100);
			}
			
			return ValueArray;
		
		},
		
		createCurve: function(StartVal, EndVal, Transition){
		
			switch(Transition.toLowerCase()){
			
				case "decelerate":
				
					return decelerate(StartVal, EndVal);
					break;
					
				case "accelerate":
				
					return accelerate(StartVal, EndVal);
					break;
					
				case "bubble":
				
					return bubble(StartVal, EndVal);
					break;
					
				default:
				
					return createLinearCurve(StartVal, EndVal);
					break;
					
			
			};
		
		},
		
		createLinearCurve: function(StartVal, EndVal){
		
			var ValueArray = new Array;
			var Difference = EndVal - StartVal;
			
			
			for(i=0;i<101;i++){
				ValueArray[i] = StartVal+Math.round(Difference * i / 100);
			}
			
			return ValueArray;
		
		},
		
		B1: function(t){ return (t*t*t);},		
		B2: function(t){ return (3*t*t*(1-t));},		
		B3: function(t){ return (3*t*(1-t)*(1-t));},		
		B4: function(t){ return ((1-t)*(1-t)*(1-t));},
				
		getValueByPercent: function(Percent,Curve) {
		
			var X = 0;
			
			X = Curve.p1 * B1(Percent) + Curve.p2 * B2(Percent) + Curve.p3 * B3(Percent) + Curve.p4 * B4(Percent);
			
			return Math.round(X);
		},
		
		cacheCurve: function(Curve){
		
			var ValueArray = new Array;
			
			for(i=0;i<101;i++){
			
				ValueArray[i] = getValueByPercent((i / 100),Curve);
			
			}
			
			return ValueArray;
		
		},
		
		__globalDrawHandler: function(){
		
			var DateObj = new Date();
			var StartTime = parseInt(DateObj.getTime());

			for(x in Animations){
				
				if(Animations[x].StopAnimation==false){
				
					Animations[x].step();
						
				};
				
			};
			
			var DateObj2 = new Date();
			var EndTime = parseInt(DateObj2.getTime());
				
			clearTimeout(__globalTimeoutID);	
			__globalTimeoutID = setTimeout(__globalDrawHandler,tick);
			
		
		
		},

		rgbHexToArray: function(rgbHex){
		
			rgbHex = rgbHex.replace("#","");
			
			var colour = new Array;
			
			if(rgbHex.length==3){
			
				colour['r'] = parseInt(rgbHex.substr(0,1) + rgbHex.substr(0,1),16);
				colour['g'] = parseInt(rgbHex.substr(1,1) + rgbHex.substr(1,1),16);
				colour['b'] = parseInt(rgbHex.substr(2,1) + rgbHex.substr(2,1),16);
			
			}else{
									
				colour['r'] = parseInt(rgbHex.substr(0,2),16);
				colour['g'] = parseInt(rgbHex.substr(2,2),16);
				colour['b'] = parseInt(rgbHex.substr(4,2),16);
			
			}
			
			return colour;
		
		}


	};
}();
AnimationUtility.init();

function Animation(){

	var TimeoutID;

	this.init = function(StartVal,EndVal,Element,Attribute,Miliseconds,AnimationType,Mode,Fade,callback,callbackDelay){
		

		if(Attribute=="Colour" || Attribute=="BackgroundColour"){
		
			this.Curve = new Array;
			
			StartVal = rgbHexToArray(StartVal);
			EndVal = rgbHexToArray(EndVal);
			
			this.Curve["r"] = cacheCurve(createCurve(StartVal["r"],EndVal["r"],AnimationType));
			this.Curve["g"] = cacheCurve(createCurve(StartVal["g"],EndVal["g"],AnimationType));
			this.Curve["b"] = cacheCurve(createCurve(StartVal["b"],EndVal["b"],AnimationType));
		
		
		}else{
		
			this.Curve = cacheCurve(createCurve(StartVal,EndVal,AnimationType));
		
		}
		
		
		/*
		if(IsArray(Element)){
		
		this.Element = Element;
		
		}else{
		
		this.Element = new Array;
		this.Element[0] = Element;
		
		};
		*/
		
		this.Element = Element;
		
		this.Attribute = Attribute;
		this.StartVal = StartVal;
		this.EndVal = EndVal;
		this.Miliseconds = Miliseconds;
		this.Fade = Fade;
		
		
		this.Direction = 1;
		
		if(callback){
		this.callback = callback;
		this.callbackDelay = callbackDelay || 0;
		}else{
		this.callbackDelay = callbackDelay || 0;
		this.callback = function(){};
		}
		
		if(Mode.match(/loop:/) || Mode.match(/repeat:/)){
		
			bits = Mode.split(":");
			this.Mode = bits[0];
			this.loopDelay = parseInt(bits[1]);
		
		}else{
		
			this.Mode = Mode;
			this.loopDelay = tick;
			
		}
		
		
		//this.Mode = Mode;
		if(Attribute=="Width" || Attribute == "Height"){
		
			this.Element.style.overflow = "hidden"
		
		};
		
		
	};
	
	this._go = function(){
		
		var DateObj = new Date;
		this.StartTime = DateObj.getTime();
		//this.TimeoutID = setTimeout("Animations['"+this.ObjectHandle+"'].step()",0);
		
		temp = function(){};
	}
	
	this._start = function(){

		this.StopAnimation = false;
		this.Direction = 1;	
		this._go();
	};
	
	this._reverse = function(){

		this.StopAnimation = false;
		this.Direction = 0;
		this._go();
	
	};
	
	this.start = function(){
	
		var DateObj = new Date;
		this.StartTime = DateObj.getTime();
		this.TimeoutID = setTimeout("Animations['"+this.ObjectHandle+"'].step()",0);
		
		temp = function(){};
	
		if(this.Fade=="fade in"){
			createAnimation(this.Element.id+"fade");
			animation(this.Element.id+"fade").init(0,100,this.Element,"Alpha",this.Miliseconds,"decelerate","single","",temp);
			animation(this.Element.id+"fade").start();
		}else if(this.Fade=="fade out"){
			createAnimation(this.Element.id+"fade");
			animation(this.Element.id+"fade").init(100,0,this.Element,"Alpha",this.Miliseconds,"decelerate","single","",temp);
			animation(this.Element.id+"fade").start();
		}else{
		
		}


		this.KillAnimation = false;
		this.StopAnimation = false;
		this.Direction = 1;	
		this._go();
	};

	
	this.reverse = function(){
	
		if(this.Fade=="fade out"){
			createAnimation(this.Element.id+"fade");
			animation(this.Element.id+"fade").init(0,100,this.Element,"Alpha",this.Miliseconds,"decelerate","single","",temp);
			animation(this.Element.id+"fade").start();
		}else if(this.Fade=="fade in"){
			createAnimation(this.Element.id+"fade");
			animation(this.Element.id+"fade").init(100,0,this.Element,"Alpha",this.Miliseconds,"decelerate","single","",temp);
			animation(this.Element.id+"fade").start();
		}else{
		
		}
	

		this.KillAnimation = false;
		this.StopAnimation = false;
		this.Direction = 0;
		this._go();
	
	};
	
	this.stop = function(){
		this.KillAnimation = true;
		this.StopAnimation = true;
	}
	
	this.step = function(){
	
		if(this.KillAnimation==false){
	
		var Percent = this.getElapsedPercent();
		

		if(this.Direction == 0){
			Percent = 100 - Percent;
			var StopAtVal = 0;
		}else{
			var StopAtVal = 100;
		}
	
		if(this.Attribute=="Colour" || this.Attribute=="BackgroundColour"){
		
			var Value = new Array;
			
			temp = "#";
			
			for(x in this.Curve){
				
				Value[x] = this.Curve[x][Percent];

				Value[x] = Value[x].toString(16);
				if(Value[x].length==1){
	
					Value[x] = "0"+Value[x];
					
				}
				temp+=Value[x];
			}
	
			
				//var temp = "#"+Value["r"].toString(16)+Value["g"].toString(16)+Value["b"].toString(16);
			Value = temp;
			
		}else{
			
			var Value = this.Curve[Percent];
			
		}
			
			
	
			
		
		
		switch(this.Attribute){
		
			case "Colour":
			
				this.Element.style.color = Value;
				break;
			
			case "BackgroundColour":
			
				
				this.Element.style.backgroundColor = Value;
				break;
		
			case "X":
		
				this.Element.style.left = Value+"px";
				break;
		
			case "Y":
		
				this.Element.style.top = Value+"px";
				break;
			
			case "Alpha":
			
				this.Element.style.opacity = Value / 100;
				this.Element.style.filter = "alpha(opacity="+Value+")";
				break;
				
			case "Width":
		
				this.Element.style.width = Value + "px";
				break;
		
			case "Height":
		
				this.Element.style.height = Value + "px";
				break;
		
			case "BackgroundScrollHorizontal" :
		
				this.Element.style.backgroundPosition = Value+"px 0";
				break;
		
			case "BackgroundScrollVertical" :
		
				this.Element.style.backgroundPosition = "0 "+Value+"px";
				break;
				
			case "Custom":
				this.Value = Value;
				this.CustomHandler();
		
		}
	
		
	
			
			if(Percent==StopAtVal){
				
				if(this.Mode=="single"){
				
					// Animation Finished
					this.StopAnimation=true;
					report("call back delay: "+this.callbackDelay);
					setTimeout(this.callback,this.callbackDelay);
					
					
				
				}else if(this.Mode=="repeat"){
					
					if(this.StopAnimation==false){
							this.StopAnimation=true;
							setTimeout("Animations['"+this.ObjectHandle+"']._start()",this.loopDelay);
					
					}else{
					
						if(this.callback){
							
							setTimeout(this.callback,this.callbackDelay);
							//this.callback();
							
						}	
					}
				
				}else if(this.Mode=="loop"){
				
					if(this.StopAnimation==false){
						this.StopAnimation=true;
						if(this.Direction==1){
						
							this.TimeoutID = setTimeout("Animations['"+this.ObjectHandle+"']._reverse()",this.loopDelay);
						
						}else{
						
							this.TimeoutID = setTimeout("Animations['"+this.ObjectHandle+"']._start()",this.loopDelay);
						
						}
					
					}else{
					
						if(this.callback){
							
							setTimeout(this.callback,this.callbackDelay);
							//this.callback();
							
						}	
					}			
				}
			}	
		};
	};
	
	this.getElapsedPercent = function(){
	
		var DateObj = new Date();
		var CurrentTime = new Number(DateObj.getTime());
			
		var ElapsedTime = CurrentTime - this.StartTime;
			
		var Percent = Math.round((ElapsedTime / (this.Miliseconds / 100)));
		
		if(Percent > 100){Percent=100};
		if(Percent < 0){Percent=0};
		return Percent;
		
	};
	
};


var LightBoxUtility = function(){

	return{
	
		init: function() {
		
			window.createLightBox = window.createLightBox || this.createLightBox;
			window.lightbox = window.lightbox || this.lightbox;
			window.getObjectHandleFromClass = window.getObjectHandleFromClass || this.getObjectHandleFromClass;
			
			LightBoxes = new Array;
		},
		
		createLightBox: function(string){
		
			LightBoxes[string] = new LightBox;
			LightBoxes[string].ObjectHandle = string;
		
		},
		
		lightbox: function(string){
		
			return LightBoxes[string];
		
		},
		
		getObjectHandleFromClass: function(className){
	
			var classes = className.split(" ");
				
			for (x in classes){
				
				if(classes[x].match(/trigger/)){
				
					bits = classes[x].split("__");
					return bits[0];
				
				}
			}
			
		}
	
	}

}();
LightBoxUtility.init();

var LightBox = function(){

	this.init = function(LightBoxWidth,LightBoxHeight,PixelsFromTop,TargetShadeOpacity,TargetHREF,CloseHREF,onLoadCustom,formValidationCustom){
		
			this.TargetHREF = TargetHREF;
			this.CloseHREF = CloseHREF;
			this.bindToAnchors();
			/*
				lightbox("staff").init(
					  800
					, 500
					, 100
					, 80
					, /t_widget_action=load/
					, "staff"
				);
			*/
			this.Width = LightBoxWidth;
			this.Height = LightBoxHeight;
			this.PixelsFromTop = PixelsFromTop;
			this.ShadeOpacity = TargetShadeOpacity;
			
			if(onLoadCustom!=undefined){
			
				report("Custom OnLoad Added");
				this.OnLoadCustom = onLoadCustom
			}else{
			
				this.OnLoadCustom = function(){return true};
			
			}
			
			if(formValidationCustom!=undefined){
			
				report("Custom Validation Added");
				this.CustomFormValidation = formValidationCustom
			}else{
			
				this.CustomFormValidation = function(){return true};
			
			}
			
			CSSRules.add("#"+this.ObjectHandle,"width:"+this.Width+"px;top:"+this.PixelsFromTop+"px;");
						
			report("Lightbox "+this.ObjectHandle+" Initilised, Width:"+this.Width+", Height:"+this.Height);
		
	}
	
	this.bindToAnchors = function(){
	
		elements = document.getElementsByTagName('a');
		
		for(i=0; i<elements.length;i++){
			
			if(elements[i].getAttribute('href').match(this.TargetHREF)){	
				
				this.processElement(elements[i],this.ObjectHandle,"click",LightBoxes[this.ObjectHandle].openLightBox);
				
			}
		}
			
	}
	
	this.autoOpenLightBox = function(url){
		

		parent.window.scrollTo(0,0)
		//ObjectHandle = getObjectHandleFromClass(this.className);
	
			report('opening light box '+this.ObjectHandle);

		handle = lightbox(this.ObjectHandle);
		
		//handle.URL = this.getAttribute('href');
		
		handle.URL = url;
		
		handle.addLightBoxDivsToDom();
		//window.onresize = LightBoxes[handle.ObjectHandle].setShadeSize;
		
		handle.animateLightBoxOpening(handle);
		
		//Using standalone timeout rather than animation callback to avoid ownership issues
		setTimeout("LightBoxes['"+this.ObjectHandle+"'].loadContentNow()",1000);

		//stopDefault(event);
		
	}
	
	this.openLightBox = function(event){
		
		parent.window.scrollTo(0,0)
		ObjectHandle = getObjectHandleFromClass(this.className);
	
			report('opening light box '+ObjectHandle);

		handle = lightbox(ObjectHandle);
		
		handle.URL = this.getAttribute('href');
		
		handle.addLightBoxDivsToDom();
		//window.onresize = LightBoxes[handle.ObjectHandle].setShadeSize;
		
		handle.animateLightBoxOpening(handle);
		
		//Using standalone timeout rather than animation callback to avoid ownership issues
		setTimeout("LightBoxes['"+ObjectHandle+"'].loadContentNow()",1000);

		stopDefault(event);
		
	}
		
	/* 
	 * User Interaction Handlers 
	 */
	
	this.linkClickedHandler = function(event){
	
		report("link clicked");
		
		handle = lightbox(getObjectHandleFromClass(this.className));
		handle.URL = this.getAttribute('href');
		
		handle.fadeOutContent();
		setTimeout("lightbox('"+handle.ObjectHandle+"').loadContentNow()",250);
		
		stopDefault(event);
		
	}
	
	this.closeClickedHandler = function(event){
	
		report("close button clicked");
		
		handle = lightbox(getObjectHandleFromClass(this.className));
		//handle.fadeOutContent();
		handle.animateLightBoxClosing();
	
		setTimeout("lightbox('"+handle.ObjectHandle+"').cleanUp()",1100);
		stopDefault(event);
	
	}
	
	this.formSubmitHandler = function(event){
	
		handle = lightbox(getObjectHandleFromClass(this.className));
		handle.URL = this.getAttribute('action');
		
		if(handle.CustomFormValidation(this)){
		
			var PostVars = "";
	
			for (var i=0;i<this.length;i++){
				
				if(this.elements[i].type=="radio"){
		
					if(this.elements[i].checked==true){
			
						PostVars = PostVars + this.elements[i].name+"="+URLEncode(this.elements[i].value)+"&";
			
					}
		
		
				}else {
	
					PostVars = PostVars + this.elements[i].name+"="+URLEncode(this.elements[i].value)+"&";
			
				}
				
			
			}
			
			handle.PostVars = PostVars;
	
			handle.fadeOutContent();
	
			//load(handle.URL,popLightBox,"",PostVars);
			
			setTimeout("lightbox('"+handle.ObjectHandle+"').submitForm()",250);
		
		}
		
		stopDefault(event);
	
	}
	
	/*
	 * AJAX Initiators
	 */ 
	
	this.submitForm = function(){
	
		report("Verifying Object Handle: "+this.ObjectHandle);

		this.addLoadingBar();				

		load(this.URL,LightBoxes[this.ObjectHandle].callback,this.ObjectHandle,this.PostVars);
	
	}
	
	this.loadContentNow = function(){
	
		report("Verifying Object Handle: "+this.ObjectHandle);

		this.addLoadingBar();				

		load(this.URL,LightBoxes[this.ObjectHandle].callback,this.ObjectHandle);
		
	
	}
	
	/* 
	 * Helper Callbacks 
	 */
	
	this.callback = function(req,ObjectHandle){
	
		/* Called on successful AJAX load */
	
		report("Lightbox "+ObjectHandle+" received data: "+req.statusText+": "+req.status);
	
		elm(ObjectHandle+"-lightbox-content-container").innerHTML = req.responseText;
		
		handle = lightbox(ObjectHandle);
		handle.OnLoadCustom();
		
		handle.attach();
		handle.hideLoadingBar();
		handle.fadeInContent();
		
	}
	
	this.cleanUp = function(){
		
		/* Used to remove Lightbox DOM Elements from DOM to clean up printing */
		
		report("clean up called");
		
		elm(this.ObjectHandle+"-lightbox-container").innerHTML = "";
		
		window.onResize = function(){};
		
	}
	
	this.finishHidingLoadBar = function(){
		
	
		if(elm("join-load-bar")){
		
			id = "join";
		
		}else if(elm("staff-load-bar")){
		
			id = "staff";
		
		}else if(elm("gallery-box-load-bar")){
		
			id = "gallery-box";
		
		}else if(elm("vacancies-load-bar")){
		
			id = "vacancies";
		
		}
		elm(id+"-load-bar").style.display="none";
		//this.Element.style.display="none";
		
	}
	
	/*
	 * Element Processing utilities
	 */ 
	 
	 this.attach = function(){
	
		elements = elm(this.ObjectHandle).getElementsByTagName('a');
		
		for(i=0; i<elements.length;i++){
			
			if(elements[i].getAttribute('href').match(this.CloseHREF)){
						
				this.processElement(elements[i],this.ObjectHandle,"click",LightBoxes[this.ObjectHandle].closeClickedHandler);

			}else if(elements[i].getAttribute('href').match(this.TargetHREF)){	

				this.processElement(elements[i],this.ObjectHandle,"click",LightBoxes[this.ObjectHandle].linkClickedHandler);
				
			}
		};
		
		elements = elm(this.ObjectHandle).getElementsByTagName('form');
		
		for(i=0; i<elements.length;i++){
		
			this.processElement(elements[i],this.ObjectHandle,"submit",LightBoxes[this.ObjectHandle].formSubmitHandler);
		
		}
		
		
	
	}
	
	this.processElement = function(element,ObjectHandle,eventType,callback){
		/* Adds events and classes to elements used as lightbox triggers */

		addEvent(element,eventType,callback)
		addClass(element,ObjectHandle+"__trigger");
		
		report("on"+eventType+" event handler added to element")
			
	}
	
		this.addLightBoxDivsToDom = function(){
	
		if(!elm(this.ObjectHandle+"-lightbox-container")){

			elms = document.getElementsByTagName('body');
			addDiv(elms[0],this.ObjectHandle+"-lightbox-container","");
			elm(this.ObjectHandle+"-lightbox-container").style.zoom = "1";

		}
		
		this.setShadeSize(handle);	

		addDiv(elm(this.ObjectHandle+"-lightbox-container"),this.ObjectHandle,"","lightbox");	
		addDiv(elm(this.ObjectHandle+"-lightbox-container"),this.ObjectHandle+"-background","","lightbox-background");
		addDiv(elm(this.ObjectHandle),this.ObjectHandle+"-lightbox-content-container","");
	
	}
	
	this.setShadeSize = function(handle){
	
		pageSize = getPageSize();
		CSSRules.add("#"+handle.ObjectHandle,"left:"+((pageSize[0] / 2) - (handle.Width / 2))+"px")+";top:"+handle.PixelsFromTop;
		CSSRules.add("#"+handle.ObjectHandle+"-background","height:"+pageSize[1]+"px");
		CSSRules.add("#"+handle.ObjectHandle+" #"+handle.ObjectHandle+"-lightbox-content-container","opacity:0;")
		
		report(handle.ObjectHandle+"-background resized to "+pageSize[0]+"px x "+pageSize[1]+"px");
	
	}
	
	
	this.addLoadingBar = function(){

		report((this.Height/2)-31);
			
		CSSRules.add("#"+this.ObjectHandle+"-load-bar-background","top:"+((this.Height/2)-31)+"px;left:"+((this.Width/2)-130)+"px");
		CSSRules.add("#"+this.ObjectHandle+"-load-bar-overlay","top:"+((this.Height/2)-31)+"px;left:"+((this.Width/2)-130)+"px;");

		if(!elm(this.ObjectHandle+"-load-bar")){
		


		
			addDiv(elm(this.ObjectHandle),this.ObjectHandle+"-load-bar","","load-bar");
			addDiv(elm(this.ObjectHandle+"-load-bar"),this.ObjectHandle+"-load-bar-background","","load-bar-background");
			addDiv(elm(this.ObjectHandle+"-load-bar"),this.ObjectHandle+"-load-bar-overlay","","load-bar-overlay");
			
		}
		
		this.animateLoadingBar();
	
	
	}
	
	/*
	 * Animation Scripts
	 */
	 
	this.fadeInContent = function(){
	
		quickAnimate(this.ObjectHandle+"-fade-in-content",20,100,elm(this.ObjectHandle+"-lightbox-content-container"),"Alpha",250,"decelerate","single","")
		/*
		createAnimation(this.ObjectHandle+"-fade-in-content");
		animation(this.ObjectHandle+"-fade-in-content").init(20,100,elm(this.ObjectHandle+"-lightbox-content-container"),"Alpha",250,"decelerate","single","");
		animation(this.ObjectHandle+"-fade-in-content").start();
		*/
	
	}
	
	this.fadeOutContent = function(){
			
		quickAnimate(this.ObjectHandle+"-fade-out-content",100,20,elm(this.ObjectHandle+"-lightbox-content-container"),"Alpha",250,"decelerate","single","")	
			
		/*
		createAnimation(this.ObjectHandle+"-fade-out-content");
		animation(this.ObjectHandle+"-fade-out-content").init(100,20,elm(this.ObjectHandle+"-lightbox-content-container"),"Alpha",250,"decelerate","single","");
		animation(this.ObjectHandle+"-fade-out-content").start();
		*/
		
	}
	
	this.animateLightBoxOpening = function(){
	
	
		quickAnimate("grow-lightbox",0,this.Height,elm(this.ObjectHandle),"Height",1000,"decelerate","single","fade in");
		//quickAnimate("move-lightbox",0,this.PixelsFromTop,elm(this.ObjectHandle),"Y",1000,"decelerate","single","");
		quickAnimate("fade-in-background",0,80,elm(this.ObjectHandle+"-background"),"Alpha",1000,"decelerate","single","")
	
		/*
		createAnimation("grow-lightbox");
		createAnimation("fade-in-background");
		createAnimation("move-lightbox");
		
		animation("grow-lightbox").init(0,this.Height,elm(this.ObjectHandle),"Height",1000,"decelerate","single","fade in");
		animation("move-lightbox").init(0,this.PixelsFromTop,elm(this.ObjectHandle),"Y",1000,"decelerate","single","");
		animation("fade-in-background").init(0,80,elm(this.ObjectHandle+"-background"),"Alpha",1000,"decelerate","single","");
		
		animation("grow-lightbox").start();
		animation("move-lightbox").start();
		animation("fade-in-background").start();
		*/
	
	}
	
	this.animateLightBoxClosing = function(){
	
		quickAnimate("shrink-lightbox",this.Height,0,elm(this.ObjectHandle),"Height",1000,"decelerate","single","fade out");
		quickAnimate("fade-lightbox-background",80,0,elm(this.ObjectHandle+"-background"),"Alpha",1000,"decelerate","single","");
		//quickAnimate("move-lightbox",this.PixelsFromTop,0,elm(this.ObjectHandle),"Y",1000,"decelerate","single","fade out");
		/*
	
		createAnimation("shrink-lightbox");
		createAnimation("fade-lightbox-background");
		createAnimation("move-lightbox");
		
		animation("shrink-lightbox").init(this.Height,0,elm(this.ObjectHandle),"Height",1000,"decelerate","single","fade in");
		animation("fade-lightbox-background").init(80,0,elm(this.ObjectHandle+"-background"),"Alpha",1000,"decelerate","single","");
		animation("move-lightbox").init(this.PixelsFromTop,0,elm(this.ObjectHandle),"Y",1000,"decelerate","single","fade out");
		
		animation("shrink-lightbox").start();
		animation("move-lightbox").start();
		animation("fade-lightbox-background").start();
		
		*/
		
	}
	
	this.animateLoadingBar = function(){
	
		report("Validating ObjectHandle: "+this.ObjectHandle);
		
		elm(this.ObjectHandle+"-load-bar").style.display="block";
	
		quickAnimate(this.ObjectHandle+"-fade-in-loadbar",0,100,elm(this.ObjectHandle+"-load-bar"),"Alpha",250,"decelerate","single","");
		quickAnimate(this.ObjectHandle+"-animate-loadbar",-260,0,elm(this.ObjectHandle+"-load-bar-background"),"BackgroundScrollHorizontal",500,"accelerate","single","");
		
		/*
	
		createAnimation(this.ObjectHandle+"-fade-in-loadbar");
		animation(this.ObjectHandle+"-fade-in-loadbar").init(0,100,elm(this.ObjectHandle+"-load-bar"),"Alpha",250,"decelerate","single","");
		animation(this.ObjectHandle+"-fade-in-loadbar").start();
	
		createAnimation(this.ObjectHandle+"-animate-loadbar");
		animation(this.ObjectHandle+"-animate-loadbar").init(-260,0,elm(this.ObjectHandle+"-load-bar-background"),"BackgroundScrollHorizontal",500,"accelerate","single","");
		animation(this.ObjectHandle+"-animate-loadbar").start();
		
		*/
	
	
	}
	
	this.hideLoadingBar = function(){
		report(this.ObjectHandle)
		quickAnimate(this.ObjectHandle+"-fade-out-loadbar",100,0,elm(this.ObjectHandle+"-load-bar"),"Alpha",250,"decelerate","single","",lightbox(this.ObjectHandle).finishHidingLoadBar);
			
		/*
		createAnimation(this.ObjectHandle+"-fade-out-loadbar");
		animation(this.ObjectHandle+"-fade-out-loadbar").init(100,0,elm(this.ObjectHandle+"-load-bar"),"Alpha",250,"decelerate","single","",lightbox(this.ObjectHandle).finishHidingLoadBar);
		animation(this.ObjectHandle+"-fade-out-loadbar").start();
		*/
		
	}
	
	
	
	

}
var jVITUtility = function () {

	
	return {
		init : function () {
	
			window.printPage = window.printPage || this.printPage;
			window.bookmarkPage = window.bookmarkPage || this.bookmarkPage;	
			window.dequote = window.dequote || this.dequote;
			window.getPageSize = window.getPageSize || this.getPageSize;
			window.getPageScroll = window.getPageScroll || this.getPageScroll;
			window.outboundLink = window.outboundLink || this.outboundLink;
			window.openWindow = window.openWindow || this.openWindow;
			window.openProblemReportingForm = window.openProblemReportingForm || this.openProblemReportingForm;
			window.processDate = window.processDate || this.processDate;
			window.addDateSuffix = window.addDateSuffix || this.addDateSuffix;
			window.getMonthName = window.getMonthName || this.getMonthName;
			window.getDays = window.padNumber || this.getDays;
			window.padTime = window.padTime || this.padTime;
			window.cleanPhone = window.cleanPhone || this.cleanPhone;
			window.cleanEmail = window.cleanEmail || this.cleanEmail;
			window.IsArray = window.IsArray || this.IsArray;
		
			
		},
		
		printPage : function(event){
			
			window.print();
		
			stopDefault(event);
		
		},
		
		bookmarkPage : function (event) {
		
			title = dequote(document.title);

			if(window.sidebar.addPanel){
				
				window.sidebar.addPanel(title,document.location,"");
	
			}else if(window.external){
			
				window.external.AddFavorite(document.location,title);
			
			}

			//return false;
			stopDefault(event);
		},
		
		dequote : function (string){
		
			return string.replace(/'/g,'\\\'');
		
		},
		
		outboundLink : function(event){
		
			openWindow(this.getAttribute('href'),800,600,1,'outboundWin','toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1');
		
			stopDefault(event);
		
		},
		
		openProblemReportingForm : function(event){
		
			url = this.getAttribute('href') + "?site_name="+SiteName;
		
			openWindow(url,640,480,1,"w_res",",scrollbars=yes,resizeable=no");
			
			stopDefault(event);
		
		},
		
		openWindow: function(url, width, height, centered, window_name, feature_string) {
		    // Javascript function to open a new window
		    // Required arguments are: url, width, height
		    // Optional arguments are: centered, window name, feature string
		    // Set window name to blank string if no window name passed
		    var childWindow;
		    
		    if (!window_name) {
		        window_name = '';
		    }
		    // Set feature string to blank string if no feature string passed
		    if (!feature_string) {
		        feature_string = '';
		    }
		    // Otherwise add a comma to the beginning
		    else {
		        feature_string = ',' + feature_string;
		    }
		    // Set starting position co-ordinates
		    var x = 0;
		    var y = 0;
		    // Get co-ordinates of center of screen if required
		    if (centered) {
		        x = Math.round((screen.availWidth - width) / 2);
		        y = Math.round((screen.availHeight - height) / 2);
		    }
		    // Build feature string
		    feature_string = 'left=' + x + ',top=' + y + ',width=' + width + ',height=' + height + feature_string;
		    // Open new window
		    childWindow = window.open(url, window_name, feature_string);
    		if (childWindow.opener == null) childWindow.opener = self;
		},
		
		/*
		
					window.processDate = window.processDate || this.processDate;
			window.addDateSuffix = window.addDateSuffix || this.addDateSuffix;
			window.getMonthName = window.getMonthName || this.getMonthName;
			
		*/
		
		processDate: function(dateObject){
		
			var datestring = padTime(dateObject.getHours())+":"+padTime(dateObject.getMinutes())+" ";
			datestring+= getDays(dateObject.getDay())+", ";
			datestring+= addDateSuffix(dateObject.getDate())+" of ";
			datestring+= getMonthName(dateObject.getMonth())+", ";
			datestring+= dateObject.getFullYear();
			
			return datestring;
		},
		
		addDateSuffix: function(number){
		
			switch(number){
			
				case 1,21,31:
				
					return number+"st";
					break;
					
				case 2,22:
				
					return number+"nd";
					break;
					
				case 3,23:
				
					return number+"rd";
					break;
					
				default:
				
					return number+"th";	
				
			
			}
		
		},
		
		getMonthName: function(number){
			
			var Months = {0: "January", 1:"February", 2:"March", 3:"April", 4:"May", 5:"June", 6:"July", 7:"August", 8:"September", 9:"October", 10:"November", 11:"December"};
			return Months[number];
		},
		
		getDays: function(number){
		
			var Days = {0: "Sun", 1:"Mon", 2:"Tue", 3:"Wed", 4:"Thu", 5:"Fri", 6:"Sat"};
			
			return Days[number];
		
		},
		
		padTime: function(number){
		
			if(number<10){return "0"+number}else{return number;}
		
		},
		
		/* these two functions are here temporarily */
		
		cleanPhone: function(string){
		
			string = string.replace(/\D+/g,'');
			string = string.replace(/^44/,'');
			string = string.replace(/^([^0]\d+)/, '0$1');
			string = string.replace(/(\d{5})(\d+)/,'$1 $2');
			
			if(string.match(/^\d{5} \d{5}\d?$/)){
			
				return string;
			
			}else{
			
				return false;
			
			}
		},
		
		cleanEmail: function(string){
		
			if(string.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)){
			
				return string;
			
			}else{
			
				return false;
			
			}
		},
		
		IsArray: function(array) { 
		
		return !!(array && array.constructor == Array); 
		
		},

		
		getPageScroll: function(){
		
			var xScroll,yScroll;
			if(self.pageYOffset){
				
				yScroll=self.pageYOffset;xScroll=self.pageXOffset;
			
			}else if(document.documentElement&&document.documentElement.scrollTop){
				
				yScroll=document.documentElement.scrollTop;
				
				xScroll=document.documentElement.scrollLeft;
				
			}else if(document.body){
			
				yScroll=document.body.scrollTop;
				xScroll=document.body.scrollLeft;
				
			}
			
			arrayPageScroll=new Array(xScroll,yScroll);
			
			return arrayPageScroll;
		},
		
		getPageSize : function(){
		
			var xScroll,yScroll;
			
			if(window.innerHeight&&window.scrollMaxY){
			
				xScroll=window.innerWidth+window.scrollMaxX;
				yScroll=window.innerHeight+window.scrollMaxY;
				
			}else if(document.body.scrollHeight>document.body.offsetHeight){
				
				xScroll=document.body.scrollWidth;
				yScroll=document.body.scrollHeight;
				
			}else{
			
				xScroll=document.body.offsetWidth;
				yScroll=document.body.offsetHeight;
				
			}
	
			var windowWidth,windowHeight;
			
			if(self.innerHeight){
				
				if(document.documentElement.clientWidth){
				
					windowWidth=document.documentElement.clientWidth;
					
				}else{
				
					windowWidth=self.innerWidth;
					
				}
	
				windowHeight=self.innerHeight;
			
			}else if(document.documentElement&&document.documentElement.clientHeight){
				
				windowWidth=document.documentElement.clientWidth;
				
				windowHeight=document.documentElement.clientHeight;
				
			}else if(document.body){
			
				windowWidth=document.body.clientWidth;
				windowHeight=document.body.clientHeight;
				
			}
	
			if(yScroll<windowHeight){
			
				pageHeight=windowHeight;
				
			}else{
			
				pageHeight=yScroll;
				
			}
	
			if(xScroll<windowWidth){
			
				pageWidth=xScroll;
				
			}else{
			
				pageWidth=windowWidth;
			
			}
	
			arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			
			return arrayPageSize;
			
		}
	};
}();
jVITUtility.init();

//jVITUtilityIsReady();
//LightBoxIsReady();
//animationUtilityIsReady();
//ConnectedSpecialIsReady();


function submit_form(form_object){document.forms[0].submit();}
function prefill(element_name,element_value){var element_array=document.getElementsByName(element_name);for(var i=0;i<element_array.length;i++){var element_type=element_array[i].type;if(element_type.match(/^select/)){prefill_select(element_array[i],element_value);}
else if(element_type=='checkbox'){prefill_checkbox(element_array[i],element_value);}
else if(element_type=='radio'){prefill_radio(element_array[i],element_value);}
else if(element_type=='text'){prefill_text(element_array[i],element_value);}
else if(element_type=='textarea'){prefill_text(element_array[i],element_value);}
else{}}}
function prefill_select(select_object,option_value){if(option_value==''){select_object.selectedIndex=0;return 1;}
for(var i=0;i<select_object.options.length;i++){if(select_object.options[i].value==option_value){select_object.selectedIndex=i;}}}
function prefill_radio(radio_object,radio_value){if(radio_object.value==radio_value){radio_object.checked=true;}
else{radio_object.checked=false;}}
function prefill_checkbox(checkbox_object,checked_flag){var checked_value=false;if(checked_flag){checked_value=true;}
checkbox_object.checked=checked_value;}
function prefill_text(text_object,text_value){text_object.value=text_value;}

