 $(document).ready(function(){
	
	
	$('ul.sf-menu').superfish({ 
               hoverClass:    'sfHover',          // the class applied to hovered list items 
				pathClass:     'overideThisToUse', // the class you have applied to list items that lead to the current page 
				pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass 
				delay:        	0,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
				animation:     {height:'show'},   // an object equivalent to first parameter of jQueryÕs .animate() method 
				speed:         'fast',           	// speed of the animation. Equivalent to second parameter of jQueryÕs .animate() method 
				disableHI:     false,              // set to true to disable hoverIntent detection 
				onInit:        function(){},       // callback function fires once Superfish is initialised Ð 'this' is the containing ul 
				onBeforeShow:  function(){},       // callback function fires just before reveal animation begins Ð 'this' is the ul about to open 
				onShow:        function(){},       // callback function fires once reveal animation completed Ð 'this' is the opened ul 
				onHide:        function(){},        // callback function fires after a sub-menu has closed Ð 'this' is the ul that just closed 
			
				autoArrows:  false,                           // disable generation of arrow mark-up 
				dropShadows: false                            // disable drop shadows 
        }); 
        
	
	//set class for links to external sites and other document types
	$('#content a[href^="http://"]').addClass('external').attr('target', '_blank');
	
	$('#content a[href^="http://henikalibrary.org/"]').removeClass('external').attr('target', '_self'); 
	$('#content a[href^="http://www.henikalibrary.org/"]').removeClass('external').attr('target', '_self'); 
	$('#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'); 
	
	/*  LIGHTBOX - Photos */
	$('a[rel*=lightbox]').lightBox({fixedNavigation:true}); 

	$('a[rel*=facebox]').facebox();
	
	$('a.cluetip').cluetip({width:'240', arrows:true, cursor: 'pointer', cluetipClass:'jtip'});
	
	$('.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();
													
					});

	// teen page
		$('.view_video').click(	
						function(){
							
							var eDiv = $('div.'+$(this).attr('rel'));
							var oDiv = $('div[class*=videodiv_]');
			
						if(eDiv.is(':hidden')){
								
								oDiv.hide('slow');
								eDiv.show('slow');
												
							}	
									
						else if(eDiv.is(':visible')){	
								eDiv.hide('slow');
							}
						
						 $(this).blur();
							
					});

	// FOL page
	$('input[name="donation"]').change(function(){
	
		$('input[name*="membership"]').removeAttr("checked");
	});
	
	
	$('input[name*="membership"]').click(function(){
		
		$('input[name*="donation"]').val(""); 
	});
	

	//POLL 
	/*$('button[name="vote"]').click(function(){
			var pollId = $('input[name="poll_id"]').val(); 
			var pollAnswer = $('input[name*="poll_answer"]:checked').val(); 	
			alert(pollId + pollAnswer);
			
			$.post('poll_results.php',{'pollId' : pollId , 'pollAnswer' : pollAnswer },function(data){
			
				alert("Data Loaded: " + data);
				
				$('#view_poll_results').html(data);
					
			});
			return false;
	});
*/
	
	$('input[name*="poll_answer"]').attr('checked','');
	$('#poll').ajaxForm({ target: '#view_poll_results', success: function() { 
            $('#view_poll_results').show();
			$('input[name*="poll_answer"]').attr('checked','');
        } 
    }); 


}); /* END DOCUMENT READY */


/* functions for teen page */
function checkEmail (strng) {
var error="";
 var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= "/[\(\)\<\>\,\;\:\\\"\[\]]/";
if (strng == "") {
   error = "Please enter an Email address.\n";
}  
 else if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid Email address.\n";
    }
    else if (strng.match(illegalChars)){
//test email for illegal characters
         error = "The Email address contains unprocessable  characters.\n";
       }
return error;    
}

function checkImgtext (strng) {
	var error = "";
	if (strng == "") {
	   error = "In the last text box, please enter the word shown in the image.\n";
	}
	var illegalChars= /[W]/;
	if (illegalChars.test(strng)) { 
		   error = "Not able process the word. Please try to match the word again. \n";
		}
	 return error;
}

function checkComments (strng) {
	var error = "";
	if (strng == "") {
	   error = "Please enter a comment.\n";
	}
	 return error;
}

function checkTeenForm(theForm) {
    var why = "";
      	why += checkEmail(theForm.Email.value);
     	 why += checkComments(theForm.Comments.value);
   
   if (why != "") {
       alert(why);
       return false;
    }
return true;
}




