
/* Setup functions called directly from page */
var isIE = /*@cc_on!@*/false;
var mma_interval = 8000;

function setupHovers()
{

	/* Find all <button> elements in the document, and set the onmouseover/onmouseout functionality (add "hv" to className on mouseover) */
	var buttons = document.getElementsByTagName('BUTTON');
	for(var i=0;i<buttons.length;i++) {
		buttons[i].onmouseover = hvOn;
		buttons[i].onmouseout  = hvOff;
	}

	/* Based on contents of input_values object, set initial values of input boxes and behaviour to clear value on focus
	   (only if it's set to original value though, so it won't clear if user changes contents)
	   This also prevents Firefox from holding values on a soft refresh (which some may consider a bad thing..) */
	var inputs = null;
	for(var j in input_values) {
		try { inputs = d(j).getElementsByTagName('INPUT'); }
		catch (e) { }
		if(inputs) {
			for(var i=0;i<inputs.length;i++) {
				if(inputs[i].type=="text") {
					inputs[i].originalValue = input_values[j];
					/* Because this is an onload function, a quick user might jump in and enter text in the box before this javascript is run, so check it's a) empty and b) doesn't have focus before setting the value */
					if((inputs[i].value=="")&&(inputs[i]!=document.activeElement)) {
						inputs[i].value = input_values[j];
					}
					inputs[i].onfocus = clrInput;
				}
			}
		}

	}


	// IE7 fails at hovers ... the following is a list of div #id's we want to apply an onmouseover-set-classname-to-hv rule to on all child <a> tags
	if(isIE) {
		var a_hv = new Array("hld_c","mre_c","mrf","pd_lb_h","db_s");
		var hi;
		// First loop does a "blind" binding of events
		for(i=0;i<a_hv.length;i++) {
			if(d(a_hv[i])) {
				hi = d(a_hv[i]).getElementsByTagName('A');
				for(j=0;j<hi.length;j++) {
					hi[j].onmouseover = hvOn;
					hi[j].onmouseout  = hvOff;
				}
			}
		}

		// Second loop goes through everything and binds the events to items with a certain classname already..
		a_hv = document.getElementsByTagName('A');
		var pcn = new Array("buy","not","checkout_now","no-thanks-button","close-button-a");
		var cn;
		for(i=0;i<a_hv.length;i++) {
			for(j=0;j<pcn.length;j++) {
				cn = pcn[j];
				if(a_hv[i].parentNode.className=="") continue;
				if ( (a_hv[i].parentNode.className && a_hv[i].parentNode.className.search(new RegExp("\\b" + cn + "\\b")) == -1)) {
					a_hv[i].onmouseover = hvOn;
					a_hv[i].onmouseout  = hvOff;
				}
			}

		}

	}


}

function setupPopups()
{

	// this function will translate combine <a> links (class=popup) to work as a popup if javascript is enabled.
	// Usage:
	// <a href="[non-JS link]" target="jsFunctionName" class="popup">Click here for info</a>
	// The above example will launch jsFunctionName() on click (if JS is enabled) and move the value of .href to .url (as it ineeds to set .href to something else)
	// So in jsFunctionName you can access the link's original href via this.url.
	var al = document.getElementsByTagName('A');
	var fn;
	for(var i=0;i<al.length;i++) {
		if(al[i].className=="popup") {
			// test existence of target attribute and if it points to a JS function that exists in the global namespace
			if(al[i].target!="") {
				fn = al[i].target;
				if(eval('typeof '+fn)=="function") {
					eval("al[i].onclick = "+fn+";");
					al[i].url     = al[i].href;
					al[i].href    = "javascript:void(0);"
					al[i].target  = "";
				}
			}
		}
	}

}

function setupMenu()
{

	var hc = d('hc');

	if(d('hc')) {

		// now we need to loop through the unordered lists and clone each one to the side menu.
		if(d('mlc')) {
			var side_menu_ul;
			var test = new Object;
			for(var i=0;i<d('mlc').childNodes.length;i++) {
				if((d('mlc').childNodes[i].tagName=="UL")&&(d('mlc').childNodes[i].className!="sub")) { 
					side_menu_ul = d('mlc').childNodes[i];
					break;
				}
			}

			var thisClass = "";
			var thisClassPieces;
			for(i=0;i<side_menu_ul.childNodes.length;i++) {
				thisClass = side_menu_ul.childNodes[i].className;
				try
				{
					if(side_menu_ul.childNodes[i].tagName=="LI") {
                        thisClassPieces = thisClass.split(" ");
                        thisClass = thisClassPieces[0];
                        test[thisClass] = side_menu_ul.childNodes[i];
                    }
				}
				catch (e)
				{
				}
			}

			var menu = hc.getElementsByTagName('LI');
			var menu_sub,menu_sub_copy;
			for(var i=0;i<menu.length;i++) {
				try
				{
					menu_sub = menu[i].getElementsByTagName('UL');
				}
				catch (e)
				{
					continue;
				}

				for(var j=0;j<menu_sub.length;j++) {

					menu_sub_copy = menu_sub[j].cloneNode(true);
					try {

                        classBits = menu[i].className.split(" ");
                        classBit = classBits[0];
 
                        test[classBit].appendChild(menu_sub_copy);
                    }
					catch (e) { }
				}

			}

		}

	}

	// be aware of potential confusion here though, because of the shuffle, element with ID "hc" becomes a child of "fc" and "fcm" becomes a child of "hc".
	// So the submenu UL's will always be in ID fcm even though it's moved to the header.
	var ma = new Array();
	if(d('mlc')) ma[ma.length] = d('mlc_a').childNodes;

	var thisEl,menus,hasSubs;

	for(var m=0;m<ma.length;m++) {

		menus = ma[m];
		hasSubs = false;

		// following code loops through and assigns the hovers on both the top level menu items as well as the submenu items (doesn't use css :hovers for compatibility reasons)
		for(i=0;i<menus.length;i++) {
			// loop through and flag the index numbers of both UL and A tags
			if (menus[i].tagName=="LI") {
				for (var j=0;j<menus[i].childNodes.length;j++) {
					if(menus[i].childNodes[j].tagName=="UL") {
						menus[i].idx = j;
						hasSubs = true;
					}
					if(menus[i].childNodes[j].tagName=="A") {
						menus[i].lnk = j;
					}
				}
				// set the hover effects for the actual menu 'button'
				if(hasSubs) {
					menus[i].onmouseover = menuOver;
					menus[i].onmouseout  = menuOut;
				} else {
					menus[i].onmouseover = function() { if(this.hv) return; this.hv = true;   doHvOn(this.childNodes[this.lnk]); }
					menus[i].onmouseout  = function() { if(!this.hv) return; this.hv = false; doHvOff(this.childNodes[this.lnk]); }
				}

				if(!hasSubs) continue;

			}

		}

	}

}

function setupBanner()
{

	if(d('mma_btn')) {
		d('mma_btn').style.display='block';
		for(var i=1;i<=5;i++) {
			d('mma_btn_'+i).num = i-1;
			d('mma_btn_'+i).onclick = function() { mma_jump(this.num); }
			if (d('mma_'+i)) {
				d('mma_'+i).style.display='block';
			}
		}

		d('mma_btn_1').active = true;
		doHvOn(d('mma_btn_1'));

		d('mma_btn_pause').onclick = mma_pause;
		d('mma_btn_play').onclick  = mma_play;

		mma = new Spry.Widget.SlidingPanels("mma_sp");
		mma.paused = false;
		mma_setint();

		if(d('mma')) {
			d('mma').onmouseover = function() { clearTimeout(mma_int); };
			d('mma').onmouseout  = function() { mma_setint(); };
		}

		d('mma_all').style.width="10000px";
		for(i=1;i<=5;i++) {
			if(d('mma_'+i)) d('mma_'+i).style.display='block';
		}

		// Setup hovers on the main Spry panel buttons
		var spry_buttons = d('mma_btn');
		if(spry_buttons) {
			for(i=0;i<spry_buttons.childNodes.length;i++) {
				thisEl = spry_buttons.childNodes[i];
				if(thisEl.tagName=="DIV") {
					thisEl.onmouseover = hvOn;
					thisEl.onmouseout  = hvOff;
				}
			}
		}

	}

	setTimeout(setupHiddenBanners,3000);

}

function setupHiddenBanners() {
	for(var i=2;i<=5;i++) {
		try
		{
			d('mma_img'+i).src=d('mma_img'+i).className;
		}
		catch (e)
		{
		}
		
	}
}

function setupProductBoxes() {

	var pp = new Array('mrc','mrd','mrg');
	var panel;
	var pk;
	for(i=0;i<pp.length;i++) {

		// pre-css-js-friendly fixups
		if(!d(pp[i])) { continue; }
		d(pp[i]+'_all').style.width="10000px";
		for(var z=1;z<=5;z++) {
			if(d(pp[i]+'_'+z)) d(pp[i]+'_'+z).style.display='block';
		}
		eval(pp[i]+" = new Spry.Widget.SlidingPanels('"+pp[i]+"_sp');");

		// Setup hovers on the control arrows on the product boxes
		panel = d(pp[i]);
		if(panel) {
			pk = panel.childNodes;
			for(j=0;j<pk.length;j++) {
				if((pk[j].tagName=="DIV")&&(pk[j].className.substring(0,3)=="btn")) {
					// get the child div within this element :)
					pk[j].panel = pp[i];
					for(k=0;k<pk[j].childNodes.length;k++) {
						if(pk[j].childNodes[k].tagName=="DIV") {
							pk[j].childNodes[k].onmouseover = hvOn;
							pk[j].childNodes[k].onmouseout = hvOff;
						}
						if(pk[j].className.substring(0,6)=="btn_rb") {
							pk[j].style.display='block';
							pk[j].childNodes[k].onclick = prod_fwd;
							panel.btn_rb_ref = pk[j];
						} else if(pk[j].className.substring(0,6)=="btn_lb") {
							pk[j].childNodes[k].onclick = prod_bck;
							panel.btn_lb_ref = pk[j];
						}
					}
				}
			}
		}
	}

}

function setupMiniCart()
{
	var t = d('mre_e');
	t.innerHTML = "&#x25BC; Hide";
	t.style.visibility = 'visible';
	t.onclick = function() {
		var t = d('mre_e');
		var i = d('mre_i');
		if(i.style.display!="none") {
			t.innerHTML = "&#x25BA; Show";
			i.style.display="none";
		} else {
			t.innerHTML = "&#x25BC; Hide";
			i.style.display="block";
		}
	}

}

function setupProductTabs()
{
	var box = false;
	try { box = d('pd_tabs'); }
	catch (e) { }
	if(!box) return false;
	if(box.className=="tabs") return true;
	box.className = "tabs";
	var cn = "tab-content";
	var ct,cl,ca,i,j,k;
	for(i=0;i<box.childNodes.length;i++) {
		ct = box.childNodes[i];
		if(ct.tagName!="UL") continue;
		box.listItems = new Array();
		for(j=0;j<ct.childNodes.length;j++) {
			cl = ct.childNodes[j];
			if(cl.tagName!="LI") continue;
			for(k=0;k<cl.childNodes.length;k++) {
				ca = cl.childNodes[k];
				if(ca.tagName=="A") {
					var t = ca.href.split("#");
					cl.refName = t[1];
					ca.href = "javascript:tabC(d('pd_tabs'),'"+t[1]+"');";
				}
			}
			box.listItems[box.listItems.length] = cl;
		}

	}
}

function setupProductImages()
{
	if(d('pd_piclnk')) {
		d('pd_piclnk').style.display='block';
		d('pd_piclnk_a').href="javascript:imgBig();";
		if(d('pd_img_')) {
			d('pd_img_').style.cursor='pointer';
			d('pd_img_').onclick = imgBig;
		}
	}

	var tnDivs, imgDivs;
	tnDivs  = new Array("pd_tn","pd_lb_tn");
	imgDivs = new Array("pd_imgtag", "pd_lb_imgtag");

	var tn,imgbox;
	var i,j,k;
	var tu,tl,ta;
	for(var l=0;l<tnDivs.length;l++) {
		tn = d(tnDivs[l]);
		imgbox = d(imgDivs[l]);
		if((tn)&&(imgbox)) {
			for(i=0;i<tn.childNodes.length;i++) {
				tu = tn.childNodes[i];
				if(tu.tagName!="UL") continue;
				for(j=0;j<tu.childNodes.length;j++) {
					tl = tu.childNodes[j];
					tl.tn     = tn;
					tl.imgbox = imgbox;
					if(tl.tagName!="LI") continue;
					for(k=0;k<tl.childNodes.length;k++) {
						ka = tl.childNodes[k];
						if(ka.tagName!="A") continue;
						tl.lnk = ka.href;
						ka.href="javascript:void(0);";
					}
					if(tnDivs[l].indexOf("lb")==-1) {
						tl.onmouseover = imgTn;
					} else {
						tl.onclick = imgTn;
					}
				}
			}
		}
	}

}

function setupReviewClipping()
{
	if(!d('customer_reviews')) return false;

	var c = d('customer_reviews').getElementsByTagName('DIV');
	var x;
	var cnt=0;
	for(var i=0;i<c.length;i++) {
		if(c[i].className=="pd_rvw") {
			cnt++;
			if(cnt>5) c[i].className="pd_rvw ext";
		}
	}
	var more = document.createElement("A");
	more.id = "pd_rvw_viewmore";
	more.textContent = "View more comments �";
	more.innerText = "View more comments �";
	if(isIE) {
		// IE has issues with rendering the expanding comments on the current design, so we just link to a page to show all
		more.href=document.location.pathname+"?view=all";
	} else {
		more.href="javascript:void(0);"
		more.onclick = moreRvws;
	}

	d('pd_rvw_box').parentNode.insertBefore(more,d('pd_rvw_box').nextSibling);

	return true;
}

function moreRvws()
{
	if(!d('customer_reviews')) return false;
	var c = d('customer_reviews').getElementsByTagName('DIV');
	var x;
	var cnt=0;
	for(var i=0;i<c.length;i++) {
		if(c[i].className=="pd_rvw ext") {
			cnt++;
			if(cnt<=5) c[i].className="pd_rvw";
		}
	}
	if(cnt<=5) d('customer_reviews').removeChild(d('pd_rvw_viewmore'));
}



function multipleItemShippingPopUp() {
	day = new Date();
	URL = 'http://www.dealsdirect.com.au/static/combined-shipping-info.htm';
	id = 102;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=480,left = 540,top = 285');");
}
function multipleItemPerfumePopUp() {
	day = new Date();
	URL = 'http://www.dealsdirect.com.au/static/combined-shipping-perfume-info.htm';
	id = 102;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=480,left = 540,top = 285');");
}
function multipleItemBooksPopUp() {
	day = new Date();
	URL = 'http://www.dealsdirect.com.au/static/combined-shipping-books-info.htm';
	id = 102;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=480,left = 540,top = 285');");
}
function picknmixWineCasePopUp() {
	day = new Date();
	URL = 'http://www.dealsdirect.com.au/static/picknmix-wine-case-info.htm';
	id = 102;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=480,left = 540,top = 285');");
}

function notifyMe()
{
	var url = this.url;
	tellWindow = window.open(url, 'notify', 'height=470, width=400, left=50,top=50, resizable, scrollbars, status');
	tellWindow.top.focus();
}

function popVeri()
{
	var url = this.url;
	tellWindow = window.open(url, 'verisign', 'height=500, width=560');
	tellWindow.top.focus();
}



/* Support global variables & functions */

var mma,mma_int;
var mrc,mrd,mrg;

function d(e) { try { return document.getElementById(e); } catch(e) { return false; } }

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function menuOver(evt)
{
	evt = (evt) ? evt : window.event;
	evt.cancelBubble = true;
	if(isIE) this.style.zIndex="10";
	doHvOn(this.childNodes[this.lnk]);
	doHvOn(this.childNodes[this.idx]);
}

function menuOut(evt)
{
	evt = (evt) ? evt : window.event;
	var onto = evt.toElement;
	if(onto!=null) {
		do {
			if(onto==this) {
				evt.cancelBubble = true;
				return;
			}
		} while((onto=onto.parentElement)!=null);
	}
	if(isIE) this.style.zIndex="";
	doHvOff(this.childNodes[this.lnk]);
	doHvOff(this.childNodes[this.idx]);
}

// generic hover functions, hvOn adds "hv" to the className of the element, hvOff removes it without affecting any other class names that may exist

function ul2sel(el)
{
	var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	if(isIE6) return false;
	if(el.tagName=="UL") {
		var newSel = document.createElement('SELECT');
		try { newSel.id = el.id; } catch (e) { }     // copy #id to select element
		var newOpt = document.createElement('OPTION');
		newOpt.text  = "Please select ...";
		newOpt.value = "";
		try { newSel.add(newOpt,null); } catch (e) { newSel.add(newOpt); }

		var li,a,count;

		count = 0;

		newSel.onchange = function() { var val = this.options[this.selectedIndex].value; if(val!="") { document.location.href = this.options[this.selectedIndex].value; } }
		for(var j=0;j<el.childNodes.length;j++) {
			li = el.childNodes[j];
			if(li.tagName=="LI") {
				// we're in the LI tag, now dive in and find the <A> tag
				for(var k=0;k<li.childNodes.length;k++) {
					a = li.childNodes[k];
					if(a.tagName=="A") {
						newOpt = document.createElement('OPTION');
						newOpt.text = a.innerText || a.textContent;
						newOpt.value = a.href;
						try { newSel.add(newOpt,null); count++; } catch (e) { newSel.add(newOpt); count++; }
						if(li.className=="act") newSel.selectedIndex = count;
					}
				}
			}
		}
		el.parentNode.insertBefore(newSel,el);
		el.parentNode.removeChild(el);
	}
}

function hvOn()
{
	doHvOn(this);
}
function doHvOn(el)
{
	addC(el,"hv");
}
function hvOff()
{
	doHvOff(this);
}
function doHvOff(el)
{
	try
	{
		if(el.active) return true;
	}
	catch (e)
	{
	}
	remC(el,"hv");
}

// clear an input box on focus/select
function clrInput()
{
	if(this.value==this.originalValue) {
		this.value = "";
	}
	return true;
}

function mma_setint()
{
	clearTimeout(mma_int);
	mma_int = setTimeout(mma_nextPanel, mma_interval);
}

function mma_jump(n)
{
	clearTimeout(mma_int);
	for(var i=1;i<=5;i++) {
		d('mma_btn_'+i).active = false;
		doHvOff(d('mma_btn_'+i));
	}
	d('mma_btn_'+(n+1)).active = true;
	doHvOn(d('mma_btn_'+(n+1)));
	mma.showPanel(n);
	if(!mma.paused) mma_setint();
}

function mma_nextPanel()
{
	var cur = mma.getContentPanelIndex(mma.currentPanel) + 1;
	if(cur==5) cur=0;
	mma_jump(cur);
}

function mma_pause()
{
	clearTimeout(mma_int);
	mma.paused = true;
	d('mma_btn_pause').style.display='none';
	d('mma_btn_play').style.display='block';
}

function mma_play()
{
	clearTimeout(mma_int);
	mma.paused = false;
	mma_setint();
	d('mma_btn_pause').style.display='block';
	d('mma_btn_play').style.display='none';
}

function prod_fwd()
{
	var el = this.parentNode;
	eval('var panel = '+this.parentNode.panel+';');
	var cur = panel.getContentPanelIndex(panel.currentPanel) + 1;
	if(cur>0) {
		el.parentNode.btn_lb_ref.style.display="block";
	}
	if(cur==(panel.getContentPanels().length-1)) {
		el.parentNode.btn_rb_ref.style.display="none";
	}
	panel.showNextPanel();
}

function prod_bck()
{
	var el = this.parentNode;
	eval('var panel = '+this.parentNode.panel+';');
	var cur = panel.getContentPanelIndex(panel.currentPanel) + 1;
	if(cur<=2) {
		el.parentNode.btn_lb_ref.style.display="none";
	}
	if(cur<=panel.getContentPanels().length) {
		el.parentNode.btn_rb_ref.style.display="block";
	}
	panel.showPreviousPanel();
}

function tabC(el,tab)
{
	var cn = "tab-content";
	var ct;
	for(var i=0;i<el.childNodes.length;i++) {
		ct = el.childNodes[i];
		if(ct.tagName!="DIV") continue;
		if(ct.className.search(new RegExp("\\b"+cn+"\\b"))!=-1) {
			ct.style.display=(ct.id==tab)?"block":"none";
		}
	}
	for(i=0;i<el.listItems.length;i++) {
		el.listItems[i].className=(el.listItems[i].refName==tab)?"active":"";
	}

}

function imgBig()
{
	if(!TINY) return false;
	TINY.box.show(false,0,907,700,0);
}

function imgTn()
{
	doImgTn(this)
}

function doImgTn(el)
{
	if(!el) return;
	rstThumbHovers(el.tn);
	doHvOn(el);
	if (d('pd_lb_img')) {
		var r = d('pd_lb_img').rotator;
		if (r != undefined) {
			if (r.loaded) r.unload();
		}
	}
	if(el.lnk && el.lnk.substring((el.lnk.length-3))=="jpg") {
		MM_preloadImages(el.lnk);
		el.imgbox.src=el.lnk;
		if(d('pd_lb_flash')) d('pd_lb_flash').style.display='none';
		if(d('pd_lb_img'))   d('pd_lb_img').style.display='block';
	} else if (el.lnk) {
		if(d('pd_lb_flash')) {
			d('pd_lb_flash').innerHTML = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' WIDTH='600' HEIGHT='600' id='movie_preview'><PARAM NAME='movie' VALUE="+el.lnk+"><PARAM NAME='quality' VALUE='high'><PARAM NAME='wmode' VALUE='transparent'><PARAM NAME='bgcolor' VALUE='#FFFFFF'><EMBED src="+el.lnk+" quality='high' bgcolor='#FFFFFF' wmode='transparent' WIDTH='600' HEIGHT='600' NAME='movie' ALIGN='' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>";
		}
		if(d('pd_lb_img'))   d('pd_lb_img').style.display='none';
		if(d('pd_lb_flash')) d('pd_lb_flash').style.display='block';
	}
}

function rstThumbHovers(el)
{
	var tn = el;
	var i,j;
	var tu,tl;
	if(tn) {
		for(i=0;i<tn.childNodes.length;i++) {
			tu = tn.childNodes[i];
			if(tu.tagName!="UL") continue;
			for(j=0;j<tu.childNodes.length;j++) {
				tl = tu.childNodes[j];
				if(tl.tagName!="LI") continue;
				doHvOff(tl);
			}
		}
	}

}


function addC(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

function remC(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

function jumpTo(anchor)
{
    /* Given an anchor, blank and set location.hash to it */
    window.location.hash = '#top';
    window.location.hash = '#'+anchor;
};

var Spry;Spry||(Spry={});if(!Spry.Widget)Spry.Widget={};Spry.Widget.SlidingPanels=function(a,b){this.element=this.getElement(a);this.enableAnimation=true;this.currentPanel=null;this.enableKeyboardNavigation=true;this.hasFocus=false;this.previousPanelKeyCode=Spry.Widget.SlidingPanels.KEY_LEFT;this.nextPanelKeyCode=Spry.Widget.SlidingPanels.KEY_RIGHT;this.currentPanelClass="spcp";this.focusedClass="spf";this.animatingClass="spa";Spry.Widget.SlidingPanels.setOptions(this,b);if(this.element)this.element.style.overflow="hidden";if(this.defaultPanel)this.currentPanel=
typeof this.defaultPanel=="number"?this.getContentPanels()[this.defaultPanel]:this.getElement(this.defaultPanel);if(!this.currentPanel)this.currentPanel=this.getContentPanels()[0];Spry.Widget.SlidingPanels.onloadDidFire?this.attachBehaviors():Spry.Widget.SlidingPanels.loadQueue.push(this)};Spry.Widget.SlidingPanels.prototype.onFocus=function(a){this.hasFocus=true;this.addClassName(this.element,this.focusedClass);return false};
Spry.Widget.SlidingPanels.prototype.onBlur=function(a){this.hasFocus=false;this.removeClassName(this.element,this.focusedClass);return false};Spry.Widget.SlidingPanels.KEY_LEFT=37;Spry.Widget.SlidingPanels.KEY_UP=38;Spry.Widget.SlidingPanels.KEY_RIGHT=39;Spry.Widget.SlidingPanels.KEY_DOWN=40;
Spry.Widget.SlidingPanels.prototype.onKeyDown=function(a){var b=a.keyCode;if(!this.hasFocus||b!=this.previousPanelKeyCode&&b!=this.nextPanelKeyCode)return true;b==this.nextPanelKeyCode?this.showNextPanel():this.showPreviousPanel();if(a.preventDefault)a.preventDefault();else a.returnValue=false;if(a.stopPropagation)a.stopPropagation();else a.cancelBubble=true;return false};
Spry.Widget.SlidingPanels.prototype.attachBehaviors=function(){var a=this.element;if(a){if(this.enableKeyboardNavigation){var b=null,c=a.attributes.getNamedItem("tabindex");if(c||a.nodeName.toLowerCase()=="a")b=a;if(b){var f=this;Spry.Widget.SlidingPanels.addEventListener(b,"focus",function(e){return f.onFocus(e||window.event)},false);Spry.Widget.SlidingPanels.addEventListener(b,"blur",function(e){return f.onBlur(e||window.event)},false);Spry.Widget.SlidingPanels.addEventListener(b,"keydown",function(e){return f.onKeyDown(e||
window.event)},false)}}if(this.currentPanel){a=this.enableAnimation;this.enableAnimation=false;this.showPanel(this.currentPanel);this.enableAnimation=a}}};Spry.Widget.SlidingPanels.prototype.getElement=function(a){if(a&&typeof a=="string")return document.getElementById(a);return a};Spry.Widget.SlidingPanels.prototype.addClassName=function(a,b){!a||!b||a.className&&a.className.search(new RegExp("\\b"+b+"\\b"))!=-1||(a.className+=(a.className?" ":"")+b)};
Spry.Widget.SlidingPanels.prototype.removeClassName=function(a,b){if(!(!a||!b||a.className&&a.className.search(new RegExp("\\b"+b+"\\b"))==-1))a.className=a.className.replace(new RegExp("\\s*\\b"+b+"\\b","g"),"")};Spry.Widget.SlidingPanels.setOptions=function(a,b,c){if(b)for(var f in b)c&&b[f]==undefined||(a[f]=b[f])};Spry.Widget.SlidingPanels.prototype.getElementChildren=function(a){var b=[];for(a=a.firstChild;a;){a.nodeType==1&&b.push(a);a=a.nextSibling}return b};
Spry.Widget.SlidingPanels.prototype.getCurrentPanel=function(){return this.currentPanel};Spry.Widget.SlidingPanels.prototype.getContentGroup=function(){return this.getElementChildren(this.element)[0]};Spry.Widget.SlidingPanels.prototype.getContentPanels=function(){return this.getElementChildren(this.getContentGroup())};Spry.Widget.SlidingPanels.prototype.getContentPanelsCount=function(){return this.getContentPanels().length};Spry.Widget.SlidingPanels.onloadDidFire=false;
Spry.Widget.SlidingPanels.loadQueue=[];Spry.Widget.SlidingPanels.addLoadListener=function(a){if(typeof window.addEventListener!="undefined")window.addEventListener("load",a,false);else if(typeof document.addEventListener!="undefined")document.addEventListener("load",a,false);else typeof window.attachEvent!="undefined"&&window.attachEvent("onload",a)};
Spry.Widget.SlidingPanels.processLoadQueue=function(a){Spry.Widget.SlidingPanels.onloadDidFire=true;a=Spry.Widget.SlidingPanels.loadQueue;for(var b=a.length,c=0;c<b;c++)a[c].attachBehaviors()};Spry.Widget.SlidingPanels.addLoadListener(Spry.Widget.SlidingPanels.processLoadQueue);Spry.Widget.SlidingPanels.addEventListener=function(a,b,c,f){try{if(a.addEventListener)a.addEventListener(b,c,f);else a.attachEvent&&a.attachEvent("on"+b,c)}catch(e){}};
Spry.Widget.SlidingPanels.prototype.getContentPanelIndex=function(a){if(a){a=this.getElement(a);for(var b=this.getContentPanels(),c=b.length,f=0;f<c;f++)if(b[f]==a)return f}return-1};
Spry.Widget.SlidingPanels.prototype.showPanel=function(a){var b=-1;b=typeof a=="number"?a:this.getContentPanelIndex(a);a=this.getContentPanelsCount();b=a>0?b>=a?a-1:b:0;var c=this.getContentPanels()[b];b=this.getContentGroup();if(c&&b){this.currentPanel&&this.removeClassName(this.currentPanel,this.currentPanelClass);this.currentPanel=c;a=-c.offsetLeft;var f=-c.offsetTop;if(this.enableAnimation){this.animator&&this.animator.stop();var e=b.offsetLeft,g=b.offsetTop;if(e!=a||g!=f){var h=this;this.addClassName(this.element,
this.animatingClass);this.animator=new Spry.Widget.SlidingPanels.PanelAnimator(b,e,g,a,f,{duration:this.duration,fps:this.fps,transition:this.transition,finish:function(){h.removeClassName(h.element,h.animatingClass);h.addClassName(c,h.currentPanelClass)}});this.animator.start()}}else{b.style.left=a+"px";b.style.top=f+"px";this.addClassName(c,this.currentPanelClass)}}return c};Spry.Widget.SlidingPanels.prototype.showFirstPanel=function(){return this.showPanel(0)};
Spry.Widget.SlidingPanels.prototype.showLastPanel=function(){return this.showPanel(this.getContentPanels().length-1)};Spry.Widget.SlidingPanels.prototype.showPreviousPanel=function(){return this.showPanel(this.getContentPanelIndex(this.currentPanel)-1)};Spry.Widget.SlidingPanels.prototype.showNextPanel=function(){return this.showPanel(this.getContentPanelIndex(this.currentPanel)+1)};
Spry.Widget.SlidingPanels.PanelAnimator=function(a,b,c,f,e,g){this.element=a;this.curX=b;this.curY=c;this.dstX=f;this.dstY=e;this.fps=60;this.duration=500;this.transition=Spry.Widget.SlidingPanels.PanelAnimator.defaultTransition;this.timerID=this.startTime=0;this.finish=null;var h=this;this.intervalFunc=function(){h.step()};Spry.Widget.SlidingPanels.setOptions(this,g,true);this.interval=1000/this.fps};
Spry.Widget.SlidingPanels.PanelAnimator.defaultTransition=function(a,b,c,f){a/=f;return b+(2-a)*a*c};Spry.Widget.SlidingPanels.PanelAnimator.prototype.start=function(){this.stop();this.startTime=(new Date).getTime();this.timerID=setTimeout(this.intervalFunc,this.interval)};Spry.Widget.SlidingPanels.PanelAnimator.prototype.stop=function(){this.timerID&&clearTimeout(this.timerID);this.timerID=0};
Spry.Widget.SlidingPanels.PanelAnimator.prototype.step=function(){var a=(new Date).getTime()-this.startTime,b=a>=this.duration,c;if(b){c=this.curX=this.dstX;a=this.curY=this.dstY}else{c=this.transition(a,this.curX,this.dstX-this.curX,this.duration);a=this.transition(a,this.curY,this.dstY-this.curY,this.duration)}this.element.style.left=c+"px";this.element.style.top=a+"px";if(b)this.finish&&this.finish();else this.timerID=setTimeout(this.intervalFunc,this.interval)};
var TINY={};var isIE6=((navigator.userAgent.indexOf("MSIE 6.")!=-1)&&(navigator.userAgent.indexOf("Opera")==-1));function T$(i){return document.getElementById(i)}
TINY.box=function(){var p,m,b,fn,ic,iu,iw,ih,ia,f=0;return{show:function(c,u,w,h,a,t){document.onkeypress=esc_hide;if(!f){if(c==false){p=d('tb');m=d('tbm');b=d('tbc');}else{p=document.createElement('div');p.id='tb';m=document.createElement('div');m.id='tbm';b=document.createElement('div');b.id='tbc';document.body.appendChild(m);document.body.appendChild(p);p.appendChild(b);}
m.onclick=TINY.box.hide;window.onresize=TINY.box.resize;if(isIE6)window.onscroll=TINY.box.resize;f=1}
if(!a&&!u){p.style.width=w?w+'px':'auto';p.style.height=h?h+'px':'auto';p.style.backgroundImage='none';if(c){b.innerHTML=c}else{b.style.display='block';}}else{b.style.display='none';p.style.width=p.style.height='100px'}
this.mask();ic=c;iu=u;iw=w;ih=h;ia=a;this.alpha(m,1,80,3);if(t){setTimeout(function(){TINY.box.hide()},1000*t)}},fill:function(c,u,w,h,a){if(u){p.style.backgroundImage='';var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');x.onreadystatechange=function(){if(x.readyState==4&&x.status==200){TINY.box.psh(x.responseText,w,h,a)}};x.open('GET',c,1);x.send(null)}else{this.psh(c,w,h,a)}},psh:function(c,w,h,a){if(a){if(!w||!h){var x=p.style.width,y=p.style.height;if(c){b.innerHTML=c;}
p.style.width=w?w+'px':'';p.style.height=h?h+'px':'';b.style.display='';w=parseInt(b.offsetWidth);h=parseInt(b.offsetHeight);b.style.display='none';p.style.width=x;p.style.height=y;}else{if(c){b.innerHTML=c;}}
this.size(p,w,h)}else{p.style.backgroundImage='none'}},hide:function(){TINY.box.alpha(p,-1,0,3)},resize:function(){TINY.box.pos();TINY.box.mask()},mask:function(){m.style.height=TINY.page.total(1)+'px';m.style.width='';m.style.width=TINY.page.total(0)+'px'},pos:function(){var t=(TINY.page.height()/2)-(p.offsetHeight/2);t=t<10?10:t;if(isIE6)p.style.top=(t+TINY.page.top())+'px';else p.style.top=t+'px';p.style.left=(TINY.page.width()/2)-(p.offsetWidth/2)+'px'},alpha:function(e,d,a){d=a;clearInterval(e.ai);if(d>0){e.style.opacity=d/100;e.style.filter='alpha(opacity='+d+')'
e.style.display='block';this.pos()
e==m?this.alpha(p,1,100):TINY.box.fill(ic,iu,iw,ih,ia)}else{e.style.display='none';e==p?TINY.box.alpha(m,-1,0,2):true}},ta:function(e,a,d){var o=Math.round(e.style.opacity*100);if(o==a){clearInterval(e.ai);if(d==-1){e.style.display='none';e==p?TINY.box.alpha(m,-1,0,2):true}else{e==m?this.alpha(p,1,100):TINY.box.fill(ic,iu,iw,ih,ia)}}else{var n=Math.ceil((o+((a-o)*.5)));n=n==1?0:n;e.style.opacity=n/100;e.style.filter='alpha(opacity='+n+')'}},size:function(e,w,h){e=typeof e=='object'?e:T$(e);clearInterval(e.si);var ow=e.offsetWidth,oh=e.offsetHeight,wo=ow-parseInt(e.style.width),ho=oh-parseInt(e.style.height);var wd=ow-wo>w?0:1,hd=(oh-ho>h)?0:1;e.si=setInterval(function(){TINY.box.ts(e,w,wo,wd,h,ho,hd)},20)},ts:function(e,w,wo,wd,h,ho,hd){var ow=e.offsetWidth-wo,oh=e.offsetHeight-ho;if(ow==w&&oh==h){clearInterval(e.si);p.style.backgroundImage='none';b.style.display='block'}else{if(ow!=w){var n=ow+((w-ow)*.5);e.style.width=wd?Math.ceil(n)+'px':Math.floor(n)+'px'}
if(oh!=h){var n=oh+((h-oh)*.5);e.style.height=hd?Math.ceil(n)+'px':Math.floor(n)+'px'}
this.pos()}}}}();TINY.page=function(){return{top:function(){return document.documentElement.scrollTop||document.body.scrollTop},width:function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},height:function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},total:function(d){var b=document.body,e=document.documentElement;return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))}}}();function esc_hide(e){if(!e)e=window.event;if(e.keyCode=="27"){TINY.box.hide();document.onkeypress=null;}}
if (!Array.prototype.contains) {
	Array.prototype.contains = function(value) {
		for (var i = 0; i < this.length; i++) {
			if (this[i] == value) {
				return true;
			}
		}
		return false;
	};
}

DD = {};
DD.Init = function() { };
DD.addClass = function(o, classname) {
	var classes;
	if (o.className == undefined) {
		classes = [];
	} else {
		classes = o.className.split(' ');
	}
	if (!classes.contains(classname)) {
		o.className += ' ' + classname.replace(/[^a-zA-Z0-9-]/,'').toLowerCase();
	}
};
DD.removeClass = function(o, classname) {
	 var regex = new RegExp('(\\s|^)' + classname);
	o.className = o.className.replace(regex,'');
};
DD.hasClass = function(o, classname) {
	if (o.className == undefined) {
		return false;
	}
	var classes = o.className.split(' ');
	return classes.contains(classname);
};
DD.getElementsByClassName = function(o, classname) {
	var results = [];
	if (typeof(o) == typeof(document) && o.body) {
		o = o.body;
	}
	for (var i = 0; i < o.childNodes.length; i++) {
		if (DD.hasClass(o.childNodes[i], classname)) {
			results.push(o.childNodes[i]);
		}
		results = results.concat(DD.getElementsByClassName(o.childNodes[i], classname));
	}
	return results;
};
DD.addEventListener = function(o, event, handler) {
	if (o.addEventListener) {
		o.addEventListener(event, handler, false);
	} else if (o.attachEvent) {
		o.attachEvent('on' + event, handler);
	}
};
DD.removeEventListener = function(o, event, handler) {
	if (o.removeEventListener) {
		o.removeEventListener(event, handler, false);
	} else if (o.detachEvent) {
		o.detachEvent('on' + event, handler);
	}
};
DD.stopPropagation = function(event) {
	if (event.stopPropagation) {
		event.stopPropagation();
	} else {
		event.cancelBubble = true;
	}
};
DD.stopSubmit = function(event) {
	if (event.preventDefault) {
		event.preventDefault();
	} else if (window.event) {
        window.event.returnValue = false;
    }
	return false;
};

DD.Popup = function(url, override) {
	var defaults = {'status':0,'toolbar':0,'location':0,'menubar':0,'width':400,'height':400}
	for (var key in override) {
		defaults[key] = override[key];
	}
	if (!override.top) defaults.top = (screen.height / 2) - (defaults.height / 2);
	if (!override.left) defaults.left = (screen.width / 2) - (defaults.width / 2);

	var opts = [];
	for (var key in defaults) {
		opts.push(key + '=' + defaults[key]);
	}
	window.open(url,'_blank', opts.join(','));
}

DD.ResultSet = function(node, url) {
	this.root = document.getElementById(node);
	this.url = url;
	var rows = this.root.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
	for (var i = 0; i < rows.length; i++) {
		this.add(rows[i]);
	}
};
DD.ResultSet.prototype.add = function(node) {
	var tmp = this;
	DD.addEventListener(node, 'mouseover', function() { DD.addClass(node, 'selected'); });
	DD.addEventListener(node, 'mouseout', function() { DD.removeClass(node, 'selected'); });
	DD.addEventListener(node, 'click', function() { document.location.href = tmp.url + '&id=' + node.id.substr('transaction-'.length); });
};

DD.Modal = function(src, opts) {
	var tmp = this;
    if (opts == null) {
		opts = {};
	}
    this.overlay = document.createElement('div');
    this.overlay.className = 'dd-overlay';
    document.body.appendChild(this.overlay);
    this.frame = document.createElement('iframe');
    if (opts.init != null) {
	    this.frame.onload = opts.init;
	}
    document.body.appendChild(this.frame);
    document.body.style.overflow = 'hidden';
    this.frame.src = src;
    this.frame.className = 'dd-popup';
    this.frame.style.width = (opts.width == null ? 550 : opts.width) + 'px';
    this.frame.style.height = (opts.height == null ? 350 : opts.height) + 'px';
	var doc = document;
	DD.addEventListener(this.frame, 'load', function() {
		tmp.frame.style.left = Math.floor((doc.body.clientWidth - tmp.frame.contentDocument.body.clientWidth) / 2) + 'px';
		tmp.frame.contentDocument.modal = tmp;
	});
};
DD.Modal.prototype.close = function() {
    document.body.removeChild(this.frame);
    document.body.removeChild(this.overlay);
	document.body.style.overflow = 'auto';
};
DD.Modal.prototype.fit = function() {
	this.frame.style.height = (this.frame.contentDocument.body.clientHeight + 8) + 'px';
}

DD.FileBrowser = function(source) {
	var tmp = this;
    this.source = source;
    var url = '/?type=filebrowser';
    if (this.source.value != '') {
		url += '&location=' + this.source.value;
	}
    this.modal = new DD.Modal(url, {'init': function() { tmp.init(); }});
	this.modal.frame.contentDocument.filebrowser = this;
};
DD.FileBrowser.prototype.init = function() {
	var i;
	var tmp = this;
	var anchors = this.modal.frame.contentDocument.getElementsByTagName('a');
	for (i = 0; i < anchors.length; i++) {
		var a = anchors[i];
		if (a.className == 'file') {
			a.addEventListener('click', function(e) { tmp.source.value = a.pathname;
			                                          DD.stopPropagation(e);
			                                          tmp.modal.close(); }, false);
		}
	}
	var buttons = this.modal.frame.contentDocument.getElementById('footer').getElementsByTagName('input');
	for (i = 0; i < buttons.length; i++) {
		switch (buttons[i].value) {
			case 'OK':
				buttons[i].addEventListener('click', function() { tmp.source.value = tmp.modal.frame.contentDocument.getElementById('location').innerHTML;
				                                                  tmp.modal.close(); }, false);
				break;
			case 'Cancel':
				buttons[i].addEventListener('click', function() { tmp.modal.close(); }, false);
				break;
			default:
				break;
		}
	}
};

DD.Url = function(url) {
	this.relative = false;
	this.protocol = null;
	this.domain = null;
	this.path = null;
	this.args = {};
	if (url == null) url = document.location.href;
	this.parse(url);
}
DD.Url.prototype.parse = function(url) {
	var regex = /^((([a-zA-Z]+):\/\/)(([a-zA-Z0-9_]+\.)+([a-zA-Z0-9_]+)))?((\/[^\/\?]*)*)(\?(.+))?/;
	var index = 0;
	match = regex.exec(url);
	if (match) {
		if (match.length >= 2) this.protocol = match[3];
		if (match.length >= 3) this.domain = match[4];
		if (match.length >= 6) this.path = match[7];
		if (match.length >= 9) {
			var args = match[10].split('&');
			for (var i = 0; i < args.length; i++) {
				var pair = args[i].split('=');
				this.args[pair[0]] = (pair.length > 1 ? pair[1] : null);
			}
		}
	}
	this.relative = (this.domain != null);
}
DD.Url.prototype.toString = function() {
	args = [];
	for (key in this.args) {
		args.push(key + '=' + this.args[key]);
	}
	return (this.protocol != null ? this.protocol + '://' : '') + (this.domain != null ? this.domain : '') + (this.path != null ? this.path : '') + '?' + args.join('&');
}

DD.FormValidator = function(form) {
	var tmp = this;
	this.form = form;
	this.error = 'The following problems were encountered:';
	this.elements = {};
	this.messages = {};
	this.realtime = false;
	this.form.validator = this;
	DD.addEventListener(this.form, 'submit', function(e) {
		if (!tmp.validate()) {
			tmp.alert();
			return DD.stopSubmit(e);
		}
	});
};
DD.FormValidator.prototype.alert = function() {
	if (this.error != null) {
		window.alert(this.getMessage());
	}
};
DD.FormValidator.prototype.require = function(name, regex, error) {
	if (this.form[name] == null) {
		alert('Field "' + name + '" does not exist');
	}
	if (error == null) {
		if (regex == null) {
			error = name + ' is required';
		} else {
			error = name + ' is not valid';
		}
	}
	this.elements[name] = ({'name':name,'regex':(regex==null?null:new RegExp(regex)),'error':error,'valid':true});
};
DD.FormValidator.prototype.validate = function(name) {
	if (name == null) {
		var eValid = false;
		this.valid = true;
		this.messages = {};
		for (var key in this.elements) {
			eValid = this.validate(key, true);
			if (this.realtimeCallback != null) {
				this.realtimeCallback(this.form[key], eValid, this.elements[key].error);
			}
		}
		return this.valid;
	} else {
		if ((this.elements[name].regex == null && this.form[name].value == '') || (this.elements[name].regex != null && !this.elements[name].regex.exec(this.form[name].value))) {
			this.valid = false;
			this.messages[name] = this.elements[name].error;
			return false;
		}
		this.messages[name] = null;
		return true;
	}
	return this.valid;
};
DD.FormValidator.prototype.setRealtime = function(callback)  {
	var key;

	this.realtimeCallback = callback;
	for (var key in this.elements) {
		this.addRealtime(this.form[key], callback);
	}
};
DD.FormValidator.prototype.addRealtime = function(node, callback) {
	var valid;
	var tmp = this;
	this.elements[node.name].realtimeHandler = function(e) {
		if (tmp.realtimeCallback != null) {
			valid = tmp.validate(node.name);
			tmp.realtimeCallback(node, valid, tmp.elements[node.name].error);
		}
	};
	DD.addEventListener(node, 'blur', function() { tmp.elements[node.name].realtimeHandler(); });
	if (node.tagName == 'SELECT') {
		DD.addEventListener(node, 'change', function() { tmp.elements[node.name].realtimeHandler(); });
	}
};
DD.FormValidator.prototype.getMessage = function() {
	var m = this.error;
	 for (key in this.messages) {
		if (this.messages[key] != null) {
			m += "\n - " + this.messages[key];
		}
	 }
	return m;
};

DD.Ajax = function(url) {
	this.url = url;
	this.data = {};
}
DD.Ajax.prototype.send = function() {
	var tmp = this;
	if (window.XMLHttpRequest && !(window.ActiveXObject)) {
		this.request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			this.request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			this.request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	if (this.responseHandler) {
		this.request.onreadystatechange = function(e) {
			if (tmp.request.readyState == 4) {
				tmp.responseHandler(tmp.request);
			}
		}
	}
	this.request.open("GET", this.url, true);
	this.request.send("");
}

DD.Rotator = function(node) {
	var i = document.createElement('div');
	i.appendChild(document.createElement('img')).src = '/img/v8/360-help.gif';
	i.lastChild.alt = 'Click and drag the photo to rotate it';
	i.appendChild(document.createElement('br'));
	i.appendChild(document.createTextNode('Click and drag the photo to rotate it'));
	this.images = [];       //Array of image resources
	this.loaded = 0;        //Number of images loaded
	this.onload = null;     //Function to be called when rotator becomes usable
	this.oncomplete = null; //Function to be called when rotator is completely loaded
	this.interval = null;   //The number of pixels the mouse has to traverse before the frame changes. Null indicates auto-calculate
	this.current = 0;       //The current frame
	this.origin = 0;        //The position on the screen the mouse-cursor was at the last time a frame changed
	this.root = node;       //The HTML node this rotator is attached to
	this.loadChunk = 4;     //The divisor used to interleave image loading
	this.instructions = i;
	this.root.rotator = this;
}
DD.Rotator.prototype.load = function() {
	var tmp = this;
	var done = 0; var i = 0;
	var interlace = Math.ceil(this.images.length / this.loadChunk);
	while (done < this.images.length) {
		for (j = 0; j < this.loadChunk; j++) {
			var index = i + (j * interlace);
			if (index >= this.images.length) break;
			var src = this.images[index];
			this.images[index] = new Image();
			DD.addEventListener(this.images[index], 'load', function() { tmp.imageLoaded(); });
			this.images[index].src = src;
			done++;
		}
		i++;
	}
	if (this.interval == null) {
		this.interval = Math.ceil(1000 / this.images.length);
	}
	this.help = document.createElement('span');
	DD.addClass(this.help, 'help');
	if (typeof this.instructions == 'object') {
		this.help.appendChild(this.instructions);
	} else {
		this.help.appendChild(document.createTextNode(this.instructions));
	}
	this.root.appendChild(this.help);
}
DD.Rotator.prototype.unload = function() {
	DD.removeEventListener(this.root, this.startRotation);
	if (this.help.parentNode != null) {
		this.root.removeChild(this.help);
	}
}
DD.Rotator.prototype.imageLoaded = function() {
	var tmp = this;
	this.loaded++;
	if (this.loaded == this.loadChunk) {
		this.root.style.backgroundRepeat = 'no-repeat';
		this.root.style.backgroundPosition = 'center center';
		this.rotate();
		this.startRotation = function(e) {
			tmp.spin(null, (e.clientX > tmp.root.offsetWidth / 2 ? -1 : 1), true);
			DD.stopPropagation(e);
			if (e.preventDefault) e.preventDefault();
			tmp.origin = e.screenX;
			var f = function(e) {
				tmp.rotate(e);
			}
			var g = function() {
				tmp.cancelSpin();
				DD.removeEventListener(document, 'mousemove', f);
				DD.removeEventListener(document, 'mousemove', g);
			}
			DD.addEventListener(document, 'mousemove', f);
			DD.addEventListener(document, 'mouseup', g);
		}
		DD.addEventListener(this.root, 'mousedown', this.startRotation);
		if (this.onload != null) {
			this.onload(this, this.loaded / this.images.length);
		}
	}
	if (this.loaded >= this.images.length && this.oncomplete) {
		this.oncomplete();
	}
}
DD.Rotator.prototype.rotate = function(e) {
	this.cancelSpin();
	if (e != null) {
		var movement = (e.screenX - this.origin) / this.interval;
		if (Math.abs(movement) > 1) {
			this.current -= Math.ceil(movement);
			this.origin = e.screenX;
		}
	}
	if (this.current < 0) this.current = this.images.length + this.current;
	this.current = Math.abs(this.current % this.images.length);
	if (this.images[this.current].complete) {
		this.root.style.backgroundImage = 'url(' + this.images[this.current].src + ')';
	}
}
DD.Rotator.prototype.spin = function(speed, direction, loop) {
	if (speed == null) speed = 40;
	if (direction == null) direction = 1;
	if (loop == null) loop = false;
	var tmp = this;
	if (this.spinEnd == false || this.spinEnd == null) this.spinEnd = this.current;
	this.current = (this.current + direction) % this.images.length;
	if (this.current < 0) this.current = this.images.length + this.current;
	this.root.style.backgroundImage = 'url(' + this.images[this.current].src + ')';
	if (this.spinEnd !== false && (this.current != this.spinEnd || loop == true)) {
		var timer = setTimeout(function() { tmp.spin(speed, direction, loop); }, speed);
	} else {
		this.spinEnd = false;
	}
	var cancel = this.cancelSpin;
	this.cancelSpin = function() {
		cancel();
		clearTimeout(timer);
	}
};
DD.Rotator.prototype.cancelSpin = function() {}

DD.FileUploader = function(node) {
	if (typeof node == 'string') {
		node = document.getElementById(node);
	}
	this.root = node.parentNode;
	DD.addClass(this.root, 'dd-file');
	this.workarea = document.createElement('span');
	this.list = document.createElement('ul');
	this.root.appendChild(this.list);
	this.name = node.name;
	this.add(node);
	node.setAttribute('multiple','true');
	this.deleted = document.createElement('span');
	this.root.appendChild(this.deleted);
	this.multi = false;
	this.maximum = null;
	this.confirm = 'Are you sure you want to remove this file from the upload list?';
}
DD.FileUploader.prototype.set = function(values) {
	for (var i = 0; i < values.length; i++) {
		var item = document.createElement('li');
		item.appendChild(document.createTextNode(values[i]));
		this.list.appendChild(item);
		this.addDeleteHandler(item);
		if (this.isFull()) {
			break;
		}
	}
}
DD.FileUploader.prototype.addDeleteHandler = function(item) {
	var tmp = this;
	DD.addEventListener(item, 'click', function(e) {
		if (tmp.confirm == false || confirm(tmp.confirm)) {
			tmp.workarea.innerHTML = '<input type="hidden" />';
			var delitem = tmp.workarea.firstChild;
			delitem.name = tmp.name + '-deleted[]';
			delitem.value = item.innerHTML;
			tmp.deleted.appendChild(delitem);
			tmp.list.removeChild(item);
			tmp.isFull();
		}
	});
}
DD.FileUploader.prototype.add = function(node) {
	var tmp = this;
	if (!node) {
		this.workarea.innerHTML = '<input type="file />';
		node = this.workarea.firstChild;
		if (this.root.childNodes.length > 0) {
			this.root.insertBefore(node, this.root.firstChild);
		} else {
			this.root.parentNode.appendChild(node);
		}
	}
	node.name = this.name + (this.name.substr(0,-2) != '[]' ? '[]' : '');
	DD.addEventListener(node, 'change', function(e) {
		if (tmp.multi && !tmp.isFull()) {
			var item = document.createElement('li');
			item.appendChild(document.createTextNode(node.value));
			item.appendChild(node);
			tmp.list.appendChild(item);
			DD.addEventListener(item, 'click', function(e) {
				if (tmp.confirm == false || confirm(tmp.confirm)) {
					tmp.list.removeChild(item);
				}
			});
			node.style.display = 'none';
			var last = tmp.add();
			tmp.isFull();
		}
	});
	return node;
}
DD.FileUploader.prototype.isFull = function() {
	var current = this.list.getElementsByTagName('li').length;
	var full = (this.maximum != null && current >= this.maximum);
	this.root.firstChild.disabled = full;
	return full;
}

DD.Menu = function (root) {
	this.root = root;
	var tmp = this;
	if (root) {
		var nodes = root.getElementsByTagName('ul')[0].children;
		for (var i = 0; i < nodes.length; i++) {
			this.add(nodes[i]);
		}
		DD.addEventListener(root.ownerDocument, 'mouseover', function() { tmp.select(); });
	}
}
DD.Menu.prototype.add = function(node) {
	tmp = this;
	DD.addEventListener(node, 'mouseover', function(e) { tmp.select(node); DD.stopPropagation(e); });
}
DD.Menu.prototype.select = function(node) {
	if (this.selected != null) {
		DD.removeClass(this.selected, 'selected');
	}
	if (node != null) {
		DD.addClass(node, 'selected');
	}
	this.selected = node;
}


