// JavaScript Document
 $(document).ready(function() {
// do stuff when DOM is ready
    $('h1').each(function() {
      string = $(this).text();
      filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
      $(this).html('<img src="/cmsimages/title-' + filename + '.gif" alt="' + string + '" />');
    });
  
	// scrollbars stuff
	$('#uparrow').click(function(){
		$('.scroll-pane')[0].scrollBy(-280);
	});
	
	$('#downarrow').click(function(){
		$('.scroll-pane')[0].scrollBy(280);
	});
	
	$('.scroll-pane').jScrollPane({scrollbarWidth: 43, scrollbarMargin: 10, animateTo: true, reinitialiseOnImageLoad: true, showArrows: true, dragMinHeight:60, dragMaxHeight:60 });

	//headernav image replacement
	
	$('#headernav ul.navtop li a').each(function() {
      string = $(this).text();
      filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
      $(this).html('<img src="/cmsimages/nav-' + filename + '.png" alt="' + string + '" />');
      $(this).css({height: '32px', overflow: 'hidden'});
      $(this).children('img').css({marginTop: '-33px'});
      
      $(this).hover(function(){
      	thismargin = $(this).children('img').css("margin-top");
      	$(this).children('img').css({marginTop: '-3px'});
      },
      function(){
      	$(this).children('img').css({marginTop: thismargin});
      });
    });
    $('#headernav ul.navtop li.selected a img').css({marginTop: '-3px'});
	
	//secondarynav image replacement
	
	$('#secondarynav ul.navsecondary li a').each(function() {
      string = $(this).text();
      filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
      $(this).html('<img src="/cmsimages/nav-' + filename + '.png" alt="' + string + '" />');
      $(this).css({height: '24px', overflow: 'hidden'});
      $(this).children('img').css({marginTop: '-28px'});
      
      $(this).hover(function(){
      	thismargin = $(this).children('img').css("margin-top");
      	$(this).children('img').css({marginTop: '3px'});
      },
      function(){
      	$(this).children('img').css({marginTop: thismargin});
      });
    });
    
    $('#secondarynav ul.navsecondary li.selected a img').css({marginTop: '3px'});
    
    // FORM VALIDATION
	/* is causing errors on other pages, putting in the page instead 
		$.extend($.validator.messages, {  
		  required: "",  
		  email: "Email not valid"
		});
		$("#contactForm").each(function(){
			this.reset();
		});

		$("#contactForm").validate({
	 
			 errorPlacement: function(error, element){
			 	//error.appendTo( element.prev("label") );
			 }
			 
		});
	*/
	// END FORM VALIDATION
		
	
});