
/*

*/

OTS.infoBubble = {};

OTS.infoBubble.active = 0;
OTS.infoBubble.curr = 0;
OTS.infoBubble.len = 0;

OTS.infoBubble.init = function(html, id, x, y, v) {
	var c = OTS.infoBubble.getCookie('popmsgr');
	if (c) {
		c = eval('({' + OTS.infoBubble.getCookie('popmsgr') + '})');
	} else {
		c = {curr:0,active:0};
	}
	if (c.active == 0) {
		if (!OTS.infoBubble.getFortune()) return;
		c.active = 1;
		OTS.infoBubble.setCookie('popmsgr', 'active:"' + c.active + '",curr:"' + c.curr + '"', 90);
	}
	var o = OTS.infoBubbleTxtObj;
	var p = o[o.p];
	if(!p) return;
	var d = p[c.curr];
	OTS.infoBubble.len = p.length;
	OTS.infoBubble.curr = c.curr;
	OTS.infoBubble.active = c.active;
	if (c.curr >= OTS.infoBubble.len) return;
	OTS.infoBubble.show(d.html, d.id, d.x, d.y, d.v);
}
OTS.infoBubble.show = function(html, id, x, y, v) {
	var id = (!id) ? 'content_pos' : id;
	if (!OTS.$(id)) return;
	var pos = (!v) ? 'bc' : v ;
	var s = '<div class="popmsgr2" style="width:175px;">';
	s += '<div style="position:relative;"><img src="http://images.onthesnow.com/ots/images/icon_info.gif" alt="" border="0" align="absmiddle" style="zoom:1; filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5;" /> ';
	s += html;
	s += '<div class="close" style="position:absolute; top:0; right:0;"><a href="#" onclick="OTS.infoBubble.hide(); return false;"><img src="http://images.onthesnow.com/ots/images/icon_close.gif" border="0" align="absmiddle" /></a></div>';
	s += '</div></div><b class="marker_' + pos + '"></b>';
	var o = OTS.$('popmsgr');
	if (!o) {
		o = document.createElement('div');
		o.id = 'popmsgr';
		o.className = 'popmsgr';
		o.style.cssText = 'font-size:11px; position:absolute; z-index:99;';
		var t = OTS.$('empty');
		if (!t) return;
		t.appendChild(o);
	}
	o.innerHTML = s;
	var p = OTS.getPos(OTS.$(id));
	p.top += y;
	p.left += x;
	OTS.setStyle(o, 'position', 'absolute');
	OTS.setStyle(o, 'left', p.left + 'px');
	OTS.setStyle(o, 'top', p.top + 'px');
}
OTS.infoBubble.hide = function() {
	var o = OTS.$('popmsgr');
	if (!o) return;
	OTS.setHTML(o, '');
	OTS.setStyle(o, 'left', '-2000px');
	OTS.infoBubble.setNext();
}
OTS.infoBubble.setNext = function() {
	OTS.infoBubble.curr = parseInt(OTS.infoBubble.curr) + 1;
	OTS.infoBubble.setCookie('popmsgr', 'active:"0",curr:"' + OTS.infoBubble.curr + '"', 90);
}
OTS.infoBubble.getFortune = function() {
	var r = Math.floor(Math.random() * 5);
	return (r == 0);
}
OTS.infoBubble.setCookie = function(n, v, l) {
	var d = new Date();
	var x = new Date(d.getTime() + (l * 24) * 3600 * 1000);
	document.cookie = n + '=' + escape(v) + ';expires=' + x.toGMTString() + ';path=/;';
}
OTS.infoBubble.getCookie = function(n) {
	var c = document.cookie.match('(^|;) ?' + n + '=([^;]*)(;|$)');
	return (c) ? unescape(c[2]) : null;
}
OTS.infoBubble.getCenter = function() {
	var x = 0;
	if (self.innerHeight) {
		x = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
	} else if (document.body) {
		x = document.body.clientWidth;
	}
	x *= .5;
	return x;
}
OTS.infoBubble.addEvent = function(o, e, m) {
	if (o.addEventListener) {
		o.addEventListener(e, m, false);
	} else {
		o.attachEvent('on' + e, m);
	}
}
OTS.infoBubble.addEvent(window, 'resize', function() { 
	OTS.infoBubble.init();
});
OTS.infoBubble.init();

