$(document).ready(function(){

 $("<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

$('.show_star_percentage').each(function(x) {
//$(this).parent().attr("id", "star_percentage" + x);
	$(this).hover(
  function () { // over  
  	$(this).find('.percentage_hide_div').show();
  	$(this).find('.show_star_percentage_back').hide();
  	//$(this).css('background', '#000');  	
  }, 
  function () {  
   //$(this).html($(this).parent().find('.show_star_percentage_back').html());
   //$(this).css('background', 'none');
    $(this).find('.percentage_hide_div').hide();
  	$(this).find('.show_star_percentage_back').show();
  });


});
/*
$('.percentage_hide_div').each(function() {
var temp_store_html;
	$(this).hover(
  function () { // over
  
   }, 
  function () {
   $(this).parent().find('.show_star_percentage').show();   
   $(this).hide();
   
  });
  });
 */
 $('.more_info_button_inline').each(function(){

		$('#benchmarks').focus();
		$(this).qtip({
			content: {
				title: {
					text: 'Category Information:',
					button: 'Close (x)'
				},
				text: $(this).parent().parent().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: {
					screen: 'true',	
					scroll: 'true',
					y: 10,
					x: 0
					
				}
			},
			hide: false,
			style: {
				fontSize: '12px',
				lineHeight: '16px',
				fontFamily: 'arial',
				background: '#ffffff',
				color: 'black',
				textAlign: 'left',
				width: 900,
				height: 300,
				overflow: "auto",
				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);
					
				},
				onShow: function() { 
					$('.qtip-content').scrollTo('100%', 300);	
					
					return true;
				},
				beforeHide: function(){
					// Fade out the modal "blanket" using the defined hide speed
					$('#qtip_blanket').fadeOut(this.options.hide.effect.length);
				}
				
			}
		});
		
	
});

 
 
$('.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: {
					screen: 'true',	
					scroll: 'true',
					y: 10,
					x: 0
					
				}
			},
			hide: false,
			style: {
				fontSize: '12px',
				lineHeight: '16px',
				fontFamily: 'arial',
				background: '#ffffff',
				color: 'black',
				textAlign: 'left',
				width: 900,
				height: 300,
				overflow: "auto",
				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);
				}
			}
		});
		

});





	( $.cookie('tcookie') )? tchange( $.cookie('tcookie') ) : tchange( 'text0' );
	$('.tchange').click(function(){ tchange( $(this).attr('id') ); return false; });
	
	$('.bar1').hover(function() { 
		
	
	});
	$('.bar2').hover(function() { 
	
	
	});
	$('.bar3').hover(function() { 
	
	
	});
	$(".off").hover(
		function () {
		    $(this).css('opacity', '1.0');
		    $(this).css('filter', 'filter:alpha(opacity=100)');
		}, 
		function () {
			$(this).css('opacity', '0.5');
		    $(this).css('filter', 'filter:alpha(opacity=50)');
		}
	);
	/*
	.off { 
	opacity:0.5;
	filter:alpha(opacity=50);
}
.active { 
	opacity:1.0;
	filter:alpha(opacity=100);
}
	*/
	
	
	//Setup Equal Height
	equalHeight($(".equal_height"));
	
	//Setup Tablesorter
	$("#report").tablesorter({widgets: ['zebra']});
	
	//Setup Slideshow
	$('.slideshow_link').hover(function(){
		ss = $(this).attr('id');
		old = $('.ssi_on').attr('id');
		
		if(ss != old){

			$('.slideshow_tab.selected').removeClass('selected');			
			$(this).parent().addClass('selected');
			
			$('#'+old+'').hide(1, function(){
				$('#'+old+'').removeClass('ssi_on');			
				$('#slideshow_image_'+ss+'').addClass('ssi_on');
				$('#slideshow_image_'+ss+'').show();	
			});
		
		}
		
	});
	
	
	//Setup Subnav
	$('.subnav_link').hover(
		function(){
			$(this).addClass('over');
			$(this).parent().addClass('over');
		}, 
		function(){
			$(this).removeClass('over');
			$(this).parent().removeClass('over');
		}
	);	
	

	//Setup Content reveal
	$('.content_reveal_link').click(function(){
				
		$(this).next().toggle();
		
		if( $(this).attr('class').match('off') ){
			$(this).attr('class', 'content_reveal_link on');
			$(this).html('<a class="more_block" href="#"><< close </a>');
		}
		else {
			$(this).attr('class', 'content_reveal_link off');
			$(this).html('<a class="more_block" href="#">read more >></a>');
		}		
		
		return false;
		
	});
	
	
	//Setup TakeCharge reveal
	$('.cbset_selector').click(function(){
		
		// swap selected item for this one
		$('.cbset_selector').removeClass('selected');
		$(this).addClass('selected');
		
		// get ids of newly selected elems
		cbset_title_id = $(this).attr('id').replace('selector', 'title');
		cbset_id = $(this).attr('id').replace('_selector', '');
		
		// hide everything
		$('.cbset_title').hide();
		$('.cbset').hide();
		
		//reveal selected elems
		$('#'+cbset_title_id+'').show();
		$('#'+cbset_id+'').show();
		
		return false;
		
	}
	);
	
});


function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

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+'');
}
	




