/*!	SWFObject v2.2 <http://code.google.com/p/swfobject/> 
	is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

$(document).ready(function(){ 
	$(document).pngFix(); 
	
	$('#footerPopNum').hover(
		function() {
			$('#populationDetails').fadeIn();	
		},
		function() {
			$('#populationDetails').fadeOut();
		}
	);
	
	$('.overviewlink a').hover( 
		function() {
			$(this).parent().find('.doit').css('display', 'block');	
		},
		function() {
			$(this).parent().find('.doit').css('display', 'none');
		}
	);

	$('.tout, .jump').hover(
		function() {
			$(this).animate({top: '-10px'}, 100, 'easeOutCubic');	
		},
		function() {
			$(this).animate({top: '0'}, 100, 'easeOutCubic');	
		}
	);
	
	/*
	$('.tout, .jump').hover(
        function() { 
        var over = $(this).find('.rollover'), 
        bottom=parseInt(over.data('bottomPos'))+5; over.stop().animate({bottom:bottom+10}, {duration:300, easing:'easeOutCubic'}) },
        function(){ 
        var over = $(this).find('.rollover'), bottom=parseInt(over.data('bottomPos')); over.stop().animate({bottom:bottom}, {duration:200}) }).find('.rollover').each(function() 	{ 
        $(this).data('bottomPos', $(this).css('bottom').replace('px', ''))
    });
	*/
	$('#sidenav li').hover(
		function() {
			$(this).animate({left: '-15px'}, 100);	
		},
		function() {
			$(this).animate({left: '-10px'}, 100);	
		}
	);


	$('.thumbs-video img').hover(
		function() {
			//$(this).effect("scale", {from:{height:25, width:45}, percent: 100, direction: 'both' }, 100);
			$(this).animate({width: 200}, 100);	
			$(this).css('z-index', 10);	
		},
		function() {
			//$(this).effect("scale", {from:{height:50, width:90}, percent: 50, direction: 'both' }, 100);
			$(this).animate({width: 45}, 100);
			$(this).css('z-index', 1);	
				
		}
	);
	
	
	
	var currentFact=1;
	var totalFacts=$('#frac-facts #icons img').length;

	function fracFacts(){
		$('#frac-facts #icons img.icon-'+ currentFact).fadeIn(function(){
			
			$('#frac-facts #facts .fact-'+ currentFact).animate({top: '8px'}, 100, 'easeOutCubic');
			
			$(this).delay(4000).fadeOut(function(){
				$('#frac-facts #facts .fact-'+ currentFact).animate({top: '65px'}, 100, 'easeOutCubic');
				if(currentFact<totalFacts){
					currentFact++;
					fracFacts();
				}else{
					currentFact=1;
					fracFacts();
				}
			});
		
		});
	}
	
	var currentLaurel=1;
	var totalLaurels=$('#footer-4 img').length;
	function laurelRotate(){
		$('img.laurel-'+ currentLaurel).fadeIn(function(){
			$(this).delay(4000).fadeOut(function(){
				if(currentLaurel<totalLaurels){
					currentLaurel++;
					laurelRotate();
				}else{
					currentLaurel=1;
					laurelRotate();
				}
			});
		
		});
	}
	
	
	
	
	var currentStill=1;
	var totalStills=$('#fracking #noflash img').length;
	
	function whatsFracking(){
		$('#fracking #noflash img#animation-'+ currentStill).fadeIn(function(){
			$(this).delay(4000).fadeOut(function(){
				if(currentStill<totalStills){
					currentStill++;
					whatsFracking();
				}else{
					currentStill=1;
					whatsFracking();
				}
			});
		
		});
	}
	
	function toggleMap(){
		$('#toggle ul li').click(function(){
			var toggleMap=$(this).attr('id');
			if($(this).attr('id')=='stories'){
				if($('li#stories').hasClass('active')){
					$('a.thumbs-video img').fadeOut();
					$('li#stories').removeClass('active');
				}else{
					$('#gasland-map a.thumbs-video img').each(function(i){
						$(this).delay(100*i).fadeIn();
					});
				
					//$('#gasland-map .stories').fadeIn();
					$('li#stories').addClass('active');
				}
			
			}else{
			
				if($(this).hasClass('active')){
					
					if($('li#shale').hasClass('active') && $('li#water').hasClass('active')){
					
						$('img.shale-water').fadeOut();
						$('#gasland-map').find('.'+toggleMap).fadeOut();
						$(this).removeClass('active');	
					
					}else{
					
						$('#gasland-map').find('.'+toggleMap).fadeOut();
						$(this).removeClass('active');	
					
					}		
			
				}else{
			
					if($('li#shale').hasClass('active') || $('li#water').hasClass('active')){
			
						$('img.shale-water').fadeIn();
						$('img.water').fadeIn();
						$('img.shale').fadeIn();
						
						$(this).addClass('active');
					}else{
						$('#gasland-map').find('.'+toggleMap).fadeIn();
						$(this).addClass('active');
					}
				}
			
			}
			
			
			
		});
	
	}

	
	function youtubeOverlay(){
		$(".thumbs-video, .feature-vid").click(function() {
			$.fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'speedIn'		:	600, 
					'speedOut'		:	200, 
					'overlayShow'	:	true,
					'padding'		: 0,
					'autoScale'		: false,
					'title'			: this.title,
					'width'		: 680,
					'height'		: 495,
					'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'			: 'swf',
					'swf'			: {
					   	 'wmode'		: 'transparent',
						'allowfullscreen'	: 'true'
					}
				});
		
			return false;
		});
	}	
		
	youtubeOverlay()
	fracFacts();
	whatsFracking();
	toggleMap();
	laurelRotate();

}); 



function clearEmail(what, check) {
	
	whatVal = document.getElementById(what).value;
	
	if(whatVal == check) {
		document.getElementById(what).value = "";
	}
	
}






