$(document).ready(function(){
( $.cookie('tcookie') )? tchange( $.cookie('tcookie') ) : tchange( 'text0' );
	$('.tchange').click(function(){ tchange( $(this).attr('id') ); return false; });
	swfobject.registerObject('movie', '9');
	
	( $.cookie('tcookie') )? tchange( $.cookie('tcookie') ) : tchange( 0 );
	$('.change_text').click( function(){
		$(this).addClass('selected');
		tchange( $(this).attr('title') );
	});


	$('#data_table').tablesorter(
		{ widgets: ['zebra'] }
	);

	
	$('.group_toggle').click(function(){
		$(this).parent().find('.support_group_info').toggle();
		return false;
	});
	
	$('.read_more').click(function(){
		$('.read_more_content').toggle();
		
		if($('.read_more_button').html() == 'read more &gt;'){
			$('.read_more_button').html('&lt; close');
		}
		else {
			$('.read_more_button').html('read more &gt;');
		}
		
		return false;
	});
	

/* Setup tool tips 
------------------------------------------------------------ */
	
	$('.legend_confidence').qtip({
		content: "The Confidence Interval shows how precise the information is.  The exact answer could be any number shown with in the blue confidence interval bar.  The shorter the area of the blue confidence interval bar, the more precise the information is.",
		show: {
			delay: 0
		},
		position: { 
	      corner: {
	         target: 'topLeft',
	         tooltip: 'bottomRight'
	      },
	      adjust: { 
	      	x: 40, 
	      	y: 35 
	      }
		},
		style: { 
			fontSize: '12px',
			fontFamily: 'georgia',
			width: 300,
			padding: 5,
			background: '#fff',
			color: 'black',
			textAlign: 'left',
			border: {
				width: 2,
				radius: 3,
				color: '#0048AA'
			},
			tip: 'bottomRight',
			name: 'blue' // Inherit the rest of the attributes from the preset dark style
		}
	
	});


	$('.legend_national_median').qtip({
		content: "The National median shows that of the medical groups  in the United States that released this information,  half the groups did better than this, and half did worse.",
		show: {
			delay: 0
		},
		position: { 
	      corner: {
	         target: 'topLeft',
	         tooltip: 'bottomLeft'
	      },
	      adjust: { 
	      	x: 40, 
	      	y: 20 
	      }
		},
		style: { 
			fontSize: '12px',
			fontFamily: 'georgia',
			width: 300,
			padding: 5,
			background: '#fff',
			color: 'black',
			textAlign: 'left',
			border: {
				width: 2,
				radius: 3,
				color: '#0048AA'
			},
			tip: 'bottomLeft',
			name: 'blue' // Inherit the rest of the attributes from the preset dark style
		}
	
	});

	$('.legend_state_average').qtip({
		content: "California Average describes the total combined score of all the participating physician organizations in California, divided by the number of physician organizations that released information.",
		show: {
			delay: 0
		},
		position: { 
	      corner: {
	         target: 'topLeft',
	         tooltip: 'bottomLeft'
	      },
	      adjust: { 
	      	x: 20, 
	      	y: 5 
	      }
		},
		style: { 
			fontSize: '12px',
			fontFamily: 'georgia',
			width: 300,
			padding: 5,
			background: '#fff',
			color: 'black',
			textAlign: 'left',
			border: {
				width: 2,
				radius: 3,
				color: '#0048AA'
			},
			tip: 'bottomLeft',
			name: 'blue' // Inherit the rest of the attributes from the preset dark style
		}
	
	});	
	
   $("<div id='qtip_blanket'>").css({
         position: 'absolute',
         top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
         left: 0,
         height: $(document).height(), // Span the full document height...
         width: '100%', // ...and full width

         opacity: 0.7, // Make it slightly transparent
         backgroundColor: 'black',
         zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
      })
      .appendTo(document.body) // Append to the document body
      .hide(); // Hide it initially

	
	$('.more_info_button').each(function(){
		
		$(this).qtip({
			content: {
				title: {
					text: 'Category Information:',
					button: 'Close (x)'
				},
				text: $(this).parent().find('.more_info_content').html()
			},
			show: {
				when: 'click', // Show it on click
				solo: true // And hide all other tooltips
			},
			position: {
				target: $(document.body), // Position it via the document body...
				corner: 'center', // ...at the center of the viewport
				adjust: {
					y: 10
				}
			},
			hide: false,
			style: {
				fontSize: '14px',
				lineHeight: '18px',
				fontFamily: 'georgia',
				background: '#ffffff',
				color: 'black',
				textAlign: 'left',
				width: 850,
				padding: '10px',
				border: {
					width: 5,
					radius: 5,
					color: '#0048AA'
				},
				name: 'blue'
			},
			api: {
				beforeShow: function(){
					// Fade in the modal "blanket" using the defined show speed
					$('#qtip_blanket').fadeIn(this.options.show.effect.length);
				},
				beforeHide: function(){
					// Fade out the modal "blanket" using the defined hide speed
					$('#qtip_blanket').fadeOut(this.options.hide.effect.length);
				}
			}
		});

	});
	
});



function tchange(t){
	switch(t){ 
		case 'text0' 	: $('#main_inner').css({'font-size' : '12px'}); break;
		case 'text1' 	: $('#main_inner').css({'font-size' : '14px'}); break;  
		case 'text2' 	: $('#main_inner').css({'font-size' : '16px'}); break;  
	}
	$('.tchange').removeClass('tchange_selected'); 
	$('#'+t+'').addClass('tchange_selected'); 
	$.cookie('tcookie', ''+t+'');
}


