function domIt() {
	if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors .length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
		anchor.target = "_blank";
		anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
		anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
		}
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "popup") {
			anchor.onclick = function() {
				var pictitle = escape(this.title.replace(" (opens in a popup window)",""));
				//url = escape(this.getAttribute("href"));
				url = this.getAttribute("href");
				window.open(url,'popup','width=760,height=480,resizable=yes,scrollbars=yes');
				return false;
			  }
			anchor.title = (anchor.title != "") ? anchor.title+" (opens in a popup window)" : "opens in a popup window";
		} else if ((anchor.getAttribute("href") && anchor.getAttribute("href").indexOf('#') != -1) && ( (anchor.pathname == location.pathname) || ('/'+anchor.pathname == location.pathname) ) && (anchor.search == location.search)) {
			if(!$(anchor).hasClassName('date-picker-control')) {
				anchor.onclick = function() {
					targetId = this.hash.substr(1);
					Effect.ScrollTo(targetId, {duration: 1.0, offset: -10 });
					if(targetId != 'header') {
						new Effect.Highlight(targetId, {delay: 1.0, startcolor: '#ffff99', endcolor: '#ffffff'});
					}
					return false;
				}
			}
		}
	}
	//End anchors
	/*var hr = document.getElementsByTagName("hr");
	for (var i=0; i<hr.length; i++) {
		var newhr = hr[i];
		var wrapdiv = document.createElement('div');
		wrapdiv.className = 'hr';
		newhr.parentNode.replaceChild(wrapdiv, newhr);
		wrapdiv.appendChild(newhr);
	}*/
	TJK_quote();
	
	/*if($('date_of_call')) {
		$('date_of_call').setMinDate('05.02.2009');
		$('date_of_call').setMaxDate('05.03.2009');
	}*/
}
var IE6 = false;
IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
document.observe('dom:loaded', function(){
	if($('skipForm')) {
		multiForm();
		$('date_of_call').onblur = function() {
			setTimeOptions();
		}
	}
	if(!IE6) {
		$$("img.help").each( function(input) {
			new Tooltip(input, {backgroundColor: "#FFDE08", borderColor: "#C96", textColor: "#000"});
		});
	}
});

/*	dynamicCSS.js v1.0 <http://www.bobbyvandersluis.com/articles/dynamicCSS.php>
	Copyright 2005 Bobby van der Sluis
	This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

function createStyleRule(selector, declaration) {
	if (!document.getElementsByTagName || !(document.createElement || document.createElementNS)) return;
	var agt = navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_iewin = (is_ie && (agt.indexOf("win") != -1));
	var is_iemac = (is_ie && (agt.indexOf("mac") != -1));
	if (is_iemac) return; // script doesn't work properly in IE/Mac
	var head = document.getElementsByTagName("head")[0]; 
	var style = (typeof document.createElementNS != "undefined") ?  document.createElementNS("http://www.w3.org/1999/xhtml", "style") : document.createElement("style");
	if (!is_iewin) {
		var styleRule = document.createTextNode(selector + " {" + declaration + "}");
		style.appendChild(styleRule); // bugs in IE/Win
	}
	style.setAttribute("type", "text/css");
	style.setAttribute("media", "screen"); 
	head.appendChild(style);
	if (is_iewin && document.styleSheets && document.styleSheets.length > 0) {
		var lastStyle = document.styleSheets[document.styleSheets.length - 1];
		if (typeof lastStyle.addRule == "object") { // bugs in IE/Mac and Safari
			lastStyle.addRule(selector, declaration);
		}
	}
}

function cnt(w,x,sep){
	var y=w.value;
	var r = 0;
	a=y.replace(/\s/g,' ');
	a=a.split(sep);
	for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;}
	x.value=r;
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}
function setElementStyleByClassName(cl, propertyName, propertyValue) {
	if (!document.getElementsByTagName) return;
	var re = new RegExp("(^| )" + cl + "( |$)");
	var el = document.all ? document.all : document.getElementsByTagName("body")[0].getElementsByTagName("*"); // fix for IE5.x
	for (var i = 0; i < el.length; i++) {
		if (el[i].className && el[i].className.match(re)) {
			el[i].style[propertyName] = propertyValue;
		}
	}
}

function myUnobtrusiveBehavior() {
	setElementStyleByClassName("toggle", "display", "none"); // fallback for IE5/Mac
	setElementStyleByClassName("toggle", "display", "block");
}

function openCentWindow(theURL,scrollb,winWidth,winHeight) { //v2.0
	
	if (winWidth>screen.width){winWidth = screen.width;}
	if (winHeight>screen.height){winHeight = screen.height;}
	if (winWidth <= 0){winWidth = screen.width;}
	if (winHeight <= 0){winHeight = screen.height;}

	leftPos = 0; leftPos = screen.width/2 - winWidth/2; // centres window
	topPos = 0; topPos = screen.height/2 - winHeight/2;  // centres window
	
	modWindow = window.open(theURL,'modWin','toolbar=no,location=no,scrollbars='+scrollb+',resizable=yes,width='+winWidth+',height='+winHeight+',left='+leftPos+',top='+topPos+'');
	modWindow.focus();
}

function TJK_quote(){// v1.1.2 Copyright (c) 2006 TJKDesign - Thierry Koblentz
// use the same paths for: SRC and STYLE (filter) attributes
// set top padding values to match the height of your images
// you may style both images using CSS: blockquote img {...}
// or individually using classes:  .q_O {...} and .q_C {...}
if (!document.getElementsByTagName || !document.createElement) return;
	var z_Q=document.getElementsByTagName("blockquote");
	for (var x=0;x<z_Q.length;x++){
	var q_O = document.createElement('img');
	q_O.alt="";
	q_O.src="/css/images/quote.gif";
	//q_O.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='/img/q_O.png')";
	if (document.all) q_O.style.paddingTop="2px";	
	q_O.style.verticalAlign="text-top";	
	q_O.className="q_O";	
	var q_C = document.createElement('img');
	q_C.alt="";
	q_C.src="/css/images/unquote.gif";	
	//q_C.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',src='/img/q_C.png')";
	if (document.all) q_C.style.paddingTop="2px";	
	q_C.style.verticalAlign="text-bottom";	
	q_C.className="q_C";		
	z_Q[x].getElementsByTagName("p")[0].insertBefore(q_O,z_Q[x].getElementsByTagName("p")[0].firstChild)
	z_Q[x].getElementsByTagName("p")[0].appendChild(q_C);
	var z_URL=z_Q[x].getAttribute("cite");
	if (z_URL){
		var z_DIV = document.createElement('div');
		var z_FROM = document.createTextNode("Quote from: ");
		z_Q[x].appendChild(z_DIV);
		z_DIV.className="q_D";
		var z_A = document.createElement('a');
		var z_DOMAIN = document.createTextNode(z_URL.slice(z_URL.indexOf("//")+2,z_URL.indexOf("/",9)));
		z_A.href=z_URL;
		z_A.appendChild(z_DOMAIN);
		z_DIV.appendChild(z_FROM);
		z_DIV.appendChild(z_A);
		}
	}
}
function confirmSubmit() {
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true ;
else
	return false ;
}

function submitform(theform) {
  if (!document.getElementById) return;
  var myform = document.getElementById(theform);
  myform.submit();
}

function showe(eleId) {
	if (!document.getElementById) return;
		var ele = document.getElementById(eleId);
		if (ele) {
			if (ele.style.display != 'block') {
				ele.style.display = 'block';
			} else {
				ele.style.display = 'none';
			}
		} else {
			return false;
		}
}
/*SKIP ORDER / REQUEST FORM*/
function sfTest1() {
	$('first_name').removeClassName('req');
	$('last_name').removeClassName('req');
	$('email').removeClassName('req');
	$('phone').removeClassName('req');
	$('post_code').removeClassName('req');
	if (valForm('skipForm')) {
		$('nextBtn').remove();
		$('sFmsg').replace('<div id="sFmsg"><p><strong>STEP 2 of 3</strong></p></div>');
		$('sec-a').hide();
		$('sec-b').hide();
		$('sec-g').hide();
		$('sec-f').hide();
		if($('i_want_to_0').checked == true) { //Skip order
			$('sec-c').show();
			$('sec-e').show();
			createNextBtn('sec-e','2');
			$('county').addClassName('req');
			$('skip_size').addClassName('req');
			$('date_of_call').addClassName('req');
			$('time_of_call').addClassName('req');
		} else {
			$('sec-d').show();
			$('sec-g').show();
			createNextBtn('sec-g','2');
		}
		$('submit').hide();
	}
}
function sfTest2() {
	if (valForm('skipForm')) {
		$('nextBtn').remove();
		$('sFmsg').replace('<div id="sFmsg"><p><strong>STEP 3 of 3</strong></p></div>');
		$('sec-c').hide();
		$('sec-d').hide();
		$('sec-e').hide();
		$('sec-f').show();
		$('first_name').addClassName('req');
		$('last_name').addClassName('req');
		$('post_code').addClassName('req');
		if($('order_type_0').checked == true) {
			$('company_input').hide();
		} else {
			$('company_input').show();
		}
		if($('i_want_to_0').checked == true) { //Skip order
			$('eReq').hide();
			$('pReq').show();
			$('phone').addClassName('req');
			$('sec-g').show();
		} else {
			$('pReq').hide();
			$('eReq').show();
			$('email').addClassName('req');
			$('sec-g').hide();
		}
		$('submit').show();
		var element = Builder.node('button',{ id: 'nextBtn', className: 'btn-back', type: 'button', onclick: 'sfTest1()' }, 'Back');
		$('submit').insert({ before: element });
	}
}
function sfBack2() {
	$('nextBtn').remove();
	$('sFmsg').replace('<div id="sFmsg"><p><strong>STEP 1 of 3</strong><br />If you would like to order a skip, or you\'d simply like more information on our services, please complete the details below.</p></div>');
	$('sec-a').show();
	$('sec-b').show();
	createNextBtn('sec-b','1');
	$('sec-c').hide();
	$('sec-d').hide();
	$('sec-e').hide();
	$('sec-f').hide();
	$('sec-g').hide();
	$('county').removeClassName('req');
	$('skip_size').removeClassName('req');
	$('date_of_call').removeClassName('req');
	$('time_of_call').removeClassName('req');
}
function createNextBtn(posIt,tNum) {
	if(tNum == '1') {
		var element = Builder.node('p', { id: 'nextBtn' }, [
		Builder.node('button',{ className: 'btn-continue', type: 'button', onclick: 'sfTest'+tNum+'()' }, 'Continue')
	]);
	} else {
		var element = Builder.node('p', { id: 'nextBtn' }, [
		Builder.node('button',{ className: 'btn-back', type: 'button', onclick: 'sfBack'+tNum+'()' }, 'Back'),
		Builder.node('button',{ className: 'btn-continue', type: 'button', onclick: 'sfTest'+tNum+'()' }, 'Continue')
	]);
	}
	$(posIt).insert({ after: element });
}

function multiForm() {
	//validTimes global declared in jcalls
	validTimes[0] = [24,24];
	validTimes[1] = [7,17];
	validTimes[2] = [7,17];
	validTimes[3] = [7,17];
	validTimes[4] = [7,17];
	validTimes[5] = [7,17];
	validTimes[6] = [8,11];
	$('first_name').removeClassName('req');
	$('last_name').removeClassName('req');
	$('email').removeClassName('req');
	$('phone').removeClassName('req');
	$('post_code').removeClassName('req');
	$('reqVals').value = 'first_name,last_name,post_code';
	if($('i_want_to_0').checked == true && ($('order_type_0').checked == true || $('order_type_1').checked == true)) {
		var oType = $$('input:checked[type="radio"][name="order_type"]').pluck('value') + "";
		$('sFmsg').replace('<div id="sFmsg"><p><strong>STEP 2 of 3</strong></p></div>');
		$('sec-a').hide();
		$('sec-b').hide();
		$('county').addClassName('req');
		$('skip_size').addClassName('req');
		$('date_of_call').addClassName('req');
		$('time_of_call').addClassName('req');
		createNextBtn('sec-e','2');
	} else {
		$('sFmsg').replace('<div id="sFmsg"><p><strong>STEP 1 of 3</strong><br />If you would like to order a skip, or you\'d simply like more information on our services, please complete the details below.</p></div>');
		createNextBtn('sec-b','1');
		$('sec-c').hide();
		$('sec-e').hide();
	}
	$('sec-d').hide();
	$('sec-f').hide();
	$('sec-g').hide();
	$('submit').hide();
	setTimeOptions();
}
function setTimeOptions() {
	var theDate = new Date(check_date('date_of_call'));
	var dayofweek = theDate.getDay();
	var dis = new Array();
	dis[0] = [0,1,2,3,4,5,6,7,8,9,10,11,12,13];
	dis[1] = [];
	dis[2] = [];
	dis[3] = [];
	dis[4] = [];
	dis[5] = [];
	dis[6] = [3,8,9,10,11,12,13];
	
	for (var i=0; i<$('time_of_call').options.length; i++) {
		var found = false;
		for(key in dis[dayofweek]) {
			if(dis[dayofweek][key] == i) {
				$('time_of_call').options[i].disabled = true;
				if ($('time_of_call').selectedIndex == i) {
					$('time_of_call').selectedIndex = -1;
				}
				found = true;
				break;
			}
		}
		if (!found) {
			$('time_of_call').options[i].disabled = false;	
		}
	}
}
/*SKIP ORDER / REQUEST FORM END*/

function valForm(formId) {
	var form = $(formId);
	var errStr = new String();
	var errNum = 0;
	var theDate = new String();
	var theDay = new String();
	var ttd = false; // today's the day
	//var required = 	$$("#"+formId+" .req");
	/*$$(".req").each( function(req) {
			errNum++							  
	});*/
	$(formId).select(".req").each( function(req) {
		var iType = req.type.toLowerCase();
		var iName = req.name.replace(/_/g, " ").toUpperCase();
		var iName = iName.replace(/-/g, "'");
		var iName = iName.replace("[]", ""); 
		var iVal = new String();
		var errMsg = new String();
		var chkType = 'string';
		switch(iType)
		{
		case "text":
			iVal = $F(req.name).replace(/^\s+|\s+$/g,"") + ""; // strip leading and trailing spaces
			iVal = iVal.replace(/\s+/g," "); // replace multiple spaces with a single space
			if (req.hasClassName('email')) {
				errMsg = " - enter a valid email address.\n";
				chkType = 'email';
			} else if (req.hasClassName('phone')) {
				errMsg = " - enter a valid phone number with area code.\n";
				chkType = 'phone';
			} else if (req.hasClassName('format-d-m-y')) {
				errMsg = " - enter a valid date.\n";
				chkType = 'date';
			} else {
				errMsg = " - type something in the text field.\n";
			}
			break;    
		case "textarea":
			iVal = $F(req.name).replace(/^\s+|\s+$/g,"") + ""; // strip leading and trailing spaces
			iVal = iVal.replace(/\s+/g," "); // replace multiple spaces with a single space
			errMsg = " - type something in the text area.\n";
			break;
		case "select-one":
			if (req.hasClassName('time')) {
				iVal = $F(req.name);
				errMsg = " - select a time in the future.\n";
				chkType = 'time';
			} else {
				iVal = $F(req.name) + "";
				errMsg = " - select an option from the drop-down list.\n";
			}
			break;
		case "select-multiple":
			iVal = $F(req.name) + "";
			errMsg = " - select one or more options from the drop-down list.\n";
			break;
		case "file":
			iVal = $F(req.name).replace(/^\s+|\s+$/g,"") + ""; // strip leading and trailing spaces
			iVal = iVal.replace(/\s+/g," "); // replace multiple spaces with a single space
			errMsg = " - choose a file on your PC to upload.\n";
			break;
		case "checkbox":
			iVal = "";
			var boxes = form.getInputs('checkbox', req.name);
			if (boxes.length > 1) {
				for(b=0;b<boxes.length;b++){
					if(boxes[b].checked){iVal = "1"}
				}
			} else {
				iVal = $F(req.name) + "";
			}
			//iVal = $$('input:checked[type="checkbox"][name='+req.name+']').pluck('value') + "";
			errMsg = " - tick one or more of the boxes.\n";
			break;
		case "radio":
			iVal = $$('input:checked[type="radio"][name='+req.name+']').pluck('value') + "";
			errMsg = " - click a radio button.\n";
			break;
		default:
			iVal = "Not a form element"; //ignore
		}
		switch(chkType)
		{
		case "email":
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(iVal)) {
				errStr+= iName + errMsg;
				errNum++ ;
			}
			break;
		case "phone":
			var filter = /(^[0-9()\s\-\+]{10,})$/gi; //only digits, space, brackets, hyphen and plus sign allowed
			if (!filter.test(iVal)) {
				errStr+= iName + errMsg;
				errNum++ ;
			}
			break;
		case "date":
			theDate = check_date(iVal);
			if (iVal.blank() || !theDate) {
				errStr+= iName + errMsg;
				errNum++ ;
			} else {
				theDate= new Date(theDate);
				var today=new Date();
				var diff=today-theDate;
				diff=Math.floor(diff/1000/60/60/24);
				if (diff > 0) { // in the past
					errStr+= iName + " - select a date in the future.\n";
					errNum++ ;
				} else if (diff < -31) { // too far in the future
					errStr+= iName + " - select a date within one month's time.\n";
					errNum++ ;
				} else if (diff == 0) { //today's date
					ttd = true;
				}
			}
			break;
		case "time":
			if(theDate) { // date is valid
				var now = parseFloat(timeNum());
				var tm = parseFloat(iVal);
				if (iVal.blank() || (ttd && now >= tm)) {
					errStr+= iName + errMsg;
					errNum++ ;
				} else {
					theDay = check_time(theDate,tm);
					if (theDay) {
						errStr+= iName + " - chosen time unavailable on a "+ theDay +".\n";
						errNum++ ;
					}
				}
			}
			break;
		default:
			if (iVal.blank()) {
				errStr+= iName + errMsg;
				errNum++ ;
			}
		}
		
	});
	if(errNum > 0) {
		alert("Sorry, you have missed some information we need.\nPlease check the following items and try again:\n\n" + errStr);
		return false;
	} else {
		return true;
	}
}

function timeNum() {
	var now=new Date();
	return now.getHours()+'.'+now.getMinutes();
}

function check_time(theDate,time) {
	var dayofweek = theDate.getDay();
	if(isNaN(time) && validTimes[dayofweek][0] != 24) {
		return false;
	} else if(time >= validTimes[dayofweek][0] && time <= validTimes[dayofweek][1] && validTimes[dayofweek][0] != 24) {
		return false;
	} else {
		dow=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
		return(dow[dayofweek]);
	}
}

// Validate Date
function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   if($(DateField)) {
   	   DateValue = $(DateField).value;
   } else {
	   DateValue = DateField;
   }
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; //day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
	  var fullmonths = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
	  return fullmonths[month - 1] + day + ',' + year;
	  //return year + ',' + month + ',' + day;
	  //DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
	  return false;
      //alert("Date is incorrect!");
      //DateField.select();
	  //DateField.focus();
   }
}
//  Validate Date End

function timeSelect() {
}

// Tooltip Object
var Tooltip = Class.create();
Tooltip.prototype = {
	initialize: function(el, options) {
		this.el = $(el);
		this.initialized = false;
		this.setOptions(options);
		
		// Event handlers
		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.updateEvent = this.update.bindAsEventListener(this);
		Event.observe(this.el, "mouseover", this.showEvent );
		Event.observe(this.el, "mouseout", this.hideEvent );
		
		// Removing title from DOM element to avoid showing it
		this.content = this.el.title;
		this.el.title = "";

		// If descendant elements has 'alt' attribute defined, clear it
		this.el.descendants().each(function(el){
			if(Element.readAttribute(el, 'alt'))
				el.alt = "";
		});
	},
	setOptions: function(options) {
		this.options = {
			backgroundColor: '#999', // Default background color
			borderColor: '#666', // Default border color
			textColor: '', // Default text color (use CSS value)
			textShadowColor: '', // Default text shadow color (use CSS value)
			maxWidth: 250,	// Default tooltip width
			align: "left", // Default align
			delay: 250, // Default delay before tooltip appears in ms
			mouseFollow: true, // Tooltips follows the mouse moving
			opacity: .85, // Default tooltips opacity
			appearDuration: .25, // Default appear duration in sec
			hideDuration: .25 // Default disappear duration in sec
		};
		Object.extend(this.options, options || {});
	},
	show: function(e) {
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		if(!this.initialized)
			this.timeout = window.setTimeout(this.appear.bind(this), this.options.delay);
	},
	hide: function(e) {
		if(this.initialized) {
			this.appearingFX.cancel();
			if(this.options.mouseFollow)
				Event.stopObserving(this.el, "mousemove", this.updateEvent);
			new Effect.Fade(this.tooltip, {duration: this.options.hideDuration, afterFinish: function() { Element.remove(this.tooltip) }.bind(this) });
		}
		this._clearTimeout(this.timeout);
		
		this.initialized = false;
	},
	update: function(e){
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		this.setup();
	},
	appear: function() {
		// Building tooltip container
		this.tooltip = Builder.node("div", {className: "tooltip", style: "display: none;" }, [
			Builder.node("div", {className:"xtop"}, [
				Builder.node("div", {className:"xb1", style:"background-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"})
			]),
			Builder.node("div", {className: "xboxcontent", style: "background-color:" + this.options.backgroundColor + 
				"; border-color:" + this.options.borderColor + 
				((this.options.textColor != '') ? "; color:" + this.options.textColor : "") + 
				((this.options.textShadowColor != '') ? "; text-shadow:2px 2px 0" + this.options.textShadowColor + ";" : "")}, this.content), 
			Builder.node("div", {className:"xbottom"}, [
				Builder.node("div", {className:"xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb1", style:"background-color:" + this.options.borderColor + ";"})
			]),
		]);
		document.body.insertBefore(this.tooltip, document.body.childNodes[0]);
		
		Element.extend(this.tooltip); // IE needs element to be manually extended
		this.options.width = this.tooltip.getWidth();
		this.tooltip.style.width = this.options.width + 'px'; // IE7 needs width to be defined
		
		this.setup();
		
		if(this.options.mouseFollow)
			Event.observe(this.el, "mousemove", this.updateEvent);
			
		this.initialized = true;
		this.appearingFX = new Effect.Appear(this.tooltip, {duration: this.options.appearDuration, to: this.options.opacity });
	},
	setup: function(){
		// If content width is more then allowed max width, set width to max
		if(this.options.width > this.options.maxWidth) {
			this.options.width = this.options.maxWidth;
			this.tooltip.style.width = this.options.width + 'px';
		}
			
		// Tooltip doesn't fit the current document dimensions
		if(this.xCord + this.options.width >= Element.getWidth(document.body)) {
			this.options.align = "right";
			this.xCord = this.xCord - this.options.width + 20;
		}
		
		this.tooltip.style.left = this.xCord - 7 + "px";
		this.tooltip.style.top = this.yCord + 18 + "px";
	},
	_clearTimeout: function(timer) {
		clearTimeout(timer);
		clearInterval(timer);
		return null;
	}
};