// 
//  application.js
//  setup
//  
//  Created by Aaron Vanderzwan on 2009-09-24.
//  Copyright 2009 Conduit Studios. All rights reserved.
// 


$(document).ready(function(){

	// jQuery('.shareThis').
	
		
	// Focus Magic
	jQuery('form.focusMagic').focusMagic();
	
	// Fancy Zoom
	jQuery('a.zoom').fancyZoom();
	
	submitFormAddLists();
	
	
	
	

	



	
	// #####################################################
	// Post SlideShow
		jQuery('.imageSS .holder').each(function(){
			var $images = jQuery(this).find('img');
			$images.hide();
			jQuery(window).load(function(){
				centerImage($images.first());
				$images.first().fadeIn('slow');
			});
			jQuery(this).parent().find('a.small').first().addClass('active');
		});
		
		
		

	
		jQuery('.imageSS > a').click(function(){
			if(jQuery(this).hasClass('active')){
				return false;
			}
			var href = jQuery(this).attr('href');
			var copyright = jQuery(this).find('img').attr('title');
			var alt = jQuery(this).find('img').attr('alt').replace('-thumb','');
			
			jQuery(this).addClass('active').siblings().removeClass('active');
			jQuery(this).parent('.imageSS').find('.holder img').fadeOut(function(){
				jQuery(this)
					.load(function(){
						jQuery(this).fadeIn();
						centerImage(jQuery(this));
					})
					.attr('src',href)
					.attr('title',copyright)
					.attr('alt',alt);
				jQuery(this).parent().find('.copyright > span').addClass("styled").html(copyright);
			});
			
			return false;
		});
	// /Post Slideshow
	// #####################################################
	
	
	// #####################################################
	// Post Images centered on gray if shorter
		function centerImage($image){
			if($image.height() > $image.width()){
				$image.height(390).parent().css({'text-align':'center'});
			}else{
				$image.height('auto');
			}
		}
	// #####################################################
	// Keep Nav at top when scroll gets there
	keepNavAtTop();
	$(window).scroll(function() {
		keepNavAtTop();
	});
	
	// #####################################################
	// Container dynamic min-height
	jQuery('.whiteBGWrapper').data('origHeight',jQuery('.whiteBGWrapper').height());
	jQuery(window).load(function(){
		resizeContentArea(jQuery(window).height());
	});
	jQuery(window).resize(function(){
		resizeContentArea(jQuery(this).height());
	});
	// #####################################################
	
	
	
	function keepNavAtTop(){
		if($(this).scrollTop() > 155) {
        $('.mainNav').addClass('abs');
    } else {
        $('.mainNav').removeClass('abs');
    }
	}
	function resizeContentArea(windowHeight){
		jQuery('.whiteBGWrapper').height('auto');
		
		var windowHeight = Math.floor(windowHeight);
		var headerHeight = jQuery('.header').outerHeight(); //Header height
		var otherSpace = jQuery('.footer').outerHeight()+8;
		var newH = windowHeight-headerHeight-otherSpace;
		
		// if(jQuery('.whiteBGWrapper').height() < jQuery(document).height()-headerHeight-otherSpace || jQuery('.whiteBGWrapper').height() > jQuery('.whiteBGWrapper').data('origHeight')){
		if(jQuery('.whiteBGWrapper .container').outerHeight()+headerHeight+otherSpace < jQuery(window).height()){
			jQuery('.whiteBGWrapper').height(newH);
		}else{
			jQuery('.whiteBGWrapper').height('auto');
		}
		// jQuery('body .whiteBGWrapper .containerHeight').remove();
		// jQuery('body .whiteBGWrapper .containerHeight2').remove();
		// var newDiv = jQuery('<div></div>').addClass('containerHeight').append(jQuery('.whiteBGWrapper .container').outerHeight()).css({'background':'pink','padding':'3px'})
		// var newDiv2 = jQuery('<div></div>').addClass('containerHeight2').append(jQuery(window).height()).css({'background':'yellow','padding':'3px'})
		// jQuery('body .whiteBGWrapper').prepend(newDiv2).prepend(newDiv);
	}
	
	
	
	// MaxImage
	jQuery('.maximage').maxImage({
		isBackground: true,
		verticalAlign: 'top',
		leftSpace: '0',
		horizontalOffset: '20',
		position: 'fixed'
	});
});

function checkMainNav (){
	var a = jQuery('body').scrollTop();
	
	alert(a);
}




function submitFormAddLists(){
	jQuery('.emailSignup .confirm').hide();
	jQuery('.init input').focus(function(){
		$('.emailSignup .confirm').slideDown('slow');
	});
	
	jQuery('.emailSignup .finalSubmit').click(function(){
		jQuery('.emailSignup .confirm').hide();
		if(jQuery(this).hasClass('onlyThis')){
			jQuery(this).parent().find('input[type=checkbox]').removeAttr('checked');
		}
		// return false;
		jQuery('.emailSignup form').submit();
	});
}

