$(document).ready(function() {
	// Hide reports
	$(".item").hide();
	// Show all links in column 1
	var countcat = 0;
	$(".item").each(function () {
		var cat_t = $(this).attr("title");
		var cat_i = $(this).attr("id");
		$("#categories").append('<a href="#'+cat_i+'_panel" title="'+cat_t+'" id="'+cat_i+'_btn"><span>'+cat_t+'</span></a>');
	});
	// function for clicking on a report link
	function rbind(){ 
		$('#categories a').click(function () {
			// remove current selected item bg
			$("#categories a").removeClass("selected");
			// get id of current button clicked
			var rep_click = $(this).attr("id");
			// remove btn ending from id
			rep_click = "#"+rep_click.replace("_btn","");	
			// hide any current report
			$("#details .item").hide();
			// show new clicked report
			$(rep_click).fadeIn("slow", function(){
				if(jQuery.browser.msie){
					$(this).get(0).style.removeAttribute('filter');
				}
			});
			// set current button to selected class
			$(this).addClass('selected');
			// scrolls 3rd column to the top
			$("div#details").scrollTo(0);
			// makes the page not navigate down
		});
	};
	// loading hash function
	function mload(){ 
		// if hash exists #value
		if(window.location.hash && window.location.hash != "" && window.location.hash != "#"){
			var ihash = window.location.hash;
			// make sure pound sign is not there
			ihash = ihash.replace("#","");
			ihash = ihash.replace("_panel","");
			// add pound sign
			var m_hash = ("#"+ihash);
			// see if element exists in the html
			if($(m_hash).length > 0){
				// click category of hash id
				$('#categories a:'+m_hash+'_btn').click();	
				// scroll to selected
				$("div#categories").scrollTo('a:'+m_hash+'_btn');
				$("div#details").scrollTo(0);
			}
			else{
				// if hash value doesnt exist in html
				$('#categories a:#desktop_gis_btn').click();
			}
		}
		else{
			// if no hash, load first item
			$('#categories a:#desktop_gis_btn').click();
		}
	};
	// execute functions
	rbind();
	mload();
});