var isOpera = (navigator.userAgent.indexOf('Opera') != -1)? true : false;
var isIE = (document.all)? true : false; 

var box_link = {
	bubble: true,
	hover: function(obj) {
		var href = this.check_bubble(obj);
		obj.onclick = function() {
			box_link.click(href);
		};
		obj.onmouseout = function() {
			box_link.reset_status();
		};
		obj.style.cursor = 'pointer';
	},
	reset_status: function() {
		window.status = '';
	},
	click: function(href) {
		if(this.bubble && href) {
			location.href = href;
			return;
		}
	},
	check_bubble: function(obj) {
		if(obj) {
			var a = obj.getElementsByTagName('a');
			for(i=0; i<a.length; i++) {
				a.item(i).onclick = function() {
					box_link.bubble = false;
					return true;
				}
				a.item(i).onmouseover = function() {
					window.status = this.innerHTML.replace(/<.+?>/gi, ' ');
				}
				a.item(i).onmouseout = function() {
					box_link.reset_status();
				}
			}
			if(a.item(0)) {
				window.status = a.item(0).innerHTML.replace(/<.+?>/gi, ' ');
				return a.item(0).href;
			}
		}
		return false;
	}
}

function mail() {
	var prefix = (arguments[0])? arguments[0] : "sales";
	var suffix = (arguments[1])? arguments[1] : "cinnamon-active.com";
	if(prefix && suffix) {
		document.write("<a href=\"mailto:"+prefix+"@"+suffix+"\">"+prefix+"@"+suffix+"</a>");
		return true;
	}
}

var login = {
	timer: false,
	login_box: false,
	login_form: false,
	login_link: false,
	init: function() {
		this.login_box = document.getElementById('login_box');
		this.login_form = document.login_form;
		this.login_link = document.getElementById('login_link');
		login_link.removeAttribute('href');
		this.login_link.onmouseover = function() {
			login.show();
		}
		this.login_link.onmouseout = function() {
			login.hide(7000);
		}
		this.login_box.onmouseover = function() {
			login.cancel();
		}
		this.login_box.onmouseout = function() {
			login.hide(2000);
		}
		this.show();
	},
	show: function() {
		login.cancel();
		this.login_box.style.display = 'inline';
		this.login_form.company.focus();
	},
	hide: function(wait) {
		login.cancel();
		this.timer = setTimeout("login.login_box.style.display = 'none';", wait);
	},
	cancel: function() {
		if(this.timer)
			window.clearTimeout(this.timer);
	}
}

var scroll = {
	active: true,
	timer: false,
	speed: 50,
	direction: '-',
	height: 90,
	orig_height: 90,
	obj: false,
	cur_offset: 0,
	content: "",
	init: function() {
		window.onload = function() {
			scroll.begin();
		}
	},
	begin: function() {
		if(document.getElementById('cinnamon-news')) {
			this.obj = document.getElementById('cinnamon-news');
			this.height = (this.obj.offsetHeight / 2) - 15;
			this.orig_height = this.obj.offsetHeight;
			this.content = this.obj.innerHTML;
			this.obj.onmouseover = function() { scroll.stop(); }
			this.obj.onmouseout = function() { scroll.start(); }
			this.timer = setTimeout("scroll.scroll()", this.speed);
		}
	},
	scroll: function() {
		if(this.active) {
			this.obj.style.position = 'relative';
			if(this.cur_offset > 0)
				this.obj.style.top = "-"+ this.cur_offset + "px";
			if(this.direction == '-')
				this.cur_offset++;
			else if(this.cur_offset > 0)
				this.cur_offset--;
			if(this.cur_offset > this.height) {
				if(this.height > 2000)
					setTimeout("scroll.reset()", 333 * this.speed);
				else
					this.obj.innerHTML += "<br />" + this.content;
					this.height += this.orig_height;
			}
		}
		var itimer = setTimeout("scroll.scroll()", this.speed);
	},
	start: function() {
		this.active = true;
	},
	stop: function() {
		this.active = false;
	},
	control: function(increment, direction) {
		this.speed = increment;
		this.direction = direction;
	},
	auto: function() {
		this.speed = 50;
		this.direction = '-';
		scroll.start();
	},
	reset: function() {
		this.obj.innerHTML = this.content;
		this.height = this.orig_height;
		this.obj.style.top = "0px";
		this.cur_offset = 0;
	}
}

scroll.init();


if(navigator.userAgent.match(/Opera/) && !location.href.match(/\.com\/(GroupEvents|LeisureWeekends)?\/?$/)) {
	var new_stylesheet = document.createElement('link');
	new_stylesheet.type = "text/css";
	new_stylesheet.rel = "stylesheet";
	new_stylesheet.href = "/adventure-opera.css";
	document.getElementsByTagName('head').item(0).appendChild(new_stylesheet);
}