/*	

	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;
}


jHover = function() {
	 if (browser != "Internet Explorer" || OS !="Mac" && OS !="an unknown operating system") {
		if (document.getElementById("categories")) {
			var sfEls = ["cat-1","cat-2","cat-4","cat-5","cat-6","cat-7","cat-8","cat-9","cat-10"];
			for (var i=0; i<sfEls.length; i++) {
				document.getElementById(sfEls[i]).onmouseover=function() {
					var dest = this.getAttribute('id');
					if (browser == "Internet Explorer" && OS =="Windows") {
						this.className+=" jhover";
					}
				}
				document.getElementById(sfEls[i]).onmouseout=function() {
					if (browser == "Internet Explorer" && OS =="Windows") {
						this.className=this.className.replace(new RegExp(" jhover\\b"), "");
					}
				}
				document.getElementById(sfEls[i]).onclick=function() {
					var dest = this.getAttribute('class');
					refOffset = dest.indexOf('-')+1;
	  				refEnd = dest.length;
	  				newDest = dest.substring(refOffset, refEnd);
					document.location="products/"+newDest+"/";
				}
			}
		}
	 }
}

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;
		}
	}
}

mooFx = function(){
	if (document.getElementById("question-list")) {
		var answerArray = document.getElementById("question-list").getElementsByTagName("dd");
		var questionArray = document.getElementById("question-list").getElementsByTagName("a");
		var expandAll = document.getElementById("expand-all");
		for (var i=0; i<answerArray.length; i++) {
			myHeight = new fx.Height(answerArray[i], {duration: 400});
			myHeight.hide();
		}
		for (var i=0; i<questionArray.length; i++) {
			questionArray[i].onclick=function() {
				var whatAnswer = this.getAttribute('href');
				refOffset = whatAnswer.indexOf('#')+1;
  				refEnd = whatAnswer.length;
  				newDest = whatAnswer.substring(refOffset, refEnd);
				myHeight = new fx.Height(newDest, {duration: 400});
				myHeight.toggle();
				if (this.expanded) {
  					this.className=this.className.replace(new RegExp("expanded\\b"), "closed");
  					this.expanded = false;
				} else {
  					this.className=this.className.replace(new RegExp("closed\\b"), "expanded");
  					this.expanded = true;
				}
				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 stripe(id) {
	var even = false;
	var evenColor = arguments[1] ? arguments[1] : "#eee";
	var oddColor = arguments[2] ? arguments[2] : "#ddd";
	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 showFields(whichLayer) {
	if (document.getElementById)
	{
	// this is the way the standards work
		document.getElementById(whichLayer).className = "";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
		document.all[whichLayer].className = "";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
		document.layers[whichLayer].className = "";
	}
}
function hideFields(whichLayer) {
	if (document.getElementById)
	{
	// this is the way the standards work
		document.getElementById(whichLayer).className = "remove";
	}
	else if (document.all)
	{
	// this is the way old msie versions work
		document.all[whichLayer].className = "remove";
	}
	else if (document.layers)
	{
	// this is the way nn4 works
		document.layers[whichLayer].className = "remove";
	}
}
toggleField = function() {
	if (document.getElementById("business")) {
		hideFields("business-options");

		var natureSel = document.getElementById("business");
		natureSel.onchange=function() {
			if (this.value == "yes") {
				showFields("business-options");
			} else {
				hideFields("business-options");
			}
		}
	}
}

popup = function() {
    var tabEls = document.getElementsByTagName("a");
    for (var i=0; i<tabEls.length; i++) {
        if (tabEls[i].getAttribute("rel")) {
            var relIndex = tabEls[i].getAttribute("rel");
            var relSplit = relIndex.split("|");
            if (relSplit[0] == "popup") {
    
                tabEls[i].onclick=function() {
                    var relIndex = this.getAttribute("rel");
                    var relSplit = relIndex.split("|");
                    var windowName = relSplit[1];
                    windowAttrib = "width=" + relSplit[2] + ",height=" + relSplit[3];
                    window.open(this.href,windowName,windowAttrib);
                    return false;
                }
            }
        }
    }
} 

window.onload = function() {
	printLink();jHover();mooFx();toggleField();popup();stripe("event-list");
}