//Load analytics scripts
function loadGAScript() {
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
}
loadGAScript();
//Call analytics after the scripts have loaded
function callGA() {
	if (typeof(_gat) == "object") { //checks if GA script has loaded
		try {
		var pageTracker = _gat._getTracker("UA-8163779-2");
		pageTracker._trackPageview();
		} catch(err) {}
	}
}

$(document).ready(function(){
	callGA();
	$('body').addClass('jsActive'); //add jsActive class to body
});

$(document).ready(function(){ //clear/restore input and textarea default values on focus/blur
	$('input[type="text"], textarea').focus(function(){
		if( $(this).val() == $(this).attr('title') ) $(this).val('');
	}).blur(function(){
		if( $(this).val() == '' ) $(this).val( $(this).attr('title') );
	});
});

$(document).ready(function(){ //open external links
	$('a[rel*="external"]').click(function(event){
		event.preventDefault();
		open(this.href);
	});
});

$(window).load(function(){	//Add extra images after page with graphics has loaded
	var origPosition = [[0,-180], [180,0], [0,180], [-180,0]];
	var newPosition = new Array(2);
	var globalImg = '';
	$('.workPreview a').each(function(){
		randomPos = Math.floor( Math.random() * origPosition.length );
		$(this).append('<img src="'+$(this).find('img').attr('src')+'" with="180" height="180" style="position:absolute; left:'+origPosition[randomPos][0]+'px; top:'+origPosition[randomPos][1]+'px;" />').hover(
			function(){ //over
				globalImg = $(this).find("img:last");
				//store return values for mouseOut
				newPosition[0] = globalImg.css('left');
				newPosition[1] = globalImg.css('top');
				globalImg.animate({left:0, top:0}, 300);
			},
			function(){ //out
				globalImg.animate({left:newPosition[0], top:newPosition[1]}, 300);
			});
	});
});

$(document).ready(function(){ //animate silverBox
	function goSpecular() {
		if($('.silverBox').length) {
			$('.silverBox .specular').animate({
				top:'175px'
			}, 2000, 'swing', function() {
				$(this).css('top', '-375px');
			});
		}
	}
	intervalID = setInterval(goSpecular, 5000);
});