$(document).ready(function(){
    
    
    // MAKES SURE BODY HEIGHT = WINDOW HEIGHT (Safari fix)
    	var window_height = $(window).height();
    	$('body.home').css('height',window_height);
    
    
	javascriptenabled();
	body_resize();
    pledgeform();
	center_logo();
	filter_by_campaign();
	askanexpert();
	pri_nav_cur();
    
});



/**
    * JAVSCRIPT ENABLED BODY CLASS
    * Useful for styling elements differently if javscript is enabled
    * ----
*/

function javascriptenabled() {
	$('body').addClass('js-true');	
}



/**
    * BODY RESIZE
    * Resizes the homepage div#page element exactly to the dimensions of the window when resized
    * ----
*/
function body_resize() {
    var window_height = $(window).height();
    //alert(window_height);
    $('body.home').css('height',window_height);
}
window.onresize = body_resize;




/**
    * LEARNING CULTURE CAMPAIGN - PLEDGE FORM
    * Enhancing the form for users with javscript
    * ----
*/

function pledgeform() {

	// ADDS THE TABS NAV IN
	$('form#pledge_form h3').after('<ul id="pledge_form_nav"><li class="one cur"><a href="#pledge_company" class="form_nav">Your company</a></li><li class="two"><a href="#pledge_contact" class="form_nav">Contact details</a></li><li class="three"><a href="#pledge_confirm" class="form_nav">Confirm</a></li></ul>');
	
	// DEALS WITH THE TABS CLASSES
	$('ul#pledge_form_nav li a').click(
		function(){
			
			$('ul#pledge_form_nav li').removeClass('cur');
			$(this).parent('li').addClass('cur');
			
		}
	);
	
	// ADD IN PREV/NEXT LINKS
	$('form#pledge_form fieldset#pledge_company').append('<a href="#pledge_contact" class="form_nav next">Next &raquo;</a>');
	
	$('form#pledge_form fieldset#pledge_contact').append('<a href="#pledge_company" class="form_nav prev">&laquo; Previous</a> <a href="#pledge_confirm" class="form_nav next">Next &raquo;</a>');
	
	$('form#pledge_form fieldset#pledge_confirm').append('<a href="#pledge_contact" class="form_nav prev">&laquo; Previous</a>');
	
	// DEALS WITH THE SHOW/HIDE
	$('a.form_nav').click(
		function(){
			
			var anchor = $(this).attr('href').split('#');
			$('form#pledge_form fieldset').hide();
			$('form#pledge_form fieldset#'+anchor[1]).show();
			
			return false;
			
		}
	);
	
	// CHANGES THE TABS WHEN PREV/NEXT LINKS ARE USED
	$('form#pledge_form fieldset a.form_nav').click(
		function(){
			
			var anchor2 = $(this).attr('href');
			
			$('ul#pledge_form_nav li').removeClass('cur');
			$('ul#pledge_form_nav li a[href="'+anchor2+'"]').parent('li').addClass('cur');
			
			return false;

		}
	);

}



/**
    * COMPANY LOGOS
    * Vertically centering the logo within container
    * ----
*/
function center_logo(){
	$('img.logo').each(function(i){
	
		var margin_height = $(this).parent().height() - $(this).height();
    	var final_height = margin_height / 2;
    	
    	$(this).css({marginTop: final_height});
	
	});
}



/**
    * FILTER BY CAMPAIGN
    * When content is filtered by a campaign, the filter-by box background fades from yellow to grey
    * ----
*/
function filter_by_campaign(){
    $('div#campaign_filter.filtered').fadeTo(250, 1);
    $('div#campaign_filter.filtered').animate({ backgroundColor: "#ffca51" }, 1000);
    $('div#campaign_filter.filtered').fadeTo(500, 1);
    $('div#campaign_filter.filtered').animate({ backgroundColor: "#ebe9e6" }, 2000);
}



/**
    * BLOG ASK AN EXPERT
    * Adds pop-up button into HTML
    * ----
*/

function askanexpert(){
	
	$('div#blog_askanexpert').append('<p class="calltoaction_button"><a href="#TB_inline?height=400&amp;width=400&amp;inlineId=blog_askanexpert_ask" class="thickbox">Ask an expert</a></p>');
	
}



/**
   * PRIMARY NAVIGATION 'CUR' POINTERS
   * Adds decorative image to current list items
   * ----
*/
function pri_nav_cur(){

$('ul#navigation_pri > li.cur').append('<img src="/assets/images/site/nav_pri_cur.gif" alt="" width="5" height="10" />');

}