/** Remove elements from DOM */
$(document).ready( function(){
	$('#header .linklove').remove();
});

/** Form highlighting */
$(document).ready(function(){
	$("form input").focus(function() {
		$(this).parents('li:eq(0)').addClass("focus");
		//$(this).next().show();
	});
	$("form input").blur(function() {
		$(this).parents('li:eq(0)').removeClass("focus");
		//$(this).next().hide();
	});
	$("form textarea").focus(function() {
		$(this).parents('li:eq(0)').addClass("focus");
	});
	$("form textarea").blur(function() {
		$(this).parents('li:eq(0)').removeClass("focus");
	});
	$("form select").focus(function() {
		$(this).parents('li:eq(0)').addClass("focus");
	});
	$("form select").blur(function() {
		$(this).parents('li:eq(0)').removeClass("focus");
	});
});

/** Form highlighting */
$(document).ready(function(){
	$("form li.required input").blur(function() {
		if($(this).val() != ""){
			$(this).next().hide();
			$(this).parents('li:eq(0)').removeClass("error");
		}
		else{
			$(this).next().show();
		} 
	});
	$("form li.required textarea").blur(function() {
		if($(this).val() != ""){
			$(this).next().hide();
			$(this).parents('li:eq(0)').removeClass("error");
		}
		else{
			$(this).next().show();
		} 
	});
});

/** Add classes to form elements */
$(document).ready(function(){
  $('input[type="text"]').parents('li:eq(0)').addClass("text");
  $('input[type="password"]').parents('li:eq(0)').addClass("password");
  $('input[type="checkbox"]').parents('li:eq(0)').addClass('checkbox');
  $('input[type="radio"]').parents('li:eq(0)').addClass('radio');
  $('input[type="submit"]').parents('li:eq(0)').addClass('submit');
  $('input[type="hidden"]').parents('li:eq(0)').addClass('hidden');
});

/** Gallery highlighting */
$(document).ready(function(){
	$('.gallery li a').mouseover(function() {
			$(this).parents('li:eq(0)').addClass('focus');
		}).mouseout(function() {
			$(this).parents('li:eq(0)').removeClass('focus');
			$(this).parents('li:eq(0)').removeClass('active');
		});
	$('.gallery li a').mousedown(function() {
			$(this).parents('li:eq(0)').addClass('active');
		}).mouseup(function(){
			$(this).parents('li:eq(0)').removeClass('active');
	});
});

/** Form button highlighting */
$(document).ready(function(){
	$('form button').mouseover(function() {
			$(this).addClass('focus');
		}).mouseout(function() {
			$(this).removeClass('focus');
			$(this).removeClass('active');
		});
	$('form button').mousedown(function() {
			$(this).addClass('active');
		}).mouseup(function(){
			$(this).removeClass('active');
	});
});

/** Form row highlighting */
$(document).ready(function(){
	$("table tr:odd").addClass("alternate");;
	$("table tr")
	.mouseover(function() { $(this).addClass("focus");})
	.mouseout(function() { $(this).removeClass("focus");})
});

/* Tabs */
$(document).ready(function () {
	var tabContainers = $('div.tabbed > div.tab');
	tabContainers.hide().filter(':first').show();
	$('ul.tabs a').click(function () {
	tabContainers.hide();
	tabContainers.filter(this.hash).show();
	$('ul.tabs li a').removeClass('current');
	$(this).addClass('current');
	return false;
	}).filter(':first').click();
}); 

/** AutoClear for Search Form */
$(document).ready( function(){
	autoFill($("#global-search #global-students"), "Search for homework, videos, events, trips...");
	autoFill($("#search #global-students"), "Search the site");
	autoFill($("#global-search #global-parents"), "Search for school policies, uniform guide, food...");
});

function autoFill(id, v){
	$(id).css({ }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ }).val(v);
		}
	});
	
}
