jQuery(function(){
	var protocol = location.protocol, _host = location.hostname, logoutLink;

	var BooksAuthors = {
		'titleSec1' : 'Most Popular Series',
		'linksSec1' : [
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_39-clues.jpg',
				linktext : 'The 39 Clues',
				linkurl : 'http://www.scholastic.com/kids/39clues/?lnkid=stacks/nav/b_and_a/titles/39clues',
				linkalt : 'The 39 Clues book site',
				linktitle : 'Go to The 39 Clues book site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_allie-finkle.jpg',
				linktext : 'Allie Finkle\'s Rules for Girls',
				linkurl : 'http://alliefinkle.scholastic.com/?lnkid=stacks/nav/b_and_a/titles/alliefinkle',
				linkalt : 'Allie Finkle\'s Rules for Girls',
				linktitle : 'Go to the Allie Finkle\'s Rules for Girls site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_animorphs.jpg',
				linktext : 'Animorphs',
				linkurl : 'http://www.scholastic.com/animorphs/index.htm?lnkid=stacks/nav/b_and_a/titles/animorphs',
				linkalt : 'Animorphs',
				linktitle : 'Go to the Animorphs site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_baby-sitters-club.jpg',
				linktext : 'The Baby Sitters Club',
				linkurl : 'http://www.scholastic.com/thebabysittersclub/?lnkid=stacks/nav/b_and_a/titles/babysittersclub',
				linkalt : 'The Baby Sitters Club',
				linktitle : 'Go to The Baby-Sitters Club site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_bone.jpg',
				linktext : 'Bone',
				linkurl : 'http://www.scholastic.com/bone/?lnkid=stacks/nav/b_and_a/titles/bone',
				linkalt : 'Bone',
				linktitle : 'Go to the Bone site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_captain-underpants.jpg',
				linktext : 'Captain Underpants',
				linkurl : 'http://www.scholastic.com/captainunderpants/?lnkid=stacks/nav/b_and_a/titles/captunderpants',
				linkalt : 'Captain Underpants',
				linktitle : 'Go to the Captain Underpants site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_dear-dumb-diary.jpg',
				linktext : 'Dear Dumb Diary',
				linkurl : 'http://www.scholastic.com/titles/deardumbdiary/?lnkid=stacks/nav/b_and_a/titles/deardumbdiary',
				linkalt : 'Dear Dumb Diary',
				linktitle : 'Go to the Dear Dumb Diary site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_goosebumps.jpg',
				linktext : 'Goosebumps',
				linkurl : 'http://www.scholastic.com/goosebumps/?lnkid=stacks/nav/b_and_a/titles/goosebumps',
				linkalt : 'Goosebumps',
				linktitle : 'Go to the Goosebumps site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_harry-potter.jpg',
				linktext : 'Harry Potter',
				linkurl : 'http://harrypotter.scholastic.com/?lnkid=stacks/nav/b_and_a/titles/harrypotter',
				linkalt : 'Harry Potter',
				linktitle : 'Go to the Harry Potter site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_how-i-survived-middle-school.jpg',
				linktext : 'How I Survived Middle School',
				linkurl : 'http://www.scholastic.com/kids/middleschoolsurvival/?lnkid=stacks/nav/b_and_a/titles/middleschool',
				linkalt : 'How I Survived Middle School',
				linktitle : 'Go to the How I Survived Middle School site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_ispy.jpg',
				linktext : 'I SPY',
				linkurl : 'http://www.scholastic.com/kids/ispy/?lnkid=stacks/nav/b_and_a/titles/ispy',
				linkalt : 'I SPY',
				linktitle : 'Go to the I SPY site'
			},
			{
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/ba_wonderstruck.jpg',
				linktext : 'Wonderstruck',
				linkurl : 'http://www.scholastic.com/wonderstruck/?lnkid=stacks/nav/b_and_a/titles/Wonderstruck',
				linkalt : 'Wonderstruck',
				linktitle : 'Go to the Wonderstruck site'
			}
		],
		'btn' : {
			btntext : 'All Book Sites',
			btnurl : 'http://www.scholastic.com/kids/favorites.htm?lnkid=stacks/nav/b_and_a/all/',
			btnalt : 'All Book sites for Kids',
			btntitle : 'See a list of all book sites'
		},
		'btnAlt' : {
			btntext : 'Featured Books &amp; Authors',
			btnurl : 'http://www.scholastic.com/kids/stacks/books/?lnkid=stacks/nav/b_and_a/featured/',
			btnalt : 'Books &amp; Authors for Kids',
			btntitle : 'Go to the Books &amp; Authors page'
		}
	};

	var Games = {
		'titleSec1' : 'Most Popular Games',
		'linksSec1' : [
			{
				linksite : 'Goosebumps',
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/games_flee-camp-jellyjam.jpg',
				linktext : 'Flee Camp Jellyjam',
				linkurl : 'http://www.scholastic.com/goosebumps/games_activities/jellyjam.htm?lnkid=stacks/nav/games/fg/1/goosebumps_campjellyjam',
				linkalt : 'Goosebumps: Flee Camp Jellyjam',
				linktitle : 'Play the Flee Camp Jellyjam game'
			},
			{
				linksite : 'Knights of the Lunch Table',
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/games_dodgearama.jpg',
				linktext : 'Dodge-a-Rama',
				linkurl : 'http://www.scholastic.com/knightsofthelunchtable/?lnkid=stacks/nav/games/fg/2/dodgearama',
				linkalt : 'Knights of the Lunch Table: Dodge-a-Rama',
				linktitle : 'Play the Knights of the Lunch Table: Dodge-a-Rama game'
			},
			{
				linksite : 'Deltora',
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/games_dragons-of-deltora.jpg',
				linktext : 'Deltora',
				linkurl : 'http://www.scholastic.com/deltora/games/?lnkid=stacks/nav/games/fg/3/deltora_dragons',
				linkalt : 'Deltora: Dragons of Deltora Adventure',
				linktitle : 'Play the Deltora: Dragons of Deltora Adventure game'
			},
			{
				linksite : 'Baby-sitters Club',
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/games_dressthegirls.jpg',
				linktext : 'Dress the Girls',
				linkurl : 'http://www.scholastic.com/thebabysittersclub/gameDressTheGirls.htm?lnkid=stacks/nav/games/fg/4/bsc_dressthegirls',
				linkalt : 'Baby-sitters Club: Dress the Girls',
				linktitle : 'Play the Baby-sitters Club: Dress the Girls game'
			},
			{
				linksite : 'Wonderstruck',
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/games_fingerspell.jpg',
				linktext : 'Fingerspell Your Name',
				linkurl : 'http://www.scholastic.com/wonderstruck/signs.html?mname=MY%20NAME%20IS?lnkid=stacks/nav/games/fg/5/wonderstruck_fingerspell',
				linkalt : 'Wonderstruck: Fingerspell Your Name',
				linktitle : 'Play the Wonderstruck: Fingerspell Your Name game'
			},
			{
				linksite : 'Middle School Survival',
				linkimg : protocol + '//www.scholastic.com/kids/stacks/common/images/nav/games-mash.jpg',
				linktext : 'M.A.S.H.',
				linkurl : 'http://www.scholastic.com/kids/middleschoolsurvival/mash/?lnkid=stacks/nav/games/fg/6/middleschoolsurvival_mash',
				linkalt : 'Middle School Survival: M.A.S.H.',
				linktitle : 'Play the Middle School Survival: M.A.S.H. game'
			}
		],
		'titleSec2' : 'More Fun',
		'linksSec2' : [
			{
				linktext : 'Poll Mania',
				linkurl : 'http://blog.scholastic.com/poll_mania/?lnkid=stacks/nav/games/pollmania',
				linktitle : 'Go to Poll Mania'
			},
			{
				linktext : 'Contests &amp; Sweepstakes',
				linkurl : 'http://blog.scholastic.com/kids_contests_sweepstakes/?lnkid=stacks/nav/games/contests',
				linktitle : 'Go to the Contests &amp; Sweepstakes page'
			}
		],
		'btn' : {
			btntext : 'All Games',
			btnurl : 'http://www.scholastic.com/kids/stacks/games/?lnkid=stacks/nav/games/all',
			btnalt : 'All Games',
			btntitle : 'Go to the Games homepage'
		}
	};

	var Blog = {
		'titleSec1' : 'Ink Splot 26',
		'mainTout' : protocol + '//www.scholastic.com/kids/stacks/common/images/logo_ink_splot.jpg',
		'mainToutLink' : 'http://blog.scholastic.com/ink_splot_26/?lnkid=stacks/nav/blog/logo',
		'mainToutAlt' : 'Ink Splot 26 Blog',
		'mainToutTitle' : 'Go to Ink Splot 26 Blog',
		'mainToutTxt' : 'Daily book news, celeb interviews, trivia, and more!',
		'titleSec2' : 'Top Categories',
		'linksSec2' : [
			{
				linktext : 'Celebrities',
				linkurl : 'http://blog.scholastic.com/ink_splot_26/celebrities/?lnkid=stacks/nav/blog/category/celeb',
				linktitle : 'Celebrity Interviews and News'
			},
			{
				linktext : 'Reads',
				linkurl : 'http://blog.scholastic.com/ink_splot_26/reads-1/?lnkid=stacks/nav/blog/category/reads',
				linktitle : 'Book Reviews, Recommendations, and News'
			},
			{
				linktext : 'Trivia',
				linkurl : 'http://blog.scholastic.com/ink_splot_26/trivia-1/?lnkid=stacks/nav/blog/category/trivia',
				linktitle : 'Trivia'
			},
			{
				linktext : 'Writing Prompts',
				linkurl : 'http://blog.scholastic.com/ink_splot_26/writing-prompt/?lnkid=stacks/nav/blog/category/writing_prompts',
				linktitle : 'Writing Prompts and Create-a-Caption'
			}
		],
		'btn' : {
			btntext : 'All Posts',
			btnurl : 'http://blog.scholastic.com/ink_splot_26/?lnkid=stacks/nav/blog/all',
			btnalt : 'Ink Splot 26 Blog',
			btntitle : 'Go to the Ink Splot 26 Blog'
		}
	};

	var Videos = {
		'titleSec1' : 'Categories',
		'linksSec1' : [
			{
				linktext : 'Inside the Book',
				linkurl : 'http://www.scholastic.com/kids/stacks/videos/index.htm?pid=1847329164&lnkid=stacks/nav/videos/insidebook',
				linktitle : 'Watch book-related videos'
			},
			{
				linktext : 'Your Favorite Series',
				linkurl : 'http://www.scholastic.com/kids/stacks/videos/index.htm?pid=1847329166&lnkid=stacks/nav/videos/yourfavseries',
				linktitle : 'Watch videos about your favorite series'
			},
			{
				linktext : 'Celebrities &amp; Entertainment',
				linkurl : 'http://www.scholastic.com/kids/stacks/videos/index.htm?pid=1847329168&lnkid=stacks/nav/videos/celebs_ent',
				linktitle : 'Watch Celebrity and Entertainment videos'
			},
			{
				linktext : 'Meet the Authors',
				linkurl : 'http://www.scholastic.com/kids/stacks/videos/index.htm?pid=1847329167&lnkid=stacks/nav/videos/authors',
				linktitle : 'Watch author videos'
			},
			{
				linktext : 'Special Events',
				linkurl : 'http://www.scholastic.com/kids/stacks/videos/index.htm?pid=1847353729&lnkid=stacks/nav/videos/events',
				linktitle : 'Watch special events videos'
			},
			{
				linktext : 'Grab Bag &amp; Funny Stuff',
				linkurl : 'http://www.scholastic.com/kids/stacks/videos/index.htm?pid=1847353728&lnkid=stacks/nav/videos/grab_funny',
				linktitle : 'Watch funny videos'
			}
		],
		'btn' : {
			btntext : 'All Videos',
			btnurl : 'http://www.scholastic.com/kids/stacks/videos/?lnkid=stacks/nav/videos/all',
			btnalt : 'All Videos',
			btntitle : 'Go to the Videos page'
		}
	};

	var MB = {
		'titleSec1' : 'Most Popular Boards',
		'linksSec1' : [
			{
				linktext : 'Buzz Board',
				linkurl : 'http://community.scholastic.com/reading-buzz-board.html?linkid=stacks/nav/boards/buzzboard',
				linktitle : 'Go to the Buzz Message Board'
			},
			{
				linktext : 'Save the Planet Board',
				linkurl : 'http://community.scholastic.com/save-the-planet.html?linkid=stacks/nav/boards/savetheplanet',
				linktitle : 'Go to the Save the Planet Message Board'
			},
			{
				linktext : 'Harry Potter Board',
				linkurl : 'http://community.scholastic.com/harry-potter-f44.html?linkid=stacks/nav/boards/harrypotter',
				linktitle : 'Go to the Harry Potter message Board'
			}
		],
		'titleSec2' : 'Community Features',
		'linksSec2' : [
			{
				linktext : 'STACKS Signatures',
				linkurl : 'http://www.scholastic.com/kids/stacks/scene/signatures/index.htm?lnkid=stacks/nav/boards/signatures',
				linktitle : 'Get a STACKS Signature for the Message Boards'
			},
			{
				linktext : 'Live Chats',
				linkurl : 'http://blog.scholastic.com/ink_splot_26/live-chats/?lnkid=stacks/nav/boards/chats',
				linktitle : 'Go to the Live Chats page'
			}
		],
		'btn' : {
			btntext : 'Join the Conversation',
			btnurl : 'http://community.scholastic.com/all-kids-boards.html?lnkid=stacks/nav/boards/all',
			btnalt : 'Message Boards',
			btntitle : 'Join the conversation of the Message Boards'
		}
	};

	var Profile = {
		'links' : [
			{
				linktext : 'Update My Avatar',
				linkurl : 'http://kids.scholastic.com/community/avatar_maker.htm?lnkid=stacks/nav/profile/updateavatar',
				linktitle : 'Update My Avatar',
				rel : 'kids_protected_url'
			},
			{
				linktext : 'View My Friends',
				linkurl : 'http://kids.scholastic.com/community/view_all_friends.htm?lnkid=stacks/nav/profile/viewfriends',
				linktitle : 'View My Friends',
				rel : 'kids_protected_url'
			},
			{
				linktext : 'Add Widgets',
				linkurl : 'http://kids.scholastic.com/community/myStacks.htm?lnkid=stacks/nav/profile/addwidgets',
				linktitle : 'Add Widgets to My Profile',
				rel : 'kids_protected_url'
			}
		],
		'btnProfile' : {
			btntext : 'My Profile',
			btnurl : 'http://kids.scholastic.com/community/my_profile.htm?lnkid=stacks/nav/profile/myprofile',
			btnalt : 'My Profile',
			btntitle : 'Go to my profile'
		},
		'btnSignIn' : {
			btntext : 'Sign In',
			//btnurl : 'https://my.scholastic.com/sps_my_account/accmgmt/FlashLogin.jsp?finalSuccessURL=' + getCleanURL(),
			btnurl : getCleanURL(),
			btnalt : 'Sign In',
			btntitle : 'Sign-In',
			rel : 'kids_protected_url'
		}
	};

 /* ============================================================================================ */

	var $stacksDD, firstRun = true, stacksTimer, stacksDelayHide, stacksDisappearDelay = 1, stacksVisible;
	var  s_nVideos = '', s_nMB = '', s_nProfile = '', s_nGames = '', s_nBlog = '', s_nBA = '';

	jQuery('#schlStacksNav a').click(function(){ saveCookie('header','bigKids'); });

	jQuery('#schlStacksNav a:gt(0)').hover(
		function(){
			if ( firstRun ) {
				jQuery('body').append('<div id="stacksDD"><div class="content"></div><div class="btm"></div></div>');
				setupStacksDD();
				firstRun = false;
			}
			$this = jQuery(this);
			$stacksDD = jQuery(this);
			jQuery('#schlStacksNav ul').css('z-index', '10003'); //for peel ad
			jQuery('#schlStacksNav ul a').removeClass('active');
			$this.addClass('active');

			clearTimeout(stacksTimer);
			stacksTimer = setTimeout( function() {
				jQuery('#schlStacksNav ul').css('z-index', '10003'); //for peel ad
				$this.addClass('active');
				showSTACKSMenu($this);
				stacksVisible = true;
			}, 10);
		},
		function(){
			jQuery('#schlStacksNav ul').css('z-index', ''); //for peel ad

			$this = jQuery(this);
			$this.removeClass('active');

			if (stacksVisible) {
				stacksDelayHide=setTimeout(function() {
					hideSTACKSMenu();
					stacksVisible = false;
				}, stacksDisappearDelay);
			}
			else { clearTimeout(stacksTimer); }


		}
	);

	function showSTACKSMenu(which) {
		var tmp = which.attr('data-stacksnav') || which.attr('rel');
		jQuery('#stacksDD').removeClass().addClass(tmp);
		setPosition(which);
		jQuery('#stacksDD .content').html(populateDD(which));
		jQuery('#stacksDD .content td').hover(function(){jQuery(this).addClass('hov');}, function(){jQuery(this).removeClass();});
		jQuery('#stacksDD').show();
	}

	function hideSTACKSMenu() { jQuery('#stacksDD').hide(); }

	function setPosition(which) {
		var btn = which.attr('data-stacksnav') || which.attr('rel');
		var offset = which.offset();
		var btn_width = which.width();
		var box_width = jQuery('#stacksDD').width();
		var left, top;
		if ( btn == 'nBA' ) {
			//left = parseInt(offset.left, 10);
			left = which.parents('ul').offset().left;
		}
		else if ( btn == 'nProfile' ) {
			left = parseInt((offset.left + btn_width + 10) - box_width, 10);
		}
		else {
			left = parseInt(offset.left - ( box_width - btn_width ) / 2, 10);
		}
		top = parseInt(offset.top + 27, 10);
		jQuery('#stacksDD').css({left : left, top: top});
	}

	function setupStacksDD() {
		jQuery('#stacksDD').bind('mouseover', function(){
			$stacksDD.addClass('active');
			jQuery('#schlStacksNav ul').css('z-index', '10003'); //for peel ad
			if ( typeof stacksDelayHide != "undefined" ) clearTimeout(stacksDelayHide);
		});
		jQuery('#stacksDD').bind('mouseout', function(){
			if (stacksVisible) {
				stacksDelayHide=setTimeout(function() {
					$stacksDD.removeClass('active');
					hideSTACKSMenu();
					stacksVisible = false;
					jQuery('#schlStacksNav ul').css('z-index', ''); //for peel ad
				}, stacksDisappearDelay);
			}
			else {
				clearTimeout(stacksTimer);
			}
		});
	}

	function populateDD(which) { var tmp = which.attr('data-stacksnav') || which.attr('rel'); return DD[tmp](); }

	var DD = {
		nBA : function() {
			if ( s_nBA == '' ) {
				s_nBA = '<h3 class="main">' + BooksAuthors['titleSec1' ] + '</h3>';
				s_nBA += getMostPopular({ 'arr': BooksAuthors.linksSec1, 'cols' : 6});
				s_nBA += getYAWYR();
				s_nBA += getButton([BooksAuthors.btn, BooksAuthors.btnAlt], 'alt');
			}
			return s_nBA;
		},

		nGames : function() {
			if ( s_nGames == '' ) {
				s_nGames = '<h3 class="main">' + Games['titleSec1' ] + '</h3>';
				s_nGames += getMostPopular({ 'arr': Games.linksSec1, 'cols' : 3});
				s_nGames += '<h3>' + Games['titleSec2' ] + '</h3>';
				s_nGames += getLinks(Games.linksSec2);
				s_nGames += getButton(Games.btn);
			}
			return s_nGames;
		},

		nBlog : function() {
			if ( s_nBlog == '' ) {
				s_nBlog = '<h3 class="main">' + Blog['titleSec1' ] + '</h3>';
				s_nBlog += '<p class="logo"><a href="' + Blog.mainToutLink + '" title="' + Blog.mainToutTitle + '"><img src="' + Blog.mainTout + '" alt="' + Blog.mainToutAlt + '" border="0" /></a></p>';
				s_nBlog += '<p class="txt">' + Blog.mainToutTxt + '</p>';
				s_nBlog += '<h3>' + Blog['titleSec2' ] + '</h3>';
				s_nBlog += getLinks(Blog.linksSec2);
				s_nBlog += getButton(Blog.btn);
			}
			return s_nBlog;
		},

		nVideos : function() {
			if ( s_nVideos == '' ) {
				s_nVideos = '<h3>' + Videos['titleSec1' ] + '</h3>';
				s_nVideos += getLinks(Videos.linksSec1);
				s_nVideos += getButton(Videos.btn);
			}
			return s_nVideos;
		},

		nMB : function() {
			if ( s_nMB == '' ) {
				s_nMB = '<h3>' + MB['titleSec1' ] + '</h3>';
				s_nMB += getLinks(MB.linksSec1);
				s_nMB += '<h3>' + MB['titleSec2' ] + '</h3>';
				s_nMB += getLinks(MB.linksSec2);
				s_nMB += getButton(MB.btn);
			}
			return s_nMB;
		},

		nProfile : function() {
			if ( s_nProfile == '' ) {
				var ud = readCookie('SPS_UD');
				if ( ud ) {
					ud = ud.split('|');
					var randomInteger=Math.floor(Math.random()*11);
					s_nProfile = '<iframe width="154" height="85" frameborder="0" scrolling="no" marginwidth="0" marginheight="0" src="' + protocol + '//kids.scholastic.com/community/getavatar.htm?lnkid=stacks/nav/profile/avatarimage&ieQuery=' + randomInteger +'"></iframe>';
					//s_nProfile += '<h5><a href="http://kids.scholastic.com/community/my_profile.htm?lnkid=stacks/nav/profile/username" title="My Profile">Hi ' + ud[1] + '!</a></h5>'
					s_nProfile += '<h5><a href="http://kids.scholastic.com/community/my_profile.htm?lnkid=stacks/nav/profile/username" title="My Profile">Hi ' + ud[1] + '!</a></h5>'
					//s_nProfile += '<p class="signout"><a href="#" onclick="maLogOut(); return false;">Sign Out</a></p>';
					if ( _host == 'kids.scholastic.com' ) logoutLink = 'http://www.scholastic.com/kids/stacks';
					else logoutLink = getCleanURL();
					var t = (logoutLink.indexOf('?')!=-1) ? '&' : '?';
					s_nProfile += '<p class="signout"><a href="' + logoutLink + t + 'lnkid=stacks/nav/profile/signout" rel="kids_logout">Sign Out</a></p>';
				}
				else {
					//s_nProfile = '<a href="https://my.scholastic.com/sps_my_account/accmgmt/FlashLogin.jsp?finalSuccessURL=' + getCleanURL() + '" title="Sign In" rel="kids_protected_url"><img src="' + protocol + '//www.scholastic.com/kids/stacks/common/images/nav/get_started.jpg" border="0" width="154" height="85" class="getStarted" /></a>';
					s_nProfile = '<a href="#" title="Sign In" rel="kids_protected_url"><img src="' + protocol + '//www.scholastic.com/kids/stacks/common/images/nav/get_started.jpg" border="0" width="154" height="85" class="getStarted" /></a>';
				}

				s_nProfile += getLinksProfile(Profile.links, ud);

				if ( ud ) {
					s_nProfile += getButton(Profile.btnProfile, 'profile');
				}
				else {
					s_nProfile += getButton(Profile.btnSignIn, 'signin');
				}
			}
			return s_nProfile;
		}
	};

	function getButton(obj, c) {
		var klass = '', btn = '', rel = obj.rel ? obj.rel : '';
		if ( c ) {	klass = ' ' + c; }
		if ( obj instanceof Array ) {
			btn = '<div class="btnWrap"><a class="btn" href="' + obj[0].btnurl + '" title="' + obj[0].btntitle + '">' + obj[0].btntext + '</a><a class="btn' + klass + '" href="' + obj[1].btnurl + '" title="' + obj[1].btntitle + '">' + obj[1].btntext + '</a></div>';
		}
		else {
			btn = '<div class="btnWrap"><a class="btn' + klass + '" href="' + obj.btnurl + '" title="' + obj.btntitle + '" rel="' + rel + '">' + obj.btntext + '</a></div>';
		}
		return btn;
	}

	function getMostPopular(obj) {
		var arrSize, site = obj.arr[0].linksite ? true : false;
		var tmp = '<table border="0" cellpadding="0" cellspacing="0">', hdr = '', content = '';
		if ( obj.arr.length % obj.cols != 0 ) arrSize = obj.arr.length + ( obj.cols - (obj.arr.length % obj.cols) );
		else arrSize = obj.arr.length;
		for ( var i = 0; i < arrSize; i++ ) {
			if ( i != 0 && i % obj.cols == 0 ) {
				if ( site ) { tmp += '<tr>' + hdr + '</tr><tr>' + content + '</tr>'; }
				else { tmp += '<tr>' + content + '</tr>'; }
				hdr = '';
				content = '';
			}
			if ( obj.arr[i] ) {
				if ( site ) { hdr += '<th>' + obj.arr[i].linksite + '</th>'; }
				content += '<td width="' + parseInt(100 / obj.cols, 10) + '%"><a href="' + obj.arr[i].linkurl + '" title="' + obj.arr[i].linktitle + '"><img src="' + obj.arr[i].linkimg + '" width="59" height="49" alt="' + obj.arr[i].linkalt + '" /></a><br /><a href="' + obj.arr[i].linkurl + '" title="' + obj.arr[i].linktitle + '">' + obj.arr[i].linktext + '</a></td>';
			}
			else {
				if ( site ) { hdr += '<th>&nbsp;</th>'; }
				content += '<td width="' + parseInt(100 / obj.cols, 10) + '%">&nbsp;</td>';
			}
		}
		if ( site )
			tmp += '<tr>' + hdr + '</tr><tr>' + content + '</tr></table>';
		else
			tmp += '<tr>' + content + '</tr></table>';
		return tmp;
	}

	function getYAWYR() {
		return tmp = '<h3 class="main">You Are What You Read</h3><p class="yawyr"><a href="http://youarewhatyouread.scholastic.com/kids/?lnkid=stacks/nav/b_and_a/YAWYR/" title="You Are What You Read"><img src="' + protocol + '//www.scholastic.com/kids/stacks/common/images/nav/yawyr_stacks_dropdown.gif" alt="You Are What You Read: Tell the World Which Books Changed Your Life" /></a></p>';
	}

	function getLinks(arr) {
		var tmp = '<ul>';
		for ( var i = 0; i < arr.length; i++ ) {
			tmp += '<li><a href="' + arr[i].linkurl + '" title="' + arr[i].linktitle + '">' + arr[i].linktext + '</a></li>';
		}
		tmp += '</ul>';
		return tmp;
	}

	function getLinksProfile(arr, sps) {
		var tmp = '<ul>';
		for ( var i = 0; i < arr.length; i++ ) {
			var rel = (sps == null) ? arr[i].rel : '';
			tmp += '<li><a href="' + arr[i].linkurl + '" title="' + arr[i].linktitle + '" rel="' + rel + '">' + arr[i].linktext + '</a></li>';
		}
		tmp += '</ul>';
		return tmp;
	}

	function getCleanURL() {
		var url = location.href,
			search = location.search,
			multiple = search.substring(1).split('&'),
			t = 'lnkid',
			tracking = 'lnkid=stacks/nav/profile/signout',
			found = false;

		if ( search ) {
			if ( multiple.length > 1 ) {
				for ( var i = 0; i < multiple.length; i++ ) {
					if ( multiple[i].indexOf(t) != -1 ) {
						delete multiple[i];
						found = true;
						break;
					}
				}
				if ( found ) {
					url = url.split('?')[0] + '?' + multiple.join('&');
				}
			}
			else {
				if ( multiple[0].indexOf(t) != -1 ) {
					var tmp = url.indexOf(t);
					url = url.substring(0,tmp-1);

				}

			}
		}
		return url.split('#')[0];
	}

	setOnSignOutHook(function(){
		var t_url = (location.search) ? '&' : '?';
		t_url += 'lnkid=stacks/nav/profile/signout';
		window.location = location.href + t_url;
	});
});

if ( typeof schl_jswrapper == 'undefined' ) document.write(unescape("%3Cscript src='/ups/javascripts/kids_popup.js' type='text/javascript'%3E%3C/script%3E"));
