/* jQUERY
--------------------------------------------------*/
$(document).ready(function() {
	
	$('div#site-branding h1').html('<a href="/" title="' + $('div#site-branding h1').html() + ' Home">' + $('div#site-branding h1').html() + '</a>');
	
	// NAV
	$('div#site-navigation ul#site-navigation-primary li').hover(
		function() {
			$('ul',this).css('left',0);
			$(this).addClass('hover');
		},
		function() {
			$('ul',this).css('left',-9999);
			$(this).removeClass('hover');
		}
	);
	
	// FAQ
	$('body.faq li h4').wrapInner('<a href="#"></a>');
	$('body.faq li h4 a').toggle(
		function() {
			$(this).parent().next('div').fadeIn('fast');
			
			return false;
		},
		function() {
			$(this).parent().next('div').fadeOut('fast');
			
			return false;
		}
	);
	
	makeColumns();
	
	// IMAGE ZOOM
	$('<div id="expandMe"><img src="/images/UILoader.gif" class="UILoader" height="32" width="32" /></div>').appendTo('body').css({
		left: -9999,
		top: -9999
	});
	
	$('a.zoomImage').click(function() {
		$this = $(this);
		
		$('div#expandMe').css({
			left: '50%',
			top: '50%'
		});
		$.BlockUI();
		
		$('<img class="preload" />').attr('src',$(this).attr('href')).load(function() {
			$img = $(this);
			
			$('div#expandMe').empty().append($img).animate({
				height: $img.height() + 20,
				marginLeft: (($img.width()/2)*-1)-20,
				marginTop: (($img.height()/2)*-1)-30,
				width: $img.width()
			},
			function() {
				$img.removeClass('preload').after('<a href="#" id="expandMe-close">Close Window</a>');
			});
			
			
		});
		
		return false;
	});
	
	$('div#UIBlock,a#expandMe-close').live('click',function() {
		$.unBlockUI();
		$('div#expandMe').empty().css({
			height: 40,
			left: -9999,
			marginLeft: -40,
			marginTop: -40,
			top: -9999,
			width: 40
		});
		
		return false;
	});
		
});

// MAKE EVEN COLUMN WIDTHS
function makeColumns() {
	$('ul.columns').each(function() {
		$this = $(this);
		
		$this.css({
			width: $this.parent().width()
		});
		$(' > li',$this).css({
			float: 'left',
			width: Math.floor($this.parent().width()/$(' > li',$this).size())
			
		});
	});
};

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

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