var IE4 = document.all;
var IE5 = (IE4 && navigator.appVersion.indexOf("MSIE 5.0") != -1);
var NN7 = (!IE4 && document.getElementById);
var NN4 = document.layers;
if (!(NN7 || IE4) && location.href.indexOf("nonstandard.htm") == -1) location.replace("nonstandard.htm");
if (IE4 && navigator.userAgent.indexOf("Opera") != -1) {
	NN7 = true;
	IE4 = false;
}
var mac = (IE4 && navigator.appVersion.indexOf("Mac") != -1);

function getStyleObject(obj) {
	var theObj = (IE4?document.all[obj]:document.getElementById(obj));
	return (theObj?theObj.style:null);
}

function getObject(obj) {
	return (IE4?document.all[obj]:document.getElementById(obj));
}

var copyright = "2004";

var tabsearch = {};
function makeSearchObject() {
	if (location.search) {
		var tmp = location.search.substring(1);
		tmp = tmp.split("&");
		for (var i = 0; i < tmp.length; i++ ) {
			tabsearch[tmp[i].substring(0,tmp[i].indexOf("="))] = unescape(tmp[i].substring(tmp[i].indexOf("=") + 1));
		}
	}
}
makeSearchObject();

/* COOKIE FUNCTIONS */

function SetCookie(name,value) {
	var argv = SetCookie.arguments
	var argc = SetCookie.arguments.length
	var expires = (argc > 2) ? argv[2] : null
	var path = (argc > 3) ? argv[3] : null
	var domain = (argc > 4) ? argv[4] : null
	var secure = (argc > 5) ? argv[5] : false
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "")
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset)
	if (endstr == -1)
	endstr = document.cookie.length
	return unescape(document.cookie.substring(offset, endstr))
}

function GetCookie(name) {
	var arg = name + "="
	var alen = arg.length
	var clen = document.cookie.length
	var i = 0
	while (i < clen) {
		var j = i + alen
		if (document.cookie.substring(i,j) == arg)
		return getCookieVal (j)
	i = document.cookie.indexOf(" ",i) + 1
	if (i == 0) break
	}
	return null
}

/* END COOKIE FUNCTIONS */


function nextPart(obj1,obj2) {
	getStyleObject(obj1).visibility = "hidden";
	getStyleObject(obj2).visibility = "visible";
}

function homeHighlight(obj,b) {
	if (b) {
		obj.style.padding = "0px";
		obj.style.borderTop = "1px solid #E26698";
		obj.style.borderBottom = "1px solid #550022";
	} else {
		obj.style.padding = "1px 0px";
		obj.style.border = "none";
	}
}

function buttonOver(obj,n) {
	obj.src = obj.src.substring(0,obj.src.length-5) + n + ".gif";
}

function imageOver(obj,x) {
	obj.style.border = (x?"1px solid #669999":"none");
	obj.style.padding = (x?"1px 0px 5px 0px":"2px 1px 6px 1px");
}

function imageOver2(obj,x) {
	obj.style.borderColor = (x?"#669999":"#334444");
}

function revealObj(obj) {
	getStyleObject(obj).display = (getStyleObject(obj).display == "block"?"none":"block");
}

/* NAVIGATION AND MENU CODE */

function getPath() {
	var tree = location.pathname.split("/");
	var start = (location.pathname.indexOf("/site/") != -1?"site":(location.pathname.indexOf("/tab/") != -1?"tab":(location.pathname.indexOf("/staging/") != -1?"staging":null)));
	if (start) {
		for (var i = 0; i < tree.length; i++) {
			if (tree[i] == start) {
				tree = tree.slice(i+1);
				break;
			}
		}
	}
	var locator = "";
	for (var i = 0; i < tree.length-1; i++) {
		locator += "../";
	}
	return locator;
}

var menu = {
	opened:null,
	overmenu:null,
	items: {
		home:"home.htm",
		shopping:{
			submenu:[
				{
					text:"home page",
					url:"index.htm"
				},
				{
					text:"fine art",
					url:"art/"
				},
				{
					text:"apparel",
					url:"apparel/"
				},
				{
					text:"for the home",
					url:"for-the-home/"
				},
				{
					text:"jewellery",
					url:"jewellery/"
				},
				{
					text:"miscellaneous",
					url:"miscellaneous/"
				},
				{
					text:"shop by supplier",
					url:"artists/"
				},
				{
					text:"shop by collection",
					url:"collections/"
				}
			]
		},
		about:{
			submenu:[
				{
					text:"welcome",
					url:"welcome.htm"
				},
				{
					text:"why scotland",
					url:"why-scotland.htm"
				},
				{
					text:"what people say",
					url:"what-people-say.htm"
				},
				{
					text:"contact us",
					url:"contact-us.htm"
				},
				{
					text:"Enquiries form",
					url:"enquiries.htm"
				},
				{
					text:"Sign up for Newsletters",
					url:"opt-in.htm"
				},
				{
					text:"Thistle & Broom video",
					url:"video.htm"
				},
				{
					text:"press information",
					url:"press/index.htm"
				},
				{
					text:"returns &amp; refunds",
					url:"refunds.htm"
				},
				{
					text:"privacy policy",
					url:"privacy.htm"
				}
			]
		},
		friends:"index.htm",
		scotland:"index.htm"
	}
};
//<img id=\"" + prop + "_main2\" class=\"navimage2\" src=\"" + getPath() + "images/bb_tab_navbar_" + prop + "0.gif\" alt=\"\" border=\"0\">\n
//		txt += "<div class=\"navitem\" id=\"" + prop + "\" style=\"background-image:url(" + getPath() + "images/bb_tab_navbar_" + prop + ".gif)\">\n<img class=\"navimage1\" src=\"" + getPath() + "images/bb_tab_navbar_" + prop + ".gif\" alt=\"\" border=\"0\">\n";

function renderNavigation() {
	var txt = "";//"<div style=\"position:relative; top:0px; left:20px\">\n";
	for (var prop in menu.items) {
		txt += "<div class=\"navitem\" id=\"" + prop + "\" style=\"background-image:url(" + getPath() + "images/bb_tab_navbar_" + prop + ".gif)\">\n<img class=\"navimage1\" src=\"" + getPath() + "images/bb_tab_navbar_" + prop + ".gif\" alt=\"\" border=\"0\">\n";
		if (typeof menu.items[prop].submenu != "undefined") {
			var sm = menu.items[prop].submenu;
			txt += "<div class=\"submenuholder\" id=\"subnav" + prop + "\">";
			for (var i = 0; i < sm.length; i++) {
				txt += "<div class=\"submenuitem\" id=\"subnav" + prop + i + "\">" + sm[i].text + "</div>\n";
			}
			txt += "</div>\n";
		}
		txt += "</div>\n";
	}
	txt += "<div class=\"searchform\"><form action=\"http://www.thistleandbroom.com/cgi-bin/user/ben/search/search.pl?\" method=\"get\"><img style=\"position:relative; top:1px\" src=\"" + (location.href.indexOf("cgi-bin") != -1?"http://www.thistleandbroom.com/":getPath()) + "images/bb_tab_search_typek.gif\" alt=\"Search\" width=\"48\" height=\"8\" border=\"0\">&nbsp;&nbsp;<input style=\"background-color:#FEFFED; color:#000000; border-color:#888888; height:16px; width:120px; font-size:xx-small\" type=\"text\" name=\"Terms\"><input type=\"hidden\" name=\"Realm\" value=\"Thistle and Broom\">&nbsp;&nbsp;<input style=\"position:relative; top:1px; border:none\" type=\"image\" src=\"" + (location.href.indexOf("cgi-bin") != -1?"http://www.thistleandbroom.com/":getPath()) + "images/bb_tab_search_gok.gif\" border=\"0\"></form></div>";
//	alert(txt);
	document.write(txt);
}

function renderBreadcrumbs() {
	var tree = location.pathname.split("/");
	if (location.pathname.indexOf("/site/") != -1) {
		for (var i = 0; i < tree.length; i++) {
			if (tree[i] == "site") {
				tree = tree.slice(i+1);
				break;
			}
		}
	}
	if (tree[tree.length-1] == "" || tree[tree.length-1].indexOf("index.htm") != -1)
		tree.length = tree.length-1;
	var txt = "";
	var pathto = ""
	for (var i = 0; i < tree.length; i++) {
		if (tree[i])
			pathto += tree[i] + "/";
		tree[i] = tree[i].replace(/.htm/g,"");
		tree[i] = tree[i].replace(/-moreinfo/g,"");
		tree[i] = tree[i].replace(/_moreinfo/g,"");
		tree[i] = tree[i].replace(/_purchase/g,"");
		tree[i] = tree[i].replace(/-/g," ");
		txt += (i < tree.length-1?"<a href=\"" + getPath() + pathto + "\">":"") + tree[i] + (i < tree.length-1?"</a>":"") + (tree[i] && i < tree.length-1?" <span class=\"breadcrumbsdash\">-</span> ":"");
	}
	if (location.search.indexOf("bbtest") != -1)
		alert(txt);
	document.write(txt);
}

function getLink(elementID) {
	if (elementID == "home") return menu.items[elementID];
	for (var prop in menu.items) {
		if (elementID == prop && menu.items[elementID] && !menu.items[elementID].submenu)
			return prop + "/" + menu.items[elementID];
		if (menu.items[prop].submenu) {
			for (var i = 0; i < menu.items[prop].submenu.length; i++) {
				if (elementID == "subnav" + prop + i && menu.items[prop].submenu[i].url)
					return prop + "/" + menu.items[prop].submenu[i].url;
			}
		}
	}
	return false;
}

function getHighlight(elementID) {
	var obj = getStyleObject(elementID);
	obj.backgroundImage = "url(" + getPath() + "images/bb_tab_navbar_" + elementID + "0.gif)";
}

function loseHighlight(e) {
	e = (e?e:window.event);
	var elementID = (IE4?e.srcElement:e.currentTarget).id;
	if (!menu.opened || menu.opened != menu.overmenu || !(menu.items[elementID] && menu.items[elementID].submenu)) {
		var obj = getStyleObject(elementID);
			obj.backgroundImage = "url(" + getPath() + "images/bb_tab_navbar_" + elementID + ".gif)";

	}
}

function loseAllHighlights(elementID) {
	var obj;
	for (var prop in menu.items) {
		if (elementID == prop) continue;
		obj = getStyleObject(prop);
		obj.backgroundImage = "url(" + getPath() + "images/bb_tab_navbar_" + prop + ".gif)";
	}
}

function getSubHighlight(e) {
	e = (e?e:window.event);
	var obj = (IE4?e.srcElement:e.currentTarget).style;
	obj.color = "#DD77AA";
	obj.cursor = (IE5?"hand":"pointer");
	if (IE4) e.cancelBubble = true;
}

function loseSubHighlight(e) {
	e = (e?e:window.event);
	var obj = (IE4?e.srcElement:e.currentTarget);
	obj.style.color = "#FFFFFF";
	if (IE4) e.cancelBubble = true;
}

function checkMenuStatus(e) {
	e = (e?e:window.event);
	var elementID = (IE4?e.srcElement:e.currentTarget).id;
//	loseAllHighlights(elementID);
	menu.overmenu = (elementID?elementID:null);
	if (elementID) {
		getHighlight(elementID);
	}
	if (menu.opened)
		checkSubMenuStatus(e);
}

function checkSubMenuStatus(e) {
	e = (e?e:window.event);
	var elementID = (IE4?e.srcElement:e.currentTarget).id;
	if (NN7) e.stopPropagation();
	else if (IE4) e.cancelBubble = true;
	if (e.type == "click") {
		if (getLink(elementID)) {
			location = getPath() + getLink(elementID);
		} else if (!menu.opened && menu.overmenu && menu.overmenu == elementID) {
			menu.opened = elementID;
			if (getObject("subnav" + elementID)) {
				getObject("subnav" + elementID).style.visibility = "visible";
			}
		} else if (menu.opened) {
			if (getObject("subnav" + menu.opened)) {
				getObject("subnav" + menu.opened).style.visibility = "hidden";
			}
//			if (menu.opened != elementID)
//				loseAllHighlights();
			menu.opened = null;
		}
	} else if (e.type == "mouseover") {
		if (menu.opened && menu.opened != elementID && elementID && elementID != "subnav" + menu.opened) { // elementID test is to prevent this routine from running when mouseover the image inside the div gives an extra event
//			next line hides the old submenu
			if (getObject("subnav" + menu.opened)) {
				status = "close";
				getObject("subnav" + menu.opened).style.visibility = "hidden";
			}
			menu.opened = elementID;
//			next line makes new submenu visible
			if (getObject("subnav" + menu.opened)) {
				status = "open";
				getObject("subnav" + menu.opened).style.visibility = "visible";
			}
		}
	}
}

function init() {
	var obj, counter;
	if (typeof tabsearch.adref != "undefined" && tabsearch.adref == "ga" && GetCookie("tab-ga1") == null) {
		window.open("http://www.thistleandbroom.com/extras/gadwin.htm","adwin","height=245,width=400,scrollbars=no,resizable=yes,location=no,buttons=no,directories=no,menubar=no,status=no");
		var expiry = new Date();
		expiry.setTime(expiry.getTime() + 157680000000);
		SetCookie("tab-ga1","true",expiry,"/");
	}
	if (NN7) {
		document.addEventListener("click", checkSubMenuStatus, false);
	} else if (IE4)
		document.onclick = checkSubMenuStatus;
	for (var prop in menu.items) {
		if (getObject(prop)) {
			counter = 0;
			obj = getObject(prop);
			if (NN7) {
				obj.addEventListener("click", checkSubMenuStatus, false);
				obj.addEventListener("mouseover", checkMenuStatus, false);
				obj.addEventListener("mouseout", loseHighlight, false);
			} else if (IE4) {
				obj.onmouseover = checkMenuStatus;
				obj.onmouseout = loseHighlight;
			}
			if (menu.items[prop].submenu) {
				for (var i = 0; i < menu.items[prop].submenu.length; i++) {
					obj = getObject("subnav" + prop + i);
					if (NN7) {
						obj.addEventListener("click", checkSubMenuStatus, false);
						obj.addEventListener("mouseover", getSubHighlight, false);
						obj.addEventListener("mouseout", loseSubHighlight, false);
					} else if (IE4) {
						obj.onmouseover = getSubHighlight;
						obj.onmouseout = loseSubHighlight;
					}
				}
			}
		} else
			return false;
	}
}
/* END NAVIGATION CODE */

function showBasketMessage(obj,colour) {
	obj.style.color = (colour?colour:"#DD77AA");
//	getStyleObject("basket" + obj.id.charAt(obj.id.length-1)).visibility = "visible";
}

function hideBasketMessage(obj,colour) {
	obj.style.color = (colour?colour:"#660033");
//	getStyleObject("basket" + obj.id.charAt(obj.id.length-1)).visibility = "hidden";
}

function showLargeCaption() {
	getStyleObject("rightcolumnlargecaption").display = (getStyleObject("rightcolumnlargecaption").display == "block"?"none":"block");
	getStyleObject("showlink").display = (getStyleObject("showlink").display == "none"?"block":"none");
}

function genericShowHide(obj) {
	getStyleObject(obj).display = (getStyleObject(obj).display == "block"?"none":"block");
}

function getMorePics(pic,n,cap,lnk) {
	if (n == "i")
		getObject("itempic").src = getPath() + "images/products/bb_tab_" + pic + "_i.jpg";
	else
		getObject("itempic").src = getPath() + "images/products/bb_tab_" + pic + "_d" + n + ".jpg";
	if (lnk)
		getObject("itemlink").href = lnk;
	if (cap) {
		if (getObject("itempic")) getObject("itempic").alt = cap;	
		if (getObject("itempiccap")) getObject("itempiccap").innerHTML = cap;
	}
}

function getCurrency(n) {
	var url = "http://www.thistleandbroom.com/ejava/ben/tab_currency.jsp?amount=" + n + "&function=convert";
	window.open(url,"currency","height=145,width=300,scrollbars=no,resizable=yes,location=no,buttons=no,directories=no,menubar=no,status=no");
}

function FormValidator(theForm){
	if (theForm.name_of_user.value == ""){
		alert("Please enter your name.");
    	theForm.name_of_user.focus();
    	return false;	
	}
	if (theForm.senderemail.value == ""){
		alert("Please enter your email address.");
    	theForm.senderemail.focus();
    	return false;	
	}
	if (!isEmailAddr(theForm.senderemail.value)){
	    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
	    theForm.senderemail.focus();
    	return false;
  	}
   	if (theForm.senderemail.value.length < 7){
		alert("Please enter a valid address in the \"email\" field.");
		theForm.senderemail.focus();
		return false;
	}
	if (theForm.otherinfo.value == ""){
		alert("Please enter your enquiry.");
    	theForm.otherinfo.focus();
    	return false;	
	}
	return true;
}

function isEmailAddr(email){
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0){
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
			result = true;
	}
	return result;
}


/* ecommerce code */
// twists order page
var twistglass = [
	{
		image:"ale",
		text:"Water or ale glass",
		price:59,
		n:132
	},
	{
		image:"red",
		text:"Red wine glass",
		price:60,
		n:138
	},
	{
		image:"white",
		text:"White wine glass",
		price:59,
		n:144
	},
	{
		image:"port",
		text:"Port glass",
		price:58,
		n:150
	},
	{
		image:"sherry",
		text:"Sherry glass",
		price:54,
		n:156
	},
	{
		image:"champ",
		text:"Champagne flute",
		price:60,
		n:162
	}
];

var twisttype = [
	{
		image:"2",
		text:"ruby / white",
		n:"017"
	},
	{
		image:"6",
		text:"air twist",
		n:"001"
	},
	{
		image:"5",
		text:"cotton twist in New White",
		n:"010"
	},
	{
		image:"4",
		text:"Contemporary rainbow / white twist",
		n:"016"
	},
	{
		image:"3",
		text:"New Blue and white",
		n:"005"
	},
	{
		image:"1",
		text:"deep purple / white twisted lattice",
		n:"015"
	}
];

var purchasebuild = {item:null,type:null,quantity:null}
var order = [];

function viewDetail(n) {
	if (getObject("purchasebigpic")) {
		viewDetail.saved = (getObject("purchasebigpic").innerHTML.toLowerCase().indexOf("<div class=\"purchasedetail\">") != -1?viewDetail.saved:getObject("purchasebigpic").innerHTML);
		getObject("purchasebigpic").innerHTML = "<div class=\"purchasedetail\"><img src=\"../../../../images/products/bb_tab_twist_stem" + twisttype[n].image + "_l.jpg\" alt=\"\" width=\"200\" height=\"340\" border=\"0\"><div class=\"purchasedetailclose\" onclick=\"hideDetail()\">x</div></div>";
	}
	selectType(n);
}
viewDetail.saved = "";

function hideDetail() {
	if (getObject("purchasebigpic")) {
		getObject("purchasebigpic").innerHTML = viewDetail.saved;
		viewDetail.saved = "";
	}
}

function selectPurchaseItem(n) {
	if (getObject("purchasebigpic"))
		getObject("purchasebigpic").innerHTML = "<img src=\"../../../../images/products/bb_tab_twist_glass_" + twistglass[n].image + "_l.jpg\" alt=\"\" width=\"200\" height=\"340\" border=\"0\">";
	purchasebuild.item = n;
	if (getObject("purchasebuilditem")) {
		getObject("purchasebuilditem").innerHTML = (purchasebuild.item != null?twistglass[purchasebuild.item].text:"") + (purchasebuild.item != null && purchasebuild.type != null?", ":"") + (purchasebuild.type != null?twisttype[purchasebuild.type].text:"");
	}	
}

function selectType(n) {
	purchasebuild.type = n;
	if (getObject("purchasebuilditem")) {
		getObject("purchasebuilditem").innerHTML = (purchasebuild.item != null?twistglass[purchasebuild.item].text:"") + (purchasebuild.item != null && purchasebuild.type != null?", ":"") + (purchasebuild.type != null?twisttype[purchasebuild.type].text:"");
	}
	if (!getObject("purchasebuilditem").innerHTML)
		getObject("purchasebuilditem").innerHTML = "No glass selected";
}

var str = ""
function addItemsToOrder() {
	if (getObject("purchasebuilder").buildquantity.value != "0")
		purchasebuild.quantity = getObject("purchasebuilder").buildquantity.value;
	if (purchasebuild.item == null) {
		alert("Please indicate which glass you would like to purchase by clicking on one of the glasses on the left, before pressing the \"Add to order\" button.");
		return;
	} else if (purchasebuild.type == null) {
		alert("Please indicate which style of twist you would on your glasses by clicking on one of the styles on the right, before pressing the \"Add to order\" button.");
		return;
	} else if (purchasebuild.quantity == null) {
		alert("Please indicate how many glasses you would like to purchase by typing in the number in the area labelled \"Quantity\", before pressing the \"Add to order\" button.");
		return;
	} else if (getObject("purchaseordertext")) {
		order[order.length] = {};
		for (var prop in purchasebuild) {
			order[order.length-1][prop] = purchasebuild[prop];
			purchasebuild[prop] = null;
		}
		buildOrder();
		selectType(null);
		if (getObject("purchasebigpic"))
			getObject("purchasebigpic").innerHTML = "<div class=\"purchaseinstructions\"><div class=\"bold\">Create your order</div><p>The initial order minimum order is two (2) stems in any combination with subsequent orders to the party and same address offered as singles (should replacement be necessary).</p><ol><li class=\"gap6\">Click on the glass you require from the list on the left<li class=\"gap6\">Select the style of twist stem from the six options on the right<li class=\"gap6\">Type in the number of these glasses you want<li class=\"gap6\">Press \"Add to order\"<li class=\"gap6\">Repeat steps 1-4 to add another type of glass to your order<li class=\"gap6\">When you've finished, press \"Add order to basket\"</ol></div>";
	}
}

function buildOrder() {
	buildOrder.total = 0;
	txt = "";
	for (var i = 0; i < order.length; i++) {
		txt += "<div style=\"float:right\">[<a href=\"javascript:removeFromOrder(" + i + ")\">delete</a>]</div>" + order[i].quantity + "x " + twistglass[order[i].item].text + " with " + twisttype[order[i].type].text + " stem (&pound;" + (twistglass[order[i].item].price * order[i].quantity) + ")<div style=\"clear:right\"></div>";
		buildOrder.total += (twistglass[order[i].item].price * order[i].quantity);
	}
	getObject("purchaseordertext").innerHTML = (txt?txt:"&nbsp;");
}
buildOrder.total = 0;

function removeFromOrder(n) {
	order.splice(n,1);
	buildOrder();
}

function addTwistsOrder() {
	var total = 0;
	var txt = "";
	for (var i = 0; i < order.length; i++) {
		total += order[i].quantity;
		for (var j = 0; j < order[i].quantity; j++) {
			txt += "011-005-" + (twistglass[order[i].item].n + order[i].type) + "-004-" + twisttype[order[i].type].n + "-0,";
		}
	}
	if (total < 2) {
		if (!confirm("We can only accept orders of less than two glasses from repeat customers. Click \"Okay\" to continue with your repeat order or \"Cancel\" to go back to the selection process to pick more glasses."))
			return;
	}
	txt = txt.substring(0,txt.length-1);
	purchaseItem(txt);
	alert("Your order has been added to your basket");
}

function twistsCurrency() {

}

// end twists page code

// Other items selection code

function selectSizeColour(a,b,name) {
	var f = document[name];
	if (!f.colour.options[f.colour.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for both options before adding to your basket");
	else {
		var tmp = f.colour.options[f.colour.selectedIndex].value.split(",");
		var x = tmp[0];
		var y = tmp[1];
		var z = f.size.options[f.size.selectedIndex].value;
		purchaseItem(a + ((parseInt(x) + (f.size.selectedIndex-1)) < 10?"00":((parseInt(x) + (f.size.selectedIndex-1)) < 100?"0":"")) + (parseInt(x) + (f.size.selectedIndex-1)) + b + y + "-" + z);
	}
}

function selectColourSize(a,b,name) {
	var f = document[name];
	if (!f.colour.options[f.colour.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for both options before adding to your basket");
	else {
		var tmp = f.size.options[f.size.selectedIndex].value.split(",");
		var x = tmp[0]; // number of colours per size
		var y = tmp[1]; // size code
		var z = f.colour.options[f.colour.selectedIndex].value;
		purchaseItem(a + ((parseInt(x) + (f.colour.selectedIndex-1)) < 10?"00":((parseInt(x) + (f.colour.selectedIndex-1)) < 100?"0":"")) + (parseInt(x) + (f.colour.selectedIndex-1)) + b + z + "-" + y);
	}
}


function selectSizeStyle(a,b,name) {
	var f = document[name];
	if (!f.style.options[f.style.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for both options before adding to your basket");
	else {
		var x = f.style.options[f.style.selectedIndex].value;
		var z = f.size.options[f.size.selectedIndex].value;
		purchaseItem(a + ((parseInt(x) + (f.size.selectedIndex-1)) < 10?"00":((parseInt(x) + (f.size.selectedIndex-1)) < 100?"0":"")) + (parseInt(x) + (f.size.selectedIndex-1)) + b + z);
	}
}

function selectSizeStyle2(a,b,name) {
	var f = document[name];
	if (!f.style.options[f.style.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for both options before adding to your basket");
	else {
		var x = f.style.options[f.style.selectedIndex].value;
		var z = f.size.options[f.size.selectedIndex].value;
		purchaseItem(a + ((parseInt(x) + (f.size.selectedIndex)) < 10?"00":((parseInt(x) + (f.size.selectedIndex)) < 100?"0":"")) + (parseInt(x) + (f.size.selectedIndex)) + b + z);
	}
}

function selectSizeColourStyle(a,b,name) {
	var f = document[name];
	if (!f.style.options[f.style.selectedIndex].value || !f.colour.options[f.colour.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for all options before adding to your basket");
	else {
		var x = f.style.options[f.style.selectedIndex].value;
		var y = f.colour.options[f.colour.selectedIndex].value;
		var z = f.size.options[f.size.selectedIndex].value;
		purchaseItem(a + ((parseInt(x) + (f.size.selectedIndex)) < 10?"00":((parseInt(x) + (f.size.selectedIndex)) < 100?"0":"")) + (parseInt(x) + (f.size.selectedIndex)) + b + y + "-" + z);
	}
}


function selectColourSizeStyle(a,b,name) {
	var f = document[name];
	if (!f.colour.options[f.colour.selectedIndex].value || !f.style.options[f.style.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for all options before adding to your basket");
	else {
		var tmp = f.colour.options[f.colour.selectedIndex].value.split(",");
		var x = tmp[0]; // this is the number of "size" offset per "colour"
		var y = tmp[1]; // this is the "colour" code
		var z = f.size.options[f.size.selectedIndex].value;
		var n = parseInt(f.style.options[f.style.selectedIndex].value,10) +  parseInt(x,10) + (f.size.selectedIndex-1);


//		alert(a + (n < 10?"00":(n < 100?"0":"")) + n + b + y + "-" + z);
		purchaseItem(a + (n < 10?"00":(n < 100?"0":"")) + n + b + y + "-" + z);
	}
}

function selectColourSizeStyle2(a,b,name) {
	var f = document[name];
	if (!f.colour.options[f.colour.selectedIndex].value || !f.style.options[f.style.selectedIndex].value || !f.size.options[f.size.selectedIndex].value)
		alert("You must select a value for all options before adding to your basket");
	else {
		var tmp = f.colour.options[f.colour.selectedIndex].value.split(",");
		var x = tmp[0]; // this is the number of "size" offset per "colour"
		var y = tmp[1]; // this is the "colour" code
		var z = f.size.options[f.size.selectedIndex].value;
		var n = parseInt(f.style.options[f.style.selectedIndex].value) +  parseInt(x) + (f.size.selectedIndex);
		purchaseItem(a + (n < 10?"00":(n < 100?"0":"")) + n + b + y + "-" + z);
	}
}

function selectThreeOptions(a,b,name,info) {
	var f = document[name];
	if (!f.colour.options[f.colour.selectedIndex].value || !f.size.options[f.size.selectedIndex].value || !f.width.options[f.width.selectedIndex].value)
		alert("You must select a value for all options before adding to your basket");
	else {
		var tmp = f.colour.options[f.colour.selectedIndex].value.split(",");
		var x = tmp[0]; // this is the number of "size" options per "colour"
		var y = tmp[1]; // this is the "colour" code
		var z = f.size.options[f.size.selectedIndex].value;
		var n = parseInt(f.width.options[f.width.selectedIndex].value) + (x * (f.colour.selectedIndex-1)) + f.size.selectedIndex-1;
		if ((info != null && info && saveInfo(f)) || info == null || !info)
			purchaseItem(a + (n < 10?"00":(n < 100?"0":"")) + n + b + y + "-" + z);
	}
}

function saveMeasurementsAndPurchase(f) {
	var txt = (GetCookie("MC_measurements")?GetCookie("MC_measurements") + " || ":"") + f.name + ": ";
//	alert(f.elements.length);
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type == "text") {
//			if (!f.elements[i].value) {
//				alert("Please supply all the required information before adding this item to your shopping basket.");
//				f.elements[i].focus();
//				return;
//			} else
				txt += f.elements[i].name + "=" + f.elements[i].value + "; ";
		}
	}
	SetCookie("MC_measurements",txt,null,"/");
	if (f.types.type.indexOf("select") == -1){
		purchaseItem(f.types.value);
//		alert(f.types.value);	
	}
	else
		purchaseItem(f.types[f.types.selectedIndex].value);
//	alert(GetCookie("MC_measurements"));	
}

// this version used for temporary orders where colours and sizes may need to be specified
function saveNotesAndPurchase(f) {
	var txt = (GetCookie("MC_measurements")?GetCookie("MC_measurements") + " || ":"") + f.name + ": ";
//	alert(f.elements.length);
	var note_set = 0;
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type == "text") {
			if (f.elements[i].value) {
				note_set = 1;
				
				
			if (f.types.type.indexOf("select") == -1)
				txt += f.types.value + "=" + f.elements[i].value + "; ";
			else
				txt += f.types[f.types.selectedIndex].value + "=" + f.elements[i].value + "; ";
			}
		}
	}
	if (note_set) //{
		SetCookie("MC_measurements",txt,null,"/");
//		alert("cookie set");
//	} else
//		alert("no cookie set");
	if (f.types.type.indexOf("select") == -1)
		purchaseItem(f.types.value);
	else
		purchaseItem(f.types[f.types.selectedIndex].value);
//	alert(GetCookie("MC_measurements"));	
}


function saveInfo(f) {
	var txt = (GetCookie("MC_info")?GetCookie("MC_info") + " || ":"") + f.name + ": ";
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type == "text") {
			if (!f.elements[i].value) {
				alert("Please supply all the required information before adding this item to your shopping basket.");
				f.elements[i].focus();
				return false;
			} else
				txt += f.elements[i].name + "=" + f.elements[i].value + "; ";
		}
	}
	SetCookie("MC_info",txt,null,"/");
	return true;
}

function saveInfoAndPurchase(f) {
	if (saveInfo(f)) {
		if (f.types.type.indexOf("select") == -1){
			purchaseItem(f.types.value);
	//		alert(f.types.value);	
		}
		else
			purchaseItem(f.types[f.types.selectedIndex].value);
	//	alert(GetCookie("MC_measurements"));	
	}
}

// end other items selection code


/* end ecommerce code */

/* SHOPPING CART SCRIPT */

function changeQuantity(n) {
	var counter = 0;
	if (GetCookie("tabcart")) {
		var tmparr = (GetCookie("tabcart").substring(0,GetCookie("tabcart").length-1)).split(",");
		for (var i = 0; i < tmparr.length; i++) {
			if (tmparr[i] == n)
				counter++;
		}
	} else {
		tmparr = [];
		counter = 0;
	}
	while (document.shoppingcart["quantity" + n].value > counter) {
		tmparr[tmparr.length] = n;
		counter++;
	}
	if (document.shoppingcart["quantity" + n].value < counter) {
		var tmparr2 = [];
		for (var i = 0; i < tmparr.length; i++) {
			if (n == tmparr[i] && document.shoppingcart["quantity" + n].value < counter) {
				counter--;
				continue;
			}
			tmparr2[tmparr2.length] = tmparr[i];
		}
		tmparr = tmparr2;
	}
	var str = "";
	for (var i = 0; i < tmparr.length; i++) {
		str += tmparr[i] + ",";
	}
	SetCookie("tabcart",str,null,"/");
}

function showSwatches(x) {
	if (getObject("swatchviewer")) {
		getStyleObject("swatchviewer").visibility = (x?"visible":"hidden");
	}
	if (getObject("purchase")) {
		getStyleObject("purchase").visibility = "hidden";
	}
}

function viewSwatch(n,x) {
	for (var i = 0; i < x; i++) {
		getStyleObject("swatch" + i).display = (n == i?"inline":"none");
	}
}

function showPurchase(x) {
	if (getObject("purchase")) {
		getStyleObject("purchase").visibility = (x?"visible":"hidden");
	}
	if (getObject("swatchviewer")) {
		getStyleObject("swatchviewer").visibility = "hidden";
	}
}


function purchaseItem(n) {
//	alert(n);
	var f = document.shoppingcart;
	if (f && f["quantity" + n])
		f["quantity" + n].value = (f["quantity" + n].value == "0"?"1":parseInt(f["quantity" + n].value) + 1);
	var tmp = (GetCookie("tabcart")?GetCookie("tabcart"):"");
	tmp += n + ",";
	SetCookie("tabcart",tmp,null,"/");
	if (getObject("itemadded")) {
		getStyleObject("itemadded").visibility = "visible";
		setTimeout("getStyleObject('itemadded').visibility = 'hidden'",3000);
	}
//	alert(GetCookie("tabcart"));
}

function subtractUnit(n) {
	var f = document.shoppingcart;
	if (f)
		f["quantity" + n].value = (parseInt(f["quantity" + n].value) > 0?parseInt(f["quantity" + n].value) - 1:"0");
	if (GetCookie("tabcart")) {
		var test = true;
		var str = "";
		var tmparr = (GetCookie("tabcart").substring(0,GetCookie("tabcart").length-1)).split(",");
		for (var i = 0; i < tmparr.length; i++) {
			if (tmparr[i] == n && test) {
				test = false;
				continue;
			}
			str += tmparr[i] + ",";
		}
		SetCookie("tabcart",str,null,"/");
	}
}

function clearAnItem(n) {
	var f = document.shoppingcart;
	f["quantity" + n].value = 0;
	if (GetCookie("tabcart")) {
		var str = "";
		var tmparr = (GetCookie("tabcart").substring(0,GetCookie("tabcart").length-1)).split(",");
		for (var i = 0; i < tmparr.length; i++) {
			if (tmparr[i] != n)
				str += n + ",";
		}
		SetCookie("tabcart",str,null,"/");
	}
}

function emptyCart() {
	SetCookie("tabcart","",null,"/");
	SetCookie("MC_measurements","",null,"/");
	var f = document.shoppingcart;
	for (var i = 0; i < f.elements.length; i++) {
		if (f.elements[i].type == "text")
			f.elements[i].value = 0;
	}
	alert("Basket emptied!");
	location.reload();
}

function continueShopping() {
	location = (document.referrer.indexOf("beetlebrow") != -1 || document.referrer.indexOf("thistleandbroom.com") != -1?document.referrer:getPath() + "shopping/");
}

// saves quantites as properties of object named as the item uids
var cartobject = {};
function makeCartObject() {
	cartobject = {};
	if (GetCookie("tabcart")) {
		var tmparr = (GetCookie("tabcart").substring(0,GetCookie("tabcart").length-1)).split(",");
		for (var i = 0; i < tmparr.length; i++) {
			if (typeof cartobject[tmparr[i]] == "undefined")
				cartobject[tmparr[i]] = 1;
			else
				cartobject[tmparr[i]] += 1;
		}
	}
}

function getTwoDecPlaces(n) {
	n = (Math.round(100 * n))/100;
	if (n.toFixed)
		return n.toFixed(2);
	else {
		n += "";
		if (n.indexOf(".") == -1)
			return n + ".00";
		else if (n.indexOf(".") == n.length - 2)
			return n + "0";
		else
			return n;
	}
}

function getDeliveryCharge(cost) {
	if (cost == 0)
		return 0;
	else if (cost <= 15)
		return 5;
	else if (cost <= 25)
		return 10;
	else if (cost <= 40)
		return 15;
	else if (cost <= 75)
		return 16;
	else if (cost <= 100)
		return 20;
	else if (cost <= 150)
		return 25;
	else if (cost <= 200)
		return 28;
	else if (cost <= 300)
		return 35;
	else if (cost <= 500)
		return 45;
	else if (cost <= 750)
		return 55;
	else if (cost <= 1000)
		return 60;
	else if (cost <= 2000)
		return 75;
	else
		return (0.045 * cost);
}

/* PROMO AND DISCOUNT CODE */
var zibbles = [{},"TAB0422","TAB-ES01","TAB-HS01","TAB-NYCC","TlusGA","HotScot",{CHESS:20,item:"999-000-9019-000-0-0"}];

function checkPromo() {
	for (var i = 0; i < zibbles.length; i++) {
		if (zibbles[i] == document.shoppingcart.promocode.value || typeof (zibbles[i][document.shoppingcart.promocode.value]) != "undefined")
			return i;
	}
	return false;
}

function promoCode() {
	if (checkPromo()) {
		renderCart();
	} else
		alert("That is not a valid promotional code. Please note that codes are case-sensitive, so \"HELLO32\" is not the same as \"hello32\". Check the code you have entered and try again.");
}


function getDiscountedPrice(uid,n) {
	if (checkPromo()) {
		if (typeof zibbles[checkPromo()].item != "undefined" && zibbles[checkPromo()].item) {
//			alert("from zibbles:" + zibbles[checkPromo()].item + "; from purchase:" + uid);
			if (zibbles[checkPromo()].item == uid) {
//				alert("!");
				return (n/100 * (100-zibbles[checkPromo()][document.shoppingcart.promocode.value]));
			}
		} else if (typeof zibbles[checkPromo()] == "string")
			return (n/10 * 9);
		else
			return (n/100 * (100-zibbles[checkPromo()][document.shoppingcart.promocode.value]));
			
	}
	return n;
}

/* END PROMO AND DISCOUNT CODE */


var deliveryspecial = false;
function renderCart() {
	var deliverycharge = 0;
	var deliverycost = 0;
	deliveryspecial = false;
	makeCartObject();
	var txt = "";
	var quantity = 0;
	var total = 0;
	var n = 0;
	var m = 0; // for promotional discount calculations
	var discounttotal = 0;
	for (var i = 0; i < currentitems.length; i++) {
		if (typeof cartobject[currentitems[i].uid] != "undefined") {
			n = (Math.round(100 * cartobject[currentitems[i].uid] * currentitems[i].price))/100;
			m = getDiscountedPrice(currentitems[i].uid,n);
			txt += "<div class=\"cartrow\">" + (currentitems[i].image?"<img src=\"images/products/bb_tab_" + currentitems[i].image + "_t1.jpg\" height=\"50\" width=\"40\" border=\"0\" alt=\"\">":"") + "<div class=\"cartitem\">" + currentitems[i].item + "<div class=\"cartitemdetails\">By " + currentitems[i].supplier + "<br>" + (currentitems[i].colour?currentitems[i].colour + "&nbsp;&nbsp;":"") + (currentitems[i].size && currentitems[i].size != "0"?"Size: " + currentitems[i].size.replace(/_/g,"-"):"") + (currentitems[i].delivery?"<br><a title=\"What is this?\" href=\"delivery-charges.htm\">This item involves a special delivery charge</a>":"") + "</div></div><div class=\"cartpricedetails\"><div class=\"cartprice\" id=\"price" + currentitems[i].uid + "\">&pound;" + getTwoDecPlaces(n) + "</div>\n<div class=\"cartbuttons\"><img class=\"cartitemadd\" src=\"images/bb_tab_shop_plus.gif\" alt=\"\" width=\"20\" height=\"20\" border=\"0\" onclick=\"recalculateTotals(true,'" + currentitems[i].uid + "')\"> <img class=\"cartitemsubtract\" src=\"images/bb_tab_shop_minus.gif\" alt=\"\" width=\"20\" height=\"20\" border=\"0\" onclick=\"recalculateTotals(false,'" + currentitems[i].uid + "')\"></div><img class=\"cartquantityimage\" src=\"images/bb_tab_shop_quantity.gif\" alt=\"\" width=\"59\" height=\"15\" border=\"0\"><input class=\"cartquantity\" type=\"text\" name=\"quantity" + currentitems[i].uid + "\" size=\"2\" value=\"" + cartobject[currentitems[i].uid] + "\" onchange=\"recalculateTotals(null,'" + currentitems[i].uid + "')\"><span style=\"font-size:80%; _font-size:60%\">&nbsp;[<a href=\"#\">Update</a>]</span></div></div>\n";
			total += n;
			discounttotal += m;
			quantity += cartobject[currentitems[i].uid];
			deliverycost += (currentitems[i].delivery?0:n);
			deliveryspecial = (currentitems[i].delivery || deliveryspecial?true:false);
		}
	}
	deliverycharge = getDeliveryCharge(deliverycost);
	txt += "<div class=\"cartcontinue\"><a href=\"javascript:continueShopping()\"><img src=\"images/bb_tab_shop_continue.gif\" alt=\"Continue shopping\" width=\"136\" height=\"16\" border=\"0\"></a></div>\n" + (deliveryspecial?"<div id=\"specialdeliverymsg\"><p>The paintings by Richard Wemyss and the Orkney Chairs by Scapa Craft incur a special delivery charge due to their size and cost. We will contact you with the details when we receive your order.<br><br>For more information, see our <a href=\"delivery-charges.htm\">shipping costs information page</a>. Click on the button below to make your payment.</p><p><a href=\"javascript:document.paymentform.submit()\"><img style=\"float:right; padding-right:15px\" src=\"images/bb_tab_shop_proceed.gif\" alt=\"Proceed to checkout\" width=\"192\" height=\"34\" border=\"0\" onmouseover=\"this.src='images/bb_tab_shop_proceed_on.gif'\" onmouseout=\"this.src='images/bb_tab_shop_proceed.gif'\"></a></p></div>":"") + "<div class=\"carttotals\">\n<div id=\"totalprice\" class=\"carttotalprice\">&pound;" + getTwoDecPlaces(total) + "</div>\n<div class=\"cartheadings\">Total</div>" + (checkPromo()?"<div class=\"cartheadings\" style=\"color:#999999\">Less promotional discount</div><div id=\"revisedtotalprice\" class=\"carttotalprice\">&pound;" + getTwoDecPlaces(discounttotal) + "</div><div class=\"cartheadings\">Revised total</div>":"") + "</div>\n<div class=\"carttotals\">\n<div id=\"deliveryprice\" class=\"carttotalprice\">&pound;" + getTwoDecPlaces(deliverycharge) + "</div>\n<div class=\"cartheadings\"><a title=\"What is this?\" href=\"delivery-charges.htm\">Package &amp; shipping" + (deliveryspecial?"<br>(Plus special delivery item)":"") + "</a></div></div>\n";
	if (checkPromo())
		total = discounttotal;
	n = (Math.round(100 * (total + deliverycharge)))/100;
	txt += "<div class=\"cartgrandtotal\">\n<div id=\"grandtotalprice\" class=\"carttotalprice\"><a href=\"javascript:getCurrency(" + getTwoDecPlaces(n) + ")\">&pound;" + getTwoDecPlaces(n) + "<br><img src=\"images/bb_tab_cc_beige.gif\" alt=\"Currency Convertor\" width=\"25\" height=\"12\" border=\"0\"></a></div><div class=\"cartheadings\">Total payable</div>\n</div>\n";
	txt += "";
	getObject("tabbasket").innerHTML = txt;
}

function recalculateTotals(q,n) {
	if (q)
		purchaseItem(n);
	else if (q == null)
		changeQuantity(n);
	else
		subtractUnit(n);
	renderCart();
}

function makeOrderNumber() {
	var alph = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",];
	var str = "";
	str += alph[Math.floor(Math.random() * 26)];
	str += alph[Math.floor(Math.random() * 26)];
	str += alph[Math.floor(Math.random() * 26)];
	var d = new Date();
	str += d.getTime();
	return str;
}

function makePayment() {
	if (GetCookie("tabcart")) {
		makeCartObject();
		writeForm();
		if (deliveryspecial) {
			if (getObject("specialdeliverymsg"))
				getStyleObject("specialdeliverymsg").visibility = "visible";
		} else
			document.paymentform.submit();
	} else
		alert("You must select an item to buy by putting it in your shopping cart before you can proceed to the checkout.");
}

function writeForm() {
	var deliverycharge = 0;
	var deliverycost = 0;
	var f = document.paymentform;
	var total = 0;
	var quantity = 0;
	var subtotal = 0;
	var items = "";
	var itemcodes = "";
	for (var prop in cartobject) {
		INNER:
		for (var i = 0; i < currentitems.length; i++) {
			if (currentitems[i].uid == prop) {
				items += cartobject[currentitems[i].uid] + " x " + currentitems[i].supplier + ", " + currentitems[i].item + ", " + currentitems[i].colour + (currentitems[i].size && currentitems[i].size != "0"?", size:" + currentitems[i].size:"") + "; ";
				itemcodes += cartobject[currentitems[i].uid] + " x " + currentitems[i].uid + "; ";
				subtotal = (Math.round(100 * cartobject[currentitems[i].uid] * currentitems[i].price))/100;
				quantity += cartobject[currentitems[i].uid];
				deliverycost += (currentitems[i].delivery?0:subtotal);
				subtotal = getDiscountedPrice(currentitems[i].uid,subtotal);
				break INNER;
			}
		}
		total += subtotal;
	}
	// this writes the how did you find tab data to the database
	if (document.shoppingcart.how_tab.selectedIndex) {
		if (document.shoppingcart.how_tab[document.shoppingcart.how_tab.selectedIndex].value.indexOf("other") != -1)
			f.MC_how_find_tab.value = document.shoppingcart.how_tab[document.shoppingcart.how_tab.selectedIndex].value;
		else
			f.MC_how_find_tab.value = document.shoppingcart.other_how_tab.value;
	}
	if (checkPromo())
		f.MC_promotion_code.value = document.shoppingcart.promocode.value;
	deliverycharge = getDeliveryCharge(deliverycost);
	f.amount.value = Math.round(100 * (total + deliverycharge))/100;
	f.desc.value = items;
	f.cartId.value = makeOrderNumber();
	f.MC_items.value = itemcodes;
// the next loop looks for form elements with the same name as any cookies stored on the system and if it finds them, writes them to the relevant field in the form e.g. MC_measurements is a cookie that stores the bespoke measurements from the kilt and roobedo items and with the newly created MC_measurements field, the measurements are passed through to be stored in the db and the cookie is reset
	for (var i = 0; i < f.elements.length; i++) {
		if (GetCookie(f.elements[i].name)) {
			f.elements[i].value = GetCookie(f.elements[i].name);
			SetCookie(f.elements[i].name,"",null,"/");
//			alert(f.elements[i].value);
        }
	}
}
/* END SHOPPING CART */


var timerID1;
function scrollItems(n) {
	if (!getStyleObject("slidecartridge").left)
		getStyleObject("slidecartridge").left = slidedata.start;
	timerID1 = setInterval("moveIt(" + n + ")",10);
}

var x = location.href.indexOf("bollox.htm") == -1;
var slidedata = 
	{
		start:(x?"-475px":"-420px"), // set to slidecartridge.value (css)
		upper:(x?30:30),              // start of cartridge = width of arrow graphic
		lower:(x?-1344:-700)          // (width of slideshow (css) - width of rhs slidecontrol (source)) -  no of images x image width - (no images - 1(margins))
	};

function moveIt(n) {
	if ((parseInt(getStyleObject("slidecartridge").left) < slidedata.upper || n < 0) && (parseInt(getStyleObject("slidecartridge").left) > slidedata.lower || n > 0))
		getStyleObject("slidecartridge").left = (parseInt(getStyleObject("slidecartridge").left) + (n*10)) + "px";
	else
 		stopScroll();
}

function stopScroll() {
	clearInterval(timerID1);
}


onload = init;
