//	Site-wide Javascript functions

//	Note: If you plan to use jQuery, it must be wrappered inside an onReady function declaration

jq(document).ready(function() {
	//	jQuery code goes here
	
	// Hide the button on the programme selector
	jq("#programme_selector_button").css({display: 'none'});
	// Auto submit form on change
	jq("#programme_selector").bind("change", function(e) {
		if (jq(this).val() > 0) {
			jq(this).parent('form').get(0).submit();
		}
	});
	
	//	Some CSS corrections
	jq("input[type=submit]").addClass('button');
	jq("input[type=checkbox]").css({background: "#fff", border: "0px"});

	//	Tooltip support

	//	This function gets the tooltip to track the movement of the mouse
	jq.fn.tooltipmove = function(e) {
//		var xMouseSpace = 15;
//		var tipWidth = 250;
//		var windowWidth = jq(window).width();
//		var compareWidth = e.pageX + xMouseSpace + tipWidth + 20; // 20 - counteracts addition of scrollbar
//
//		if (compareWidth > windowWidth) {
//			jq("#helptexthover").css("left",  xMouseSpace - tipWidth);
//		    jq("#helptexthover").css("top", e.pageY + 20);
//		} else {
//		    jq("#helptexthover").css("left", xMouseSpace);
//		    jq("#helptexthover").css("top", e.pageY + 20);
//		}
	};

	initStatNational();
	initStatRegional();
	initPlanningDatabase();

});

function hidePlanningDatabase()
{
	jq('DIV[class*=row_aspect_planning_database_]').each(function(index,value){
		if(jq(value).hasClass('row_aspect_planning_database_find') || jq(value).hasClass('row_aspect_planning_database_why')){
		}else{
			jq(value).hide();
		}
	});
}
function showPlanningDatabase()
{
	jq('DIV[class*=row_aspect_planning_database_]').fadeIn();
}
function initPlanningDatabase()
{
	var checked = jq('#aspect_planning_database_n').attr('checked');
	if(checked){
		hidePlanningDatabase();
	}
	jq('INPUT[name=aspect_planning_database]').bind('change',function(){
		var checked = jq('#aspect_planning_database_n').attr('checked');
		if(checked){
			hidePlanningDatabase();
		}else{
			showPlanningDatabase();
		}
	});
}














function hideStatRegional()
{
	jq('DIV[class*=row_aspect_stat_regional_]').each(function(index,value){
		if(jq(value).hasClass('row_aspect_stat_regional_find') || jq(value).hasClass('row_aspect_stat_regional_why')){
		}else{
			jq(value).hide();
		}
	});
}
function showStatRegional()
{
	jq('DIV[class*=row_aspect_stat_regional_]').fadeIn();
}
function initStatRegional()
{
	var checked = jq('#aspect_stat_regional_n').attr('checked');
	if(checked){
		hideStatRegional();
	}
	jq('INPUT[name=aspect_stat_regional]').bind('change',function(){
		var checked = jq('#aspect_stat_regional_n').attr('checked');
		if(checked){
			hideStatRegional();
		}else{
			showStatRegional();
		}
	});
}


function hideStatNational()
{
	jq('DIV[class*=row_aspect_stat_national_]').each(function(index,value){
		if(jq(value).hasClass('row_aspect_stat_national_find') || jq(value).hasClass('row_aspect_stat_national_why')){
		}else{
			jq(value).hide();
		}
	});
}
function showStatNational()
{
	jq('DIV[class*=row_aspect_stat_national_]').fadeIn();
}
function initStatNational()
{
	var checked = jq('#aspect_stat_national_n').attr('checked');
	if(checked){
		hideStatNational();
	}
	jq('INPUT[name=aspect_stat_national]').bind('change',function(){
		var checked = jq('#aspect_stat_national_n').attr('checked');
		if(checked){
			hideStatNational();
		}else{
			showStatNational();
		}
	});
}


