// JavaScript Document

$(document).ready(function(){

	//If class=inFieldLabel, Move the label within field and hide them onClick (jquery.infieldlabel.min.js)
	if ($('form.inFieldLabel').length !=0) {
		$('.inFieldLabel label').inFieldLabels();		
	};

	/* Grossir texte */
	if($('#article-content').get(0)){$('#textSize').css('display','block');} else {$('#textSize').css('display','none');}
	
	/* What is fibromyalgia - Facts */
	
	$(".question-tab a").click(function(){ 
		$(this).parent().parent().parent().addClass('block');
		$(this).parent().parent().children('.question-tab').children('a').css('cursor','default');
		
		if(!$(this).hasClass('reality')) {$(this).parent().parent().children('.question-tab').children('a').removeClass('reality');}
		if(!$(this).parent().parent().children('.question-tab').children('a').hasClass('extend-orange')){$(this).addClass('extend-orange');}
		if($(this).hasClass('reality')){$(this).parent().parent().next('div').children('div').children('.answer').addClass('reality');}

		return false; 
	});
	
	$(".close").click(function(){		
		$(this).parent().parent().parent().removeClass("block");
		$(this).parent().parent().parent().children(".options").children("li").children("a").removeClass("extend-orange");
		$(this).parent().parent().parent().children(".options").children(".reality-tab").children("a").addClass("reality");
		$(this).parent().parent().parent().children(".options").children("li").children("a").css("cursor","pointer");
		
		$(this).parent().children(".answer").removeClass("reality");
		
		return false;
	});
	
	/* Do I have fibromyalgia - Assess your symptoms */
	$(".tender-spot").hover(function(){
			$(this).next("div").css("display","block");	
			return false;
		},function(){$(this).next("div").css("display","none");});
	
	$(".tender-spot-close").click(function(){
		$(this).parent().removeClass("tabContentVisible");
		$(this).parent().parent().removeClass("open");
		return false;
	});
	
	/* Do I have fibromyalgia - Ask our expert */
	$("#expand_all").click(function(){ 
		$(".tab").addClass("open"); 
		$(".tabContent").addClass("tabContentVisible"); 
		return false; 
	});
	
	$("#collapse_all").click(function(){ 
		$(".tab").removeClass("open"); 
		$(".tabContent").removeClass("tabContentVisible"); 
		return false; 
	});
	
	$(".tab .tab-title").click(function(){ 
		$(this).parent().children(".tabContent").toggleClass("tabContentVisible"); 
		$(this).parent("div").toggleClass("open");
		
		if(jQuery(".conversation").get(0)){
			$(this).parent().parent(".conversation").toggleClass("convHeight"); 
			$(this).parent().parent(".conversation").next(".border-dotted").toggleClass("invisible");	
		}
		
		return false; 
	});
	
	/* Do I have fibromyalgia - Ask our expert - Glossary Box */
	$(".glossaryLink").hover(function(){$(this).next().toggleClass("visible");});
	$(".glossary_box").hover(function(){$(this).toggleClass("visible");});
	


if(jQuery(".change-tabs").get(0))
	{_tabs.tabsLoad();} 
	

       /* Support fibromyalgia - Twitter */
       $("a#btn-tweet").click(function(){
              var tweetStatus = $("textarea#txt-tweet").val();

              if(tweetStatus.length == ""){
                   $("#err_tweet_field").css("display", "visible");
                   $("#err_tweet_field").text("Please insert your tweet");
                   return false
;
               }else if(tweetStatus.length > 140){
                   $("#err_tweet_field").css("display", "visible");
                   $("#err_tweet_field").text("Please shorten your tweet, Twitter accepts a maximum of 140 characters");                   
                   return false;

               }else{
                   $("#err_tweet_field").hide();
                   $("#err_tweet_field").text("");
                   $(this).attr("href","http://twitter.com/home?status=")
                   var tweetHref = $(this).attr("href") + encodeURIComponent(tweetStatus) ;
                   $(this).attr("href", tweetHref );
              }
       });
       
/* find empty N/A and remove them */
		$(".list-resources span:contains('N/A')").css("display", "none");

/* cut texte at first line */
/* $(".list-resources span a").svTruncate(); */
 
});

/* Living with pain - Onglets de changement de contenu */
var _tabs = 
{
	tabsLoad : function()
	{
		var open_first = 0;
		if (this.open_first){open_first=this.open_first;}
		jQuery(".change-tabs li a").click(_tabs.tabsChange); // add fonction on tabs links
		jQuery(".change-tabs-content").hide(); // hide all content
		jQuery(".change-tabs-content:eq("+open_first+")").show(); // show first tab content
		jQuery(".change-tabs li:eq("+open_first+")").addClass("selected"); // show first tab selected
	},
	tabsChange : function()
	{
		var leIndex = jQuery(".change-tabs li").index(jQuery(this).parent()); // index of clicked link
		var leIndexCurrent = jQuery(".change-tabs li").index(jQuery(".change-tabs li.selected")); // index of opened link
		if(!jQuery(this).closest("li").hasClass("selected")) // if not already open
		{
			jQuery(".change-tabs li").removeClass("selected");
			jQuery(this).closest("li").addClass("selected");
			
			jQuery(".change-tabs-content:eq(" + leIndexCurrent + ")").fadeOut("normal", function() // hide curent content
			{
				jQuery(".change-tabs-content:eq(" + leIndex + ")").fadeIn("normal"); // show clicked content									
			});
		}
		return false;
	} 
};

/* Text size */

function textSize(size){
		_size = size + 'px';
		$('#article-content').css("font-size",_size);
}



/* Do I have fibromyalgia - Ask our expert - Glossary Box */
function callGlossary(baseURL){
		$('.glossary_box').hover(function(){$('.glossary_box').removeClass('visible');});
		$('.glossary_box').removeClass('visible');
		window.location.href= baseURL + '/what_is_fibromyalgia/glossary/';
		$('.glossary_box').hover(function(){$(this).toggleClass('visible');});
}

