/*
/////////////////////////////
Copyright (c) 2009 Seth Van Booven
MountainGetaway.com Globals
Version 1.0 (2009-02-25)
/////////////////////////////
*/

/*
/////////////////////////////
	Globals
/////////////////////////////
*/

if (typeof OTS == 'undefined') {
	var OTS = {};
}

OTS.domain = '';
OTS.baseURL = '' + OTS.domain;
OTS.imgURL = '' + OTS.domain;
/*
OTS.domain = 'mountaingetaway.com';
OTS.baseURL = 'http://dev1.' + OTS.domain;
OTS.imgURL = 'http://dev1.' + OTS.domain;
*/

OTS.$ = function() {
	var oArr = [];
	var len = arguments.length;
	for (var i = 0; i < len; ++i) {
		var o = arguments[i];
		if (typeof o == 'string') {
			o = document.getElementById(o);
		}
		if (len == 1) return o;
		oArr.push(o);
	}
	return oArr;
}

OTS.getElm = function(id) {
	return (typeof id != 'object') ? OTS.$(id) : id;
}

OTS.hasParent = function(obj, parent) {
	var el = OTS.getElm(obj);
	var an = OTS.getElm(parent);
	while (el != document && el != null) {
		if (el == an) return true;
		el = el.parentNode;
	}
	return false;
}

OTS.isContained = function(obj, e) {
	var e = window.event || e;
	var c = e.relatedTarget || ((e.type == 'mouseover') ? e.fromElement : e.toElement);
	while (c && c != obj) {
		try {
			c = c.parentNode;
		} catch(e){
			c = obj;
		}
	}
	if (c == obj)	{
		return true;
	} else {
		return false;
	}
}

OTS.setHTML = function(id, s) {
	var o = OTS.getElm(id);
	if (!o) return;
	o.innerHTML = s;
}

OTS.addHTML = function(id, s) {
	var o = OTS.getElm(id);
	if (!o) return;
	o.innerHTML += s;
}

OTS.getHTML = function(id) {
	var o = OTS.getElm(id);
	if (!o) return;
	return o.innerHTML;
}

OTS.setStyle = function(id, s, v) {
	var o = OTS.getElm(id);
	if (!o) return;
	if (s == 'opacity') {
		OTS.setOpacity(o, v);
	} else {
		o.style[s] = v;
	}
}

OTS.getStyle = function(id, s) {
	var o = OTS.getElm(id);
	if (!o) return;
	if (s == 'opacity') {
		
	} else {
		if (o.currentStyle) {
			var x = o.currentStyle[s];
		} else if (window.getComputedStyle) {
			var x = document.defaultView.getComputedStyle(o, null).getPropertyValue(s);
		}
		return x;
	}
}

OTS.setClass = function(id, s) {
	var o = OTS.getElm(id);
	if (!o) return;
	o.className = s;
}

OTS.addClass = function(id, s) {
	var o = OTS.getElm(id);
	if (!o) return;
	var n = s;
	if (o.className != '') {
		n = ' ' + n;
	}
	o.className += n;
}

OTS.delClass = function(id, s) {
	var o = OTS.getElm(id);
	if (!o) return;
	var n = s;
	if (o.className != '') {
		n = ' ' + n;
	}
	o.className = o.className.replace(n, '');
}

OTS.setOpacity = function(o, opacity) {
	o.style.opacity = (opacity / 100);
	o.style.MozOpacity = (opacity / 100);
	o.style.KhtmlOpacity = (opacity / 100);
	o.style.filter = 'alpha(opacity=' + opacity + ')';
}

OTS.getPos = function(obj) {
	return {
		left : OTS.getOffset(obj, 'left'),
		top : OTS.getOffset(obj, 'top')
	}
}

OTS.getOffset = function(obj, type) {
	var curoffset = (type == 'left') ? obj.offsetLeft : obj.offsetTop;
	var elm = obj.offsetParent;
	while (elm != null) {
		curoffset += (type == 'left') ? elm.offsetLeft : elm.offsetTop;
		var ml = parseInt(OTS.getStyle(elm, 'marginLeft'));
		if (type == 'left' && ml > 0 && document.all) {
			curoffset -= ml;
		}
		elm = elm.offsetParent;
	}
	return curoffset;
}

OTS.getPageScroll = function(obj) {
	var o = obj;
	var y;
	if (obj == null) {
		if (self.pageYOffset) {
			y = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			y = document.documentElement.scrollTop;
		} else if (document.body) {
			y = document.body.scrollTop;
		}
	} else {
		if (o.pageYOffset) {
			y = o.pageYOffset;
		} else if (o.documentElement && o.documentElement.scrollTop) {
			y = o.documentElement.scrollTop;
		} else if (o) {
			y = o.scrollTop;
		}
	}
	return y;
}

OTS.setPageScroll = function(obj, y) {
	var o = obj;
	if (o.pageYOffset) {
		o.pageYOffset = y;
	} else if (o.documentElement && o.documentElement.scrollTop) {
		o.documentElement.scrollTop = y;
	} else if (o) {
		o.scrollTop = y;
	}
}

OTS.getPageSize = function() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	return {
		pageWidth : pageWidth,
		pageHeight : pageHeight,
		windowWidth : windowWidth,
		windowHeight : windowHeight
	}
}

OTS.getQuery = function(v) {
	var q = unescape(location.search).substring(1);
	if (!q) return '';
	var j = q.split('&');
	for (var i = 0; i < j.length; i++) {
		var c = j[i].split('=');
		c[0] = c[0].replace(/^\s+|\s+$/g, '');
		c[1] = c[1].replace(/^\s+|\s+$/g, '');
		if (v == c[0]) {
			return c[1];
		}
	}
	return '';
}

OTS.setCookie = function(name, value, hours, path, domain) {
	if (!hours) hours = 1000000; /* 100+ years */
	var d = new Date();
	d.setTime(d.getTime() + (hours * 3600 * 1000));
	document.cookie = name + '=' + escape(value) + ';expires=' + d.toGMTString() + ';path=' + ((path) ? path : '/') + ((domain) ? ';domain=' + domain : '');
}

OTS.getCookie = function(name) {
	if (!name) {
		return document.cookie;
	} else {
		var cArr = document.cookie.split(';');
		for (var i = 0; i < cArr.length; ++i) {
			var c = cArr[i].split('=');
			if (c[0] && c[1]) {
				c[0] = c[0].replace(/^\s+|\s+$/g, '');
				c[1] = c[1].replace(/^\s+|\s+$/g, '');
				if (name == c[0]) {
					return unescape(c[1]);
				}
			}
		}
		return '';
	}
}

OTS.delCookie = function(name, path, domain) {
	if (OTS.getCookie(name)) {
		document.cookie = name + '=' + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}
}

OTS.noValue = function(o, c) {
	if (o.value != o.title) return;
	o.value = '';
	if (!c) c = 'recall';
	o.className = o.className.replace(c, '');
}

OTS.reValue = function(o, c) {
	if (o.value != '') return;
	o.value = o.title;
	if (!c) c = 'recall';
	o.className += ' ' + c;
}

OTS.randArray = function(a) {
	for (var j, x, i = a.length; i; j = parseInt(Math.random() * i), x = a[--i], a[i] = a[j], a[j] = x);
	return a;
}

OTS.ajax = function(url, method, post, xml) {
	this.url = url;
	this.method = method;
	this.error = this.processErr;
	this.post = (post == null) ? 'get' : post;
	this.xml = (xml == null) ? '' : xml;
	this.id = null;
	this.html = '';
}
OTS.ajax.prototype.request = function() {
	if (window.XMLHttpRequest) {
		this.req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		this.req = new ActiveXObject('Microsoft.XMLHTTP');
	}
	if (this.req) {
		var _this = this;
		this.req.onreadystatechange = function() {
			_this.processReq();
		};
		this.req.open(this.post, this.url, true);
		this.req.send(null);
	} else {
		return;
	}
}
OTS.ajax.prototype.processReq = function() {
	if (this.req.readyState == 4) {
		if (this.req.status == 200) {
			var s = (this.xml == 'xml') ? this.req.responseXML : this.req.responseText;
			this.method(s, this.id, this.html);
		} else {
			/*alert('There was a problem retrieving your request. ' + this.req.statusText);*/
		}
	}
}
OTS.ajax.prototype.processErr = function(s) {
	/*alert('There was a problem retrieving your request. ' + s);*/
}

OTS.gaTrkImp = function(a) {
	if (typeof pageTracker != 'object') return;
	if (a) {
		pageTracker._trackPageview(a);
	} else {
		pageTracker._trackPageview();
	}
}
OTS.gaTrkEvt = function(a, b, c) {
	if (typeof pageTracker != 'object') return;
	pageTracker._trackEvent(a, b, c);
}

OTS.ease = {};
OTS.ease.strongEaseOut = function(t,b,c,d) {
	return c*((t=t/d-1)*t*t*t*t+1)+b;
}

/*
/////////////////////////////
	SubNav
/////////////////////////////
*/

OTS.subnav = {
	active : false,
	mactive : false,
	sactive : false,
	sactive2 : false,
	t1 : null,
	t2 : null,
	classset : false,
	classname : '',
	old : null,
	curr : null,
	h : 200
};
OTS.subnav.setClass = function() {
	if (OTS.subnav.classset) return;
	OTS.subnav.classname = OTS.$('gn2').className;
	OTS.subnav.classset = true;
}
OTS.subnav.isShown = function() {
	if (OTS.subnav.active) {
		OTS.subnav.show();
	}
	OTS.subnav.setClass();
}
OTS.subnav.clickShow = function() {
	if (OTS.subnav.active) {
		OTS.subnav.doHide();
	} else {
		OTS.subnav.doShow();
	}
}
OTS.subnav.show = function() {
	//if (OTS.subnav.sactive) return;
	OTS.subnav.clearHide();
	OTS.subnav.doShow();
}
OTS.subnav.doShow = function() {
	if (OTS.subnav.sactive) return;
	OTS.setClass(OTS.$('gn2'), 'over');
	OTS.setClass(OTS.$('gsnav'), 'on');
	OTS.subnav.active = true;
	OTS.subnav.slide();
	//OTS.subnav.doShowDone;
}
OTS.subnav.doShowDone = function() {
	OTS.subnav.sactive = true;
	OTS.subnav.sactive2 = false;
	OTS.setStyle(OTS.$('gsnav'), 'height', OTS.subnav.h + 'px');
	OTS.setStyle(OTS.$('gsnav'), 'overflow', 'visible');
}
OTS.subnav.slide = function() {
	if (OTS.subnav.sactive2) return;
	OTS.subnav.clearSlide();
	OTS.subnav.sactive2 = true;
	OTS.setStyle(OTS.$('gsnav'), 'height', '0');
	OTS.setStyle(OTS.$('gsnav'), 'overflow', 'hidden');
	OTS.subnav.t = (new Date()).getTime();
	OTS.subnav.b = 0;
	OTS.subnav.c = OTS.subnav.h - OTS.subnav.b;
	OTS.subnav.d = 200;
	OTS.subnav.t2 = setInterval("OTS.subnav.animate()", 10);
}
OTS.subnav.animate = function() {
	if (OTS.subnav.sactive) return;
	var t = (new Date()).getTime() - OTS.subnav.t;
	if (t > OTS.subnav.d) {
		OTS.subnav.clearSlide();
		OTS.subnav.doShowDone();
		return;
	} else {
		var y = OTS.ease.strongEaseOut(t, OTS.subnav.b, OTS.subnav.c, OTS.subnav.d);
		OTS.setStyle(OTS.$('gsnav'), 'height', y + 'px');
	}
}
OTS.subnav.hide = function() {
	OTS.subnav.clearHide();
	if (OTS.subnav.active) {
		OTS.subnav.t1 = setTimeout('OTS.subnav.doHide()', 250);
	}
}
OTS.subnav.doHide = function() {
	OTS.setClass(OTS.$('gn2'), OTS.subnav.classname);
	OTS.setClass(OTS.$('gsnav'), '');
	OTS.subnav.hideMenus();
	OTS.subnav.active = false;
	OTS.subnav.sactive = false;
	OTS.subnav.sactive2 = false;
}
OTS.subnav.clearHide = function() {
	if (OTS.subnav.t1) {
		clearTimeout(OTS.subnav.t1);
		OTS.subnav.t1 = null;
	}
}
OTS.subnav.clearSlide = function() {
	if (OTS.subnav.t2) {
		clearInterval(OTS.subnav.t2);
		OTS.subnav.t2 = null;
	}
}

/////////////////////////////

OTS.subnav.clickMenu = function(n) {
	if (OTS.subnav.curr == n && OTS.subnav.mactive) {
		OTS.subnav.hideMenus();
	} else {
		OTS.subnav.menu(n);
	}
}
OTS.subnav.menu = function(n) {
	OTS.subnav.old = OTS.subnav.curr;
	OTS.subnav.curr = n;
	OTS.subnav.removeMenu(OTS.subnav.old);
	OTS.subnav.doMenu(n);
}
OTS.subnav.doMenu = function(n) {
	if (OTS.$('snsnav' + n)) OTS.subnav.removeMenu(n);
	OTS.subnav.makeMenu(n);
	OTS.subnav.mactive = true;
}
OTS.subnav.hideMenus = function() {
	OTS.subnav.removeMenu(OTS.subnav.old);
	OTS.subnav.removeMenu(OTS.subnav.curr);
}
OTS.subnav.removeMenu = function(n) {
	var o = OTS.$('snsnav' + n);
	if (!o) return;
	o.parentNode.removeChild(o);
	OTS.subnav.mactive = false;
	OTS.subnav.toggleObjects('visible');
}
OTS.subnav.makeMenu = function(n) {
	var na = n - 1;
	var tLen = OTS.subnavMenu[na].length;
	var cols = (tLen > 5) ? Math.ceil(tLen / 5) : 1;
	var c = 0;
	var s = '<table cellpadding="10" cellspacing="0" border="0"><tr>';
	for (var j = 0; j < cols; j++) {
		s += '<td valign="top"><ul>';
		for (var i = 0; i < Math.floor(tLen / cols); i++) {
			s += '<li>';
			s += '<a href="' + OTS.subnavMenu[na][c].u + 'deals/" title="' + OTS.subnavMenu[na][c].t + '">' + OTS.subnavMenu[na][c].t + '</a> ';
			s += '<small>' + OTS.subnavMenu[na][c].s + '</small>';
			s += '</li>';
			c++;
		}
		s += '</ul></td>';
	}
	s += '</tr></table>';
	s += '<div class="snsmarker" onclick="OTS.subnav.clickMenu(' + n + ');"></div>';
	var html = '<div id="snsnav' + n + '" class="snsnav">';
	html += s;
	html += '</div>';
	//OTS.addHTML(OTS.$('sn' + n), html);
	OTS.addHTML(OTS.$('gsnav'), html);
	OTS.subnav.toggleObjects('hidden');
}
OTS.subnav.toggleObjects = function(s) {
	if (window.XMLHttpRequest) return;
	var elms1 = document.getElementsByTagName('select');
	for (var i = 0; i < elms1.length; i++) {
		OTS.setStyle(elms1[i], 'visibility', s);
	}
	var elms2 = document.getElementsByTagName('iframe');
	for (var i = 0; i < elms2.length; i++) {
		OTS.setStyle(elms2[i], 'visibility', s);
	}
	var elms3 = document.getElementsByTagName('object');
	for (var i = 0; i < elms3.length; i++) {
		OTS.setStyle(elms3[i], 'visibility', s);
	}
	var elms4 = document.getElementsByTagName('embed');
	for (var i = 0; i < elms4.length; i++) {
		OTS.setStyle(elms4[i], 'visibility', s);
	}
}

/*
/////////////////////////////
	ScrollToTop
/////////////////////////////
*/

OTS.scrollToObj = function(o) {
	var o = OTS.$(o);
	if (!o) return;
	var p = OTS.getPos(o);
	var t = (new Date()).getTime();
	var b = OTS.getPageScroll();
	var c = p.top - b;
	var d = 250;
	var s = new OTS.scrollTo(t, b, c, d);
}
OTS.scrollToTop = function() {
	var t = (new Date()).getTime();
	var b = OTS.getPageScroll();
	var c = 0 - b;
	var d = 250;
	var s = new OTS.scrollTo(t, b, c, d);
}
OTS.scrollTo = function(t, b, c, d) {
	this.slideClear();
	this.t = t;
	this.b = b;
	this.c = c;
	this.d = d;
	var _this = this;
	this.t1 = window.setInterval(function() {
		_this.slideAni();
	}, 10);
};
OTS.scrollTo.prototype.slideAni = function() {
	var t = (new Date()).getTime() - this.t;
	if (t > this.d) {
		this.slideClear();
		//scrollTo(0, 0);
		return;
	} else {
		var x = OTS.ease.strongEaseOut(t, this.b, this.c, this.d);
		scrollTo(0, x);
	}
}
OTS.scrollTo.prototype.slideClear = function() {
	if (this.t1) {
		window.clearInterval(this.t1);
		this.t1 = null;
	}
}

/*
/////////////////////////////
	Misc
/////////////////////////////
*/

OTS.popWin = function(url, name, options) {
	return window.open(url, name, options);
}
OTS.popWinOptions = function(w, h, toolbar, status, scrollbars, resizeable) {
	var sw = screen.width;
	var sh = screen.height;
	if (w == null) w = (sw >= 1024) ? 925 : 625;
	if (h == null) h = (sw >= 1024) ? 600 : 500;
	if (toolbar == null) toolbar = 'no';
	if (status == null) status = 'yes';
	if (scrollbars == null) scrollbars = '1';
	if (resizeable == null) resizeable = 'yes';
	var cx = (sw * .5) - (w * .5);
	var cy = (sh * .5) - (h * .5);
	var sOptions = 'toolbar=' + toolbar + ',menubar=no,status=' + status + ',scrollbars=' + scrollbars + ',resizable=' + resizeable + ',screenX=' + cx + ',screenY=' + cy + ',left=' + cx + ',top=' + cy + ',width=' + w + ',height=' + h + '';
	return sOptions;
}

OTS.printThis = function(id) {
	var o = OTS.$(id);
	if (!o) {
		o = document.body;
		/*o = OTS.$('storypage');*/
	}
	if (!o) return;
	var s = o.innerHTML;
	s = s.split('<!-- STORY STARTS HERE -->');
	s = s[1].split('<!-- STORY ENDS HERE -->');
	s = s[0];
	s = s.replace(/(\n|\r)+/ig, '');
	s = s.replace(/<script[^>]*?>.*?<\/script>/ig, '');
	s = s.replace(/<style[^>]*?>.*?<\/style>/ig, '');
	s = s.replace(/on(click|mouseover|mouseout)="([^>]+)"/ig, '');
	s = s.replace(/(<img([^>]+)>)/ig, '');
	var html = '';
	html += '<html><head><title>Print this page</title>';
	html += '<link rel="stylesheet" href="' + OTS.imgURL + '/mg/css/print.css" media="all" />';
	html += '</head><body onload="if(window.print)window.print();">';
	html += '<p><img src="' + OTS.imgURL + '/mg/images/logo_bk_sm.gif" alt="" border="0" align="left" /> <div align="right"><a href="#" onclick="window.print(); return false;">Print this page</a></div></p><br clear="all" />';
	html += s;
	html += '<p>URL: <a href="' + location.href + '">' + location.href + '</a></p>';
	html += '<hr /><p>Copyright &#169; 1968-2008 Mountain News Corp. All Rights Reserved.</p>';
	html += '</body></html>';
	var p = OTS.popWin('', 'print_pop', OTS.popWinOptions(650, 450));
	p.document.write(html);
	p.document.close();
}

OTS.emailThis = function(id, title) {
	var b = '';
	var o = OTS.$(id);
	if (!o) {
		o = OTS.$('storybody');
	}
	if (o) {
		b = o.innerHTML;
		b = b.replace(/<br(\s+\/)?>/ig, '\n');
		b = b.replace(/(<([^>]+)>)/ig, '');
		ba = b.split(' ');
		var ts = '';
		for (var i = 0; i < ba.length; i++) {
			ts += ba[i] + ' ';
			if (i == 50) {
				ts += '...';
				break;
			}
		}
		b = ts;
	}
	b = b.replace(/#/g, '%23');
	b = b.replace(/&/g, '%26');
	b = b.replace(/\n+/ig, '%0D%0A');
	b += '%0D%0A%0D%0AURL: ' + location.href;
	var t = 'Mountain Getaway';
	if (title == null) {
		title = '';
		var hd = OTS.$('storyhd');
		if (hd) {
			title = '- ' + hd.innerHTML
		}
	}
	t += ' ' + title;
	t = t.replace(/#/g, '%23');
	t = t.replace(/&/g, '%26');
	var s = 'mailto:?subject=' + t + '&body=' + b;
	location.href = s;
}

OTS.doArtLnks = function(id) {
	var o = OTS.$('storybody');
	if (!o) return;
	var lnks = o.getElementsByTagName('a');
	for (var i = 0, l = lnks.length; i < l; i++) {
		var a = lnks[i];
		if (a.onclick) continue;
		a.onclick = function() {
			var t0 = (OTS.$('storyhd')) ? (OTS.$('storyhd').innerText || OTS.$('storyhd').textContent) : '';
			var t1 = (id) ? id : t0;
			var t2 = this.innerText || this.textContent;
			var t3 = this.href;
			var t = t1 + ' + ' + t2 + ' + ' + t3;
			OTS.gaTrkEvt('ARTLNKS', 'open', t);
			if (OTS.getCookie('ifm_hide') != 'true') {
				if ((this.href.indexOf('http://') > -1) && (this.href.indexOf('mountaingetaway') == -1)) {
					var hd = (document.title != '') ? document.title : t0;
					var u = '/f/?u=' + this.href + '&r=' + location.href + '&t=' + hd;
					window.open(u, 'MGEXTLNK');
					return false;
				}
			}
		}
	}
};

OTS.doTAHeight = function(o) {
	var id = o.id;
	var o1 = OTS.$(id);
	if (!o1) return;
	var o2 = OTS.$(id + '_stmp');
	if (!o2) {
		o1.ppS = false;
		o1.ppH = o1.offsetHeight;
		o2 = document.createElement('div');
		o2.id = id + '_stmp';
		o2.className = 'fTxt';
		OTS.setStyle(o2, 'width', o1.offsetWidth - 26 + 'px');
		OTS.setStyle(o2, 'position', 'absolute');
		OTS.setStyle(o2, 'top', 0);
		OTS.setStyle(o2, 'left', '-2000px');
		OTS.setStyle(o2, 'visibility', 'hidden');
		document.body.appendChild(o2);
	}
	var s = o1.value;
	s = s.replace(/\n/g, '<br />');
	OTS.setHTML(o2, s);
	var h1 = o1.offsetHeight;
	var h2 = o2.offsetHeight;
	if (h2 > h1) {
		if (o1.ppS == false) o1.ppS = true;
		if (h2 > 600) h2 = 600;
		OTS.setStyle(o1, 'height', (h2 + 30) + 'px');
	} else {
		if (o1.ppS == true) {
			if (h2 < o1.ppH) h2 = o1.ppH - 30;
			OTS.setStyle(o1, 'height', (h2 + 30) + 'px');
		}
	}
}

OTS.showMoreNav = {
	opened : false,
	txt : ''
}
OTS.showMoreNav.toggle = function(id) {
	var o = OTS.$(id + '_more');
	if (!o) return;
	var o1 = OTS.$(id + '_morelink');
	if (!o1) return;
	if (OTS.showMoreNav.opened == false) {
		OTS.showMoreNav.txt = OTS.getHTML(o1);
		OTS.showMoreNav.opened = true;
	}
	if (OTS.getStyle(o, 'display') == 'none') {
		OTS.setStyle(o, 'display', 'inline');
		OTS.setHTML(o1, 'Less');
	} else {
		OTS.setStyle(o, 'display', 'none');
		OTS.setHTML(o1, OTS.showMoreNav.txt);
	}
}

/*
/////////////////////////////
	Tabs
/////////////////////////////
*/

OTS.tabs = function(tabs, container, curr) {
	this.curr = (curr) ? curr : 0;
	this.tabs = tabs;
	this.container = container;
	this.contentArr = [];
	this.loadNav();
	this.loadContent();
	this.set(this.curr);
}
OTS.tabs.prototype.loadNav = function() {	
	var o = OTS.$(this.tabs);
	if (!o) return;
	OTS.setStyle(o, 'display', 'block');
	var _this = this;
	var t = o.getElementsByTagName('li');
	for (var i = 0; i < t.length; i++) {
		t[i].id = this.tabs + '_' + i;
		t[i].num = i;
		t[i].onclick = function() {
			_this.set(this.num);
			return false;
		}
	}
}
OTS.tabs.prototype.loadContent = function() {	
	var o = OTS.$(this.container);
	if (!o) return;
	OTS.setStyle(o, 'display', 'block');
	var t = o.getElementsByTagName('div');
	for (var i = 0; i < t.length; i++) {
		if (t[i].id.indexOf(this.tabs) > -1) {
			this.contentArr.push(t[i].id);
			OTS.setStyle(t[i], 'display', 'none');
		}
	}
}
OTS.tabs.prototype.set = function(n) {
	this.old = this.curr;
	this.curr = n;
	this.draw();
}
OTS.tabs.prototype.draw = function() {
	this.drawNav();
	this.drawContent();
}
OTS.tabs.prototype.drawNav = function() {
	var oo = OTS.$(this.tabs + '_' + this.old);
	if (oo) OTS.setClass(oo, '');
	var o = OTS.$(this.tabs + '_' + this.curr);
	if (o) OTS.setClass(o, 'on');
}
OTS.tabs.prototype.drawContent = function() {
	var oo = OTS.$(this.contentArr[this.old]);
	if (oo) OTS.setStyle(oo, 'display', 'none');
	var o = OTS.$(this.contentArr[this.curr]);
	if (o) OTS.setStyle(o, 'display', 'block');
}

/*
/////////////////////////////
	Helpful
/////////////////////////////
*/

OTS.helpfulReqURL = OTS.baseURL + '/community/ajax/ajax_comment_helpful.html';
OTS.helpful = {
	vote : function(id, w) {
		if (w == 'up') {
			OTS.helpful.doUp(id);
		} else {
			OTS.helpful.doDown(id);
		}
	},
	doUp : function(id) {
		var o = OTS.$('hpfl_up_' + id);
		if (!o) return;
		var r = new OTS.ajax(OTS.helpfulReqURL + '?o=up&id=' + id, OTS.helpful.setUp);
		r.id = id;
		r.html = o.innerHTML;
		r.request();
		OTS.setHTML(o, '<span class="iloading"></span>');
	},
	setUp : function(s, id, html) {
		var d = eval('(' + s + ')');
		if (d.success == 1) {
			OTS.setHTML('hpfl_up_' + id, '<span>' + d.upvote + '</span> <span class="ithmbsup chkd"></span>');
			OTS.setHTML('hpfl_dn_' + id, '<span>' + d.dnvote + '</span> <span class="ithmbsdn chkdoff"></span>');
		} else {
			OTS.setHTML('hpfl_up_' + id, html);
		}
	},
	doDown : function(id) {
		var o = OTS.$('hpfl_dn_' + id);
		if (!o) return;
		var r = new OTS.ajax(OTS.helpfulReqURL + '?o=dn&id=' + id, OTS.helpful.setDown);
		r.id = id;
		r.html = o.innerHTML;
		r.request();
		OTS.setHTML(o, '<span class="iloading"></span>');
	},
	setDown : function(s, id, html) {
		var d = eval('(' + s + ')');
		if (d.success == 1) {
			OTS.setHTML('hpfl_dn_' + id, '<span>' + d.dnvote + '</span> <span class="ithmbsdn chkd"></span>');
			OTS.setHTML('hpfl_up_' + id, '<span>' + d.upvote + '</span> <span class="ithmbsup chkdoff"></span>');
		} else {
			OTS.setHTML('hpfl_dn_' + id, html);
		}
	},
	doLogin : function() {
		OTS.doLogin('helpful');
	}
}

OTS.flagOptions = {
	reportas : 'Report Item As',
	choose : 'Choose one',
	additional : 'Additional Comments?',
	comments : 'Comments',
	report : 'Report',
	flag : [
		'Obscenity/vulgarity',
		'Hate speech',
		'Personal attack',
		'Advertising/Spam',
		'Copyright/Plagiarism',
		'Other'
	]
}
OTS.flagReqURL = OTS.baseURL + '/community/ajax/ajax_comment_flag.html';
OTS.flag = {
	active : false,
	report : function(id, target, e) {
		OTS.flag.oAb = OTS.$('hpfl_ab_' + id);
		if (!OTS.flag.oAb) return;
		OTS.flag.target = target;
		OTS.flag.showMenu(id);
	},
	showMenu : function(id) {
		var s = '<div class="ttip2" style="width:150px;">';
		s += '<form id="abuse_form" name="abuse_form" action="" method="post" onsubmit="OTS.flag.doReport(this); return false;" style="width:140px; padding:5px 10px 5px 5px; position:relative;">';
		s += '<input type="hidden" name="review_id" value="' + id + '" />';
		s += '<div class="close" style="position:absolute; top:0; right:0;"><a href="#" onclick="OTS.flag.hideMenu(); return false;"><img src="' + OTS.imgURL + '/mg/images/icon_close_sm_bk.gif" alt="X" border="0" align="absmiddle" /></a></div>';
		s += '<div id=""><strong>' + OTS.flagOptions.reportas + ':</strong><br /><select id="abuse_flag" name="abuse_flag">';
		s += '<option value="">' + OTS.flagOptions.choose + '</option>';
		for (var i = 0; i < OTS.flagOptions.flag.length; i++) {
			s += '<option value="' + (i + 1) + '">' + OTS.flagOptions.flag[i] + '</option>';
		}
		s += '</select></div><p id="report_comment_link"><a href="#" onclick="OTS.flag.showComment(); return false;">' + OTS.flagOptions.additional + '</a></p>';
		s += '<div id="report_comment" style="display:none;"><strong>' + OTS.flagOptions.comments + ':</strong><br /><textarea id="abuse_comment" name="abuse_comment"></textarea></div>';
		s += '<input type="submit" value="' + OTS.flagOptions.report + '" /></form>';
		s += '</div><b class="marker"></b>';
		var o = OTS.$('flag_menu');
		if (!o) {
			o = document.createElement('div');
			o.id = 'flag_menu';
			o.className = 'ttip';
			document.body.appendChild(o);
		}
		o.innerHTML = s;
		var p = OTS.getPos(OTS.flag.target);
		if (document.all) p.left += 20;
		OTS.setStyle(o, 'position', 'absolute');
		OTS.setStyle(o, 'left', p.left + 'px');
		OTS.setStyle(o, 'top', (p.top + 20) + 'px');
		OTS.flag.active = true;
	},
	hideMenu : function() {
		var o = OTS.$('flag_menu');
		if (!o) return;
		OTS.setHTML(o, '');
		OTS.setStyle(o, 'left', '-2000px');
		OTS.flag.active = false;
	},
	doReport : function(o) {
		var abuse_flag = escape(o.abuse_flag.value);
		if (abuse_flag == '') return;
		var abuse_comment = escape(o.abuse_comment.value);
		OTS.flag.doReq(o.review_id.value, abuse_flag, abuse_comment);
	},
	doReq : function(id, abuse_flag, abuse_comment) {
		var o = OTS.$('hpfl_ab_' + id);
		if (!o) return;
		var u = OTS.flagReqURL + '?o=ab&id=' + id + '&abuse_flag=' + abuse_flag + '&abuse_comment=' + abuse_comment;
		var r = new OTS.ajax(u, OTS.flag.doUpdate);
		r.id = id;
		r.html = o.innerHTML;
		r.request();
		OTS.setHTML(o, '<span class="iloading"></span>');
		OTS.flag.hideMenu();
	},
	doUpdate : function(s, id, html) {
		var d = eval('(' + s + ')');
		if (d.success == 1) {
			OTS.setHTML('hpfl_ab_' + id, '<span class="iabuse chkd">Reported</span>');
		} else {
			OTS.setHTML('hpfl_ab_' + id, html);
		}
	},
	showComment : function() {
		OTS.setStyle('report_comment_link', 'display', 'none');
		OTS.setStyle('report_comment', 'display', 'block');
	},
	closeMenu : function(e) {
		var o = e.target || e.srcElement;
		if (!OTS.hasParent(o, 'flag_menu') && o.className.indexOf('iabuse') == -1) {
			if (OTS.flag.active == true) {
				OTS.flag.hideMenu();
			}
		}
	},
	doLogin : function() {
		OTS.doLogin('abuse');
	}
}

addEvent(document, 'click', OTS.flag.closeMenu);

/*
/////////////////////////////
	Ratings
/////////////////////////////
*/

OTS.ratingsReqURL = OTS.baseURL + '/community/ajax/ajax_rating.html';
OTS.ratings = {
	t1 : null,
	active : false,
	showMore : function(id, target) {
		OTS.ratings.clearHide();
		OTS.ratings.target = target;
		OTS.ratings.t1 = setTimeout('OTS.ratings.doShow(' + id + ')', 500);
	},
	hideMore : function() {
		OTS.ratings.clearHide();
		if (OTS.ratings.active == true) {
			OTS.ratings.t1 = setTimeout('OTS.ratings.doHide()', 200);
		} else {
			
		}
	},
	doHide : function() {
		OTS.ratings.clearHide();
		var o = OTS.$('ratings_menu');
		if (!o) return;
		OTS.setHTML(o, '');
		OTS.setStyle(o, 'left', '-2000px');
		OTS.ratings.active = false;
	},
	doShow : function(id) {
		/*
		var u = OTS.ratingsReqURL + '?id=' + id;
		var r = new OTS.ajax(u, OTS.ratings2.doUpdate);
		r.id = id;
		r.request();
		*/
		var o = OTS.$('rev_rating' + id);
		if (!o) return;
		var html = o.innerHTML;
		html = '<ul class="rater_min rater_min_sm">' + html + '</ul>';
		OTS.ratings.doUpdate(html, id);
		OTS.ratings.active = true;
	},
	doUpdate : function(s, id) {
		var html = '<div class="ttip2">';
		html += s;
		html += '</div><b class="marker"></b>';
		var o = OTS.$('ratings_menu');
		if (!o) {
			o = document.createElement('div');
			o.id = 'ratings_menu';
			o.className = 'ttip';
			document.body.appendChild(o);
		}
		o.innerHTML = html;
		var p = OTS.getPos(OTS.ratings.target);
		OTS.setStyle(o, 'position', 'absolute');
		OTS.setStyle(o, 'left', p.left + 'px');
		OTS.setStyle(o, 'top', (p.top + 25) + 'px');
	},
	clearHide : function() {
		clearTimeout(OTS.ratings.t1);
	}
}

OTS.rating = {
	showMore : function(target, size) {
		OTS.rating.target = target;
		var html = '<span>';
		html += OTS.rating.target.innerHTML;
		html += '</span><b class="marker"></b>';
		var o = OTS.$('rating_menu');
		if (!o) {
			o = document.createElement('div');
			o.id = 'rating_menu';
			o.className = 'ttip_sm';
			document.body.appendChild(o);
		}
		o.innerHTML = html;
		var w = 80;
		var h = 1;
		if (size == 'sm') {
			w = 52;
			h = 4;
		}
		var p = OTS.getPos(OTS.rating.target);
		OTS.setStyle(o, 'position', 'absolute');
		OTS.setStyle(o, 'left', (p.left + w) + 'px');
		OTS.setStyle(o, 'top', (p.top - h) + 'px');
	},
	hideMore : function() {
		var o = OTS.$('rating_menu');
		if (!o) return;
		OTS.setHTML(o, '');
		OTS.setStyle(o, 'left', '-2000px');
	}
}

/*
/////////////////////////////
	Litebox
/////////////////////////////
*/

OTS.litebox = {
	load : function() {
		OTS.litebox.subbox = document.createElement('div');
		OTS.litebox.subbox.id = 'litebox';
		OTS.litebox.subbox.style.textAlign = 'center';
		OTS.litebox.subbox.style.width = '100%';
		OTS.litebox.subbox.style.display = 'none';
		OTS.litebox.subbox.style.position = 'absolute';
		OTS.litebox.subbox.style.top = '0';
		OTS.litebox.subbox.style.left = '0';
		OTS.litebox.subbox.style.zIndex = '9998';
		
		OTS.litebox.content = document.createElement('div');
		OTS.litebox.content.id = 'litebox_content';
		OTS.litebox.content.style.display = 'none';
		OTS.litebox.content.style.position = 'relative';
		OTS.litebox.content.style.margin = '0 auto';
		OTS.litebox.subbox.appendChild(OTS.litebox.content);
		
		/*var body = document.getElementsByTagName('body').item(0);*/
		/*document.body.appendChild(OTS.litebox.subbox);*/
		var o = OTS.$('empty');
		if (!o) return;
		o.appendChild(OTS.litebox.subbox);
	},
	showDiv : function(obj) {
		/*
		litebox.Obj = $(obj);
		if (!litebox.Obj) return;
		litebox.Obj = litebox.Obj.clone();
		litebox.Obj.injectInside(litebox.SubBox);
		litebox.Obj.setStyle('display', 'block');
		*/
		
		OTS.litebox.show();
	},
	showIframe : function(u, w, h) {
		/*
		if (!litebox.SubBox) return;
		litebox.Obj = new Element('div', {'id' : 'litebox_iframe'});
		litebox.Obj.injectInside(litebox.SubBox);
		litebox.Obj.addClass('litebox_frame');
		litebox.Obj.setHTML('<iframe src="' + u + '" width="' + w + '" height="' + h + '" allowtransparency="true" framespacing="0" frameborder="no" scrolling="auto"></iframe>');
		litebox.Obj.setStyle('display', 'block');
		*/
		
		OTS.litebox.show();
	},
	showAjax : function(u) {
		if (!OTS.litebox.subbox) return;
		
		var pgeSizeArr = OTS.getPageSize();
		var pgeScroll = OTS.getPageScroll();
		
		OTS.litebox.subbox.style.display = 'block';
		
		OTS.litebox.content.innerHTML = '<span class="iloading"></span>';
		OTS.litebox.content.style.width = '30px';
		OTS.litebox.content.style.display = 'block';
		
		var lightboxTop = pgeScroll + ((pgeSizeArr[3] * .5) - (OTS.litebox.subbox.offsetHeight * .5));
		OTS.litebox.content.style.top = lightboxTop + 'px';
		
		var r = new OTS.ajax(u, OTS.litebox.writeAjax);
		r.request();
	},
	writeAjax : function(s) {
		var pgeSizeArr = OTS.getPageSize();
		var pgeScroll = OTS.getPageScroll();
		
		OTS.litebox.content.innerHTML = '<div id="litebox_data" class="litebox">' + s + '</div>';
		OTS.litebox.content.style.width = '600px';
		OTS.litebox.content.style.display = 'block';
		
		var subbox_close = document.createElement('div');
		subbox_close.innerHTML = '<a href="#" onclick="litebox.hide(); return false;"><img src="' + OTS.imgURL + '/mg/images/icon_close_sm_bk.gif" alt="" border="0" /></a>';
		subbox_close.style.position = 'absolute';
		subbox_close.style.top = '20px';
		subbox_close.style.right = '20px';
		OTS.litebox.content.appendChild(subbox_close);
		
		var lightboxTop = pgeScroll + ((pgeSizeArr[3] * .5) - (OTS.litebox.subbox.offsetHeight * .5));
		OTS.litebox.content.style.top = lightboxTop + 'px';
		
		OTS.litebox.toggleObjects('hidden');
	},
	show : function() {
		/*
		litebox.Box.addEvent('click', litebox.hide);
		litebox.Box.setStyle('height', Window.getScrollHeight());
		litebox.Box.setStyle('visibility', 'visible');
		litebox.Box.setStyle('opacity', '.8');
		litebox.SubBox.setStyle('display', 'block');
		litebox.SubBox.setStyle('top', ((Window.getHeight() * .5) - (litebox.Obj.offsetHeight * .5) + (Window.getScrollTop() - 120)));
		litebox.SubBox.setStyle('left', (Window.getWidth() * .5) - (litebox.SubBox.offsetWidth * .5));
		litebox.Close = new Element('div').injectInside(litebox.SubBox).addClass('litebox_close');
		litebox.Close.addEvent('click', litebox.hide);
		*/
	},
	hide : function() {
		OTS.litebox.content.innerHTML = '';
		OTS.litebox.subbox.style.display = 'none';
		OTS.litebox.toggleObjects('visible');
	},
	toggleObjects : function(s) {
		var elms = document.getElementsByTagName('select');
		for (var i = 0; i != elms.length; i++) {
			elms[i].style.visibility = s;
		}
		var elms2 = document.getElementsByTagName('iframe');
		for (var i = 0; i != elms2.length; i++) {
			elms2[i].style.visibility = s;
		}
		var elms3 = document.getElementsByTagName('object');
		for (var i = 0; i != elms3.length; i++) {
			elms3[i].style.visibility = s;
		}
		var elms4 = document.getElementsByTagName('embed');
		for (var i = 0; i != elms4.length; i++) {
			elms4[i].style.visibility = s;
		}
	}
}

OTS.loginReg = {
	load : function() {
		OTS.loginReg.Form = OTS.$('loginreg_box');
		if (!OTS.loginReg.Form) return;
		
		var ja = document.getElementsByTagName('a');
		for (var i = 0; i < ja.length; i++) {
			if (ja[i].className == 'signin') {
				ja[i].onclick = function() {
					OTS.loginReg.show();
					return false;
				}
				/*ja[i].href = '#';*/
			}
		}
		
		OTS.loginReg.Box = OTS.$('litebox');
		if (OTS.loginReg.Box) OTS.loginReg.Box.onclick = function() {
			OTS.loginReg.hide();
			return false;
		}
		
		OTS.loginReg.Close = document.createElement('div');
		OTS.loginReg.Close.className = 'litebox_close';
		OTS.loginReg.Form.appendChild(OTS.loginReg.Close);
		if (OTS.loginReg.Close) OTS.loginReg.Close.onclick = function() {
			OTS.loginReg.hide();
			return false;
		}
	},
	show : function(s) {
		var pgeSizeArr = OTS.getPageSize();
		var pgeScroll = OTS.getPageScroll();
		var f = OTS.loginReg.Form;
		OTS.setStyle(OTS.loginReg.Box, 'height', pgeSizeArr.pageHeight + 'px');
		OTS.setStyle(OTS.loginReg.Box, 'display', 'block');
		OTS.setStyle(OTS.loginReg.Box, 'opacity', '80');
		var t = (pgeSizeArr.windowHeight * .5) - (f.offsetHeight * .5);
		if (pgeSizeArr.windowHeight > 600) {
			t = 120;
		}
		OTS.setStyle(OTS.loginReg.Form, 'top', (pgeScroll + t) + 'px');
		OTS.setStyle(OTS.loginReg.Form, 'left', (pgeSizeArr.pageWidth * .5) - (f.offsetWidth * .5) + 'px');
		var o = OTS.$('user_login');
		if (!o) return;
		o.user_name.focus();
		OTS.litebox.toggleObjects('hidden');
		OTS.loginReg.showMsgr(s);
	},
	hide : function() {
		OTS.setStyle(OTS.loginReg.Form, 'top', '-1000px');
		OTS.setStyle(OTS.loginReg.Form, 'left', '-2000px');
		OTS.setStyle(OTS.loginReg.Box, 'display', 'none');
		OTS.litebox.toggleObjects('visible');
		OTS.loginReg.hideMsgr();
	},
	showMsgr : function(s) {
		var o = OTS.$('login_msgr');
		if (!o) return;
		//if (!s) s = 0;
		if (!s) return;
		var t = '<div class="login_msgr">';
		t += OTS.loginMsgTxtObj[s];
		t += '</div>';
		OTS.setHTML(o, t);
	},
	hideMsgr : function() {
		var o = OTS.$('login_msgr');
		if (!o) return;
		OTS.setHTML(o, '');
	}
}

/*
/////////////////////////////
	Litebox
/////////////////////////////
*/

OTS.litebox = {
	load : function() {
		OTS.litebox.subbox = document.createElement('div');
		OTS.litebox.subbox.id = 'litebox';
		OTS.litebox.subbox.style.textAlign = 'center';
		OTS.litebox.subbox.style.width = '100%';
		OTS.litebox.subbox.style.display = 'none';
		OTS.litebox.subbox.style.position = 'absolute';
		OTS.litebox.subbox.style.top = '0';
		OTS.litebox.subbox.style.left = '0';
		OTS.litebox.subbox.style.zIndex = '9998';
		
		OTS.litebox.content = document.createElement('div');
		OTS.litebox.content.id = 'litebox_content';
		OTS.litebox.content.style.display = 'none';
		OTS.litebox.content.style.position = 'relative';
		OTS.litebox.content.style.margin = '0 auto';
		OTS.litebox.subbox.appendChild(OTS.litebox.content);
		
		/*var body = document.getElementsByTagName('body').item(0);*/
		/*document.body.appendChild(OTS.litebox.subbox);*/
		var o = OTS.$('empty');
		if (!o) return;
		o.appendChild(OTS.litebox.subbox);
	},
	showDiv : function(obj) {
		/*
		litebox.Obj = $(obj);
		if (!litebox.Obj) return;
		litebox.Obj = litebox.Obj.clone();
		litebox.Obj.injectInside(litebox.SubBox);
		litebox.Obj.setStyle('display', 'block');
		*/
		
		OTS.litebox.show();
	},
	showIframe : function(u, w, h) {
		/*
		if (!litebox.SubBox) return;
		litebox.Obj = new Element('div', {'id' : 'litebox_iframe'});
		litebox.Obj.injectInside(litebox.SubBox);
		litebox.Obj.addClass('litebox_frame');
		litebox.Obj.setHTML('<iframe src="' + u + '" width="' + w + '" height="' + h + '" allowtransparency="true" framespacing="0" frameborder="no" scrolling="auto"></iframe>');
		litebox.Obj.setStyle('display', 'block');
		*/
		
		OTS.litebox.show();
	},
	showAjax : function(u) {
		if (!OTS.litebox.subbox) return;
		
		var pgeSizeArr = OTS.getPageSize();
		var pgeScroll = OTS.getPageScroll();
		
		OTS.litebox.subbox.style.display = 'block';
		
		OTS.litebox.content.innerHTML = '<span class="iloading"></span>';
		OTS.litebox.content.style.width = '30px';
		OTS.litebox.content.style.display = 'block';
		
		var lightboxTop = pgeScroll + ((pgeSizeArr[3] * .5) - (OTS.litebox.subbox.offsetHeight * .5));
		OTS.litebox.content.style.top = lightboxTop + 'px';
		
		var r = new OTS.ajax(u, OTS.litebox.writeAjax);
		r.request();
	},
	writeAjax : function(s) {
		var pgeSizeArr = OTS.getPageSize();
		var pgeScroll = OTS.getPageScroll();
		
		OTS.litebox.content.innerHTML = '<div id="litebox_data" class="litebox">' + s + '</div>';
		OTS.litebox.content.style.width = '600px';
		OTS.litebox.content.style.display = 'block';
		
		var subbox_close = document.createElement('div');
		subbox_close.innerHTML = '<a href="#" onclick="litebox.hide(); return false;"><img src="' + OTS.imgURL + '/ots/images/icon_close.gif" alt="" border="0" /></a>';
		subbox_close.style.position = 'absolute';
		subbox_close.style.top = '20px';
		subbox_close.style.right = '20px';
		OTS.litebox.content.appendChild(subbox_close);
		
		var lightboxTop = pgeScroll + ((pgeSizeArr[3] * .5) - (OTS.litebox.subbox.offsetHeight * .5));
		OTS.litebox.content.style.top = lightboxTop + 'px';
		
		OTS.litebox.toggleObjects('hidden');
	},
	show : function() {
		/*
		litebox.Box.addEvent('click', litebox.hide);
		litebox.Box.setStyle('height', Window.getScrollHeight());
		litebox.Box.setStyle('visibility', 'visible');
		litebox.Box.setStyle('opacity', '.8');
		litebox.SubBox.setStyle('display', 'block');
		litebox.SubBox.setStyle('top', ((Window.getHeight() * .5) - (litebox.Obj.offsetHeight * .5) + (Window.getScrollTop() - 120)));
		litebox.SubBox.setStyle('left', (Window.getWidth() * .5) - (litebox.SubBox.offsetWidth * .5));
		litebox.Close = new Element('div').injectInside(litebox.SubBox).addClass('litebox_close');
		litebox.Close.addEvent('click', litebox.hide);
		*/
	},
	hide : function() {
		OTS.litebox.content.innerHTML = '';
		OTS.litebox.subbox.style.display = 'none';
		OTS.litebox.toggleObjects('visible');
	},
	toggleObjects : function(s) {
		var elms = document.getElementsByTagName('select');
		for (var i = 0; i != elms.length; i++) {
			elms[i].style.visibility = s;
		}
		var elms2 = document.getElementsByTagName('iframe');
		for (var i = 0; i != elms2.length; i++) {
			elms2[i].style.visibility = s;
		}
		var elms3 = document.getElementsByTagName('object');
		for (var i = 0; i != elms3.length; i++) {
			elms3[i].style.visibility = s;
		}
		var elms4 = document.getElementsByTagName('embed');
		for (var i = 0; i != elms4.length; i++) {
			elms4[i].style.visibility = s;
		}
	}
}

OTS.loginReg = {
	load : function() {
		OTS.loginReg.Form = OTS.$('loginreg_box');
		if (!OTS.loginReg.Form) return;
		
		var ja = document.getElementsByTagName('a');
		for (var i = 0; i < ja.length; i++) {
			if (ja[i].className == 'signin') {
				ja[i].onclick = function() {
					OTS.loginReg.show();
					return false;
				}
				/*ja[i].href = '#';*/
			}
		}
		
		OTS.loginReg.Box = OTS.$('litebox');
		if (OTS.loginReg.Box) OTS.loginReg.Box.onclick = function() {
			OTS.loginReg.hide();
			return false;
		}
		
		OTS.loginReg.Close = document.createElement('div');
		OTS.loginReg.Close.className = 'litebox_close';
		OTS.loginReg.Form.appendChild(OTS.loginReg.Close);
		if (OTS.loginReg.Close) OTS.loginReg.Close.onclick = function() {
			OTS.loginReg.hide();
			return false;
		}
	},
	show : function(s) {
		var pgeSizeArr = OTS.getPageSize();
		var pgeScroll = OTS.getPageScroll();
		var f = OTS.loginReg.Form;
		OTS.setStyle(OTS.loginReg.Box, 'height', pgeSizeArr.pageHeight + 'px');
		OTS.setStyle(OTS.loginReg.Box, 'display', 'block');
		OTS.setStyle(OTS.loginReg.Box, 'opacity', '80');
		var t = (pgeSizeArr.windowHeight * .5) - (f.offsetHeight * .5);
		if (pgeSizeArr.windowHeight > 600) {
			t = 120;
		}
		OTS.setStyle(OTS.loginReg.Form, 'top', (pgeScroll + t) + 'px');
		OTS.setStyle(OTS.loginReg.Form, 'left', (pgeSizeArr.pageWidth * .5) - (f.offsetWidth * .5) + 'px');
		var o = OTS.$('user_login');
		if (!o) return;
		o.user_name.focus();
		OTS.litebox.toggleObjects('hidden');
		OTS.loginReg.showMsgr(s);
	},
	hide : function() {
		OTS.setStyle(OTS.loginReg.Form, 'top', '-1000px');
		OTS.setStyle(OTS.loginReg.Form, 'left', '-2000px');
		OTS.setStyle(OTS.loginReg.Box, 'display', 'none');
		OTS.litebox.toggleObjects('visible');
		OTS.loginReg.hideMsgr();
	},
	showMsgr : function(s) {
		var o = OTS.$('login_msgr');
		if (!o) return;
		//if (!s) s = 0;
		if (!s) return;
		var t = '<div class="login_msgr">';
		t += OTS.loginMsgTxtObj[s];
		t += '</div>';
		OTS.setHTML(o, t);
	},
	hideMsgr : function() {
		var o = OTS.$('login_msgr');
		if (!o) return;
		OTS.setHTML(o, '');
	}
}

/*
/////////////////////////////
	Auth validation
/////////////////////////////
*/

OTS.loginMsgTxtObj = {
	'generic' : "Generic",
	'login' : "Login",
	'register' : "Register",
	'favorites' : "Favorites",
	'helpful' : "Helpful",
	'abuse' : "Abuse",
	'review' : "Review",
	'comment' : "Comment",
	'blog' : "Blog"
}

OTS.doLogin = function(s) {
	OTS.loginReg.show(s);
}

OTS.loginTxtObj = {
	't1' : 'Username or E-mail',
	't2' : 'Password'
}
OTS.validateLogin = function() {
	var f = document.user_login;
	var s = '';
	if (f.user_name.value == '') s += OTS.loginTxtObj.t1 + "<br />";
	if (f.password.value == '') s += OTS.loginTxtObj.t2 + "<br />";
	if (s != '') {
		OTS.validateWriteErrs('login_errors', s);
		return false;
	} else {
		f.submit();
	}
}

OTS.registerTxtObj = {
	't1' : 'Username',
	't2' : 'E-mail Address',
	't3' : 'Passord',
	't4' : 'Retype Password'
}
OTS.validateReg = function() {
	var f = document.user_register;
	var s = '';
	if (f.user_name.value == '') s += OTS.registerTxtObj.t1 + "<br />";
	if (f.email.value == '') s += OTS.registerTxtObj.t2 + "<br />";
	if (f.password.value == '') s += OTS.registerTxtObj.t3 + "<br />";
	if (f.password_check.value == '') s += OTS.registerTxtObj.t4 + "<br />";
	if (s != '') {
		OTS.validateWriteErrs('reg_errors', s);
		return false;
	} else {
		f.submit();
	}
}

OTS.validateWriteErrs = function(id, s) {
	var s = '' + '<h4>Error</h4>' + s + '';
	var elm = OTS.$(id);
	if (elm) {
		elm.innerHTML = '<div class="errors">' + s + '</div>';
		elm.style.display = 'block';
	} else {
		s = s.replace(/<\/h4>/g, "\n\n");
		s = s.replace(/<br \/>/g, "\n");
		s = s.replace(/(<([^>]+)>)/ig,""); 
		alert(s);
	}
}

/*
/////////////////////////////
	
/////////////////////////////
*/

if (document.all && !window.XMLHttpRequest) {
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
}

window.onerror = function() {
	/*return true;*/
}

function globalInit() {
	//litebox.load();
	//OTS.loginReg.load();
}

function addEvent(o, t, m) {
	if (o.addEventListener) {
		o.addEventListener(t, m, true);
		return true;
	} else if (o.attachEvent) {
		var r = o.attachEvent('on' + t, m);
		return r;
	} else {
		return false;
	}
}
function addEvent2(o, t, m) {
	if (o.attachEvent) {
		o['e' + t + m] = m;
		o[t + m] = function() {
			o['e' + t + m](window.event);
		}
		o.attachEvent('on' + t, o[t + m]);
	} else {
		o.addEventListener(t, m, false);
	}
}
function removeEvent(o, t, m) {
	if (o.detachEvent) {
		o.detachEvent('on' + t, o[t + m]);
		o[t + m] = null;
	} else {
		o.removeEventListener(t, m, false);
	}
}
addEvent(window, 'load', globalInit);

/*
/////////////////////////////
	Calendar
/////////////////////////////
*/

OTS.madCalArr = [];
function madCalSelector(oName, formObj, dateformat) {
	this.oName = oName;
	this.calObj = null;
	this.dateFormat = dateformat || 'yyyy-mm-dd';
	this.monthSelected;
	this.yearSelected;
	this.dateSelected;
	this.omonthSelected;
	this.oyearSelected;
	this.formObj = document.getElementById(formObj) || eval(formObj);
	this.htmlIcon = '';
	this.htmlCal = '';
	this.active = false;
	this.event = null;
	this.Config = new CalConfig();
	this.calDate = new CalDate();
	this.init();
}
madCalSelector.prototype.init = function() {
	var o = document.getElementById(this.oName);
	if (!o) return;
	//o.innerHTML = this.makeIcon();
	var _this = this;
	o.onclick = function() {
		_this.showCalSelector(this);
	};
	OTS.madCalArr.push(this.oName);
}
madCalSelector.prototype.makeIcon = function() {
	var s = '<a class="ico" onclick="' + this.oName + '.showCalSelector(this);"><img src="' + this.Config.imgDir + this.Config.imgArr[0] + '" alt="' + this.Config.choosedate + '" border="0" /></a>';
	return s;
}
madCalSelector.prototype.makeCal = function() {
	var s = '';
	s += '<div class="cal_hd">';
	s += '<span class="cal_prev" onclick="' + this.oName + '.decMonth();"><img src="' + this.Config.imgDir + this.Config.imgArr[1] + '" alt="' + this.Config.previous + '" border="0" /></span>';
	s += '<span class="cal_next" onclick="' + this.oName + '.incMonth();"><img src="' + this.Config.imgDir + this.Config.imgArr[2] + '" alt="' + this.Config.next + '" border="0" /></span>';
	s += '<span id="' + this.oName + '_month" class="cal_month"></span>';
	s += '<span class="cal_close" onclick="' + this.oName + '.hideCalSelector();"><img src="' + this.Config.imgDir + this.Config.imgArr[3] + '" alt="' + this.Config.close + '" border="0" /></span>';
	s += '</div>';
	s += '<div id="' + this.oName + '_content"></div>';
	if (this.Config.showToday == 1) {
		s += '<div class="cal_today">';
		s += this.Config.strTodayis 
		s += ' <a href="#" onclick="' + this.oName + '.monthSelected=' + this.oName + '.calDate.monthNow; ' + this.oName + '.yearSelected=' + this.oName + '.calDate.yearNow; ' + this.oName + '.buildCalSelector(); return false;" title="' + this.Config.strCurrentMonth + '">';
		s += this.Config.dayNameArr[(this.calDate.today.getDay() - this.Config.weekStart == -1) ? 6 : (this.calDate.today.getDay() - this.Config.weekStart)] + ', ' + this.calDate.dateNow + ' ' + this.Config.monthNameArr[this.calDate.monthNow].substring(0, 3) + ' ' + this.calDate.yearNow + '</a>';
		s += '</div>';
	}
	s += '';
	return s;
}
madCalSelector.prototype.closeAllCals = function() {
	for (var i = 0; i < OTS.madCalArr.length; i++) {
		var o = document.getElementById(OTS.madCalArr[i] + '_cal');
		if (o) {
			o.parentNode.removeChild(o);
			var r = eval(OTS.madCalArr[i]);
			r.clearSlide();
			r.active = false;
			r.sactive = false;
		}
	}
}
madCalSelector.prototype.hideCalSelector = function() {
	this.clearSlide();
	var o = document.getElementById(this.oName + '_cal');
	if (!o) return;
	o.parentNode.removeChild(o);
	this.active = false;
	this.sactive = false;
}
madCalSelector.prototype.showCalSelector = function(target) {
	if (!this.active) {
		this.closeAllCals();
		this.buildCalFormat();
		var o = document.getElementById(this.oName + '_cal');
		if (!o) {
			o = document.createElement('div');
			o.id = this.oName + '_cal';
			o.className = 'calSelector';
			o.style.cssText = this.Config.calselectorstyle;
			document.body.appendChild(o);
		}
		var s = this.makeCal();
		o.innerHTML = '<div id="' + this.oName + '_cal_str">' + s + '</div>';
		this.buildCalSelector();
		//var p = this.getPos(target);
		var p = this.getPos(target.parentNode);
		o.style.top = (p.top + 23) + 'px';
		o.style.left = (p.left + 0) + 'px';
		this.nudge(o, target);
		var _this = this;
		o.onclick = function() {
			_this.setIndex(this);
		}
		this.slide();
		this.active = true;
	} else {
		this.hideCalSelector();
	}
}
madCalSelector.prototype.doShowDone = function() {
	this.sactive = false;
	var o = document.getElementById(this.oName + '_cal_str');
	o.style.height = this.h + 'px';
}
madCalSelector.prototype.slide = function() {
	if (this.sactive) return;
	this.clearSlide();
	this.sactive = true;
	var o = document.getElementById(this.oName + '_cal_str');
	this.h = o.offsetHeight;
	o.style.height = '0';
	this.t = (new Date()).getTime();
	this.b = 0;
	this.c = this.h - this.b;
	this.d = 200;
	this.t1 = setInterval(this.oName + ".animate()", 10);
}
madCalSelector.prototype.animate = function() {
	var t = (new Date()).getTime() - this.t;
	if (t > this.d) {
		this.clearSlide();
		this.doShowDone();
		return;
	} else {
		var y = OTS.ease.strongEaseOut(t, this.b, this.c, this.d);
		document.getElementById(this.oName + '_cal_str').style.height = y + 'px';
	}
}
madCalSelector.prototype.clearSlide = function() {
	if (this.t1) {
		clearTimeout(this.t1);
		this.t1 = null;
	}
}
madCalSelector.prototype.nudge = function(o, t) {
	var w = 0;
	if (self.innerHeight) {
		w = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		w = document.documentElement.clientWidth;
	} else if (document.body) {
		w = document.body.clientWidth;
	}
	if (w == 0) return;
	var wx = w * .5;
	if (parseInt(o.style.left) > wx) {
		var x = parseInt(o.style.left);
		//x -= (o.offsetWidth - 20);
		x -= ((o.offsetWidth - 0) - t.parentNode.offsetWidth);
		o.style.left = x + 'px';
	}
}
madCalSelector.prototype.getPos = function(obj) {
	return {
		left : this.getOffset(obj, 'left'),
		top : this.getOffset(obj, 'top')
	}
}
madCalSelector.prototype.getOffset = function(obj, type) {
	var curoffset = (type == 'left') ? obj.offsetLeft : obj.offsetTop;
	var elm = obj.offsetParent;
	while (elm != null) {
		curoffset += (type == 'left') ? elm.offsetLeft : elm.offsetTop;
		elm = elm.offsetParent;
	}
	return curoffset;
}
madCalSelector.prototype.addEvent = function(o, t, m) {
	if (o.addEventListener) {
		o.addEventListener(t, m, false);
	} else if (o.attachEvent) {
		o.detachEvent('on' + t, m);
		o.attachEvent('on' + t, m);
	}
}
madCalSelector.prototype.delEvent = function(o, t, m) {
	if (o.removeEventListener) {
		o.removeEventListener(t, m, false);
	} else if (o.detachEvent) {
		o.detachEvent('on' + t, m);
	}
}
madCalSelector.prototype.setIndex = function(o) {
	o.style.zIndex++;
}
madCalSelector.prototype.buildCalFormat = function() {
	var A = this.getFormat();
	var c = A[0];
	var f = A[1];
	var tch = 0
	if (c != '') {
		var aData = this.formObj.value.split(c);
		for (var i = 0; i < 3; i++) {
			if ((f[i] == 'd') || (f[i] == 'dd')) {
				this.dateSelected = parseInt(aData[i], 10);
				tch++;
			} else if ((f[i] == 'm') || (f[i] == 'mm')) {
				this.monthSelected = parseInt(aData[i], 10) - 1;
				tch++;
			} else if (f[i] == 'yyyy') {
				this.yearSelected = parseInt(aData[i], 10);
				tch++;
			} else if (f[i] == 'mmm') {
				for (var j = 0; j < 12; j++) {
					if (aData[i] == this.monthNameArr[j]) {
						this.monthSelected = j;
						tch++;
					}
				}
			} else if (f[i] == 'mmmm') {
				for (var j = 0; j < 12; j++) {
					if (aData[i] == this.monthNameArr2[j]) {
						this.monthSelected = j;
						tch++;
					}
				}
			}
		}
	}
	if ((tch != 3) || isNaN(this.dateSelected) || isNaN(this.monthSelected) || isNaN(this.yearSelected)) {
		this.dateSelected = this.calDate.dateNow;
		this.monthSelected = this.calDate.monthNow;
		this.yearSelected = this.calDate.yearNow;
	}
	this.odateSelected = this.dateSelected;
	this.omonthSelected = this.monthSelected;
	this.oyearSelected = this.yearSelected;
}
madCalSelector.prototype.buildCalData = function() {
	var d = {};
	d.NDM;
	d.datePointer;
	d.arrND = [31,0,31,30,31,30,31,31,30,31,30,31];
	d.dateMessage;
	d.startDate = new Date(this.yearSelected, this.monthSelected, 1);
	d.endDate;
	if (this.monthSelected == 1) {
		d.endDate = new Date(this.yearSelected, this.monthSelected + 1, 1);
		d.endDate = new Date(d.endDate - (24 * 60 * 60 * 1000));
		d.NDM = d.endDate.getDate();
	} else {
		d.NDM = d.arrND[this.monthSelected];
	}
	d.datePointer = 0;
	d.dayPointer = d.startDate.getDay() - this.Config.weekStart;
	if (d.dayPointer < 0) {
		d.dayPointer = 6;
	}
	d.WN = this.WeekNbr(d.startDate);
	return d;
}
madCalSelector.prototype.buildCalSelector = function() {
	var d = this.buildCalData();
	var p = new madCalPrinter(this, d);
	document.getElementById(this.oName + '_content').innerHTML = p.printedCal;
	document.getElementById(this.oName + '_month').innerHTML = ' ' + this.Config.monthNameArr[this.monthSelected] + ' ' + this.yearSelected + ' ';
}
madCalSelector.prototype.closeCalSelector = function() {
	this.hideCalSelector();
	this.formObj.value = this.constructDate(this.dateSelected, this.monthSelected, this.yearSelected);
}
madCalSelector.prototype.incMonth = function() {
	this.monthSelected++;
	if (this.monthSelected > 11) {
		this.monthSelected = 0;
		this.yearSelected++;
	}
	this.buildCalSelector();
}
madCalSelector.prototype.decMonth = function() {
	this.monthSelected--;
	if (this.monthSelected < 0) {
		this.monthSelected = 11;
		this.yearSelected--;
	}
	this.buildCalSelector();
}
madCalSelector.prototype.WeekNbr = function(n){
	var year = n.getFullYear();
	var month = n.getMonth() + 1;
	var day;
	if (this.Config.weekStart == 0) {
		day = n.getDate() + 1;
	} else {
		day = n.getDate();
	}
	var a = Math.floor((14 - month) / 12);
	var y = year + 4800 - a;
	var m = month + 12 * a - 3;
	var b = Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400);
	var J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
	var d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
	var L = Math.floor(d4 / 1460);
	var d1 = ((d4 - L) % 365) + L;
	return Math.floor(d1 / 7) + 1;
}
madCalSelector.prototype.padZero = function(n) {
	return (n < 10) ? '0' + n : n;
}
madCalSelector.prototype.constructDate = function(d, m, y) {
	var s = this.dateFormat;
	s = s.replace("dd", "<e>");
	s = s.replace("d", "<d>");
	s = s.replace("<e>", this.padZero(d));
	s = s.replace("<d>", d);
	s = s.replace("mmmm", "<p>");
	s = s.replace("mmm", "<o>");
	s = s.replace("mm", "<n>");
	s = s.replace("m", "<m>");
	s = s.replace("<m>", m + 1);
	s = s.replace("<n>", this.padZero(m+1));
	s = s.replace("<o>", this.Config.monthNameArr[m]);
	s = s.replace("<p>", this.Config.monthNameArr2[m]);
	s = s.replace("yyyy", y);
	s = s.replace("yy", this.padZero(y % 100));
	return s;
}
madCalSelector.prototype.getFormat = function() {
	var c = ' ';
	var f = this.dateFormat.split(c)
	if (f.length < 3) {
		c = '/';
		f = this.dateFormat.split(c)
		if (f.length < 3) {
			c = '.';
			f = this.dateFormat.split(c)
			if (f.length < 3) {
				c = '-';
				f = this.dateFormat.split(c)
				if (f.length < 3) {
					c = '';
				}
			}
		}
	}
	return [c, f];
}
function madCalPrinter(CObj, CalData) {
	this.CObj = CObj;
	this.CalData = CalData;
	this.printedCal = '';
	var Config = this.CObj.Config;
	var s = '<table class="calendar" cellpadding="0" cellspacing="0" border="0"><tr>';
	if (CObj.Config.showWeekNumber == 1) {
		s += '<td class="cal_week_hd">' + CObj.Config.strWeek + '</td><td rowspan="7"><div class="divider"></div></td>';
	} 
	for (var i = 0; i < 7; i++)	{
		s += '<td class="cal_hd">' + CObj.Config.dayNameArr[i] + '</td>';	
	}
	s += '</tr><tr>';
	if (CObj.Config.showWeekNumber == 1) {
		s += '<td class="cal_week">' + CalData.WN + '</td>';
	}
	for (var i = 1; i <= CalData.dayPointer; i++) {
		s += '<td class="cal_empty"></td>';
	}
	for (CalData.datePointer = 1; CalData.datePointer <= CalData.NDM; CalData.datePointer++) {
		CalData.dayPointer++;
		s += '<td class="cal_normal">';
		var dateMessage = '';
		if ((CalData.datePointer == CObj.calDate.dateNow) && (CObj.monthSelected == CObj.calDate.monthNow) && (CObj.yearSelected == CObj.calDate.yearNow)) { 
			s += '<a class="cal_day_curr" href="#" onclick="' + CObj.oName + '.dateSelected=\'' + CalData.datePointer + '\'; ' + CObj.oName + '.closeCalSelector(); return false;">' + CalData.datePointer + '</a>';
		} else if (CalData.dayPointer % 7 == (Config.weekStart * -1) + 1) { 
			s += '<a class="cal_day" href="#" onclick="' + CObj.oName + '.dateSelected=\'' + CalData.datePointer + '\'; ' + CObj.oName + '.closeCalSelector(); return false;">' + CalData.datePointer + '</a>';
		} else { 
			s += '<a class="cal_day" href="#" onclick="' + CObj.oName + '.dateSelected=\'' + CalData.datePointer + '\'; ' + CObj.oName + '.closeCalSelector(); return false;">' + CalData.datePointer + '</a>';
		}
		s += '</td>';
		if ((CalData.dayPointer + CObj.Config.weekStart) % 7 == CObj.Config.weekStart) { 
			s += '</tr><tr>' ;
			if ((CObj.Config.showWeekNumber == 1) && (CalData.datePointer < CalData.NDM)) {
				s += '<td class="cal_week">' + (CObj.WeekNbr(new Date(CObj.yearSelected, CObj.monthSelected, CalData.datePointer + 1))) + '</td>';
			}
		}
	}
	this.printedCal = s;
}
function CalDate() {
	this.today = new Date();
	this.dateNow = this.today.getDate();
	this.monthNow = this.today.getMonth();
	this.yearNow = this.today.getFullYear();
}
function CalConfig() {
	this.imgArr = ['icon_calendar.gif','icon_prev_sm.gif','icon_next_sm.gif','icon_close_sm_bk.gif'];
	this.imgDir = '/mg/images/';
	this.calselectorstyle = 'width:200px; overflow:hidden;';
	this.weekStart = 0;// 0 - sunday : 1 - monday
	this.showWeekNumber = 1;
	this.showToday = 1;
	this.strCurrentMonth = 'Go To Current Month';
	this.strTodayis = 'Today is';
	this.strWeek = 'Wk';
	this.strselectDate = 'Select [date] as date.' // do not replace [date], it will be replaced by date.
	this.close = 'Close Calendar';
	this.next = 'Next';
	this.previous = 'Previous';
	this.choosedate = 'Choose a Date';
	this.monthNameArr = ["January","February","March","April","May","June","July","August","September","October","November","December"];
	this.monthNameArr2 = ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];
	if (this.weekStart == 0) {
		this.dayNameArr = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
	} else {
		this.dayNameArr = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
	}
}
