//Fade Function
(function(jQuery) {
	jQuery.fn.customFadeIn = function(speed, callback) {
		jQuery(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				jQuery(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	jQuery.fn.customFadeOut = function(speed, callback) {
		jQuery(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				jQuery(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

//Equal Height Divs
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
jQuery(document).ready(function(){
								
	//Equal Publications
	equalHeight(jQuery('#sectors li'));
	
	//Project Modal Window
	jQuery('a[name="modal"]').live('click', function(e) {
		var project_id = jQuery(this).attr('rel');
		var id = jQuery(this).attr('href');
		
		if (project_id) {
			jQuery.post("/includes/get_project_inc.php", {project_id: project_id}, 
				function(project_details) {
					jQuery("#project_modal").html(project_details);
			});
			
			var maskHeight = jQuery(document).height();
			var maskWidth = jQuery(window).width();
			jQuery('#popup_bg').css({'width':maskWidth,'height':maskHeight});	
			jQuery('#popup_bg').customFadeIn(1000, function() {});
			var winH = jQuery(window).height();
			var winW = jQuery(window).width();
			//jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
			jQuery(id).css("top", jQuery(window).scrollTop()+20 + "px");
			jQuery(id).css('left', winW/2-jQuery(id).width()/2);
			jQuery(id).customFadeIn(1000, function() {});
		}
        else {
            alert('No Project ID has been provided.');

        }
		return false;
	});
	jQuery('a.close_popup').live('click', function(e) {										   
		jQuery('#popup_bg, .window').customFadeOut('fast', function() {});
		jQuery('a.close_popup').hide();	
		return false;
	});	
	jQuery(document).keypress(function(e){
		if(e.keyCode==27){
			jQuery('#popup_bg, .window').customFadeOut('fast', function() {});
			jQuery('a.close_popup').hide();	
		}
	});
	
	
});
