/* jQUERY
--------------------------------------------------*/
$(document).ready(function() {
	
	/* Dev links */
	$('a[href=#]').click(function() {
		alert('This link has not been implemented.');
		
		return false;
	});
	
	/* Preload images */
	$.preloadImages('/framework/images/ajax-loader-16Black.gif');
	
	/* Focus style for contact form */
	$('input:text, textarea').focus(function() {
		$(this).addClass('focus');
	});
	$('input:text, textarea').blur(function() {
		$(this).removeClass('focus');
	});
	
	// Open external links in new window :P
	$('a.external').click(function() {
		window.open( $(this).attr('href') , "popupwin" );
		
		return false;
	});
	
	/* Fix positioning on Bobby */
	$('body#activities div#site-wrapper').append('<div id="bobby">');
	$('body#activities div#bobby').css({
		bottom: $('div#site-info').outerHeight()
	});
		
	/* Load content pages into modal container */
	$('a.load-content').click(function() {
		$this = $(this);
		
		$.ajaxInfo('Loading content &hellip;');
		
		$.ajax({
			url: $(this).attr('href'),
			cache: false,
			success: function(html) {
				$.removeAjaxInfo();
				
				$.BlockUI();
				$('<div id="content-modal">').appendTo('body').html( '<div id="content-modal-content">' + $(html).html() + '<a href="#" id="content-modal-close">Close Window</a></div>' );
				
			}
		});
		
		return false;
	});
	
	$('div#UIBlock,a#content-modal-close').live('click',function() {
		$.unBlockUI();
		$('div#content-modal').remove();
		
		return false;
	});
	
	$('div#contact-success').animate({
		top: 130
	},3000,function() {
		$(this).fadeOut('slow',function() {
			window.location = "contact.asp";
		});
	});
		
});

/* FUNCTION: BlockUI */
$.BlockUI = function() {
	$('<div id="UIBlock"></div>').css({
		background: '#000',
		height: '100%',
		left: 0,
		opacity: 0.75,
		position: 'fixed',
		top: 0,
		width: '100%',
		zIndex: 900
	}).appendTo('body');
	if ($.browser.msie && ($.browser.version < 7)) {
		$('div#UIBlock').css({
			position: 'absolute',
			top: $(window).scrollTop()
		});
	}
};

/* FUNCTION: unBlockUI */
$.unBlockUI = function() {
	$('#UIBlock').fadeOut(100,function() {
		$(this).remove();
	});
};

/* FUNCTION: Universal AJAX Info */
$.ajaxInfo = function(message) {
	$('<div id="ajaxInfo">' + message + '<img src="/framework/images/ajax-loader-16Black.gif" width="16" height="16" /></div>').appendTo('body');
	$('div#ajaxInfo').css({
		marginLeft: '-' + ($('div#ajaxInfo').outerWidth()/2) + 'px'
	});
	if ($.browser.msie) {
		$('div#ajaxInfo').css({
			background: '#000',
			opacity: 0.75
		});
	}
};
$.removeAjaxInfo = function() {
	$('#ajaxInfo').fadeOut(100,function() {
		$(this).remove();
	});
};

/* FUNCTION: Preload images */
$.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		$('<img>').attr('src', arguments[i]);
	}
};