/* --------------------------------------------------------------------
	Branche selector
-------------------------------------------------------------------- */

$(document).ready(function() {
	
	if ( $('.highlightBox').length < 1 ) return; 

	$('.highlightBox').each(function() {
		// vars
		var more = 	$('a.more', this);
		
		//console.log($(more).attr('rel'))
		if($(more).attr('rel') == "gotoExternal") {
			$(this)
			.css('cursor', 'pointer')
			.click(function(e) {
				$(more).trigger('click');
			});
		} else {
			$(this)
			.css('cursor', 'pointer')
			.click(function(e) {
				$(this).unbind('click');
				$(more)
				.click(function(e) {
					window.location  = e.target.href;
				})
				.trigger('click');
			});
		}
		
		// do fade when overlay necessary
		if (!$(this).hasClass("nooverlay")) {
			$(this).hover(function() {
				fadeIn(this);
				$(more).addClass('hover');
			}, function() {
				fadeOut(this);
				$(more).removeClass('hover');
			});
		}
			
		function fadeIn(box) {
			$('.overlay', box).stop().css({ opacity: '0', top: '0' }).animate({opacity: '1', top: '0'}, 500);
			$('p:first', box).stop().animate({opacity: '0', top: '0'}, 100);
		}
		
		function fadeOut(box) {
			$('.overlay', box).stop().animate({opacity: '0', top: '0'}, 100);
			$('p:first', box).stop().animate({opacity: '1'}, 500);
		}
		
	});

});
