jQuery.noConflict();
jQuery(document).ready(function() {
	// Hide reports
	jQuery(".report").hide();
	// Open new window links (unneccessary with this new script but can be turned on)
		//jQuery('.m_content a[rel=window]').attr('target','_blank');
	// Show all links in column 1
	jQuery(".category").each(function () {
		var cat_t = jQuery(this).attr("title");
		var cat_i = jQuery(this).attr("id");
		//var cat_d = jQuery(this).attr("alt");
		var desccat = "desc" + cat_i;
		jQuery("#categories").append('<a href="#'+cat_i+'"  id="'+cat_i+'_btn" onMouseOver="moveBox(event,50,-50);showText('+desccat+');" onMouseOut="hideText();">'+cat_t+'</a>');
	});
	
	// function for clicking on a report link
	function rbind(){ 
		jQuery('#reports a').click(function () {
			// remove current selected item bg
			jQuery("#reports a").removeClass("selected");
			// get id of current button clicked
			var rep_click = jQuery(this).attr("id");
			// remove btn ending from id
			rep_click = "#"+rep_click.replace("_btn","");	
			// hide any current report
			jQuery("#details .report").hide();
			// show new clicked report
			jQuery(rep_click).show();
			// set current button to selected class
			jQuery(this).addClass('selected');
			// makes the page not navigate down
			return false;
		});
	};
	// function for clicking on a category link
	function cbind(){ 
		jQuery('#categories a').click(function () {
			// hide current report
			jQuery("#details .report").hide();
			// remove selected category class
			jQuery("#categories a").removeClass("selected");
			// get id of current category button
			var cat_click = jQuery(this).attr("id");
			// remove btn ending
			cat_click = cat_click.replace("_btn","");
			// remove all report links from column2
			jQuery("#reports a").remove();
			// variables for current category
			var cc2 = "#"+cat_click+" .report";
			var cc3 = "#"+cat_click+" .report:first";
			// show all reports for the category
			jQuery(cc2).each(function () {
				var rep_t2 = jQuery(this).attr("title");
				var rep_i2 = jQuery(this).attr("id");
								jQuery("#reports").append('<a href="#'+rep_i2+'"  id="'+rep_i2+'_btn">'+rep_t2+'</a>');

				//jQuery("#reports").append('<a href="#'+rep_i2+'" title="'+rep_t2+'" id="'+rep_i2+'_btn">'+rep_t2+'</a>');
				// see if this report is featured
				if(jQuery(this).hasClass("featured")){
					// give link a class of featured
					jQuery("#"+rep_i2+"_btn").addClass("featured_link");
				}
			});
			jQuery("#reports a:first").addClass('selected');
			jQuery(this).addClass('selected');
			jQuery(cc3).show();
			// scroll to first item
			jQuery("div#categories").scrollTo("a:#"+cat_click+"_btn");
			jQuery("div#reports").scrollTo(0);
			rbind();
			// makes the page not navigate down
			return false;
		});
	};
	// loading hash function
	function mload(){ 
		// if hash exists #value
		if(window.location.hash){
			var ihash = window.location.hash;
			// make sure pound sign is not there
			ihash = ihash.replace("#","");
			// add pound sign
			var m_hash = ("#"+ihash);
			// see if element exists in the html
			if(jQuery(m_hash).length > 0){
				//find closest parent of the id
				var parentid = jQuery(m_hash).closest("div.category").attr("id");
				// click category of hash id
				jQuery('#categories a:#'+parentid+'_btn').click();
				// remove pound key
				var j_hash = m_hash.replace("#","");
				// click report of hash id
				jQuery('#reports a#'+j_hash+'_btn').click();
				// scroll to selected
				jQuery("div#categories").scrollTo('a:#'+parentid+'_btn');
				jQuery("div#reports").scrollTo('#'+j_hash+'_btn');
			}
			else{
				// if hash value doesnt exist in html
				jQuery('#categories a:first').click();
			}
		}
		else{
			// if no hash, load first item
			jQuery('#categories a:first').click();
		}
	};
	// execute functions
	rbind();
	cbind();
	mload();
});