/*
jQUERY
--------------------------------------------------*/
$(document).ready(function() {
	
	/* Preload images */
	$.preloadImages('/framework/images/ajax-loader-16Black.gif');
	
	// Home page cycle plugin
	$('div#site-branding-slideshow').cycle({
		timeout: 7000
	});
	
	// DEVELOPMENT LINKS
	$('a[href=#]').click(function() {
		alert('This link has not been implemented.');
		
		return false;
	});
	
	// Open external links in new window :P
	$('a.external').click(function() {
		window.open( $(this).attr('href') , "popupwin" );
		
		return false;
	});
	
	// NAVIGATION SETUP
	$('div#site-navigation ul ul').each(function() {
		$(this).prepend('<li class="top">');
		$('li:last',this).addClass('last');
	});
	
	// NAVIGATION HOVER/DROP-DOWN
	$('div#site-navigation ul > li').hover(
		function() {
			$this = $(this);
			
			$('a',this).addClass('hover');
			$('ul',this).css({
				top: 37,
				left: ($this.width() + 1 - 252)/2
			});
		},
		function() {
			$('a',this).removeClass('hover');
			$('ul',this).css({
				top: -9999,
				left: -9999
			});
		}
	);
	
	/* 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;
	});
		
});

/* 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]);
	}
};
