﻿/*
 * Things that need to get done on every page
 */

window.onload = function() {
	console.log("hi!");
	// Make all external links open in a new window/tab.
	$("a").each( function() {
		var url = $(this).attr("href")
		if (url.indexOf("http://") != -1)
			$(this).attr("target", "_blank");
	});

	// Make all anchor link scroll if there is one.
	var address = ("" + window.location).split("#");
	if (address.length == 2) {
		anchor = '[name="' + address[1] + '"]';	
		$('html,body').animate({scrollTop: $(anchor).offset().top}, 0);
	}
	
	if (supports("border-radius")) {
		loadcss("rounded.css");
	}
	else {
		loadjs("js/niftycube.js");
		loadcss("niftyCorners.css");
		Nifty("div.box h6", "top normal");
		Nifty("div.innerbox", "bottom normal");
		Nifty("div.boxtop", "normal");
		
		// IE HACK.
		if (jQuery.browser.msie) {
			jQuery('.innerbox').each( function(i) {
				var id = "#" + this.id;
				if (id.match("_long") != null)
					this.style.display = 'none';
			});
		}	
	}
};
 
function loadjs(source) {
	$('head').append("<script type='text/javascript' src='" + source + "'></script>");
}

function loadcss(source) {
	$('head').append("<link rel='stylesheet' type='text/css' href='" + source + "'/>");
}

function supports(prop) {
	var div = document.createElement('div'),
		vendors = 'Khtml Ms O Moz Webkit'.split(' '),  
		len = vendors.length;
	
	if (prop in div.style) return true;
	
	prop = prop.replace(/^[a-z]/, function(val) {  
         return val.toUpperCase();  
      });
	
	while (len--) {
		if ( vendors[len] + prop in div.style )
            return true;      
	}
	return false;
}

