var $grade = getQueryVariable("grades");
if (typeof $grade != "undefined") {
	if ( $grade == "preschool" || $grade == "gradeschool" || $grade == "middleschool" ) {
		$grade = 'parent_' + $grade + '_inc';
	}
	else { $grade = 'parent_gradeschool_inc'; }
}
else {
	$grade = readCookie('parentGrade') ? readCookie('parentGrade') : 'parent_gradeschool_inc';
}
var $currTab = 'tab_' + $grade.substring(0,$grade.length-4);
var $curr = $grade;
document.write('<style type="text/css">');
document.write('#' + $grade + '{display: block;}');
document.write('</style>');



addLoadEvent(function() {
	(function($){		
		$('#parentTabs a').hover(
			function() { $(this).addClass("on"); }, 
		    function() { if ( !$(this).hasClass("selected") ) {	$(this).removeClass("on"); } }
		);
	  $('#parentTabs a').click(function(){
		if ( $(this).hasClass('selected') ) { return false; }
		$('#parentTabs a').removeAttr("class");
		$(this).addClass("on").addClass("selected");
		$currTab = $(this).attr("id");
		$('#parent_preschool_inc, #parent_gradeschool_inc, #parent_middleschool_inc').hide();
		$('#parentGrades').removeClass().addClass($(this).parent().attr("id").substring(4) + '_on');		
		$curr = $(this).parent().attr("id").substring(4) + '_inc';
		$('#' + $curr).fadeIn();
		return false;
	  });
	})(jQuery);
});

addLoadEvent(function(){
	jQuery('#query').bind('focus',function(){ if ( this.value == this.defaultValue ) { this.value = ""; } }).bind('blur',function(){
			if ( this.value == "" ) { this.value = this.defaultValue; } });;
});


function displayTabs() {
	var selected1 = selected2 = selected3 = '';
	switch($currTab){
		case 'tab_parent_preschool': selected1 = ' class="on selected" '; break;
		case 'tab_parent_gradeschool': selected2 = ' class="on selected" '; break;
		case 'tab_parent_middleschool': selected3 = ' class="on selected" '; break;
		default: break;
	}
	var tabs = '<ul>';
	tabs += '<li id="tab_parent_preschool"><a href="#"' + selected1 + ' title="PRESCHOOL"></a></li>';
	tabs += '<li id="tab_parent_gradeschool"><a href="#"' + selected2 + ' title="GRADE SCHOOL"></a></li>';
	tabs += '<li id="tab_parent_middleschool"><a href="#"' + selected3 + ' title="MIDDLE SCHOOL"></a></li>';
	tabs += '</ul>';
	document.write(tabs);
}

function makeDefault() {
		saveCookie('parentGrade', $curr);
		return false;
}

function gotoPage() {
	location.href = "http://teacher.scholastic.com" + document.Title.Page.options[document.Title.Page.selectedIndex].value;
}

// Popup offset
function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

var callout = "";

function showDiv(btnid) {
	if(callout != "" && callout != "parentsCallout") {
		document.getElementById(callout).style.display = "none";
	}
	obj = document.getElementById("parentsCallout");
	obj2 = document.getElementById(btnid);
	oBoxCurrent = obj2.parentNode.parentNode.parentNode.parentNode;
	temp = getposOffset(obj2, "top") + 16;
	temp2 = getposOffset(obj2, "left") - 55;
	obj.style.top = temp + "px";
	obj.style.left = temp2 + "px";
	obj.style.display = "block";
	callout = "parentsCallout";
}
function hideDiv(which, c) {
	var obj = document.getElementById(which);
	obj.style.display = "none";
	callout = "";
}
