// open external links in new browser
function externalLinks()
{
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
			anchor.target = "_blank";
		}
	}
}

// |||||||||||||||||||||||||||||||||||||||||||
// Globally used call-on functions

// Centered pop-up window
function openWindow(url, width, height, toolbar, scroll, center)
{
	var name = new Date();
	name = name.getTime();
	name = name.toString();
	toolbar = toolbar ? 'yes' : 'no';
	scroll = scroll ? 'yes' : 'no';
	var features = 'toolbar=' + toolbar + ',menubar=' + toolbar + ',location=' + toolbar + ',status=' + toolbar + ',scrollbars=' + scroll + ',resizable=' + scroll;
	if (width) features += ',width=' + width;
	if (height) features += ',height=' + height;
	if (center) {
		if (width && window.screen.availWidth) {
			var x = Math.round((window.screen.availWidth - parseInt (width)) / 2);
			features += ',screenX=' + x + ',left=' + x;
		}
		if (height && window.screen.availHeight) {
			var y = Math.round((window.screen.availHeight - parseInt (height)) / 2);
			features += ',screenY=' + y + ',top=' + y;
		}
	}
	window.open(url, name, features);
}
var openCenter = function(url, width, height) {
	openWindow(url, width, height, false, false, true);
}
var openCenterChrome = function(url, width, height) {
	openWindow(url, width, height, true, false, true);
}
var openCenterScroll = function(url, width, height) {
	openWindow(url, width, height, false, true, true);
}
var openCenterChromeScroll = function(url, width, height) {
	openWindow(url, width, height, true, true, true);
}

// |||||||||||||||||||||||||||||||||||||||||||
// Inititalize listeners and functions

// replace hr tags with styled divs
this.styleHRs = function()
{
	$("hr").each(function() {
		$(this).replaceWith('<div class="line"><\/div>');
	});
}

// remove outline from clicked portfolio links
this.blurLinks = function()
{
	$('#portfolio-nav a').each(function() {
		$(this).focus(function() {
			$(this).blur();					  
		});
	});
}

this.tooltip = function()
{	
	xOffset = 10;
	yOffset = 30;		

	$("a.tooltip").hover(function(e) {											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.fadeIn("fast");
	},
	function() {
		this.title = this.t;
		$("#tooltip").remove();
	});
	
	$("a.tooltip").mousemove(function(e) {
		$("#tooltip")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px");
	});			
};

$(document).ready(function() {
	styleHRs(); 
	blurLinks();
	//tooltip();
});
