(function($) {
	$(document).ready(function() {
		checkAnchor();
		
		$("#tabber .tabber-tabs a").click(function() {
			anchor = $(this).attr("href");
			document.location.hash = anchor.substring(1);
			checkAnchor();

			return false;
		});		
	});
	

	var currentAnchor = null;  
	var sections = new Array();
	sections[0] = "featured-news";
	sections[1] = "meet-your-neighbor";
	sections[2] = "its-your-business";
	
	
	//Function which chek if there are anchor changes, if there are, sends the ajax petition  
	function checkAnchor(){  
		//Check if it has changes  
		if(currentAnchor != document.location.hash){  
			currentAnchor = document.location.hash;  
			
			//if there is not anchor, the loads the default section  
			if(!currentAnchor) { 
				section = sections[0];
				query = "section=" + sections[0];  
			} else {  
				//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2  
				var splits = currentAnchor.substring(1).split('&');  
			
				//Get the section  
				var section = splits[0];  
				delete splits[0];  
			
				//Create the params string  
				var params = splits.join('&');  
				var query = "section=" + section + params;  
			}  
			
			
			//Send the petition
			if(in_array(section, sections)) updateTabber(section);  
		}  
	} 

	function updateTabber(section) {
		$("#tabber .tabber-section").removeClass("visible");
		$('#tabber .tabber-section[rel="' + section + '"]').addClass("visible");
		
		$("#tabber .tabber-tabs li").removeClass("active");
		$('#tabber .tabber-tabs a[href="#' + section + '"]').parent().addClass("active");
	}
})(jQuery); 


function in_array(string, array) {
	for (i = 0; i < array.length; i++) {
		if(array[i] == string) return true;
	}
	
	return false;
}