/*
@description loads top splash randomly and initialises resource search form
@author DC
@created 2008-09-29
*/
$(function(){
	$('.main-teaser').hide();
	randTeaser=$('.main-teaser')[Math.floor(Math.random() * $('.main-teaser').length)];
	$(randTeaser).show(); //all others are hidden with css
	
	Advanced.addFormToggle();
	Advanced.events.keystageToYeargroup();
});

/* simplified version of javascript from resource index template */

window.Advanced = {
    events: {
		keystageToYeargroup: function(event) {
			if ($('#country option:selected').text() == 'Scotland'){
				//load the yeargroup dropdown via ajax
				$.ajax({
					url: '../../display_includes/resource_search/yeargroup.rm?is_ajax=true',
					data: jQuery("#searchcontainer form").serialize(),
					type: 'post', complete: function(xhr) {
						$("#yeargroupkeystage").html(xhr.responseText);
						Advanced.addFormToggle();
					}
				});
			} else {
				//load the keystage dropdown via ajax
				$.ajax({
					url: '../../display_includes/resource_search/keystage.rm?is_ajax=true',
					data: jQuery("#searchcontainer form").serialize(),
					type: 'post', complete: function(xhr) {
						$("#yeargroupkeystage").html(xhr.responseText);
						Advanced.addFormToggle();
					}
				});
			}
		}
	},
	addFormToggle: function() {
		//bind the change evnet on the country drop down
		$('#country').change(Advanced.events.keystageToYeargroup);
		// deal with search box
		var defaultText = "Enter search term";
		$('#keyword').focus(function() {
			if (this.value == defaultText) {
				$(this).val('');
			}
		}).blur(function() {
			if (this.value == '') {
				$('#keyword').val(defaultText);
			}
		});
	}
};
