url = "http://www.healthaccess-strategies.com/";
$(document).ready(function(){
	//$("#services .tools").css("opacity", 0.6);
	function addslashes (str) {
		 return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
	}
	
	//Definitions in the text content
	/*
	$("a.definition").each(function() {
		var definition = addslashes($(this).attr("title"));
		var title = $(this).text();
		title = addslashes(title.toUpperCase());
		$(this).attr("title", "").attr("onmouseover", "Tip('"+definition+"', TITLE, '"+title+"', WIDTH, 300);").attr("onmouseout", "UnTip();");
	});*/
	
	//Long title
	if ($("h1 span").width()>177) {
		$("h1").css("background-image", "url("+url+"img/onglet-titre-long01.png)");
	}
	
	// Dropdown table
	$("table tr th").hover(function() {
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");
	});
	$("table[summary=dropdown] tr:even").css("cursor", "pointer");
	$("table[summary=dropdown] tr:odd").hide();
	$("table[summary=dropdown] tr th").click(function() {
		if ($(this).parent().next("tr").css("display")=="none") {
			$(this).parent().next("tr").show();
		} else {
			$(this).parent().next("tr").hide();
		}
	});
	
	var ancre = location.hash;
	if (ancre!="") {
		var className = ancre.replace("#", "");
		$("#submenu-services li."+className+"").parent().addClass("selected");
		$("#services div.graphic").hide();
		$("div.service div.tools-content").hide();
		$(ancre).fadeIn("slow", function() {
			$("div.service div.tools-content").slideDown("slow");
		});
	}/*
	$("#services .tools").toggle(function(){
		//$(this).animate({opacity:1},400);
		$(this).children(".tools-title").children("img").attr("src", url+"img/moins.png");
		$(this).children(".tools-content").slideDown("slow");
	}, function() {
		//$(this).animate({opacity:0.6},400);
		$(this).children(".tools-title").children("img").attr("src", url+"img/plus.png");
		$(this).children(".tools-content").slideUp("fast");
	});*/
	
	$("ul#submenu-services li").click(function() {
		$("div.graphic").hide();
		$("ul#submenu-services li").parent().removeClass("selected");	
		$("div.service").hide();
		$("div.service div.tools-content").hide();
		$(this).parent().addClass("selected");
		
		var className = $(this).attr("class");
		$("#"+className).fadeIn("slow", function() {
			$("div.service div.tools-content").slideDown("slow");
		});
	});
	
	$("div.dots div").hover(function() {
		var areaName = $(this).attr("class");
		Showmap(areaName);
	}, function() {
		var areaName = $(this).attr("class");
		Hidemap(areaName);
	});
		
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};

	$("#terms .term a").click(function() {
		$("#terms .term").css("background-color", "transparent");
		var href = $(this).attr("href");
		url = href.split("#");
		$.scrollTo( 'a[name='+url[1]+']', 1000, { onAfter:function(){
			$("#term_"+url[1]).css("background-color", "#DFDFDF");
		} } );
	});
	/*
	$("#services h2").toggle(function(){
		$(this).parent().children(".description").show("fast");
	}, function() {
		$(this).parent().children(".description").hide("fast");
	});
	$("#services .tools").hover(function(){
		$(this).animate({opacity:1},400);
	}, function() {
		$(this).animate({opacity:0.9},400);
	});
	
	$("ul#submenu-services li").click(function() {
		$("ul#submenu-services li").css("list-style-type", "disc");
		$(this).css("list-style-type", "circle");
		$(".description").hide("slow");
		$(".tools-content").hide("slow");
		$(".tools-title img").attr("src", url+"img/plus.png");
		$(".service").css("background-image", "none").css("padding", "0px");
		var className = $(this).attr("class");
		//$("#"+className).flash( '#20419A', 1000 );
		//$("#"+className+" .description").show("slow");
		//$("#"+className+" .tools-content").show("fast");
		$("#"+className).css("background-image", "url(http://www.from-scratch.fr/dev/has/img/px-transparent.png)").css("padding", "10px");
		$("#"+className+" .description").show("slow");
		$("#"+className+" .tools-title img").attr("src", url+"img/moins.png");
		$("#"+className+" .tools-content").show("slow");
		//$.scrollTo($("#"+className),500);
	});*/
	// Map
});

function Showmap(area) {
	$("#map-"+area).show();
	$("#desc-"+area).show();
}
function Hidemap(area) {
	$("#map-"+area).hide();
	$("#desc-"+area).hide();
}
	
jQuery.fn.flash = function( color, duration )
{

    var current = this.css( 'color' );

    this.animate( { color: 'rgb(' + color + ')' }, duration / 2 );
    this.animate( { color: current }, duration / 2 );

}


offset = new Array();
function toFloat(elt,d) {	
	offset[elt]= $(elt).offset().top;
	$(window).scroll(function() {
		$(elt).stop();
		var topToWindow = ($(window).scrollTop()>offset[elt])?$(window).scrollTop()-offset[elt]:0;
		if (topToWindow>40) {
			$(elt).animate({marginTop:topToWindow-40},{duration:d,queue:false});
		} else {
			$(elt).animate({marginTop:0},{duration:d,queue:false});
		}
	});
}
//toFloat('#submenuarea',500);
//toFloat('div.logo',500);

