$(document).ready(function() {

	//candy box functionality
	if($("#candy") && !$.browser.safari){
		$(".slidedown").slideUp("fast");
		$(".slideTrigger strong").css("cursor", "pointer").css("color","#0789c4");
		$("#candy").hover(function(){ $(".slidedown").show("slow"); }, function(){ $(".slidedown").hide("slow"); });
	}
	if($.browser.safari){
		$('body').css('background-image','none');
		$('#go').val('Search');
	}
	//open any anchor with a rel="" in a new window
	if($("a[rel]")){
		$("a[rel]").click(function() {
			newWindow = window.open(this, "newWin", "width=750,height=550,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes")
			newWindow.focus();
			return false; //stop link from working normally
		});
	}

	if($("a#freeresources_opener")){
		$("a#freeresources_opener").hover( function(){ $("#freeresources").show("slow"); }, function(){  } );
	}

	// Accordion for homepage promos
	if($("#promo_slider").accordion){
		$("#promo_slider").accordion({
			active: '.default_open',
			header: '.head',
			navigation: false,
			event: 'mouseover',
			autoheight: true,
			animated: 'easeslide',
			active: '.default_open'
		});
	}

	$("#searchInput").focus( function() { if($(this).val() == "Enter author, title, or keyword") { $(this).val(""); } });
	$("#searchInput").blur( function() { if($(this).val() == "") { $(this).val("Enter author, title, or keyword"); } });

	$("#go").click(
	function() {
	//first - determine if a new value was entered into the search field
	x = $("#search_dropdown").val();
		if ($("#searchInput").val() != "" && $("#searchInput").val() != "Enter author, title, or keyword") {
			//determine if this is a product (catalog) search or site search
			if (x == "2") {
				//this is a site search - so we submit the form normally
				$("#search_dropdown").val("0");  //this resets dropdown
				$("#form_search").attr("method", "get");
				$("#form_search").attr("action", "/sitesearch.htm");
				$("#form_search").submit();
			}
			else if (x == "1") {
				//this is a product (catalog) search - code to COME
				$("#search_dropdown").val("0");  //this resets dropdown
				$("#form_search").submit();
			}
			else {
				//nothing was selected, so submit to catalog by default
				$("#search_dropdown").val("0");  //this resets dropdown
				$("#form_search").submit();
			}
		}
		else {
			$("#search_dropdown").val("0");  //this resets dropdown
		}
	});
	
	// ################################################################## //
	// # Code added for Omniture Custom Link tracking -- Updated 11/24/09
	// ################################################################## //
	if ($('a[rel1!=""]')){
		$("a[rel1]").click(function() {

			//Home Page promos
			if ($(this).attr('rel1') == "omnipromotrack"){	
				var cus_link_name = ' Gale Schools Home - '+$(this).attr('title')+' - Waterfall Promo';
			}
			
			//Other links
			else if (($(this).attr('rel1') == "omnilinktrack") || ($(this).attr('rel1') == "omniexlinktrack")){	
				var cus_link_name = $(this).attr('title');				
			}
			
			//If title value exists
			if ($(this).attr('title') != ""){	
				
				//Omniture code
				var s = s_gi('thgaleschool');
				s.linkTrackVars = 'None';
				s.linkTrackEvents = 'None';	
				
				s.tl($(this),'o',cus_link_name);
			}
			
			//If external link, open in new window
			if ($(this).attr('rel1') == "omniexlinktrack"){
				window.open( $(this).attr('href') );
        		return false;
			}
		});		
	}
	
	
	// ############################################# //
	// # Sci-Try Archives Toggle
	// ############################################# //
	
	var currentTime = new Date();
	var year = currentTime.getFullYear();
	var classArr = [];
	var count = -1;
	//var exp = '2007';
	
	for(var i=year; i>2002; i--) {
		count = count + 1;
		classArr[count] = i;
	}
	
	$(document).ready(function() {
		if($("#sci-try-log") || $("#coloring-archive")) {
			$('.magicHandle').each(function() {
				$(this).css('display', 'none');
			});
			jQuery.each(classArr, function(){
				var number = this;
				$('#'+number+'toggle').click(function(){
					$('.magicHandle').each(function(){ $(this).slideUp(); });
					$('#'+number).slideDown();
					return false;
				});
			});

		}
	});
	
	
	// ############################################# //
	// # Testimonials Archive
	// ############################################# //
	
	var show = param('show');
	if($("#testimonials-archive")) {
		$('#testimonials-archive blockquote').each(function() { $(this).css('display', 'none'); });
		if(show) { $('#'+show).css('display', 'block'); }
		else { $('#one').css('display', 'block'); }
	}


}); // end document.ready

//adjusts the left nav catalog > View Wish List link and the top nav order center links for login/logout
function GetCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
