
/*
	
	Hand Crafted by Nevub -> [www.nevub.com || info@nevub.com]
	Copyright (c) 2007 Nevub.  All Rights Reserved.
	
*/

function mto(obj, dom, user){
	if (!obj.href || !dom || !user) return;
	obj.href = 'mai' + 'lto:' + user + '@' + dom;
}

function popWin(url, winName, w, h, scroll) {
	var sw = screen.width;
	var sh = screen.height;
	var cx = (.5 * sw) - (w * .5);
	var cy = (.5 * sh) - (h * .5);
	var values = 'toolbar=no,status=yes,menubar=no,scrollbars=' + scroll + ',resizable=yes,screenX=' + cx + ',screenY=' + cy + ',left=' + cx + ',top=' + cy + ',width=' + w + ',height=' + h + '';
	window.open(url, winName, values);
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var ja = document.getElementsByTagName('a');
	for (var i = 0; i < ja.length; i++) {
		var a = ja[i];
		if ((a.href.indexOf('http://') > -1) && (a.href.indexOf('redpaperplanes') == -1)) {
			a.target = '_blank';
			//a.title += ' - This link will open in a new window';
		}
	}
}

function globalInit() {
	externalLinks();
}

function addEvent(obj, evType, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent('on' + evType, fn);
		return r;
	} else {
		return false;
	}
}
addEvent(window, 'load', globalInit);

window.onerror = function() {
	return true;
}

/////////////////////////////

var gallery = {
	num : 0,
	curr : 0,
	old : null,
	t1 : null,
	load : function() {
		var pg = document.getElementById('photogallery');
		if (!pg) return;
		this.feed = pg.getElementsByTagName('div');
		this.img = [];
		for (var i = 0; i < this.feed.length; i++) {
			this.img[i] = this.feed[i].innerHTML;
		}
		this.tLen = this.img.length;
		pg.innerHTML = '<div id="gallery" style="width:100%"></div>';
		pg.style.display = 'block';
		this.obj = document.getElementById('gallery');
		if (!this.obj) return;
		for (var i = 0; i < this.img.length; i++) {
			this.obj.innerHTML += '<span id="photo' + i + '" style="display:none;">' + this.img[i] + '</span>';
		}
		this.setData();
	},
	setData : function() {
		clearTimeout(this.t1);
		if (this.curr > (this.tLen - 1)) {
			this.curr = 0;
		}
		if (this.curr < 0) {
			this.curr = (this.tLen - 1);
		}
		var oto = document.getElementById('photo' + this.old);
		if (oto) oto.style.display = 'none';
		var to = document.getElementById('photo' + this.curr);
		if (to) to.style.display = 'block';
		if (this.tLen > 1) {
			this.fadeIn();
		}
	},
	doNav : function(v) {
		if (this.num > 0 && this.num < 100) return;
		this.old = this.curr;
		this.curr = parseInt(v);
		this.fadeOut();	
	},
	doNext : function() {
		this.old = this.curr;
		this.curr++;
		this.fadeOut();
	},
	fadeIn : function() {
		if (this.num < 100) {
			this.setFade(this.num);
			this.num += 5;
			setTimeout('gallery.fadeIn()', 10);
		} else {
			this.num = 100;
			this.setFade(100);
			this.t1 = setTimeout('gallery.doNext()', 3000);
		}
	},
	fadeOut : function() {
		if (this.num > 0) {
			this.setFade(this.num);
			this.num -= 5;
			setTimeout('gallery.fadeOut()', 10);
		} else {
			this.num = 0;
			this.setFade(0);
			this.setData();
		}
	},
	setFade : function(opacity) {
		this.obj.style.opacity = (opacity / 100);
		this.obj.style.MozOpacity = (opacity / 100);
		this.obj.style.KhtmlOpacity = (opacity / 100);
		this.obj.style.filter = 'alpha(opacity=' + opacity + ')';
	}
}

/////////////////////////////

function sliderX(obj) {
	this.s1 = document.getElementById(obj);
	if (!this.s1) return;
	var imgs = this.s1.innerHTML;
	this.s1.innerHTML = '<table><tr><td nowrap="nowrap">' + imgs + imgs + imgs + '</td></tr></table>';
	this.speed = 0;
	this.started = 0;
	this.maxw = this.s1.offsetWidth;
	this.t1 = null;
	var _this = this;
	this.s1.onmousemove = this.s1.onmouseover = function(e) {
		_this.startMove(e);
	}
	this.s1.onmouseout = function() {
		_this.endMove();
	}
}
sliderX.prototype.findPos = function(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft, curtop];
}
sliderX.prototype.startMove = function(e) {
	var p = this.s1.parentNode;
	var px = this.findPos(p);
	var x = (document.all) ? event.x : (e.pageX - px[0]);
	var w = p.offsetWidth * .5;
	var v = w * .0001;
	this.speed = Math.round((x - w) * v);
	if (this.started == 0) {
		this.started = 1;
		this.move();
	}
}
sliderX.prototype.endMove = function(e) {
	this.speed = 0;
	this.started = 0;
	clearTimeout(this.t1);
}
sliderX.prototype.move = function() {
	var s = (parseInt(this.s1.style.left) - this.speed);
	if (parseInt(this.s1.style.left) <= -((this.maxw / 3) * 2)) {
		s = -(this.maxw / 3);
	}
	if (parseInt(this.s1.style.left) >= 0) {
		s = -(this.maxw / 3);
	}
	this.s1.style.left = s + 'px';
	if (this.started != 0) {
		var _this = this;
		this.t1 = setTimeout(function(){_this.move()}, 1);
	}
}

/////////////////////////////

var fly = {
	rate : 0,
	xmax : 50,
	ymax : 50,
	xArr : [],
	yArr : [],
	tLen : 16,
	load : function() {
		for (var i = 0; i < this.tLen; i++) {
			var o = document.getElementById('o' + (i + 1));
			this.xArr[i] = parseInt(o.style.left);
			this.yArr[i] = parseInt(o.style.top);
		}
		fly.move(); 
	},
	move : function() {
		for (var i = 0; i < this.tLen; i++) {
			var o = document.getElementById('o' + (i + 1));
			o.style.top = this.yArr[i] + Math.cos((2 * Math.sin(this.rate / (2 + i))) + i * 9) * this.ymax * (Math.sin(1 + this.rate / 1) + 0.8) * Math.cos((this.rate + i * 25) / 1) + 'px';
			o.style.left = this.xArr[i] + Math.sin((2 * Math.sin(this.rate / 2)) + i * 9) * this.xmax * (Math.sin(1 + this.rate / (1 + i)) + 0.8) * Math.cos((this.rate + i * 25) / 1) + 'px';
		}
		this.rate += .02;
		setTimeout('fly.move()', 10);
	}
}

/////////////////////////////

