// JavaScript Document
// JavaScript Document
/*
cookie.set(name,value,[expiredays])
cookie.get(name)
cookie.remove(name)

queryString(name,[defaultValue,href])

Event.add(object,type,function)
	eg Event.add(document.getElementById('test'),'click',function(){alert('hello')})
Event.remove(object,type,function)

getElementsByClass(searchClass,node,tag)
	eg getElementsByClass('dropShadow',document,'a')

DropShadow.Start()
	any element with a DropShadow as its class will be made into a drop shadow element

Element.Height(elementID)
Element.Width(elementID)
Element.Top(elementID)
Element.Left(elementID)

Grow.Height(elementID,endHeight,speed)
Grow.Width(elementID,endWidth,speed)
Grow.Both(elementID,endHeight,endWidth,speed)

Shrink.Height(elementID,speed)
Shrink.Width(elementID,speed)
Shrink.Both(elementID,speed)

Slide.Right(elementID,pixels,speed,[position eg relative])
Slide.Left(elementID,pixels,speed,[position eg relative])
Slide.Up(elementID,pixels,speed,[position eg relative])
Slide.Down(elementID,pixels,speed,[position eg relative])

Page.Height()
Page.Width()

*/

var cookie = {
	set : function(name,value,expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate);
	},
	get : function(name){
		if (document.cookie.length>0){
			var cookies = document.cookie
			cookies = cookies.split(";")
			for(var n=0;n<cookies.length;n++){
				var namePos = cookies[n].indexOf(name.toLowerCase() + "=");
				if(namePos >= 0){
					var value = cookies[n].split("=")[1]
					value = value.replace(/\+/g, ' ');
					return(unescape(value));
					break;
				}
			}
		}
		return null
	},
	remove : function(name){
		cookie.set(name,null,-1);
	}
}
function queryString(name,defaultValue,href){
	if(href==null)href = document.location.href
	var q = href
	if(q.indexOf("?") > 0){
		q = q.split("?")[1];
		var params = q.split("&");
		for(var n=0;n<params.length;n++){
			var namePos = params[n].indexOf(name.toLowerCase() + "=");
			if(namePos >= 0){
				var value = params[n].split("=")[1];
				value = value.replace(/\+/g, ' ');
				return(unescape(value));
				break;
			}
		}
	}
	return (defaultValue==null ? null : defaultValue)
}
var Event = {
	add: function(obj,type,fn) {
		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]);
		} else
		obj.addEventListener(type,fn,false);
	},
	remove: function(obj,type,fn) {
		if (obj.detachEvent) {
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		} else
		obj.removeEventListener(type,fn,false);
	}
}

var DropShadow = {
	n : null,
	dsLeft : null,
	dsTop : null,
	dsContainer : null,
	dsWidth : null,
	dsHeight : null,
	Start : function(){
		var el = getElementsByClass('dropShadow',document);
		for(var i=0;i<el.length;i++){
			DropShadow.n = null;DropShadow.dsContainer = null;
			DropShadow.dsLeft = null;DropShadow.dsTop = null;
			DropShadow.dsWidth = null;DropShadow.dsHeight = null;
			DropShadow.add(el[i].id);
		}
	},
	add : function(id,colour,offsetX,offsetY,opacity){
		if(DropShadow.n==null){
			offsetX = ((offsetX==null) ? 3 : (offsetX/2));
			offsetY = ((offsetY==null) ? 3 : (offsetY/2));
			opacity = ((opacity==null) ? 90 : opacity);
			colour = ((colour==null) ? "black" : colour);
			DropShadow.dsWidth = ((DropShadow.dsWidth==null) ? Element.Width(id)-12 : DropShadow.dsWidth);
			DropShadow.dsHeight = ((DropShadow.dsHeight==null) ? Element.Height(id)-12 : DropShadow.dsHeight);
			
			document.getElementById(id).style.zIndex = 120;
			DropShadow.dsContainer =  id +"_dropshadow"
			var frmEle = document.createElement('div');
			frmEle.setAttribute('id',DropShadow.dsContainer);
			frmEle.style.position = 'absolute';
			frmEle.style.top=0;
			frmEle.style.left=0;
			frmEle.innerHTML+= "&nbsp;"
			frmEle.style.zIndex = 119;
			document.body.appendChild(frmEle);
		
			DropShadow.dsLeft = Element.Left(id);
			DropShadow.dsTop = Element.Top(id);
	
			DropShadow.n=0;
		}
		dsID = DropShadow.dsContainer + DropShadow.n
		var parentDiv = document.getElementById(id);
		//parentDiv.style.zIndex = 50
		var frmEle = document.createElement('div');
		frmEle.setAttribute('id',dsID);

		frmEle.style.position = 'absolute';
		frmEle.style.backgroundColor=colour;
		frmEle.style.MozOpacity=(opacity/100);
		frmEle.style.opacity = (opacity / 100);
		frmEle.style.filter = "alpha(opacity=" + opacity + ")"; 
		frmEle.style.zIndex = parentDiv.style.zIndex - 1;

		frmEle.style.width = DropShadow.dsWidth + (DropShadow.n*2) + 'px';
		frmEle.style.height = DropShadow.dsHeight + (DropShadow.n*2) + 'px';

		frmEle.style.top = DropShadow.dsTop+ (offsetY) +(6-DropShadow.n)+'px';
		frmEle.style.left = DropShadow.dsLeft + (offsetX) +(6-DropShadow.n) +'px';
		document.getElementById(DropShadow.dsContainer).appendChild(frmEle);
	
		document.getElementById(dsID).innerHTML+= "&nbsp;";
		var modifier =9;
		if(DropShadow.n==0){
			for(DropShadow.n=1;DropShadow.n<12;DropShadow.n++){
				DropShadow.add(dsID,colour,offsetX,offsetY,opacity-(modifier*DropShadow.n));
			}
		}
	},
	remove : function(id){
		if(document.getElementById(id +"_dropshadow")!=null)document.body.removeChild(document.getElementById(id +"_dropshadow"));
	}
}

var Element = {
	Hide : function(id){
		var el = document.getElementById(id);
		el.style.display = 'none';
	},
	Show : function(id){
		var el = document.getElementById(id);
		el.style.display = '';
	},
	Toggle : function(id){
		var el = document.getElementById(id);
		el.style.display = (el.style.display != 'none' ? 'none' : '' );
	},
	Height : function(id){
		var oHeight;
		if(document.getElementById){
			oHeight = document.getElementById(id).offsetHeight;
		}else if (document.layers){
			oHeight = document.layers[id].clip.height;
		}
		return oHeight;
	},
	Width : function(id){
		var oWidth;
		if(document.getElementById){
			oWidth = document.getElementById(id).offsetWidth;
		}else if (document.layers){
			oWidth = document.layers[id].clip.width;
		}
		return oWidth;
	},
	Top : function(id){
		var oTop;
		if(document.getElementById){
			oTop = document.getElementById(id).offsetTop;
		}else if (document.layers){
			oTop = document.layers[id].clip.top;
		}
		return oTop;
	},
	Left : function(id){
		var oLeft;
		if(document.getElementById){
			oLeft = document.getElementById(id).offsetLeft;
		}else if (document.layers){
			oLeft = document.layers[id].clip.left;
		}
		return oLeft;
	}
}

var Page = {
	Height : function(){
		var  browseHeight;
		if(document.layers||(document.getElementById&&!document.all)){
		   browseHeight=window.innerHeight;
		}else if(document.all){
		   browseHeight=document.body.clientHeight;
		}
		return browseHeight;
	},
	Width : function(){
		var browseWidth;
		if(document.layers||(document.getElementById&&!document.all)){
		   browseWidth=window.outerWidth;
		}else if(document.all){
		   browseWidth=document.body.clientWidth;
		}
		return browseWidth;
	}
}

var Grow = {
	StepSpeed : 2,
	Height : function(id,endHeight,speed,pos){
		if(pos==null)pos='relative'
		if(speed==null)speed=10
		var el = document.getElementById(id);
		el.style.position=pos
		el.style.height = '0px';
		el.style.display = '';
		el.style.overflow='hidden';
		Grow.growHeight(id,endHeight,speed);
	},	
	growHeight : function(id,endHeight,speed){
		var el = document.getElementById(id);
		if(Element.Height(id) < endHeight){
		el.style.height = Element.Height(id) + speed +'px';
		var timer = setTimeout(function(){Grow.growHeight(id,endHeight,speed)},Grow.StepSpeed);
		}
	},
	Width : function(id,endWidth,speed,pos){
		if(pos==null)pos='relative'
		if(speed==null)speed=10
		var el = document.getElementById(id);
		el.style.position=pos
		el.style.width = '0px';
		el.style.display = '';
		el.style.overflow='hidden';
		Grow.growWidth(id,endWidth,speed);
	},
	growWidth : function(id,endWidth,speed){
		var el = document.getElementById(id);
		if(Element.Width(id) < endWidth){
		el.style.width = Element.Width(id) + speed +'px';
		var timer = setTimeout(function(){Grow.growWidth(id,endWidth,speed)},Grow.StepSpeed);
		}
	},
	Both : function(id,endHeight,endWidth,speed,pos){
		if(pos==null)pos='relative'
		if(speed==null)speed=10
		var el = document.getElementById(id);
		el.style.position=pos
		el.style.width = '0px';
		el.style.height = '0px';
		el.style.display = '';
		el.style.overflow='hidden';
		if(endHeight > endWidth){
			var modifier = endHeight/endWidth;
			var s = (speed / modifier);
			Grow.growWidth(id,endWidth,s);
			Grow.growHeight(id,endHeight,speed);
		}else if(endWidth > endHeight){
			var modifier = endWidth/endHeight;
			var s = (speed / modifier);
			Grow.growWidth(id,endWidth,speed);
			Grow.growHeight(id,endHeight,s);
		}else{
			Grow.growWidth(id,endWidth,speed);
			Grow.growHeight(id,endHeight,speed);
		}
	}
}
var Shrink = {
	StepSpeed : 2,
	Height : function(id,speed){
		var el = document.getElementById(id);
		el.style.display = '';
		el.style.overflow='hidden';
		Shrink.shrinkHeight(id,speed,Element.Height(id));
	},	
	shrinkHeight : function(id,speed,count){
		var el = document.getElementById(id);
		if(count > 0){
			el.style.height = count +'px';
			var timer = setTimeout(function(){Shrink.shrinkHeight(id,speed,count)},Shrink.StepSpeed);
			count=count-speed
		}else{
			Element.Hide(id);
			el.style.height = ''
		}
	},
	Width : function(id,speed){
		var el = document.getElementById(id);
		el.style.display = '';
		el.style.overflow='hidden';
		Shrink.shrinkWidth(id,speed,Element.Width(id));
	},	
	shrinkWidth : function(id,speed,count){
		var el = document.getElementById(id);
		if(count > 0){
			el.style.width = count +'px';
			var timer = setTimeout(function(){Shrink.shrinkWidth(id,speed,count)},Shrink.StepSpeed);
			count=count-speed
		}else{
			Element.Hide(id);
			el.style.width = ''
		}
	},
	Both : function(id,speed){
		var el = document.getElementById(id);
		el.style.display = '';
		el.style.overflow='hidden';
		var startHeight = Element.Height(id);
		var startWidth = Element.Width(id);
		if(startHeight > startWidth){
			var modifier = startHeight/startWidth;
			var s = (speed / modifier);
			Shrink.shrinkWidth(id,s,Element.Width(id));
			Shrink.shrinkHeight(id,speed,Element.Height(id));
		}else if(startWidth > startHeight){
			var modifier = startWidth/startHeight;
			var s = (speed / modifier);
			Shrink.shrinkWidth(id,speed,Element.Width(id));
			Shrink.shrinkHeight(id,s,Element.Height(id));
		}else{
			Shrink.shrinkWidth(id,speed,Element.Width(id));
			Shrink.shrinkHeight(id,speed,Element.Height(id));
		}
	}
}
var Toggle = {
	Height : function(id,end,speed){
		var startHeight = Element.Height(id);
		if(startHeight <=0){
			Grow.Height(id,end,speed)
		}else{
			Shrink.Height(id,speed)
		}
	},
	Width : function(id,end,speed){
		var startWidth = Element.Width(id);
		if(startWidth <=0){
			Grow.Width(id,end,speed)
		}else{
			Shrink.Width(id,speed)
		}
	},
	WidthHeight : function(id,endHeight,endWidth,speed,pos){
		var startWidth = Element.Width(id);
		if(startWidth <=0){
			Grow.Both(id,endHeight,endWidth,speed,pos)
		}else{
			Shrink.Both(id,speed)
		}
	},
	Visibility : function(id){
		var el = document.getElementById(id);
		el.style.display = (el.style.display != 'none' ? 'none' : '' );
	},
	Fade : function(id,speed){
		var el = document.getElementById(id);
		if(parseInt(el.style.MozOpacity)!=0){
			Fade.Out(id,speed,100);
		}else{
			Fade.In(id,speed,0);
		}
	}
}

var Fade = {
	In : function(id,speed,opacity){
		var el = document.getElementById(id)
		el.style.position='relative';
		el.style.hasLayout
		if(opacity==null)opacity = 0;
		if(opacity <= 100){
			el.style.MozOpacity=(opacity/100);
			el.style.opacity = (opacity / 100);
			el.style.filter = "alpha(opacity=" + opacity + ")";
			timer = setTimeout(function(){Fade.In(id,speed,opacity),2}); 
			opacity = opacity+speed;
		}
	},
	Out : function(id,speed,opacity){
		var el = document.getElementById(id)
		el.style.position='relative';
		el.style.hasLayout
		if(opacity==null)opacity = 100
		if(opacity >= 0){
			el.style.position='relative';
			el.style.width=Element.Width(id)
			el.style.height=Element.Height(id)
			el.style.MozOpacity=(opacity/100);
			el.style.opacity = (opacity / 100);
			el.style.filter = "alpha(opacity=" + opacity + ")";
			timer = setTimeout(function(){Fade.Out(id,speed,opacity),2}); 
			opacity = opacity-speed
		}
	}
}
var Slide = {
	Right : function(id,end,speed,pos,count){
		if(count==null){
			count=Element.Left(id);
			end = end + count;
		}
		if(pos==null)pos='relative'
		var el = document.getElementById(id);
		el.style.position=pos
		if(count <= end){
			el.style.left = count +'px';
			var timer = setTimeout(function(){Slide.Right(id,end,speed,pos,count)},1);
			count=count+speed;
		}else{
			el.style.left = end+'px';
		}
	},
	Left : function(id,end,speed,pos,count){
		if(count==null){
			count=Element.Left(id);
			end = count - end;
		}
		if(pos==null)pos='relative'
		var el = document.getElementById(id);
		el.style.position=pos
		if(count >= end){
			el.style.left = count +'px';
			var timer = setTimeout(function(){Slide.Left(id,end,speed,pos,count)},1);
			count=count-speed;
		}else{
			el.style.left = end+'px';
		}
		
	},
	Down : function(id,end,speed,pos,count){
		if(count==null){
			count=Element.Top(id);
			end = end + count;
		}
		if(pos==null)pos='relative'
		var el = document.getElementById(id);
		el.style.position=pos
		if(count <= end){
			el.style.top = count +'px';
			var timer = setTimeout(function(){Slide.Down(id,end,speed,pos,count)},1);
			count=count+speed;
		}else{
			el.style.top = end+'px';
		}
	},
	Up : function(id,end,speed,pos,count){
		var el = document.getElementById(id);
		if(count==null){
			count=Element.Top(id);
			end = count - end;
		}
		if(pos==null)pos='relative'
		el.style.position=pos
		if(count >= end){
			el.style.top = count +'px';
			var timer = setTimeout(function(){Slide.Up(id,end,speed,pos,count)},1);
			count=count-speed;
		}else{
			el.style.top = end+'px';
		}
	}
}
function debug(msg){
	if(document.getElementById("debug")==null){
		var frmEle = document.createElement('div');
		frmEle.setAttribute('id',"debug");
		document.body.appendChild(frmEle);
	}
	document.getElementById("debug").innerHTML = msg;
}


function getElementsByClass(searchClass,node,tag) {
	var i;var j;
	var classElements = new Array();
	if ( node == null )node = document;
	if ( tag == null )tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

var googleMap = {
	text : null,
	add : function(container,postcode,lat,lng,zoom){
		if(zoom==null)zoom=12
		if (GBrowserIsCompatible()) {
			var point = new GLatLng(lat, lng);
			var map = new GMap2(document.getElementById(container));
			map.setCenter(point, zoom);
			map.addControl(new GMapTypeControl());
			map.addControl(new GSmallMapControl());
			var marker = new GMarker(point)
			map.addOverlay(marker);
			map.addOverlay(googleMap.createMarker(point,googleMap.text,map));
			googleMap.addMarker(point,googleMap.text,map)
		}
	},
	createMarker : function(point,text,map){
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
		googleMap.addMarker(point,text,map)
	  });
	  return marker;
	},
	addMarker : function(point,text,map){
		var el = document.createElement('div');
		el.innerHTML = text;
		map.openInfoWindow(point,el);
	}
}

 
unload = GUnload