var TINY={};
function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.slider=function(){
	function slide(n,p){this.n=n; this.init(p)}
	slide.prototype.init=function(p){
		var s=this.x=T$(p.id), u=this.u=T$$('ul',s)[0], c=this.m=T$$('li',u), l=c.length, i=this.l=this.c=0; this.b=1;
		if(p.navid&&p.activeclass){this.g=T$$('li',T$(p.navid)); this.s=p.activeclass}
		this.a=p.auto||0; this.p=p.resume||0; this.r=p.rewind||0; this.e=p.elastic||false; this.v=p.vertical||0; s.style.overflow='hidden';
		for(i;i<l;i++){if(c[i].parentNode==u){this.l++}}
		if(this.v){;
			u.style.top=0; this.h=p.height||c[0].offsetHeight; u.style.height=(this.l*this.h)+'px'
		}else{
			u.style.left=0; this.w=p.width||c[0].offsetWidth; u.style.width=(this.l*this.w)+'px'
		}
		this.nav(p.position||0);
		if(p.position){this.pos(p.position||0,this.a?1:0,1)}else if(this.a){this.auto()}
		if(p.left){this.sel(p.left)}
		if(p.right){this.sel(p.right)}
	},
	slide.prototype.auto=function(){
		this.x.ai=setInterval(new Function(this.n+'.move(1,1,1)'),this.a*1000)
	},
	slide.prototype.move=function(d,a){
		var n=this.c+d;
		if(this.r){n=d==1?n==this.l?0:n:n<0?this.l-1:n}
		this.pos(n,a,1)
	},
	slide.prototype.pos=function(p,a,m){
		var v=p; clearInterval(this.x.ai); clearInterval(this.x.si);
		if(!this.r){
			if(m){
				if(p==-1||(p!=0&&Math.abs(p)%this.l==0)){
					this.b++;
					for(var i=0;i<this.l;i++){this.u.appendChild(this.m[i].cloneNode(1))}
					this.v?this.u.style.height=(this.l*this.h*this.b)+'px':this.u.style.width=(this.l*this.w*this.b)+'px';
				}
				if(p==-1||(p<0&&Math.abs(p)%this.l==0)){
					this.v?this.u.style.top=(this.l*this.h*-1)+'px':this.u.style.left=(this.l*this.w*-1)+'px'; v=this.l-1
				}
			}else if(this.c>this.l&&this.b>1){
				v=(this.l*(this.b-1))+p; p=v
			}
		}
		var t=this.v?v*this.h*-1:v*this.w*-1, d=p<this.c?-1:1; this.c=v; var n=this.c%this.l; this.nav(n);
		if(this.e){t=t-(8*d)}
		this.x.si=setInterval(new Function(this.n+'.slide('+t+','+d+',1,'+a+')'),10)
	},
	slide.prototype.nav=function(n){
		if(this.g){for(var i=0;i<this.l;i++){this.g[i].className=i==n?this.s:''}}
	},
	slide.prototype.slide=function(t,d,i,a){
		var o=this.v?parseInt(this.u.style.top):parseInt(this.u.style.left);
		if(o==t){
			clearInterval(this.x.si);
			if(this.e&&i<3){
				this.x.si=setInterval(new Function(this.n+'.slide('+(i==1?t+(12*d):t+(4*d))+','+(i==1?(-1*d):(-1*d))+','+(i==1?2:3)+','+a+')'),10)
			}else{
				if(a||(this.a&&this.p)){this.auto()}
				if(this.b>1&&this.c%this.l==0){this.clear()}
			}
		}else{
			var v=o-Math.ceil(Math.abs(t-o)*.1)*d+'px';
			this.v?this.u.style.top=v:this.u.style.left=v
		}
	},
	slide.prototype.clear=function(){
		var c=T$$('li',this.u), t=i=c.length; this.v?this.u.style.top=0:this.u.style.left=0; this.b=1; this.c=0;
		for(i;i>0;i--){
			var e=c[i-1];
			if(t>this.l&&e.parentNode==this.u){this.u.removeChild(e); t--}
		}
	},
	slide.prototype.sel=function(i){
		var e=T$(i); e.onselectstart=e.onmousedown=function(){return false}
	}
	return{slide:slide}
}();
TINY.box=function(){
	var j,m,b,g,v,p=0;
	return{
		show:function(o){
			v={opacity:70,close:1,animate:1,fixed:1,mask:1,maskid:'',boxid:'',topsplit:2,url:0,post:0,height:0,width:0,html:0,iframe:0};
			for(s in o){v[s]=o[s]}
			if(!p){
				j=document.createElement('div'); j.className='tbox';
				p=document.createElement('div'); p.className='tinner';
				b=document.createElement('div'); b.className='tcontent';
				m=document.createElement('div'); m.className='tmask';
				g=document.createElement('div'); g.className='tclose'; g.v=0;
				document.body.appendChild(m); document.body.appendChild(j); j.appendChild(p); p.appendChild(b);
				m.onclick=g.onclick=TINY.box.hide; window.onresize=TINY.box.resize
			}else{
				j.style.display='none'; clearTimeout(p.ah); if(g.v){p.removeChild(g); g.v=0}
			}
			p.id=v.boxid; m.id=v.maskid; j.style.position=v.fixed?'fixed':'absolute';
			if(v.html&&!v.animate){
				p.style.backgroundImage='none'; b.innerHTML=v.html; b.style.display='';
				p.style.width=v.width?v.width+'px':'auto'; p.style.height=v.height?v.height+'px':'auto'
			}else{
				b.style.display='none'; 
				if(!v.animate&&v.width&&v.height){
					p.style.width=v.width+'px'; p.style.height=v.height+'px'
				}else{
					p.style.width=p.style.height='100px'
				}
			}
			if(v.mask){this.mask(); this.alpha(m,1,v.opacity)}else{this.alpha(j,1,100)}
			if(v.autohide){p.ah=setTimeout(TINY.box.hide,1000*v.autohide)}else{document.onkeyup=TINY.box.esc}
		},
		fill:function(c,u,k,a,w,h){
			if(u){
				if(v.image){
					var i=new Image(); i.onload=function(){w=w||i.width; h=h||i.height; TINY.box.psh(i,a,w,h)}; i.src=v.image
				}else if(v.iframe){
					this.psh('<iframe src="'+v.iframe+'" width="'+v.width+'" frameborder="0" height="'+v.height+'"></iframe>',a,w,h)
				}else{
					var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
					x.onreadystatechange=function(){
						if(x.readyState==4&&x.status==200){p.style.backgroundImage=''; TINY.box.psh(x.responseText,a,w,h)}
					};
					if(k){
    	            	x.open('POST',c,true); x.setRequestHeader('Content-type','application/x-www-form-urlencoded'); x.send(k)
					}else{
       	         		x.open('GET',c,true); x.send(null)
					}
				}
			}else{
				this.psh(c,a,w,h)
			}
		},
		psh:function(c,a,w,h){
			if(typeof c=='object'){b.appendChild(c)}else{b.innerHTML=c}
			var x=p.style.width, y=p.style.height;
			if(!w||!h){
				p.style.width=w?w+'px':''; p.style.height=h?h+'px':''; b.style.display='';
				if(!h){h=parseInt(b.offsetHeight)}
				if(!w){w=parseInt(b.offsetWidth)}
				b.style.display='none'
			}
			p.style.width=x; p.style.height=y;
			this.size(w,h,a)
		},
		esc:function(e){e=e||window.event; if(e.keyCode==27){TINY.box.hide()}},
		hide:function(){TINY.box.alpha(j,-1,0,3); document.onkeypress=null; if(v.closejs){v.closejs()}},
		resize:function(){TINY.box.pos(); TINY.box.mask()},
		mask:function(){m.style.height=this.total(1)+'px'; m.style.width=this.total(0)+'px'},
		pos:function(){
			var t;
			if(typeof v.top!='undefined'){t=v.top}else{t=(this.height()/v.topsplit)-(j.offsetHeight/2); t=t<20?20:t}
			if(!v.fixed&&!v.top){t+=this.top()}
			j.style.top=t+'px'; 
			j.style.left=typeof v.left!='undefined'?v.left+'px':(this.width()/2)-(j.offsetWidth/2)+'px'
		},
		alpha:function(e,d,a){
			clearInterval(e.ai);
			if(d){e.style.opacity=0; e.style.filter='alpha(opacity=0)'; e.style.display='block'; TINY.box.pos()}
			e.ai=setInterval(function(){TINY.box.ta(e,a,d)},20)
		},
		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==j?TINY.box.alpha(m,-1,0,2):b.innerHTML=p.style.backgroundImage=''
				}else{
					if(e==m){
						this.alpha(j,1,100)
					}else{
						j.style.filter='';
						TINY.box.fill(v.html||v.url,v.url||v.iframe||v.image,v.post,v.animate,v.width,v.height)
					}
				}
			}else{
				var n=a-Math.floor(Math.abs(a-o)*.5)*d;
				e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
			}
		},
		size:function(w,h,a){
			if(a){
				clearInterval(p.si); var wd=parseInt(p.style.width)>w?-1:1, hd=parseInt(p.style.height)>h?-1:1;
				p.si=setInterval(function(){TINY.box.ts(w,wd,h,hd)},20)
			}else{
				p.style.backgroundImage='none'; if(v.close){p.appendChild(g); g.v=1}
				p.style.width=w+'px'; p.style.height=h+'px'; b.style.display=''; this.pos();
				if(v.openjs){v.openjs()}
			}
		},
		ts:function(w,wd,h,hd){
			var cw=parseInt(p.style.width), ch=parseInt(p.style.height);
			if(cw==w&&ch==h){
				clearInterval(p.si); p.style.backgroundImage='none'; b.style.display='block'; if(v.close){p.appendChild(g); g.v=1}
				if(v.openjs){v.openjs()}
			}else{
				if(cw!=w){p.style.width=(w-Math.floor(Math.abs(w-cw)*.6)*wd)+'px'}
				if(ch!=h){p.style.height=(h-Math.floor(Math.abs(h-ch)*.6)*hd)+'px'}
				this.pos()
			}
		},
		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))
		}
	}
}();
/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};
/*  Prototype JavaScript framework, version 1.5.0_pre0
 *  (c) 2005 Sam Stephenson 
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
 * The Dollar Function:
/*--------------------------------------------------------------------------*/

function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(Element.extend(element));
  }
  return results.length < 2 ? results[0] : results;
}
function prependElement(parentID,child) {
	// Create The Element Dynamically. Here we are creating  Div   
	//var ele=document.createElement("div");
	// Assume our Parent Element  ID is  container
	// So  function  goes like below 
	//prependElement('container',ele)
	parent=document.getElementById(parentID);
	parent.insertBefore(child,parent.childNodes[0]);
}
function appendElement(parentID,child) {
	// Create The Element Dynamically. Here we are creating  Div   
	//var ele=document.createElement("div");
	// Assume our Parent Element  ID is  container
	// So  function  goes like below 
	//appendElement('container',ele)
	parent=document.getElementById(parentID);
	parent.appendChild(child);
}
/*
This script is copyright (c) 2006 Elliot Swan under the
Creative Commons Attribution-ShareAlike 2.5 license:
http://creativecommons.org/licenses/by-sa/2.5/
More information on this script can be found at: 
http://www.elliotswan.com/2006/04/12/move-and-copy/
Move.element('e', 'target', 'type');
*/
var Move =	{
  copy	:   function(e, target)	{
	    var eId      = document.getElementById(e);
	    var copyE    = eId.cloneNode(true);
	    var cLength  = copyE.childNodes.length -1;
	    copyE.id     = e+'copy';

	    for(var i = 0; cLength >= i;  i++)	{
	    if(copyE.childNodes[i].id) {
	    var cNode   = copyE.childNodes[i];
	    var firstId = cNode.id;
	    cNode.id    = firstId+'copy'; }
	    }
	    document.getElementById(target).appendChild(copyE);
	},
  element:  function(e, target, type)	{
	    var eId =  document.getElementById(e);
	    if(type == 'move') {
	       document.getElementById(target).appendChild(eId);
	    }

	    else if(type == 'copy')	{
	       this.copy(e, target);
	    }
	}
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}
function concat_collection(obj1, obj2) {
	var i;
	var arr = new Array();
	var len1 = obj1.length;
	var len2 = obj2.length;
	for (i=0; i<len1; i++) {
		arr.push(obj1[i]);
	}
	for (i=0; i<len2; i++) {
		arr.push(obj2[i]);
	}
	return arr;
}
function visirMe() {
	var anchors = getElementsByClassName("hider");
	for (var i=0; i<anchors.length; i++) {
		anchors[i].style.display = 'inline-block';
	}
} addLoadEvent(visirMe);
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var atags = document.getElementsByTagName("a");
	var areas = document.getElementsByTagName("area");
	var anchors = concat_collection(atags, areas);
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if( (anchor.rel == "externalLink") || (anchor.getAttribute("class") == "externalLink") ) {
			anchor.onclick = function(){
				if (this.href.match(/^http\:/i)) {
					var awr = "/cgi-bin/awredir.pl?url=";
					//var openMe = window.open(awr + this.href,'externalLink');
					window.location = awr + this.href;
					return false;
				}
			}
		}
	}
} addLoadEvent(externalLinks);
function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name) { return unescape(y); }
	}
}
function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (this.hasClass(ele,cls)) ele.className += " ";
	ele.className += cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,'');
	}
}
function setNavigators() {
	if (document.getElementById("premon")) {
		var premon = document.getElementById("premon");
		premon.onclick = function() {
			var myDate = this.rel;
			//console.log(myDate);
			ajaxChangeCalendar( myDate );
			return false;
		};
	}
	if (document.getElementById("nexmon")) {
		var nexmon = document.getElementById("nexmon");
		nexmon.onclick = function() {
			var myDate = this.rel;
			ajaxChangeCalendar( myDate );
			return false;
		};
	}
	return;
}
function checkCal() { 
	if (!document.getElementById('eventCal')) return;
	var myCalDate=getCookie("calDate"); 
	if (myCalDate!=null && myCalDate!="") { 
		ajaxChangeCalendar( myCalDate );
	}
}
function ajaxChangeCalendar( date ) {
	var loader = dhtmlxAjax.getSync("/" + "calendar" + ".xml?MY=" + date);
	if(loader.xmlDoc.responseXML!=null) {
		document.getElementById("eventCal").innerHTML = loader.xmlDoc.responseXML.getElementsByTagName("calendar")[0].childNodes[0].nodeValue;
		setCookie("calDate",date,1);
	}
	setNavigators();
	openBox();
	return false;
}
//function loadTiny(){var slideshow=new TINY.slider.slide('slideshow',{id:'slider',auto:4,resume:false,vertical:false,navid:'',activeclass:'current',position:0,rewind:false,elastic:true,left:'slideleft',right:'slideright'});}
function openBox() {
	var areas1 = getElementsByClassName("evc","a");
	var areas2 = getElementsByClassName("mi","a");
	var areas = concat_collection(areas1, areas2);
	for (var i=0; i<areas.length; i++) {
		areas[i].onclick = function(){
			TINY.box.show({url:this.href+'?ID=sm',width:640,height:400,boxid:'eBox'});
			return false;
		};
	}
	var merchPops = getElementsByClassName("mc","li");
	for (var i=0; i<merchPops.length; i++) {
		merchPops[i].onclick = function(){
			window.location = this.getAttribute("rel");
			//TINY.box.show({url:this.getAttribute("rel")+'?ID=sm',width:640,height:480,boxid:'eBox'});
			return false;
		};
	}
	var picPops1 = getElementsByClassName("lPic","img");
	var picPops2 = [];var k;
	if(document.getElementById("mPics")) {
		k = document.getElementById("mPics");
		picPops2 = k.getElementsByTagName("img");
	}
	var picPops = concat_collection(picPops1, picPops2);
	for (var i=0; i<picPops.length; i++) {
		picPops[i].onmouseover = function(){
			this.title='click to enlarge';
			this.style.cursor='pointer';
		};
		picPops[i].onclick = function(){
			if(picPops.length>1) {
				TINY.box.show({iframe:k.getAttribute("rel")+'?ID=sm'+this.alt,width:640,height:480,boxid:'picBox'/*,openjs:function(){focusiframe();}*/});
			} else {
				var s=this.src.replace(/\/(medium|thumb)/i,'');
				TINY.box.show({image:s,width:640,height:480,boxid:'picBox'});
			}
			return false;
		};
	}
	if(document.getElementById("evMore")) {
		document.getElementById("evMore").onclick = function(){
			setCookie("calDate",0,1);
		};
	}
}
function hoverMap(){
	var areas = document.getElementsByTagName("area");
	for (var i=0; i<areas.length; i++) {
		areas[i].onmouseover = function(){
			var s = this.id.replace(/m/i,'md');
			//document.getElementById('mallMap').src='/graphics/mallLayout/'+s+'.png';
			//console.log(s);
			document.getElementById(s).style.width="21px";
			document.getElementById(s).style.height="21px";
			//document.getElementById(s).style.display="block";
			document.getElementById('shoutBox').innerHTML=this.getAttribute("name");
		};
		areas[i].onmouseout = function(){
			var s = this.id.replace(/m/i,'md');
			//document.getElementById('mallMap').src=map;
			//document.getElementById(s).style.display="none";
			document.getElementById(s).style.width="0";
			document.getElementById(s).style.height="0";
			document.getElementById('shoutBox').innerHTML='';
		};
	}
	var map=document.getElementById('mallLayout');
	var anchors = map.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		anchors[i].onmouseover = function(){
			var s = this.id.replace(/md/i,'m');
			document.getElementById('shoutBox').innerHTML=document.getElementById(s).getAttribute("name");
		};
		anchors[i].onmouseout = function(){
			var s = this.id.replace(/md/i,'m');
			document.getElementById('shoutBox').innerHTML='';
		};
	}
}
function merchDir(){
	if(document.getElementById('catNav')) {
		var hs = document.getElementsByTagName("h2");
		if(document.getElementById('mallLayout')) {
			document.getElementById('mallLayout').className='merchList';
			var uls = document.getElementsByTagName("ul");
			for (var i=0; i<uls.length; i++) {
				if(i!=0) uls[i].style.paddingTop='1em';
			}
		}
		var divs = getElementsByClassName("merchList","div");
		var anchors = document.getElementById('catNav').getElementsByTagName("a");
		for (var i=0; i<divs.length; i++) {
			if(i!=0) divs[i].style.display='none';
			hs[i].style.display='none';
		}
		document.getElementById('catNav').className='catMenu';
		for (var i=0; i<anchors.length; i++) {
			anchors[i].onclick = function(){
				var s = this.getAttribute("href").replace("#",'');
				for (var i=0; i<divs.length; i++) {
					divs[i].style.display='none';
				}
				document.getElementById(s).style.display='block';
				anchorClass();
				addClass(this,'active');
				return false;
			};
		}
	}
}
function anchorClass() {
		var anchors = document.getElementById('catNav').getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			removeClass(anchors[i],'active');
		}
}
