$(function(){

	//Get the current url (so we can set the active section)
	
	var sTmpLoc = document.location.href;
	var aURL = document.location.href.split('/');
	//First remove all the active classes
	$('div#btActive').attr('id', '');
	$('div#btRight').remove();
	$('div.button').removeClass('active');
	if(aURL[3]=='events'){
		var oActive = $('.btEvents');
		//Put the Events png above the content
		$('#js_headerImage').attr('src', 'http://taoschamber.org/graphics/taoschamber/content/titles/events.png');
		
	} else {
		var oActive = $('.btBusinessDirectory');
		//Put the Events png above the content
		$('#js_headerImage').attr('src', 'http://taoschamber.org/graphics/taoschamber/content/titles/business_directory.png');
	}
	$('#js_headerImage').supersleight({shim:'images/pixel.gif'});

	//Add the active button state	
	oActive.parent().addClass('active');
	oActive.parent().find('a').remove();
	oActive.attr('id', 'btActive');
	oActive.parent().prepend("<div id='btRight'></div>");


	//Remove the chambermaster footer
	$('#cm_pbfooter').remove();	
	//$('div#cm_events_index div h1').remove();	

	//Rebuild the 'Hot Deals' img	
	$('#cm_hotdeal_img').wrap("<div class='cm_hotdeal_img_wrapper'></div>");
	
	//If a webpage is external, then make sure that it opens in a new window
	var tmp_href = '';
	$('div#content_holder a').each(function(){
		tmp_href = $(this).attr('href');
		
		//Set the target to blank if the url is nonlocal
		if(tmp_href.substr(0,36)!='http://chambermaster.taoschamber.org'){
			$(this).attr('target', '_blank');
		}
		
		//Remove any links to the homepage (keep navigation in the header and footer)
		if(tmp_href=='http://www.taoschamber.org'){
			$(this).remove();
		}
		
	});

});
