function setCookie(c_name,value){
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+ 20000);
	document.cookie = c_name+ "=" + escape(value) + '; path=/; domain=.tait.co.nz; expires=' + exdate.toGMTString();
	document.cookie = c_name+ "=" + escape(value) + '; path=/; domain=.taitworld.com; expires=' + exdate.toGMTString();
}

function Animator(id) {
	var self = this;
	self.element = $(id);

	self.slide = function(from, to, style, oncomplete) {
		self.from = parseInt(from, 10);
		self.to = parseInt(to, 10);
		self.style = (style || 'top');
		self.oncomplete = oncomplete;
	
		self.interval = setInterval(function() {
			var distance = (self.to - self.from);
			if (Math.abs(distance) <= 1) {
				clearInterval(self.interval);
				self.from = self.to;
			} else {
				self.from += (distance / 3);
			}
			self.element.style[self.style] = self.from + 'px';				
			if ((self.from === self.to) && self.oncomplete) {self.oncomplete.call(self)}
		}, 32);
	}
}

function popup_help(anchor) {
	window.open(anchor.href, 'sso', 'width=400, height=500, scrollbars=yes');
	return false;
}

function close_login_bar(id) {
	var e = ($(id) || $('login-successful') || $('sso-welcome'));
	new Animator(e).slide(e.clientHeight, 0, 'height', function() {this.element.style.display = 'none'});
}

function hide_in_future_clicked(checkbox) {
	if (checkbox.checked) {
		setCookie('taitLoginBarState', 'hide');
		close_login_bar();
	}
}
