// struct of heights
function pageHeights(){
	var heights={};
	heights.bodyHeight=$('doc_body').getHeight(),
	heights.contentHeight=$('structure2').getHeight(),
	heights.footerHeight=$('footer_c').getHeight();
	return heights
}

// do the footer placement guff 
function footerPlacement(){
	var heights=pageHeights(),
			fixFooter=0;
	
	// now do some simple maths
	var whiteSpace=parseInt((heights.bodyHeight-heights.contentHeight)-heights.footerHeight);
	if(whiteSpace < 0){whiteSpace=0};
	if(whiteSpace > 0){fixFooter=1}else{fixFooter=0}
	
	// now fix the footer 
	if(fixFooter){
		// absolute pos to bottom 
		$('footer_c').className='footer_absolute';
	}else{
		// float like normal 
		$('footer_c').className='footer_float';		
	}
}

// force the background2 to 100% height (this will be called on scroll 
function backgroundHeight(){
	var heights=pageHeights();
	heights.resizeHeight=parseInt(heights.contentHeight+heights.footerHeight);
	$('background').setStyle({height:heights.resizeHeight+'px'});
	$('background2').setStyle({height:heights.resizeHeight+'px'});
}

// tell the footer to do its thing on page load 
Event.observe(window,'load',function(){footerPlacement()});
Event.observe(window,'resize',function(){footerPlacement()});
Event.observe(window,'scroll',function(){backgroundHeight()});

// social tabbing 
function change_social(tab){
	// close them all first
	$('social_a_twitter').className='';
	$('social_a_facebook').className='';
	$('social_a_flickr').className='';
	$('social_body_twitter').hide();
	$('social_body_facebook').hide();
	$('social_body_flickr').hide();
	// activate the one they want 
	$('social_a_'+tab).className='selected';
	$('social_body_'+tab).show();	
}

// filter form call
function filter_call(url){
	var formhash = $('filterform').serialize(true); 
	new Ajax.Updater('ajax_load',url,{parameters:formhash,onLoading:function(request){$('ajax_indicator1').show()},onComplete:function(request){$('ajax_indicator1').hide();footerPlacement()}});
}

// submit comment 
function submit_comment(url){
	var formhash = $('comment_form').serialize(true); 
	new Ajax.Updater('comments_c',url,{parameters:formhash,onLoading:function(request){$('ajax_indicator2').show()},onComplete:function(request){$('ajax_indicator2').hide();footerPlacement()}});
}
