var flyoutActive = false;
var flyoutTimer;

function showOffices() {
	hideDoctorFlyouts();
	$("#nav_btns .offices a").addClass("active");
	$("div.offices-flyout").css("display", "block");
}

function showServices() {
	hideDoctorFlyouts();
	$("#nav_btns .emc a").addClass("active");
	$("div.menu-flyout").css("display", "block");
}

function hideFlyouts() {
	$("div.menu-flyout").css("display", "none");
	$("div.offices-flyout").css("display", "none");
	$("#nav_btns .offices a").removeClass("active");
	$("#nav_btns .emc a").removeClass("active");
}

function bindFlyoutFunctions() {
	$("#nav_btns .offices a").bind('mouseover', function() { hideFlyouts(); showOffices(); }).bind('mouseout', function() { hideFlyouts(); });
	$("#nav_btns .emc a").bind('mouseover', function() { hideFlyouts(); showServices(); }).bind('mouseout', function() { hideFlyouts(); });
	$("div.menu-flyout").bind('mouseover', function() { hideFlyouts(); showServices(); }).bind('mouseout', function() { hideFlyouts(); });
	$("div.offices-flyout").bind('mouseover', function() { hideFlyouts(); showOffices(); }).bind('mouseout', function() { hideFlyouts(); });
}

function hideDoctorFlyouts() {
	$(".bt-wrapper").hide();
}

function hideFlyoutConditional() {
	if (!flyoutActive) hideDoctorFlyouts();
}

function foOn() {
	flyoutActive = true;
	clearTimeout(flyoutTimer);
}

function foOff() {
	flyoutActive = false;
	flyoutTimer = setTimeout('hideFlyoutConditional()', 2000);
}

function doctorFlyout(id) {
	theContent = $("#doctorFlyout_"+id).html();
	doDoctorFlyout(id, theContent);
}

function doDoctorFlyout(id, theContent) {
	$("#dr_"+id).bt(theContent,
	{
		trigger: ['focus mouseover', ''],
		positions: ['right'],
		windowMargin: 10,
		clickAnywhereToClose: true,
		closeWhenOthersOpen: true,
		contentSelector: "$('#doctorFlyout_"+id+"')",
		//ajaxPath: 'ajax/dr_flyout.php?id='+id,
		strokeStyle: "#bbb",
		shadow: true,
		shadowColor: "#777", 
		fill: '#fafafa',
		width: '459px',
		hoverIntentOpts: {
			interval: 0,
			timeout: 0
		},
		postShow: function() {
			$(".bt-content").bind('mouseover', function() { foOn(); }).bind('mouseout', function() { foOff(); });
			$("#dr_"+id).bind('mouseover', function() { foOn(); });
			$("#dr_"+id).bind('mouseout', function() { foOff(); });
		}
	});
}

function hideFlyoutConditional() {
	if (!flyoutActive) hideDoctorFlyouts();
}

function ifoOn() {
	flyoutActive = true;
	clearTimeout(flyoutTimer);
}

function ifoOff() {
	flyoutActive = false;
	flyoutTimer = setTimeout('hideFlyoutConditional()', 2000);
}


function doctorInsuranceFlyout(id) {
	$("#see_all_insurance").bt({
		trigger: ['focus mouseover', ''],
		positions: ['bottom'],
		windowMargin: 10,
		padding: '15px',
		clickAnywhereToClose: true,
		closeWhenOthersOpen: true,
		contentSelector: "$('#dr_insurance_flyout_content').html()",
		strokeStyle: "#bbb",
		shadow: true,
		shadowColor: "#777", 
		fill: '#fafafa',
		width: '499px',
		hoverIntentOpts: {
			interval: 0,
			timeout: 0
		},
		postShow: function() {
			$(".bt-content").bind('mouseover', function() { ifoOn(); }).bind('mouseout', function() { ifoOff(); });
			$("#dr_"+id).bind('mouseover', function() { ifoOn(); });
			$("#dr_"+id).bind('mouseout', function() { ifoOff(); });
		}
	});
}

$(document).ready(function() {

$('img.rounded').one('load',function () {
	var img = $(this);
	var img_width = img.width();
	var img_height = img.height();
	
	// build wrapper
	var wrapper = $('<div class="rounded_wrapper"></div>');
	wrapper.width(img_width);
	wrapper.height(img_height);
	
	// move CSS properties from img to wrapper
	wrapper.css('float', img.css('float'));
	img.css('float', 'none')
	
	wrapper.css('margin-right', img.css('margin-right'));
	img.css('margin-right', '0')

	wrapper.css('margin-left', img.css('margin-left'));
	img.css('margin-left', '0')

	wrapper.css('margin-bottom', img.css('margin-bottom'));
	img.css('margin-bottom', '0')

	wrapper.css('margin-top', img.css('margin-top'));
	img.css('margin-top', '0')

	wrapper.css('display', 'block');
	img.css('display', 'block')

	// IE6 fix (when image height or width is odd)
	if ($.browser.msie && $.browser.version == '6.0')
	{
		if(img_width % 2 != 0)
		{
			wrapper.addClass('ie6_width')
		}
		if(img_height % 2 != 0)
		{
			wrapper.addClass('ie6_height')			
		}
	}

	// wrap image
	img.wrap(wrapper);
	
	// add rounded corners
	img.after('<div class="tl"></div>');
	img.after('<div class="tr"></div>');
	img.after('<div class="bl"></div>');
	img.after('<div class="br"></div>');
}).each(function(){
	if(this.complete) $(this).trigger("load");
});
	
});

function processSearchMessaging(count, spec, office, ins) {
	if (count==0) {
		$("#findDR").hide();
		$("#noRecords").show();
	} else {
		$("#searchSelectAdjustmentMessage").show();
	}
	if (spec==1) {
		$("select#specialty").get(0).selectedIndex = 0;
		$("#specialty_dropdown dt a").html("Any Specialty<span class=\"value\">ALLVALUES</span>");
	}
	if (office==1) {
		$("select#office").get(0).selectedIndex = 0;
		$("#office_dropdown dt a").html("Any Office<span class=\"value\">ALLVALUES</span>");
	}
	if (ins==1) {
		$("select#insurance").get(0).selectedIndex = 0;
		$("#insurance_dropdown dt a").html("Any Insurance<span class=\"value\">ALLVALUES</span>");
	}
}
