/* Copyright (c) 2009 WhiteInteractive
 *
 * Version: 4.0
 *
 * Requires: jQuery 1.3.1+, jQuery Cookie plugin
 */

(function($){

		  
	$.visualTweaks = function() {
		// ********************************************************************** 
		// Make any section or page specific visual tweaks that can't be achieved
		// with CSS alone.
		// **********************************************************************

	}
	
	$.onLoadWindow = function() {
		centreWindow();
		$(window).bind('resize',function(event) {
			centreWindow();
		});
	}
	
	function centreWindow() {
		// ********************************************************************** 
		// Centre the Landing page movie
		// **********************************************************************
		
		var intWinWidth;
		var intWinHeight;
		var intNewLeft;
		var intNewTop;
		
		intWinWidth = $(window).width();
		intWinHeight = $(window).height();
		
		intNewLeft = parseInt((intWinWidth - 965) / 2);
		intNewTop = parseInt((intWinHeight - 600) / 2);
		if (intNewLeft < 0) {
			intNewLeft = 0;	
		}
		if (intNewTop < 0) {
			intNewTop = 0;	
		}
		
		$('#landingPage').css("left",String(intNewLeft) + "px");
		$('#landingPage').css("top",String(intNewTop) + "px");
	}
	
	$.fontSize = function() {
		// ********************************************************************** 
		// If the fontsize cookie is set then the site fontsize is increased
		// **********************************************************************
		
		if ($.cookie('fontsize') == "1") {
			$('body').css("font-size","1.2em");
		} else if ($.cookie('fontsize') == "2") {
			$('body').css("font-size","1.4em");
		}	
	}
	
	function saveFontSize(i) {
		// ********************************************************************** 
		// Saves the font size as a cookie or deletes as appropriate
		// **********************************************************************
		
		if (i == '1') {
			$.cookie('fontsize','1');
			$('body').css("font-size","1.1em");
		} else if (i == '2') {
			$.cookie('fontsize','2');
			$('body').css("font-size","1.2em");
		} else { 
			$.cookie('fontsize', null);
			$('body').css("font-size","1em");
		}
	}
	
	$.createFontSizeLinks = function() {
		// ********************************************************************** 
		// Attaches events to the font sizing links
		// **********************************************************************
		
		$('#fontSize0').bind('click',function(event) {
			saveFontSize('0');
		});
		
		$('#fontSize1').bind('click',function(event) {
			saveFontSize('1');
		});
		
		$('#fontSize2').bind('click',function(event) {
			saveFontSize('2');
		});
	}
	
	$.createQuestionnaire = function() {
		// ********************************************************************** 
		// Attaches events to the questionnaire elements
		// **********************************************************************
		
		 
		$('input[name=rdo1A]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo1B]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo1C]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo1D]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo1E]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo2A]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo2B]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo2C]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo2D]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo2E]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo2F]').bind('click',function(event) {
			recalculateScore();
		});
		$('input[name=rdo3A]').bind('click',function(event) {
			recalculateScore();
		});

	}
	
	function recalculateScore() {
		// ********************************************************************** 
		// Calculates the score for the questionnaire
		// **********************************************************************
		
		var intScore = 0;
		
		intScore = intScore + parseInt($('input[name=rdo1A]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo1B]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo1C]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo1D]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo1E]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo2A]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo2B]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo2C]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo2D]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo2E]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo2F]:checked').val());
		intScore = intScore + parseInt($('input[name=rdo3A]:checked').val());
		
		$('#questScoreTotal').html(String(intScore));
	}
	
})(jQuery);
