$(document).ready(function() {  
                           
	if ($('#navigation'))
		$('#navigation').navigation();
	                         
}); 

(function($){  
    $.fn.extend({   
    
        navigation: function(options) {  
            return this.each(function() {            
                  // Collect tabs in navigation  
			      var items = $(" a", $(this));  
                  
                  //  Setup           
                  items.each(function(i) {
	                 var item = $(this) 
					 item.attr('tabNumber',i) 
					});   
					
				 // There is a problem with the map and iPad at present
				// disable the map on ipad only
			 /*   if (/\(iPad; U; CPU OS 3_2_1/.test(navigator.userAgent))   
				  {  
				  document.getElementById('coolgmap').style.display = "none";
				  //alert(navigator.userAgent);  
			      }      */
					
				 // Respond to clicks on items
                  items.click(function(e,i) {   
	 				e.preventDefault() 
					var item = $(this) 
					var anchor = item.attr('href')
					var tab = $(anchor)
	                
					// Select tab 
				    items.each(function(){
						 $(this).removeClass('selected')   
					  });
					
                     $(this).addClass('selected') 
				    
					// We simply slide the entire tabs element over
                    var width = tab.width()  
					var tabNo = item.attr('tabNumber') 
                    var offset =  width*tabNo
				    
				   /*works around a bug in Safari meaning full redraw wasn't happening */
				    $("#tabs").css({webkitTransform:'scale(1)'}) 
				       
				 	$("#tabs").animate({         
						marginLeft:"-"+offset+"px"  
						}, 800, function(){}
						);
				              
					    // Prevent browser scroll by removing anchor id temp
					  /* var anchorTag = $(anchor)
                       anchorTag.attr('id', '');
                     
					   // Set the address bar to url#anchor
					   document.location.hash = anchor;   
						 
					   anchorTag.attr('id', anchor); // restore id   */ 
                  });  
            });  
        }   
 
    });  
})(jQuery);  
