// JavaScript Document

//On Mouseover
$('.slider').mouseover(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.slider').removeClass('selected').next().slideUp(); //Remove all "selected" state and slide up the immediate next container
		$(this).toggleClass('selected').next().slideDown(); //Add "selected" state to clicked trigger and slide down the immediate next container
	}
	return false; //Prevent the browser jump to the link anchor
});

function highlight_active_slider(){
	//Set default open/close settings for submenus
	$('.submenu').hide(); //Hide/close all submenus
	// Set active category
	$('.slider').attr('id','');
	var ch = window.location.pathname;
	var divobj = $('.slider').attr('class');
	if( ch.indexOf( "practice" ) !== -1 ){
		$('.practice').attr('id','selected');
	} else if( ch.indexOf( "procedures" ) !== -1 ){
		$('.procedures').attr('id','selected');
	} else if( ch.indexOf( "forms" ) !== -1 ){
		$('.forms').attr('id','selected');
	} else if( ch.indexOf( "financing" ) !== -1 ){
		$('.financing').attr('id','selected');
	} else if( ch.indexOf( "resources" ) !== -1 ){
		$('.resources').attr('id','selected');
	} else if (ch == ch){
		$('.practice').attr('id','selected');
	}
	$('#selected').next().show(); //show/open the immediate next container
}

// image description popups
function swapContent(cv){
	$('.images li').attr('id', null);
	$('li.'+cv).attr('id','over');
	$("#image_info").html('<img id="loading" src="../images/loading.gif"/>').show();
	var url="image_info.php";
	$.post(url,{contentVar:cv}, function(data){
		$("#image_info").html(data).show(1000);
	});
}

// find active sublink
function highlight_active_sublink (){
	$(".submenu a").attr('id','');
	$(".submenu a").each(function(){
		var current_href = $(this).attr("href");
		if (document.location == current_href) {
			$(this).attr('id', 'sub_selected');	
		}
	});
}

// Referring Doctor extraction chart
/* see if anything is previously checked and reflect that in the view*/
$(".checklist input:checked").parent().addClass("selected");
 
/* handle the user selections */
$(".checklist .checkbox-select").click(
	function(event) {
	event.preventDefault();
	$(this).parent().addClass("selected");
	$(this).parent().find(":checkbox").attr("checked","checked");
});
 
$(".checklist .checkbox-deselect").click(
	function(event) {
	event.preventDefault();
	$(this).parent().removeClass("selected");
	$(this).parent().find(":checkbox").removeAttr("checked");
});

// GO BUCKS Easter Egg
function go_bucks (){
	$("img#brian").hover(function(){
		$("#go_bucks").animate({top:'180px'},{queue:false,duration:500});
	}, function(){
		$("#go_bucks").animate({top:'0px'},{queue:false,duration:500});
	});
}
  
$(document).ready(function(){
	// set menu height to equal content
	var f_height = $('#content').outerHeight(true);
	if (f_height >= 500){
		$('.menu').css('height', f_height);
	} else {
		$('.menu').css('height', 500);
		$('#content').css('height',488);
	}
	// make entire menu li clickable
	$(".menu li").click(function(){
	window.location=$(this).find("a").attr("href"); return false;
	});
	
	highlight_active_sublink();
	highlight_active_slider();
	
});
