/*
-------------------- CUFON --------------------
(target elements for font replacement here)
-----------------------------------------------
*/
// The code below prevents jquery toggle and window redirect from working in IE 8
 
var cufonDeclarations = function(){
	Cufon.replace('#banner-headline, #banner-links', {
		fontFamily: 'houshka'
	});
}
cufonDeclarations(); //Apply Cufon declarations while page is being loaded


/*
-------------------- INITIALISE ON DOCUMENT READY --------------------
----------------------------------------------------------------------
*/

$(document).ready( function() { //When the document is ready
	/* ----- Add class to body (can be used to trigger styles when js is enabled) - */
	$("body").addClass("js-on");
	
	
	/*----- Detect for ie6 and target png fix for this browser - */
	var ie6 = document.getElementById && document.all && (navigator.appVersion.indexOf("MSIE 6.") >= 0);
	if (ie6) {
		DD_belatedPNG.fix('.png_bg');
	}
	
	
	/* ----- Open external links in a new window - */
	$('a[rel="external"]')
	.attr({
		target: "_blank", 
		title: "Opens in a new window"
	})
	.addClass('ext');
	
	

	
	/* ----- Show & hide question/answer boxes on mythbusters page - */
	var myths ='.myth';
	$(myths).children('.myth-answer').hide();
	$(myths).addClass('closed').removeClass('open');	
	$('.myth-heading').css('cursor','pointer');
	
	$(myths).children('.myth-heading').click(function() {
		if ($(this).parent('.myth').hasClass('closed')) {
		$(this).parent('.myth').addClass('open').removeClass('closed');
		} else {
		$(this).parent('.myth').addClass('closed').removeClass('open');
		}
		$(this).siblings('.myth-answer').slideToggle();
		return false;
	
	});
	

	
	//Show hashed myth
	var hash = window.location.hash;
	if(hash != ''){
		$('.myth' + hash + ' .myth-heading').trigger('click');
	}

	// Call escape key function
	escapeKey();
	
	// CLC Feedback form function
	clcFeedback();
	
	/* ----- Output print page and bookmark page links into html - */
	/* ----- (the link for bookmark page is injected by the bookmark page plugin) - */
	$("#nav-social ul").prepend("<li id=\"print-page\"><a href=\"javascript:void(0);\" onclick=\"window.print()\">Print page</a></li><li id=\"bookmark-page\"></li>");	
	
	$('.response').hide();
		
}); //End doc ready function


/*
-------------------- FUNCTIONS ---------------------------------------
----------------------------------------------------------------------
*/


//Escape Key function
var escapeKey = function(a){
	//Find element to pull href from
	var e;
	if (a == null) {
		e = '#close-window a';
	}else{
		e == a;
	}

	// get href from link
	var myhref = '';
	if($(e).attr('href') == ''){
		myhref = "http://www.google.com";
	}else{
		myhref = $(e).attr('href');
	}

	// append title with instruction
	if($(e).attr('title') != null){
		var title = $(e).attr('title');
		$(e).attr('title', title + ' (Shortcut - Press Escape)');
	}
	
	// look for keypress
	$(document).keypress(function(e){
		var keycode = 27; // 27 - esc
		if (e.keyCode == keycode) {
			window.location.href = myhref;
			return false;
		}
	});
}

var clcFeedback = function(){
	$('#clcFeedback input').hide();
	$('#clcFeedback label a').click(function(){
		var input = $(this).parent('label').siblings('input');
		$(input).trigger('click');
		$('#clcFeedback form').submit();
		return false;
	});
	
	$('.panel.feedback').hide(); // Hide this on original doc ready event so it doesnt flicker
}
var clcFeedbackThanks = function()
{
	$(document).ready(function(){
		$('.panel.feedback').fadeIn(3000);	
	});
}
var emailSent = function()
{	
	$(document).ready(function(){
		$('form.contactForm').slideUp('2000',function(){
			$('.response').fadeIn('3000');
		});
		
	});
}

//Special call back function
var k = [], a = "38,38,40,40,37,39,37,39,66,65";
jQuery(document).keydown(function(e) {
  k.push( e.keyCode );
  if ( k.toString().indexOf( a ) >= 0 ){
	jQuery(document).unbind('keydown',arguments.callee);
		
		jQuery("body").addClass("scbf");
	
  }
});





/*
-------------------- VARIABLES ---------------------------------------
----------------------------------------------------------------------
*/
var addthis_config = {
  data_use_flash: false
}


