// Script.js - Wowza
// ------------------------------------------------------------------------------------------------

$(document).ready(function(){


$('.alternate_hidden_text').jqm();


$('.alternate_hidden_text').jqmAddClose('.hideX'); 

$('.show_more_info_modal_content').click(function() { 
	$('.alternate_hidden_text').jqmShow();
	$(document).scrollTop(0);
	$('body').scrollTop(0);

})





//Setup Column Controls
	$(".halfColumns").columnize({columns: 3});

//toggle for faq
 //hide the all of the element with class msg_body
  $(".msg_body").hide();
  //toggle the componenet with class msg_body
  $(".msg_head").click(function()
  {
    $(this).next(".msg_body").slideToggle(200);
  });


//Setup "show_hide_blocks"
	$('.show_hide_block ul').hide();
	$('.show_hide_block p').hide();
	$('.show_hide_block h3').css('cursor', 'pointer');
	$('.show_hide_block h3').click(function(){
		$(this).nextUntil('h3').toggle();
	}); 

	
	var showh3 = parseInt( $('#showh3').val() );	
	i=0;
	$('.show_hide_block h3').each(function(){
		i++;
		if(i == showh3){
			$(this).nextUntil('h3').show();
		}
	});
	

	$('#average_label').qtip({
         content: "Click for definition",
         position: {
            corner: {
               tooltip: 'bottomMiddle',
               target: 'topMiddle'
            }
         },
         style: {
            tip: true, // Give it a speech bubble tip with automatic corner detection,
      		'font-size': 12
         }			
	});

	$('#average_label').qtip({
		content: {
			text: 'This thin vertical black line shows the average performance rate for this topic for all 40 POs in southeast Michigan. (For more information, see &#34;<a href="reports.php?s=physician_organizations&v=po_about_the_data">About the Data</a>&#34;)',
			title: {
				text: 'Average Performance',
				button: 'close'
			}
		},
         style: {
      		'font-size': 12
         },
		show: 'click',
		hide: false,	
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomRight'
			},
			adjust: { 
				x: 0,
				y: 0
			}	
		}	
	});



	$('#top20_label').qtip({
         content: "Click for definition",
         position: {
            corner: {
               tooltip: 'bottomMiddle',
               target: 'topMiddle'
            }
         },
         style: {
            tip: true, // Give it a speech bubble tip with automatic corner detection,
      		'font-size': 12
         }			
	});
	$('#top20_label').qtip({
		content: {
			text: 'This lightly shaded, vertical green bar shows Physician Organizations (POs) with the top scores for this topic; it works like a "benchmark" to help compare how well physicians in the POs are giving care. Click on "About the Data" in the left navigation area for more detail about the Top 20%.',
			title: {
				text: 'Top 20%',
				button: 'close'
			}
		},
         style: {
      		'font-size': 12
         },
		show: 'click',
		hide: false,	
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomRight'
			},
			adjust: { 
				x: 0,
				y: 0
			}
		}	
	});
	
	
	$('#top25_label').qtip({
         content: "Click for definition",
         position: {
            corner: {
               tooltip: 'bottomMiddle',
               target: 'topMiddle'
            }
         },
         style: {
            tip: true // Give it a speech bubble tip with automatic corner detection
         }			
	});
	$('#top25_label').qtip({
		content: {
			text: 'This lightly shaded, vertical green bar shows Physician Organizations (POs) with the top scores for this topic; it works like a "benchmark" to help compare how well physicians in the POs are giving care. Click on "About the Data" in the left navigation area for more detail about the Top 25%.',
			title: {
				text: 'Top 25%:',
				button: 'close'
			}
		},
		show: 'click',
		hide: false,	
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomRight'
			},
			adjust: { 
				x: 0,
				y: 0
			}
		}	
	});

/*$('.ipa_avg_container').qtip({
   content: {
         text: false // Use each elements title attribute
      },
	position: {
			corner: {
				target: 'center',
				tooltip: 'center'
			},
			adjust: { 
				x: 0,
				y: 0
			}
			
	}
});*/
$('.score').qtip({
   content: {
         text: false // Use each elements title attribute
      },
	position: {
			corner: {
				target: 'rightMiddle',
				tooltip: 'leftMiddle'
			},
			adjust: { 
				x: 15,
				y: 0
			},
			 style: {
          	  tip: true // Give it a speech bubble tip with automatic corner detection
         }
			
	
			
	}
});

$('.pe_qtip_info').qtip({
   content: {
         text: false // Use each elements title attribute
      },
	position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { 
				x: 15,
				y: 0
			},
			 style: {
				 'font-size': '12px',
				'line-height': '22px',
          		tip: true // Give it a speech bubble tip with automatic corner detection
				
         	}
         
			
	
			
	},
	 show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      }
});

$('#pe_1').qtip({
   content: {
   
	title: {
            text: "How Well Doctors Communicate with Patients",
            button: '(X)'
         },
	
    text: $('#pe_text_more_info_2').html()
	
      },
	position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { 
				x: 15,
				y: 0
			}
			  
      },
	 hide: false,	  
      style: {
        		width: { max: 300 },
				padding: '14px',
		        "font-size": '12px',
        		"line-height": '20px',
         border: {
            width: 1,
            radius: 1,
            color: '#666666'
         },
         name: 'light'   
			
	
			
	},
	 show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      }
});

$('#pe_2').qtip({
	hide: false,
   content: {
   		
   		title: {
            text: "Helpful, Courteous, and Respectful Office Staff",
            button: '(X)'
         },
         text: $('#pe_text_more_info_3').html() // Use each elements title attribute
      },
	position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { 
				x: 15,
				y: 0
			}
			  
      },
      style: {
        		width: { max: 300 },
				padding: '14px',
		        "font-size": '12px',
        		"line-height": '20px',
         border: {
            width: 1,
            radius: 1,
            color: '#666666'
         },
         name: 'light'   
			
	
			
	},
	 show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      }
});
$('#pe_3').qtip({
	hide: false,
   content: {
		title: {
            text: "Getting Timely Appointments, Care, and Information",
            button: '(X)'
         },
   		
         text: $('#pe_text_more_info_4').html() // Use each elements title attribute
      },
	position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { 
				x: 15,
				y: 0
			}
			  
      },
      style: {
        		width: { max: 300 },
				padding: '14px',
		        "font-size": '12px',
        		"line-height": '20px',
         border: {
            width: 1,
            radius: 1,
            color: '#666666'
         },
         name: 'light'   
			
	
			
	},
	 show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      }
});
$('#pe_4').qtip({
	hide: false,
   content: {
		title: {
            text: "Patient Ratings of Doctors",
            button: '(X)'
         },
        text: $('#pe_text_more_info_5').html() // Use each elements title attribute
      },
	position: {
			corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: { 
				x: 15,
				y: 0
			}
			  
      },
      style: {
        		width: { max: 300 },
				padding: '14px',
		        "font-size": '12px',
        		"line-height": '20px',
         border: {
            width: 1,
            radius: 1,
            color: '#666666'
         },
         name: 'light'   
			
	
			
	},
	 show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      }
});


   $('#pe_more_info_1').qtip(
   {
      content: {
         title: {
            text: 'Medical Centers',
            button: '(X)'
         },
         text: $('#pe_text_more_info_1').html()
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { max: 500 },
         padding: '14px',
         "font-size": '12px',
         "line-height": '20px',
         border: {
            width: 9,
            radius: 9,
            color: '#666666'
         },
         name: 'light'
      },
      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);
         }
      }
   });
    /*  $('#pe_more_info_2').qtip(
   {
      content: {
         title: {
            text: 'How Well Doctors Communicate With Patients ',
            button: 'Close'
         },
         text: $('#pe_text_more_info_2').html()
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { max: 350 },
         padding: '14px',
         border: {
            width: 9,
            radius: 9,
            color: '#666666'
         },
         name: 'light'
      },
      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);
         }
      }
   });
	   $('#pe_more_info_3').qtip(
   {
      content: {
         title: {
            text: 'Helpful, Courteous, and Respectful Office Staff ',
            button: 'Close'
         },
         text: $('#pe_text_more_info_3').html()
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { max: 350 },
         padding: '14px',
         border: {
            width: 9,
            radius: 9,
            color: '#666666'
         },
         name: 'light'
      },
      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);
         }
      }
   });
      $('#pe_more_info_4').qtip(
   {
      content: {
         title: {
            text: 'Getting Timely Appointments, Care, and Information ',
            button: 'Close'
         },
         text: $('#pe_text_more_info_4').html()
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { max: 350 },
         padding: '14px',
         border: {
            width: 9,
            radius: 9,
            color: '#666666'
         },
         name: 'light'
      },
      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);
         }
      }
   });
      $('#pe_more_info_5').qtip(
   {
      content: {
         title: {
            text: "Patients' Rating of the Doctor ",
            button: 'Close'
         },
         text: $('#pe_text_more_info_5').html()
      },
      position: {
         target: $(document.body), // Position it via the document body...
         corner: 'center' // ...at the center of the viewport
      },
      show: {
         when: 'click', // Show it on click
         solo: true // And hide all other tooltips
      },
      hide: false,
      style: {
         width: { max: 350 },
         padding: '14px',
         border: {
            width: 9,
            radius: 9,
            color: '#666666'
         },
         name: 'light'
      },
      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);
         }
      }
   });*/
   // Create the modal backdrop on document load so all modal tooltips can use it
   $('<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





//Setup Text Controls
	( $.cookie('tcookie') )? tchange( $.cookie('tcookie') ) : tchange( 'text0' );
	$('.tchange').click(function(){ tchange( $(this).attr('id') ); return false; });
	
	
//Setup Search Input
	$('#si').click	(function(){ if( $(this).val()=='Search' ){ $(this).val(''); } });
	$('#si').blur	(function(){ if( $(this).val()=='' ){ $(this).val('Search'); } });
	
	if ( $('#pe_text_more_info_1').length <= 0 ) { 
		$('.data_table').tablesorter({ 
			widgets: ['zebra'],
			textExtraction: function(node) { 
	            // extract data from markup and return it  
	            return node.childNodes[0].innerHTML; 
	        }
		});
	}
	
	
// Setup Historic Data
	$('.view_historic_data').click(function(){
		id = $(this).attr('id');
				
		$('#'+id+'_graph').toggle('fast');
		$('.view_historic_data_graphs').hide();
		
		return false;
	});
	
// Setup read more
	$('.read_more_button').click(function(){
		$('.measure_text').slideToggle('fast', 'linear', function(){});
		
		if( $(this).hasClass('on') ){
			$(this).find('img').attr('src', 'assets/button_read_more.gif');
			$(this).removeClass('on');
		}
		else {
			$(this).find('img').attr('src', 'assets/button_read_less.gif');
			$(this).addClass('on');
		}
		
		return false;
	});
	
	
//Setup Collapse / Expand
	$('#hide_show').click(function(){
		if( $(this).attr('class') == 'hide'){

			$('.select_list_item a').each(function(){
				if( ! ($(this).attr('class') == 'selected') ){
					$(this).parent().hide();
				}
			});
			
			$(this).attr('class', 'show');
			$(this).html("<img alt='' src='assets/button_show_choices.gif' />");
			
		}
		else {

			$('.select_list_item a').each(function(){
				$(this).parent().show();
			});
			
			$(this).attr('class', 'hide');
			$(this).html("<img alt='' src='assets/button_hide_choices.gif' />");			
		}
	});
});


function tchange(t){
	switch(t){ 
		case 'text0' 	: $('body').css({'font-size' : '100%'}); break;
		case 'text1' 	: $('body').css({'font-size' : '110%'}); break;  
		case 'text2' 	: $('body').css({'font-size' : '120%'}); break;  
	}
	$('.tchange').removeClass('tchange_selected'); 
	$('#'+t+'').addClass('tchange_selected'); 
	$.cookie('tcookie', ''+t+'');
}

