/*	

	Dusted Design Partners Limited

*/

/* BROWSER SNIFFER */
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
        browser = "Konqueror";
        OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
        browser = "Mozilla"
        version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac"
        else if (checkIt('win')) OS = "Windows"
        else OS = "an unknown operating system";
}

function checkIt(string)
{
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
}


printLink = function() {
	if (document.getElementById("footer-print")) {
		var printBut = document.getElementById("footer-print");
		printBut.onclick=function() {
			if (window.print) {
				window.print();
			} else {
				alert("Unfortunately your browser doesn't support printing via Javascript.\nTo print this page please select \"File > Print...\" in your browser's menu.");
			}
			return false;
		}
	}
}

  // this function is needed to work around 
  // a bug in IE related to element attributes
function hasClass(obj) {
	var result = false;
	if (obj.getAttributeNode("class") != null) {
		result = obj.getAttributeNode("class").value;
	}
	return result;
}   

function stripeWant(id) {
	var even = false;
	var evenColor = arguments[1] ? arguments[1] : "#333";
	var oddColor = arguments[2] ? arguments[2] : "#222";
	var statList = document.getElementById(id);
	
	if (! statList) { return; }
	
	var lis = statList.getElementsByTagName("li");
	
	for (var h = 0; h < lis.length; h++) {
		var myli = lis[h]
		if (! hasClass(myli) && ! myli.style.backgroundColor) {
			myli.style.backgroundColor = even ? evenColor : oddColor;
		}
		even =  ! even;
	}
}

function stripeSpecialities(id) {
	var even = false;
	var evenColor = arguments[1] ? arguments[1] : "#ccc";
	var oddColor = arguments[2] ? arguments[2] : "#e5e5e5";
	var statList = document.getElementById(id);
	
	if (! statList) { return; }
	
	var lis = statList.getElementsByTagName("li");
	
	for (var h = 0; h < lis.length; h++) {
		var myli = lis[h]
		if (! hasClass(myli) && ! myli.style.backgroundColor) {
			myli.style.backgroundColor = even ? evenColor : oddColor;
		}
		even =  ! even;
	}
}

mooFxWant = function(){
	if (document.getElementById("want-list")) {
		wantHeight = new fx.Height('want-list', {duration: 400});
		wantHeight.hide();
		if (document.getElementById("want-toggle")) {
			var toggleBut = document.getElementById("want-toggle").getElementsByTagName("a");
			for (var i=0; i<toggleBut.length; i++) {
				toggleBut[i].onclick=function() {
					wantHeight.toggle();
					return false;
				}
			}
		}
		document.getElementById("want-list").style.visibility = "visible";
	}
}

mooFxBookTable = function(){
	if (browser == "Internet Explorer" && version == "5") {
			return false;
	} else {
		if (document.getElementById("gallery-container")) {
			document.getElementById("gallery-container").style.visibility = "visible";
		}
		if (document.getElementById("book-table")) {
			document.getElementById("book-table").style.display = "block";
			bookHeight = new fx.Height('book-table', {duration: 400});
			bookHeight.hide();
			if (document.getElementById("book-toggle")) {
				document.getElementById("book-toggle").style.display = "block";
				var toggleBut = document.getElementById("book-toggle").getElementsByTagName("a");
				for (var i=0; i<toggleBut.length; i++) {
					toggleBut[i].onclick=function() {
						bookHeight.toggle();
						if (document.getElementById("gallery-container")) {
							if (document.getElementById("gallery-container").style.visibility == "visible") {
								document.getElementById("gallery-container").style.visibility = "hidden";
							} else {
								document.getElementById("gallery-container").style.visibility = "visible";
							}
						}
						if (this.className != "selected") {
							this.className = "selected";
						} else {
							this.className = "";
						}
						return false;
					}
				}
			}
			if (document.getElementById("remote-book")) {
				var remoteBut = document.getElementById("remote-book");
				remoteBut.onclick=function() {
					bookHeight.toggle();
					if (document.getElementById("gallery-container")) {
						if (document.getElementById("gallery-container").style.visibility == "visible") {
							document.getElementById("gallery-container").style.visibility = "hidden";
						} else {
							document.getElementById("gallery-container").style.visibility = "visible";
						}
					}
					var toggleBut = document.getElementById("book-toggle").getElementsByTagName("a");
					if (toggleBut[0].className != "selected") {
						toggleBut[0].className = "selected";
					} else {
						toggleBut[0].className = "";
					}
				}
			}
			document.getElementById("book-table").style.visibility = "visible";
			document.getElementById("book-toggle").style.visibility = "visible";
		}
	}
}

removeSpaces = function() {
	if (document.getElementById("telephone")) {
		telField = document.getElementById("telephone");
		telField.onblur = function() {
			var tstring = "";
			string = telField.value;
			splitstring = string.split(" ");
			for(i = 0; i < splitstring.length; i++) {
				tstring += splitstring[i];
			}
			telField.value = tstring;
		}
	}
}

displayTel = function() {
	
	if (document.getElementById("rest-number")) {
	
		para = document.getElementById("rest-number");
		dropDown = document.getElementById("which_restaurant");
		actionO = 'http://www.opentable.com/interim.asp?ref=639'
		actionG = 'index.php';
		dropDown.onchange = function() {
			if (dropDown.value == "1") {
				para.innerHTML = "Tel: 020 7256 6877";
				document.r.action = actionG;
			} else if (dropDown.value == "2") {
				para.innerHTML = "Tel: 020 7987 9494";
				document.r.action = actionG;
			} else if (dropDown.value == "3") {
				para.innerHTML = "Tel: 020 7242 7727";
				document.r.action = actionG;
			} else if (dropDown.value == "4") {
				para.innerHTML = "Tel: 020 7626 5180";
				document.r.action = actionG;
			} else if (dropDown.value == "5") {
				para.innerHTML = "Tel: 020 7431 8222";
				document.r.action = actionG;
			} else if (dropDown.value == "6") {
				para.innerHTML = "Tel: 0161 833 4333";
				document.r.action = actionG;
			} else if (dropDown.value == "7") {
				para.innerHTML = "Tel: 020 8858 7711";
				document.r.action = actionO;
			} else if (dropDown.value == "8") {
				para.innerHTML = "Tel: 020 7734 4040";
				document.r.action = actionG;
			} else if (dropDown.value == "9") {
				para.innerHTML = "Tel: 020 8948 4030";
				document.r.action = actionG;
			} else if (dropDown.value == "10") {
				para.innerHTML = "Tel: 020 7584 9901";
				document.r.action = actionG;
			} else if (dropDown.value == "11") {
				para.innerHTML = "Tel: 020 7490 1676";
				document.r.action = actionG;
			} else if (dropDown.value == "12") {
				para.innerHTML = "Tel: 020 7407 5222";
				document.r.action = actionG;
			} else if (dropDown.value == "13") {
				para.innerHTML = "Tel: 020 7734 4040";
				document.r.action = actionG;
			} else {
				para.innerHTML = "&nbsp;";
			}
		}
	}
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
if (window.attachEvent) window.attachEvent("onload", correctPNG);


window.onload = function() {
	mooFxBookTable();mooFxWant();printLink();stripeWant('want-list');stripeSpecialities("specialities-list");stripeSpecialities("specialities-list-2");stripeSpecialities("tasting-list");removeSpaces();displayTel();
}
