// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Pop-up functions for utility windows

function pop(){
window.open("http://www.37signals.com/mailing.html","Join_the_37signals_Mailing_List","height=400,width=700,scrollbars=yes,resizable=0,marginheight=7,marginwidth=7,leftmargin=7,topmargin=7");
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Cookie checker for external link targeting

// Let's initialize these variables
var svnPrefs = ""
var where = ""
var expireDate = new Date

// Regular expression for our sites
re = /^(http):\/\/\S+\.(37signals|37s)\.\S+$/i

// The life of this cookie is 12 months
expireDate.setMonth(expireDate.getMonth()+12)

// Evaluate a particular cookie and its value
function cookieVal(cookieName) {
	thisCookie = document.cookie.split("; ");
	for (i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1];
			}
		}
	return 0;
}

// Do you even have a cookie?
if (document.cookie != "") {
	svnPrefs = cookieVal("svnPreferences");
}

// Set the cookie
function setCookie() {
	svnPrefs = (document.targetForm.targetToggle.checked ? true : false);
	document.cookie = "svnPreferences=" +svnPrefs+ ";expires=" + expireDate.toGMTString();
	setTargetLinker();
}

// Use cookie setting for link target preference on Homepage
function setHomeTargetLinker() {
	if (document.cookie != "") {
		svnPrefs = cookieVal("svnPreferences");
		if (svnPrefs == "true") {
			where = "_blank";
			document.targetForm.targetToggle.checked = true;
		}
		else {
			where = "_self";
			document.targetForm.targetToggle.checked = false;
		}
		for (var i=0; i<=(document.links.length-1); i++) {
			if (re.test(document.links[i])) {
			document.links[i].target = "_self";
			}
			else {
			document.links[i].target = where;
			}
		}
	}
}

// Use cookie setting for link target preference on internal pages
function setTargetLinker() {
	if (document.cookie != "") {
		svnPrefs = cookieVal("svnPreferences");
		if (svnPrefs == "true") {
			where = "_blank";
		}
		else {
			where = "_self";
		}
		for (var i=0; i<=(document.links.length-1); i++) {
			if (re.test(document.links[i])) {
			document.links[i].target = "_self";
			}
			else {
			document.links[i].target = where;
			}
		}
	}
}


// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Coded by Travis Beckham
// www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// Detect Constructor

Detect = function() {
	var agent = navigator.userAgent.toLowerCase(); 
	this._mac = agent.indexOf('mac') != -1;
	this._win = !this._mac;
	this._w3c = document.getElementById;
	this._iex = document.all;
	this._ns4 = document.layers;
}
Detect.prototype.getObj = function(name) {
	if(this._w3c){
		return document.getElementById(name);
	}else if(this._iex){
		return document.all[name];
	}else if(this._ns4){
		return this.getObjNS4(document,name);
	}
}
Detect.prototype.getObjNS4 = function(obj, name) {
	var d = obj.layers;
	var result,temp;
	for(var i=0; i<d.length; i++){
		if(d[i].id == name){
		 	result = d[i];
		}else if(d[i].layers.length){
			var temp = getObjNS4(d[i],name);
		}
		if(temp){
			result = temp;
		}
	}
	return result;
}
Detect.prototype.getStyle = function(obj) {
	return (this._ns4) ? obj : obj.style;
}
Detect.prototype.getScrollTop = function(){
	return this._iex ? document.body.scrollTop : window.pageYOffset;
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

// MenuDiv Constructor

MenuDiv = function(name){
	if(name){
		this._inherit = Detect; this._inherit(name);
		this._id  = name;
		this._el  = this.getObj(this._id);
		this._css = this.getStyle(this._el);
		this._by  = this.getTop();
		return this;
	}
}
MenuDiv.prototype = new Detect();

MenuDiv.prototype.getTop = function(){
	return parseInt(this._css.top || 0);
}

MenuDiv.prototype.scrollMenu = function(){
	var ty = this._by+this.getScrollTop();
	var my = this.getTop();
	if (ty > 110) {
		// Slow speed
		//this._css.top = (my+(ty-my)/2)+5;
		
		// Quick speed
		this._css.top = ty+10;
	} else {
		this._css.top = 110;
	}
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

API = new Detect();

function createObjects(){
	API.menu = new MenuDiv('Sidebar');
	menuInterval = setInterval('API.menu.scrollMenu()',50);
}

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
