function launch(newURL, newName, newFeatures)
{
	var remote = open(newURL, newName, newFeatures);
	return remote;
}

function popuplaunch(theURL,theNAME,theWIDTH,theHEIGHT)
{
	Remote = launch(theURL, theNAME, "width="+theWIDTH+", height="+theHEIGHT+", channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,title=0,left=100,top=0");
}

function sitelaunch(theURL)
{
	var avw = screen.availWidth-10;
	var avh = screen.availHeight-30;
	Remote = launch(theURL, "highteasite", "height="+avh+",width="+avw+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,title=0,left=0,top=0");
}

function shoplaunch(theURL)
{
	var avw = screen.availWidth-10;
	var avh = screen.availHeight-30;
	Remote = launch(theURL, "highteashop", "height="+avh+",width="+avw+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,title=0,left=0,top=0");
}

function urlcheck()
{
	if (location.search)
	{
		var theurl = location.search ? unescape(location.search.substring(1)) : 'someDefaultURLHere.html';
		document.getElementById('birdcage').src=theurl;
	}
}

function framecheck()
{
	if (top == window)
	{
		var theurl=self.location;
		self.location='../main.html?'+theurl;
	}
}

function simple_browser_detect(whatone)
{
	var sUserAgent = navigator.userAgent;
	var isThisone = sUserAgent.indexOf(whatone) > -1;
	return isThisone;
}


function autoloadbigpic()
{
	document.getElementById('bigpicloader').style.display = 'block';
	if (simple_browser_detect('MSIE 6'))
		{document.getElementById('cartAdd').className = 'off';}
}

function ihazloaded()
{
	document.getElementById('ihazbigpic').innerHTML = frames['thebigpic'].document.getElementById('iisbigpic').innerHTML;
}

function closebigpic()
{
	if (simple_browser_detect('MSIE 6'))
		{document.getElementById('cartAdd').className = 'on';}
	document.getElementById('bigpicloader').style.display='none';
	document.getElementById('ihazbigpic').innerHTML='<!-- ie -->';
}

function loadbigpic(theURL)
{
	autoloadbigpic();
	frames['thebigpic'].location = 'http://highteawithmrswoo.com.au/store/bigpic-image.html?'+theURL;
}

function setcookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}



function getcookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function deletecookie(name,path,domain)
{
	if (getcookie(name))
	{document.cookie = name+"="+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+";expires=Thu, 01-Jan-1970 00:00:01 GMT";}
}


var cookiechecked = 'false';
function checkcookie()
{
	var whatsthepic = getcookie('hightearandpic');

	if (whatsthepic!=null && whatsthepic!="")
	{
		document.getElementById('accrandpic').innerHTML = '<img src="../shop/site-images/account-rand-pic'+whatsthepic+'.png" width="65" height="49" border="0" alt="account settings" />';
	}
	else
	{
	    if (cookiechecked=='false')
	    {
	    	cookiechecked = 'true';
	    	whatpic = Math.round(Math.random()*3)+1;			// 3+1 = 4 options
	    	setcookie('hightearandpic',whatpic,'6','/','','');
	    	checkcookie();
	    }

	}
}


function rollnav(rollstate)
{

//note: using these subdivs as IE6 hates multiple instances of #idname.classname style CSS entries... for some reason!!
//annoying as it means extra otherwise unnecassary HTML

	document.getElementById('navmap1a').className=rollstate;
	document.getElementById('navmap2a').className=rollstate;
	document.getElementById('navexit2').className=rollstate;
	document.getElementById('mrswoo2').className=rollstate;

	if(document.getElementById('logon2'))
		{document.getElementById('logon2').className=rollstate;}
	if(document.getElementById('navmap3a'))
		{document.getElementById('navmap3a').className=rollstate;}
}

function navon(navid)
{
	document.getElementById(navid).className='navon';
}

function onstatechange(whatid,whatclass)
{

	if (whatid=='nada')
		{return;}
	else
	{
		if (whatclass=='lost property')
			{
				whatclass='lostproperty';
			}
	
		document.getElementById(whatid).className = 'navon'+whatclass;
	}
	

}

function siteonstate(whatlang,whatid,whatstate)
{
	document.getElementById('nav2b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('nav3b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('nav4b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('nav5b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('nav6b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('nav7b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('nav8b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('lang1b').style.backgroundImage='url(images/blank.gif)';
	document.getElementById('lang1c').style.backgroundImage='url(images/blank.gif)';

	if (whatstate=='none')
	{
		document.getElementById('main').className='';
	}
	else
	{
		document.getElementById(whatid).style.backgroundImage='url(images/'+whatlang+'-onstate-'+whatstate+'.png)';

// currently, clicking on profile or translation links highlights ALL languages via the langstate() function, hence this is currently redundent. Not in original code design!
		if (whatlang=='au')
			{document.getElementById('lang1c').style.backgroundImage='url(images/au-onstate-language-english.png)';}
		if (whatlang=='cn')
			{document.getElementById('lang1c').style.backgroundImage='url(images/cn-onstate-language-chinese.png)';}
		if (whatlang=='it')
			{document.getElementById('lang1c').style.backgroundImage='url(images/it-onstate-language-italian.png)';}
		if (whatlang=='jp')
			{document.getElementById('lang1c').style.backgroundImage='url(images/jp-onstate-language-japanese.png)';}
	}
}

// used to override siteonstate calls and make clicking on profile or translation links highlight ALL languages. Not in original code design!
function langstate(dowhat)
{
	document.getElementById('lang1c').style.backgroundImage='url(images/all-onstate-language.png)';
}



function siteroll(whatlang,whatstate)
{
	if(whatstate=='off')
	{
		document.getElementById('main').className='';
		document.getElementById('lang1b').style.backgroundImage='url(images/blank.gif)';
	}
	else
	{
		document.getElementById('main').className=whatlang+'-'+whatstate;
	}
}

function siterolllang(whatlang,whatstate)
{
	document.getElementById('lang1b').style.backgroundImage='url(images/'+whatlang+'-onstate-'+whatstate+'.png)';
}



function loadcollection(whatfile)
{
	document.getElementById('loading').style.display='block';
	parent.frames['hiddeniframe'].location = whatfile;
}


function displaycollection(whatfile)
{
	var avw = screen.availWidth-10;
	var avh = screen.availHeight-30;
	parent.document.getElementById('colpop').innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="'+avw+'" height="'+avh+'" id="colpopouter"><tr><td width="'+avw+'" height="'+avh+'" align="center" valign="center">' + parent.frames['hiddeniframe'].document.getElementById('thepop').innerHTML + '</td></tr></table>';
}


function closecollection(whatfile)
{
	document.getElementById('loading').style.display='none';
	parent.document.getElementById('colpop').innerHTML = '';
}


function closecollection2(whatfile)
{
	frames['birdcage'].document.getElementById('loading').style.display='none';
	document.getElementById('colpop').innerHTML = '';
}


//Written by Nathan Faubion: http://n-son.com
//Use this or edit how you want, just give me
//some credit!

function jsScroller (o, w, h) {
	var self = this;
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) {
		if (list[i].className.indexOf("scroller-container") > -1) {
			o = list[i];
		}
	}
	
	//Private methods
	this._setPos = function (x, y) {
		if (x < this.viewableWidth - this.totalWidth) 
			x = this.viewableWidth - this.totalWidth;
		if (x > 0) x = 0;
		if (y < this.viewableHeight - this.totalHeight) 
			y = this.viewableHeight - this.totalHeight;
		if (y > 0) y = 0;
		this._x = x;
		this._y = y;
		with (o.style) {
			left = this._x +"px";
			top  = this._y +"px";
		}
	};
	
	//Public Methods
	this.reset = function () {
		this.content = o;
		this.totalHeight = o.offsetHeight;
		this.totalWidth	 = o.offsetWidth;
		this._x = 0;
		this._y = 0;
		with (o.style) {
			left = "0px";
			top  = "0px";
		}
	};
	this.scrollBy = function (x, y) {
		this._setPos(this._x + x, this._y + y);
	};
	this.scrollTo = function (x, y) {
		this._setPos(-x, -y);
	};
	this.stopScroll = function () {
		if (this.scrollTimer) window.clearInterval(this.scrollTimer);
	};
	this.startScroll = function (x, y) {
		this.stopScroll();
		this.scrollTimer = window.setInterval(
			function(){ self.scrollBy(x, y); }, 40
		);
	};
	this.swapContent = function (c, w, h) {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("scroller-container") > -1) {
				o = list[i];
			}
		}
		if (w) this.viewableWidth  = w;
		if (h) this.viewableHeight = h;
		this.reset();
	};
	
	//variables
	this.content = o;
	this.viewableWidth  = w;
	this.viewableHeight = h;
	this.totalWidth	 = o.offsetWidth;
	this.totalHeight = o.offsetHeight;
	this.scrollTimer = null;
	this.reset();
};


function jsScrollbar (o, s, a, ev) {
	var self = this;
	
	this.reset = function () {
		//Arguments that were passed
		this._parent = o;
		this._src    = s;
		this.auto    = a ? a : false;
		this.eventHandler = ev ? ev : function () {};
		//Component Objects
		this._up   = this._findComponent("scrollbar-up", this._parent);
		this._down = this._findComponent("scrollbar-down", this._parent);
		this._yTrack  = this._findComponent("scrollbar-track", this._parent);
		this._yHandle = this._findComponent("scrollbar-handle", this._yTrack);
		//Height and position properties
		this._trackTop = findOffsetTop(this._yTrack);
		this._trackHeight  = this._yTrack.offsetHeight;
		this._handleHeight = this._yHandle.offsetHeight;
		this._x = 0;
		this._y = 0;
		//Misc. variables
		this._scrollDist  = 5;
		this._scrollTimer = null;
		this._selectFunc  = null;
		this._grabPoint   = null;
		this._tempTarget  = null;
		this._tempDistX   = 0;
		this._tempDistY   = 0;
		this._disabled    = false;
		this._ratio = (this._src.totalHeight - this._src.viewableHeight)/(this._trackHeight - this._handleHeight);
		
		this._yHandle.ondragstart  = function () {return false;};
		this._yHandle.onmousedown = function () {return false;};
		this._addEvent(this._src.content, "mousewheel", this._scrollbarWheel);
		this._removeEvent(this._parent, "mousedown", this._scrollbarClick);
		this._addEvent(this._parent, "mousedown", this._scrollbarClick);
		
		this._src.reset();
		with (this._yHandle.style) {
			top  = "0px";
			left = "0px";
		}
		this._moveContent();
		
		if (this._src.totalHeight < this._src.viewableHeight) {
			document.getElementById('cage').className='scrolloff';
			this._disabled = true;
			this._yHandle.style.visibility = "hidden";
			if (this.auto) this._parent.style.visibility = "hidden";
		} else {
			document.getElementById('cage').className='scrollon';
			this._disabled = false;
			this._yHandle.style.visibility = "visible";
			this._parent.style.visibility  = "visible";
		}
	};
	this._addEvent = function (o, t, f) {
		if (o.addEventListener) o.addEventListener(t, f, false);
		else if (o.attachEvent) o.attachEvent('on'+ t, f);
		else o['on'+ t] = f;
	};
	this._removeEvent = function (o, t, f) {
		if (o.removeEventListener) o.removeEventListener(t, f, false);
		else if (o.detachEvent) o.detachEvent('on'+ t, f);
		else o['on'+ t] = null;
	};
	this._findComponent = function (c, o) {
		var kids = o.childNodes;
		for (var i = 0; i < kids.length; i++) {
			if (kids[i].className && kids[i].className == c) {
				return kids[i];
			}
		}
	};
	//Thank you, Quirksmode
	function findOffsetTop (o) {
		var t = 0;
		if (o.offsetParent) {
			while (o.offsetParent) {
				t += o.offsetTop;
				o  = o.offsetParent;
			}
		}
		return t;
	};
	this._scrollbarClick = function (e) {
		if (self._disabled) return false;
		
		e = e ? e : event;
		if (!e.target) e.target = e.srcElement;
		
		if (e.target.className.indexOf("scrollbar-up") > -1) self._scrollUp(e);
		else if (e.target.className.indexOf("scrollbar-down") > -1) self._scrollDown(e);
		else if (e.target.className.indexOf("scrollbar-track") > -1) self._scrollTrack(e);
		else if (e.target.className.indexOf("scrollbar-handle") > -1) self._scrollHandle(e);
		
		self._tempTarget = e.target;
		self._selectFunc = document.onselectstart;
		document.onselectstart = function () {return false;};
		
		self.eventHandler(e.target, "mousedown");
		self._addEvent(document, "mouseup", self._stopScroll, false);
		
		return false;
	};
	this._scrollbarDrag = function (e) {
		e = e ? e : event;
		var t = parseInt(self._yHandle.style.top);
		var v = e.clientY + document.body.scrollTop - self._trackTop;
		with (self._yHandle.style) {
			if (v >= self._trackHeight - self._handleHeight + self._grabPoint)
				top = self._trackHeight - self._handleHeight +"px";
			else if (v <= self._grabPoint) top = "0px";
			else top = v - self._grabPoint +"px";
			self._y = parseInt(top);
		}
		
		self._moveContent();
	};
	this._scrollbarWheel = function (e) {
		e = e ? e : event;
		var dir = 0;
		if (e.wheelDelta >= 120) dir = -1;
		if (e.wheelDelta <= -120) dir = 1;
		
		self.scrollBy(0, dir * 20);
		e.returnValue = false;
	};
	this._startScroll = function (x, y) {
		this._tempDistX = x;
		this._tempDistY = y;
		this._scrollTimer = window.setInterval(function () {
			self.scrollBy(self._tempDistX, self._tempDistY); 
		}, 40);
	};
	this._stopScroll = function () {
		self._removeEvent(document, "mousemove", self._scrollbarDrag, false);
		self._removeEvent(document, "mouseup", self._stopScroll, false);
		
		if (self._selectFunc) document.onselectstart = self._selectFunc;
		else document.onselectstart = function () { return true; };
		
		if (self._scrollTimer) window.clearInterval(self._scrollTimer);
		self.eventHandler (self._tempTarget, "mouseup");
	};
	this._scrollUp = function (e) {this._startScroll(0, -this._scrollDist);};
	this._scrollDown = function (e) {this._startScroll(0, this._scrollDist);};
	this._scrollTrack = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._scroll(0, curY - this._trackTop - this._handleHeight/2);
	};
	this._scrollHandle = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._grabPoint = curY - findOffsetTop(this._yHandle);
		this._addEvent(document, "mousemove", this._scrollbarDrag, false);
	};
	this._scroll = function (x, y) {
		if (y > this._trackHeight - this._handleHeight) 
			y = this._trackHeight - this._handleHeight;
		if (y < 0) y = 0;
		
		this._yHandle.style.top = y +"px";
		this._y = y;
		
		this._moveContent();
	};
	this._moveContent = function () {
		this._src.scrollTo(0, Math.round(this._y * this._ratio));
	};
	
	this.scrollBy = function (x, y) {
		this._scroll(0, (-this._src._y + y)/this._ratio);
	};
	this.scrollTo = function (x, y) {
		this._scroll(0, y/this._ratio);
	};
	this.swapContent = function (o, w, h) {
		this._removeEvent(this._src.content, "mousewheel", this._scrollbarWheel, false);
		this._src.swapContent(o, w, h);
		this.reset();
	};
	
	this.reset();
};