$(document).ready(function() { 
           
       $('div.index table tbody th a').each(function(i){
            hrefParts=this.href.split('/');
            urlParts=window.location.href.split('/');
            
             $(this).attr("className","sort");
            
            if(hrefParts.length>0){           
                if(urlParts[urlParts.length-2]==hrefParts[hrefParts.length-2]){
                   if(urlParts[urlParts.length-1]=='direction:asc'){
                    $(this).attr("className","sortAsc");
                   }
                   else{
                    $(this).attr("className","sortDesc");
                   }
                }
            }   
       });
   
   //$('#action_msg').insertAfter("#view_content h1");
   
   $('.required label').append(' <span style="color:#cc0000">*</span>'); 
   
    $(function()
{
	$('#news_items').jScrollPane({showArrows:true,dragMaxHeight:25});
});
  
   //date picker
   $('#appointmentDate').datepicker({ dateFormat: 'dd/mm/yy' });
   
   
   $('#registerRequests').bind('submit', function(){
           
            var error=new Array();
            
            var name=$('#registerRequests input[name="data[RegisterRequest][name]"]').val();         
            var email_address=$('#registerRequests input[name="data[RegisterRequest][email_address]"]').val();
            var phone_number=$('#registerRequests input[name="data[RegisterRequest][telephone]"]').val();            
           
            
            //check for errors
            if(name==''){
                error.push(" - Please enter your name");
            }
           
            if(email_address==''){
                error.push(" - Please enter your email address");
            }   
            
            if(phone_number==''){
                error.push(" - Please enter your phone number");
            } 
           
                           
            if(error.length>0){             
                $('#error_msg').css("display","block");                
                $('#error_msg').html('The following error(s) occured:<br />'+error.join("<br />"));                
                $('html,body').animate({scrollTop: 150}, 1000);
                return false;
            }
          
            return true;
       }); 
       
       
       $('#bookAppointment').bind('submit', function(){
           
            var error=new Array();
            
            var name=$('#bookAppointment input[name="data[AppointmentRequest][name]"]').val();         
            var email_address=$('#bookAppointment input[name="data[AppointmentRequest][email_address]"]').val();
            var phone_number=$('#bookAppointment input[name="data[AppointmentRequest][telephone]"]').val();            
           
            
            //check for errors
            if(name==''){
                error.push(" - Please enter your name");
            }
           
            if(email_address==''){
                error.push(" - Please enter your email address");
            }   
            
            if(phone_number==''){
                error.push(" - Please enter your phone number");
            } 
           
                           
            if(error.length>0){             
                $('#error_msg').css("display","block");                
                $('#error_msg').html('The following error(s) occured: '+error.join(" "));                
                $('html,body').animate({scrollTop: 150}, 1000);
                return false;
            }
          
            return true;
       }); 
       
       
       //newsletter form
       $('form#newsletter_form').bind('submit',function(){
       		//alert($('form#newsletter_form').attr('action'));
       		   
       		if($('input#newsletter_email').val()==''){
       			$('p.msg').css("display","block");            
       			$('p.msg').html('<span style="color:#cc0000;">Please insert your email address</span>');   
       			return false;
       		}
       		
       		$.post($('form#newsletter_form').attr('action'),
		  { 'data[email_address]': $('input#newsletter_email').val()},
		  function(data){
		    $('p.msg').html('<span style="color:#999;">You have been subscribed to our newsletter</span>');	
		    //alert(data);
		  }
		);
		return false;
       });
       
       //pagination
       $('div.pagination ul li a').bind('click',function(){
       		var current_element = this;
       		$.ajax({
       		  type: "GET",	
		  url: $(this).attr('href'),
		  processData: false,
		  dataType: 'html',
		  success: function(data) {
			  $(current_element).parents('div.image_gallery').html(data);
			  prettyPhoto.init();
		
		  }
		});
		
		return false;
       
       });
       
       
});



sfHover = function() {
    if(document.getElementById("main_nav")){
    	var sfEls = document.getElementById("main_nav").getElementsByTagName("LI");

    	for (var i=0; i<sfEls.length; i++) {
    		sfEls[i].onmouseover=function() {
    			this.className+=" sfhover";
    		}
    		sfEls[i].onmouseout=function() {
    			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    		}
    	}
    }
}

if (window.attachEvent) window.attachEvent("onload", sfHover);
