 $(document).ready(function(){
	
	// NAV - SUPERFISH/SUCKERFISH
	$("#nav").superfish({
	});

	
	//set class for links to external sites and other document types
	$('#content a[href^="http://"]').addClass('external').attr('target', '_blank');
	$('#content a[href$=".pdf"]').addClass('pdf').attr('target','_blank');
	$('#content a[href$=".ppt"]').addClass('powerpoint').attr('target','_blank');
	$('#content a[href$=".doc"]').addClass('word').attr('target','_blank');
	$('#content a[href$=".xls"]').addClass('excel').attr('target','_blank');
	$('#content a[href$=".csv"]').addClass('excel').attr('target','_blank');
	
	$('#content a.remove_external').removeClass('external').attr('target', '_blank');


	$('.submit-button').hover(
		 function () {
			$(this).css({'cursor':'pointer' });
		}, 
		function () {
		$(this).css({'cursor':'default' });
		}

	);
	
	$('.submit-button').click(
		 function () {
			$(this).css({ 'border-color':'#CCCCCC','border-top-color' : '#999999', 'border-left-color':'#999999' });
		}, 
		function () {
		$(this).css({'cursor':'default', 'border-color':'#CCCCCC #999999 #999999 #CCCCCC' });
		}

	);
	
	

	$('.view_details').click(	
		function(){
			var toggleHide = 'images/templates/hide.gif';
			var toggleShow = 'images/templates/view.gif';
			var eDiv = $('div.'+$(this).attr('rel'));
			var eImg = $(this).children('img');

		if(eDiv.is(':hidden')){
				$(this).children('img').attr('src', toggleHide);
				eDiv.show('slow');
			
			}								
			
		else if(eDiv.is(':visible')){
				$(this).children('img').attr('src', toggleShow);
				eDiv.hide('slow');
			
			}
		
		 $(this).blur();
					
	});

	
	

///hide-show fieldsets
	$('.view_fieldset').click(	
			function(){
			
			var eFieldset = $('#'+$(this).attr('rel'));
			$(this).addClass('active');
			if(eFieldset.is(':hidden')){
				// hide all previously opened fieldset
				$('.view_fieldset').each(function(){
					if($('#'+ $(this).attr('rel')).is(':visible')){
						$('#'+ $(this).attr('rel')).hide('slow');
						$(this).removeClass('active');
					}
				});
					
				eFieldset.show('slow');
				$(this).addClass('active');
				
					
			}
			else if(eFieldset.is(':visible')){
				//do nothing 
				//eFieldset.hide('slow');		
			}
			
			$(this).blur();
			return false;
	});


	///hide-show directory
	$('.view_all_detail').click(	
			function(){
			var eId = $(this).attr('rel');
			
			if($('.location-div-inner-' + eId).is(':hidden')){
				// open all 
					$('.location-div-inner-' + eId).show('slow');			
					$('.description-div-inner-' + eId).show('slow');
					$('.specialization-div-inner-' + eId).show('slow');	
					$('.headquarters-div-inner-' + eId).show('slow');	
					$('.attachments-div-inner-' + eId).show('slow');		

					$(this).text('Close Detail');
			}
			else if($('.location-div-inner-' + eId).is(':visible')){
				//close all
					$('.location-div-inner-' + eId).hide('slow');			
					$('.description-div-inner-' + eId).hide('slow');	
					$('.specialization-div-inner-' + eId).hide('slow');	
					$('.headquarters-div-inner-' + eId).hide('slow');	
					$('.attachments-div-inner-' + eId).hide('slow');		
					
					
					$(this).text('View Detail');
					
			}
			
			$(this).blur();
			return false;
	});


	$("#nonprofit_type_ids_div input:checkbox").limit(5);
	$("#specialization_area_ids_div input:checkbox").limit(4);
	
	
	if (navigator.appVersion.indexOf("Mac")!=-1){
		$('.tabs-div').css({'padding' : '0'}) ;

	}

}); /* END DOCUMENT READY */

	
	$.fn.limit = function(n) {
		var self = this;
		this.click(function(){ return (self.filter(":checked").length<=n); });
	}



