$(document).ready(function() {

	// set target for external links
	$("a[href^='http://']").click(function(){
		window.open(this.href);
		return false;
	});

	$("a[href^='https://']").click(function(){
		window.open(this.href);
		return false;
	});

	$("a[href^='http://']:not(:has(img))").addClass("external");
	$("a[href^='https://']:not(:has(img))").addClass("external");

	$("a[href$='.doc']").addClass("icon-doc").click(function(){
		window.open(this.href);
		return false;
	});
	
	$("a[href$='.pdf']").addClass("icon-pdf").click(function(){
		window.open(this.href);
		return false;
	});
	
	$("a[href$='.xls']").addClass("icon-xls").click(function(){
		window.open(this.href);
		return false;
	});

	// load random background
	loadRandomBackground();
});

function loadPortfolioImage(imgSrc) {
	$(function() {
		$('#portfolioLargeImg').empty();
		$('#portfolioLargeImg').addClass('loading');
		var img = new Image();
		$(img).load(function () {
			$(this).hide();
			$('#portfolioLargeImg').append(this);
			$('#portfolioLargeImg').removeClass('loading');
			$(this).fadeIn();
		}).error(function () {
			// notify the user that the image could not be loaded
		}).attr('src', imgSrc);
	});
}

var myBackgrounds = new Array();

function loadRandomBackground() {
    var randomIndex = Math.floor(Math.random() * myBackgrounds.length);
    var imgSrc = myBackgrounds[randomIndex];

	if(!(jQuery.browser.msie && jQuery.browser.version.substr(0,1) == '6')) {
		$(function() {
			var img = new Image();
			$(img).load(function() {
				$('#phRandomBackground').fadeOut(2000,function() {
					$('#phRandomBackground').attr('style', 'background: url(' + imgSrc + ') no-repeat top center');
					$('#phRandomBackground').fadeIn(2000);
					setTimeout('loadRandomBackground()', 15000);
				});
			}).attr('src', imgSrc);
		});
	}
}

function disableButton(obj,id) {
	obj.style.display = 'none';
	var btn = document.getElementById(id + 'Disabled');
	if (btn != null) btn.style.display = 'block';
}