	/*
		dependencies:
			common.js
	*/

		var ActiveModalWindow = '';
		var ModalFunctionFire = false;
		var ModalEscape = false;

		function FireKeyEvent(e){
			keycode = GetKeyCode(e);
			if(ModalFunctionFire == false){
				if(keycode == 76 && !loggedInObject.getStatus()){
					if(ModalFunctionFire == false){
						Modal_Open('Login', null, null, 'btn_Login');
					}
				}
			}

			//escape -- exit
			if(keycode == 27){
				ReturnToRest();
			}
		}


		function Modal_Open(_windowtype, _event, _ajax, _id){
			//alert("MODAL OPEN " + _event);
			//alert("WINDOW OPEN " + _windowtype);
			var modalwindow = document.getElementById('ModalWindow_'+_windowtype);
			if(_event != null){
//				alert('event != null');
				position = getPosition(_event);
//				alert(position.x + ':' + position.y);
				SetPosition(modalwindow, 'modal', position);
			}else{
				ModalFunctionFire = true;
//				alert('event == null');
				var tmp_obj = document.getElementById(_id);
				var tmp_pos = getElementPosition(tmp_obj);
				position = {x:(tmp_pos[0]+16), y:(tmp_pos[1]+16)};
//				alert(position.x + ':' + position.y);
				SetPosition(modalwindow, 'modal', position);
			}

			modalwindow.style.display = 'block';
			//sIFR.replaceElement(named({sSelector:"div.div_subheadline", sFlashSrc:"/_sifr/Univers57Cond.swf", sColor:"#333333", sWmode:"transparent"}));

			//TODO:  The line below was uncommented originally.  Will comment to determine if it handles
			//CloseModalWindow();
			ActiveModalWindow = _windowtype;
		}

		function PositionModalWindow(_id, e){
			position = getPosition(e);
			var modal = document.getElementById('ModalWindow_'+_id);
			SetPosition(modal, 'modal', position);
		}

		function SetPosition(_obj, _class, _position){
			_obj.className = _class;
			_obj.style.display = 'block';
//			_obj.style.left = position.x-30 + "px";
//			_obj.style.top = position.y+10 + "px";

			if(_obj.id.indexOf('Dictionary') > -1){
				_obj.style.left = position.x-15 + "px";
				_obj.style.top = position.y-(_obj.offsetHeight+20) + "px";
			}else{
				_obj.style.left = position.x-2 + "px";
				_obj.style.top = position.y+20 + "px";
			}
		}

		function HideWindow(){
			var modal = document.getElementById('div_modal');
			modal.className = 'modal_off';
			modal.style.display = 'none';
			var modal = document.getElementById('div_modal_bg');
			modal.className = 'modal_off';
			modal.style.display = 'none';
		}

		function OpenModalWindow(_type, _genus, _id){
			if(_genus != null){
				switch(_genus){
					case 'literature':
						document.getElementById('ModalWindow_WhatYouWant').style.marginTop = '75px';
						document.getElementById('CenterBlock_Arrow').style.marginTop = '15px';
						OpenModalWindow_Finish(_type, _type);
						break;
					case 'history':
						document.getElementById('ModalWindow_WhatYouWant').style.marginTop = '110px';
						document.getElementById('CenterBlock_Arrow').style.marginTop = '15px';
						OpenModalWindow_Finish(_type, _type);
						break;
					case 'ratings':
						if(ActiveModalWindow != ''){
							tmp_amw = ActiveModalWindow + ',' + _type;
						}else{
							tmp_amw = _type;
						}
						OpenModalWindow_Finish(_type, tmp_amw);
						break;
				}
			}else{
				//alert("TYPE IS " + _type);
				if(_type == "Options")
				{
					OpenModalWindow_Finish(_type, _type, _id);
				}
				else
				{
					OpenModalWindow_Finish(_type, _type);
				}
			}
		}


		function OpenModalWindow_Finish(_type, _amw, _id){
			// if user clicks on OPTIONS link, clear any messages that are displayed in OPTIONS popup modal window.
			if("ModalWindow_Options" == 'ModalWindow_'+_type)
			{
				if(_id == 0 || _id == undefined)
				{
					if(GetCookie("pageOption") != null)
					{
						page_options = GetCookie("pageOption");
						page_options_cookie = page_options.substring(page_options.indexOf(":")+1);
						Ajax_ProcessPageOptionsCookieUser(page_options_cookie);
						//alert("cookie " + page_options_cookie);
					}
					else
					{
						//alert("ID IS " + _id);
						Ajax_ProcessPageOptionsCookieUser(0);
					}
				}

				var clear_page_options_message = document.getElementById("div_page_option_message");
				clear_page_options_message.innerHTML = "";
			}

			document.getElementById('ModalWindow_'+_type).style.display = 'block';
			CloseModalWindow();
			ActiveModalWindow = _amw;
		}

		function CloseModalWindow(modalWndow){
			//alert('ModalWindow_'+ActiveModalWindow);
			//alert("Close ACTIVE MODAL: " + ActiveModalWindow);
			//alert("Close MODAL FUNCTION FIRE " + ModalFunctionFire);
			if(modalWndow == undefined || modalWndow == null)
			{
				//alert("INSIDE FIRST");
				if(ActiveModalWindow != '' && ModalFunctionFire == false){
					if(ActiveModalWindow.indexOf(',') > -1){
						var tmp_amw = ActiveModalWindow.split(',');
						var new_amw = '';
						for(i=0;i<tmp_amw.length-1;i++){
							if(new_amw != ''){
								new_amw += ',';
							}
							new_amw += tmp_amw[i];
						}
						ActiveModalWindow = new_amw;
						document.getElementById('ModalWindow_'+tmp_amw[tmp_amw.length-1]).style.display = 'none';

					}else{
						document.getElementById('ModalWindow_'+ActiveModalWindow).style.display = 'none';
						ActiveModalWindow = '';
					}
				}
			}
			else
			{
				//alert("INSIDE LAST");
				ModalFunctionFire = false;
				if(modalWndow != '' && ModalFunctionFire == false){
					if(modalWndow.indexOf(',') > -1){
						var tmp_amw = modalWndow.split(',');
						var new_amw = '';
						for(i=0;i<tmp_amw.length-1;i++){
							if(new_amw != ''){
								new_amw += ',';
							}
							new_amw += tmp_amw[i];
						}
						modalWndow = new_amw;
						document.getElementById('ModalWindow_'+tmp_amw[tmp_amw.length-1]).style.display = 'none';

					}else{
						document.getElementById('ModalWindow_'+modalWndow).style.display = 'none';
						modalWndow = '';
					}
				//ModalFunctionFire = true;
				}

			}

			if("ModalWindow_Options" == 'ModalWindow_'+ActiveModalWindow)
			{
			  page_options_msg_set = false;
			}
		}

		function firemodalevent(_val){
			document.getElementById('tmp_ModalFunctionFire').innerHTML = '['+_val+']';
			ModalFunctionFire = _val;
		}

		function firemodalescape(_val){
			document.getElementById('tmp_ModalEscape').innerHTML = '['+_val+']';
			ModalEscape = _val;
		}

		function PopulateDictionaryWindow(_obj){
			document.getElementById('ModalWindow_Dictionary_Title').innerHTML = _obj.innerHTML;
		}
		//end -> ModalWindow functions



function ShowDeleteDialogue(_type, _sfn, _cfn, _eid, _x, _y)
{
	// set type of item to be deleted text
	document.getElementById('ModalWindow_Delete_Type').innerHTML = _type;

	// map submit function and element id
	var dfs = document.getElementById('ModalWindow_Delete_Submit');
	dfs.el_id = _eid;
	dfs.del_go = _sfn;

	// map cancel function and element id
	var dfc = document.getElementById('ModalWindow_Delete_Cancel');
	dfc.el_id = _eid;
	dfc.del_no = _cfn;

	var df = document.getElementById('ModalWindow_Delete');
	df.style.top = _y;
	df.style.left = _x;
	df.style.display = 'block';
}

function HideFoldersDialogue(_name)
{
	document.getElementById('ModalWindow_ChooseFolder').style.display = 'none';
	document.getElementById('ModalWindow_CreateFolder').style.display = 'none';
	document.getElementById('ModalWindow_CreateFolder_Input').value = 'Name Your New Folder';

	if(_name)
	{
		document.getElementById('ModalWindow_ConfirmSave_Name').innerHTML = _name;
		document.getElementById('ModalWindow_ConfirmSave').style.display = 'block';
		setTimeout("document.getElementById('ModalWindow_ConfirmSave').style.display = 'none';", 2000);
	}
}

function ShowFoldersDialogue(_eid, _etp, _x, _y)
{
	// map values and set position coords for both dialogues
	var cfs = document.getElementById('ModalWindow_ChooseFolder_Submit');
	cfs.el_id = _eid;
	cfs.el_tp = _etp;

	var cfd = document.getElementById('ModalWindow_ChooseFolder');
	cfd.style.top = _y;
	cfd.style.left = _x;

	var ccs = document.getElementById('ModalWindow_CreateFolder_Submit');
	ccs.el_id = _eid;
	ccs.el_tp = _etp;

	var ccd = document.getElementById('ModalWindow_CreateFolder');
	ccd.style.top = _y;
	ccd.style.left = _x;

	var fss = document.getElementById('ModalWindow_ChooseFolder_Select');
	if(fss.options.length > 1)
		cfd.style.display = 'block';
	else
		ccd.style.display = 'block';

	var sfd = document.getElementById('ModalWindow_ConfirmSave');
	sfd.style.top = _y;
	sfd.style.left = _x;

	updateMyFoldersDropdown();
}

function DisplayCreateFoldersDialogue()
{
	HideFoldersDialogue();
	document.getElementById('ModalWindow_CreateFolder').style.display = 'block';
}

function ShowCreateFoldersDialogue(_x, _y)
{
	var ccs = document.getElementById('ModalWindow_CreateFolder_Submit');
	ccs.el_id = false;
	ccs.el_tp = '';

	var ccd = document.getElementById('ModalWindow_CreateFolder');
	ccd.style.top = _y;
	ccd.style.left = _x;
	ccd.style.display = 'block';
}

function ShowComingSoonDialogue(e)
{
	//var mouse = getPosition(e);

	var df = document.getElementById('ModalWindow_ComingSoon');
	// dialogue height is 120px, bubbles height is 35px
	df.style.top = (mouse.y-120-35) + 'px';
	// dialoge width is 300px, arbitrary additional adjustment
	df.style.left = (mouse.x-250) + 'px';
	df.style.display = 'block';
	setTimeout("document.getElementById('ModalWindow_ComingSoon').style.display = 'none';", 6500);
}

function ShowShmoopTipDialogue(e, _tip)
{
	//var mouse = getPosition(e);
	
	var x = Event.pointerX(e);
	var y = Event.pointerY(e);

	var gutter = $('page').positionedOffset()['left'];

	var df = $('ModalWindow_ShmoopTip');
	
	// arbitrary adjustment
	var lo = (x-gutter) + 'px';
	// dialogue height is 120px, bubbles height is 35px
		
	var to = (y - df.getHeight()) + 'px';

	$('ModalWindow_ShmoopTip_Content').innerHTML = _tip;
	
	df.style.top = to;
	
	if(x-150 > 0)
		df.style.left = lo;
	else
		df.style.left = '10px';
		
	df.style.display = 'block';
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function CitationStyle_OnChange(value, title, subject, euroDate, usDate, url){
	urlMarkup = url;
	wrkURL = "";
	//trim all spaces
	title = title.trim();
	subject = subject.trim();
	title = title.replace(/%/ig, "\'");
	title = title.replace(/#/ig, "\'");
	switch (value){
		case 'mla':
			/*bug in IE, it does not wrap url's gracefully.  Force a line break after 25 characters*/
			origURL = urlMarkup;
			//alert("BEFORE " + urlMarkup);
			//get length of url
			urlLen = urlMarkup.length;
			numberOfTimesToWrap = Math.round(urlLen / 25);
			startingValue = 0;
			endingValue = 25;
			for(z=1; z<= numberOfTimesToWrap; z++)
			{
				wrkURL += urlMarkup.substring(startingValue, endingValue);
				wrkURL += "<br/>";
				startingValue = endingValue;
				endingValue += 25;
			}

			//endingValue += 25;
			wrkURL += urlMarkup.substring(startingValue);
			urlMarkup = "&lt;" + wrkURL + "&gt;";

			document.getElementById('mla_Message').style.display = 'none';
			document.getElementById('ModalWindow_CiteShmoop_Content').style.backgroundColor = '#feface';
			mlaCounter =  "'" + title + "'" + "  Shmoop " + subject + ".  " + euroDate + "  " + urlMarkup;
			//alert("MLA COUNTER " + mlaCounter.length);
			_tip = '<table id="ModuleWindow_CiteShmoop_TableCitation" style="border: 0px solid black;" cellpadding="0" cellspacing="0" border="0"><tr><td><strong> Works Cited:</strong><br/><br/></td></tr>';
			_tip +=	'<tr style="text-align: left;"><td>Shmoop Editorial Team. \"' + title +  '.\"&nbsp;&nbsp;<span><em>Shmoop.com</em>. Shmoop University, Inc., 11 Nov. 2008. Web. </span>' + String(euroDate) + '.</td></tr>';
			/*_tip +=	'<tr><td><span>'  + newURL + '.</span></td></tr>';*/
			_tip +=	'<tr><td><br/><strong>In-text Citation</strong><br/><br/></td></tr>';
			_tip +=	'<tr style="text-align: left;"><td>(Shmoop Editorial Team).</td></tr>';
			//_tip +=	'<tr align="right"><td><input style="border: 0px;" type="image" src="/media/07_2008/dialogue_boxes/sh-popup_copy_to_clipboard.gif" value="Submit" onclick="SelectCode(' + "'" + "selector_mla" + "'" + ');" /></td></tr>';
			_tip += '</table>';
			_tip += '<textarea id="selector_mla" style="width:1px;height:1px;margin-top:-240px;margin-left:-1000px;">Works Cited list (at end of paper):\n';
			_tip += '\"' + title + '.\"&nbsp;&nbsp;Shmoop ' + subject + '.&nbsp;' + String(euroDate) + '&nbsp;&nbsp;' + origURL + '.\n\nIn-line reference:\n';
			_tip += '(Shmoop ' + subject + ',&nbsp;\"' + title + '\")';
			_tip += '</textarea>';
			//document.getElementById('ModalWindow_CiteShmoop_Content').style.height = '240px';
			if (parseInt(mlaCounter.length) <= 150)
			    addHeight = 105;
			else
			    addHeight = 65

			mlaCount = parseInt(mlaCounter.length) + addHeight;
			//alert(mlaCount + "px");
			//document.getElementById('ModalWindow_CiteShmoop_Content').style.height = mlaCount + "px";
			document.getElementById('ModalWindow_CiteShmoop_Content').style.display = 'block';
			document.getElementById('ModalWindow_CiteShmoop_Content').innerHTML = _tip;
			document.getElementById('spanNoSweat').style.display = 'none';
			document.getElementById('spanDone').style.display = 'block';
			//var mouse = getPosition(CiteDialogEvent);
			break;
		case 'apa':
			/*bug in IE, it does not wrap url's gracefully.  Force a line break after 25 characters*/
			origURL = url;
			/*wrkURL = url.substring(0, 25);
			wrkURL += "<br/>";
			wrkURL += url.substring(25);
			url = wrkURL;
			*/
			//alert("BEFORE " + urlMarkup);
			//get length of url
			urlLen = url.length;
			numberOfTimesToWrap = Math.round(urlLen / 25);

			startingValue = 0;
			endingValue = 25;
			for(z=1; z<= numberOfTimesToWrap; z++)
			{
				wrkURL += url.substring(startingValue, endingValue);
				wrkURL += "<br/>";
				startingValue = endingValue;
				endingValue += 25;
			}
			//alert(wrkURL);
			wrkURL += url.substring(startingValue);
			url = wrkURL;

			document.getElementById('mla_Message').style.display = 'none';
			document.getElementById('ModalWindow_CiteShmoop_Content').style.backgroundColor = '#feface';
			apaCounter =  "Shmoop " + subject + ". " + title  + " Retrieved " + usDate + ", from  " + urlMarkup;
			//alert("APA COUNTER " + apaCounter.length);
			//alert(apaCounter);
			year = usDate.split(" ");

			_tip = '<table id="ModuleWindow_CiteShmoop_TableCitation" cellpadding="0" cellspacing="0" border="0">';
			_tip +=	'<tr><td><strong> References section (at end of paper):</strong><br/><br/></td></tr>';
		        _tip += '<tr style="text-align: left;"><td><span>Shmoop Editorial Team. (November 11, 2008). <em>' + title  + '</em>. </span><span>Retrieved ' + usDate + ', from </span><span>'  + url + '</span></td></tr>';
			_tip +=	'<tr><td><br/><strong>In-line reference:</strong><br/><br/></td></tr>';
			_tip +=	'<tr style="text-align: left;"><td>(Shmoop Editorial Team, 2008).</td></tr>';
			//_tip +=	'<tr><td align="right"><input style="border: 0px;" type="image" src="/media/07_2008/dialogue_boxes/sh-popup_copy_to_clipboard.gif" value="Submit" onclick="SelectCode(' + "'" + "selector_mla" + "'" + ');" /></td></tr>';
			_tip +=	'</table>';
			_tip +=	'<textarea id="selector_mla" style="width:1px;height:1px;margin-top:-240px;margin-left:-1000px;">References section (at end of paper):\n';
			_tip +=	'Shmoop ' + subject + '.&nbsp;&nbsp;' + title + '.&nbsp;&nbsp;Retrieved ' + String(usDate);
			_tip +=	', from &nbsp;&nbsp;' + origURL + '\n\nIn-line reference:\n';
			_tip +=	'(Shmoop ' + subject + ',&nbsp;&nbsp;' + year[2] + ')';
			_tip +=	'</textarea>';
			//document.getElementById('mla_Message').style.marginTop = '-85px';

			if (parseInt(apaCounter.length) <= 150)
			    addHeight = 90;
			else
			    addHeight = 30;

			apaCount = parseInt(apaCounter.length) + addHeight;
			//alert(apaCount + "px");
			//document.getElementById('ModalWindow_CiteShmoop_Content').style.height = apaCount + 'px';
			//document.getElementById('ModalWindow_CiteShmoop_Content').style.height = '220px';
			document.getElementById('ModalWindow_CiteShmoop_Content').style.display = 'block';
			document.getElementById('ModalWindow_CiteShmoop_Content').innerHTML = _tip;
			document.getElementById('spanNoSweat').style.display = 'none';
			document.getElementById('spanDone').style.display = 'block';

			break;
		case 'chicago':
			/*bug in IE, it does not wrap url's gracefully.  Force a line break after 25 characters*/
			origURL = url;
			/*wrkURL = url.substring(0, 25);
			wrkURL += "<br/>";
			wrkURL += url.substring(25);
			url = wrkURL;*/

			urlLen = url.length;
			numberOfTimesToWrap = Math.round(urlLen / 25);

			startingValue = 0;
			endingValue = 25;
			for(z=1; z<= numberOfTimesToWrap; z++)
			{
				wrkURL += url.substring(startingValue, endingValue);
				//wrkURL += "<br/>";
				startingValue = endingValue;
				endingValue += 25;
			}
			//alert(wrkURL);
			wrkURL += url.substring(startingValue);
			url = wrkURL;

			document.getElementById('mla_Message').style.display = 'none';
			document.getElementById('ModalWindow_CiteShmoop_Content').style.backgroundColor = '#feface';
			chicagoCounter =  "Shmoop " + subject + ".  " + "'" + title  + "'" + ",  " + url + "  (" + euroDate + ")";
			//alert("CHICAGO COUNTER " + chicagoCounter.length);

			_tip = '<table id="ModuleWindow_CiteShmoop_TableCitation" cellpadding="0" cellspacing="0" border="0">';
			_tip += '<tr"><td><strong>Bibliography (at end of paper):</strong><br/><br/></td></tr>';
			_tip +=	'<tr style="text-align: left;"><td>Shmoop Editorial Team</span>.&nbsp;&nbsp;\"' + title +  '.\"&nbsp;&nbsp;<span><em>Shmoop University, Inc.</em> 11 November 2008. ' + url + '</span><span>&nbsp;&nbsp;(accessed '  + usDate + ').</span></td></tr>';
			_tip +=	'<tr><td><br/><strong>Footnote:</strong><br/><br/></td></tr>';
			_tip +=	'<tr style="text-align: left;"><td><sup>1</sup>Shmoop Editorial Team,&nbsp;&nbsp;\"' + title +  ', \"<span ><em>Shmoop University, Inc.,</em> 11 November 2008, ' + url + '</span><span >&nbsp;&nbsp;(accessed '  + usDate  + ').</span></td></tr>';
			//_tip += '<tr><td align="right"><input style="border: 0px;" type="image" src="/media/07_2008/dialogue_boxes/sh-popup_copy_to_clipboard.gif" value="Submit" onclick="SelectCode(' + "'" + "selector_mla" + "'" + ');" /></td></tr>';
			_tip +=	'</table>';
			_tip +=	'<textarea id="selector_mla" style="width:1px;height:1px;margin-top:-240px;margin-left:-1000px;">Bibliography (at end of paper):\n';
			_tip +=	'Shmoop ' + subject + '.&nbsp;&nbsp;\"' + title + '.\"&nbsp;&nbsp;' + origURL + '&nbsp;&nbsp;(' + String(euroDate) + ').';
		        _tip +=	'\n\nFootnote:\n';
			_tip +=	'Shmoop ' + subject + ',&nbsp;&nbsp;\"' + title + '\",&nbsp;&nbsp;'+ origURL + '&nbsp;&nbsp;(' + euroDate + ').';
			_tip +=	'</textarea>';

			if (parseInt(chicagoCounter.length) <= 150)
			    addHeight = 135;
			else
			    addHeight = 105;

			chicagoCount = parseInt(chicagoCounter.length) + addHeight;
			//alert(chicagoCount + "px");
			//document.getElementById('ModalWindow_CiteShmoop_Content').style.height = chicagoCount + 'px';
			//document.getElementById('ModalWindow_CiteShmoop_Content').style.height = '295px';
			document.getElementById('ModalWindow_CiteShmoop_Content').style.display = 'block';
			document.getElementById('ModalWindow_CiteShmoop_Content').innerHTML = _tip;
			document.getElementById('spanNoSweat').style.display = 'none';
			document.getElementById('spanDone').style.display = 'block';
			break;
		case 'select':
		    ShowCiteShmoopDialogue();
		    break;

	}
}

var CiteDialogEvent;
function ShowCiteShmoopDialogue()
{

	//CiteDialogEvent = e;
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'block';
	document.getElementById('mla_Message').style.display = 'none';
	document.getElementById('citationStyle').selectedIndex = 0;
	document.getElementById('ModalWindow_CiteShmoop_DivCloseTip').style.marginTop = '0px';
	document.getElementById('ModalWindow_CiteShmoop_DivCloseTip').height = '10px';

	document.getElementById('ModalWindow_CiteShmoop_Content').style.backgroundColor = '#ffffff';

	var output;
	document.getElementById('ModalWindow_CiteShmoop_Content').innerHTML = '';
	document.getElementById('spanNoSweat').style.display = 'block';
	document.getElementById('spanDone').style.display = 'none';
	document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';
}

var CreateStickiesDialogEvent;

function ShowCreateStickiesDialogue()
{
	// hide all other boxes but display 'create stickies' only if user logged in

	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';

	if(loggedInObject.getStatus()) {
		document.getElementById('ModalWindow_CreateStickies').style.display = 'block';
	}
	else
	{
		var d = new LoginDialog();
		d.message = "You must be logged in in order to create stickies";
		d.onLoggedIn = function()
		{
			ShowCreateStickiesDialogue();
		} 
		d.create();
	}
}

/*function ShowCreateStickiesContent(title, url, type)
{
	if (ShmoopUser_auth == false) {
		/*var d = new LoginDialog();
		d.message = "You must log in in order to use stickies";
		d.create();
		//MOOdalBox.open("javascript:display_auth_panel(false, 'refreshStickies(true)')", "", "");
	} else {
		//refreshStickies(false);
	}
}*/

var DictionaryDialogEvent;
function ShowDictionaryDialogue()
{
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'block';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';
	OpenDictionary();
	//ShowDictionaryContent(e);
}

function ShowDictionaryContent()
{
	//me.stopPropagation();
//	OpenDictionary(e);
}

var MyFoldersDialogEvent;
var LoginAttempts = 0;
function ShowMyFoldersDialogue(title, url, type)
{
	hideAllDialogs();
	if (loggedInObject.getStatus())
	{
		document.getElementById('ModalWindow_MyFolders').style.display = 'block';
		refreshMyFolders();
	}
	else
	{
		var d = new LoginDialog();
		d.message = 'You must log in to use My Folders';
		d.onLoggedIn = function() {
			ShowMyFoldersDialogue('','','');
		}
		d.create();
		LoginAttempts++;
	}
}

function hideUserDialogs()
{
	if (document.getElementById('ModalWindow_CreateStickies')) {
		document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	}
	if (document.getElementById('ModalWindow_MyFolders')) {
		document.getElementById('ModalWindow_MyFolders').style.display = 'none';
	}
}

function hideAllDialogs()
{
	if (document.getElementById('ModalWindow_CiteShmoop')) {
		document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	}
	if (document.getElementById('ModalWindow_Dictionary')) {
		document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	}
	hideUserDialogs();
}

var u= window.location.href;
var t= document.title;
var share_window = null;

function social_network_click(_group)
{
	switch(_group)
	{
		case "facebook":
			var facebookURL = "http://www.facebook.com/sharer.php?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t);
			share_window = window.open(facebookURL,"sharer","toolbar=0,status=0,width=626,height=436");
			break;
		case "twitter":
			share_window = window.open("about:blank", "twitter", "toolbar=no,width=700,height=400");
			GetBitly_Ajax(u);
			break;
	}
}

function GetBitly_Ajax(u)
{
	var url = "/ajax/ShortenURL/?long_url="+u;
	new Ajax.Request(url, { onComplete:GetBitly_Ajax_Response } );
}

function GetBitly_Ajax_Response(_response)
{
	var twitterURL = "http://twitter.com/home?status=Reading%20" + encodeURIComponent(t) + "%20" + _response.responseText;
	//update share_window with twitter URL
	share_window.location.href = twitterURL;
}

function ReturnToRest(e){
	if ($('ModalWindow_Dictionary'))
	{
		if ($('ModalWindow_Dictionary').style.display == 'block')
		{
			OpenDictionary();
		}
	}
}


/*  START KITTIE.JS */
	var selected_kittie_index;

	function DestroyAddKittieText(){
       //alert("HEY");
        if(ModalFunctionFire == false){
			//alert("HEY");
			try{
				document.getElementById('span_kittie').style.display = 'block';
				document.getElementById('txt_kittie_title').style.display = 'none';
				document.getElementById('div_blank_kittie').style.display = 'block';
			}catch(err){
				//nothing
			}
        }
    }

    function DisplayCreateKittie(_e)
    {
    	var x = Event.pointerX(_e);
    	var y = Event.pointerY(_e);

		var gutter = $('page').positionedOffset()['left'];

		// arbitrary adjustment
		var lo = (x-25-gutter) + 'px';
		// dialogue height is 120px, bubbles height is 35px
		var to = (y-120-35) + 'px';

		ShowCreateFoldersDialogue(lo, to);
    }

	var tmp_addtokittie_id = null;
	function AddToKittie(e, _id)
	{
		var mouse = getPosition(e);
		// arbitrary adjustment
		var lo = (mouse.x-25) + 'px';
		// dialogue height is 120px, bubbles height is 35px
		var to = (mouse.y-120-35) + 'px';
		ShowFoldersDialogue(_id, 'clipping', lo, to);
	}

	function SaveItemToFolder(_id, _tp, _enc)
	{
		// don't submit with empty values
		if(!_enc.match(/^\s*$/))
		{
			var url = '/ajax/AddToFolder?';
			url += 'item_token='+_id;
			url += '&item_type='+_tp;
			url += '&folder_enc='+encodeURIComponent(_enc);

			if(_tp == 'clipping')
			{
				url += '&item_id='+ShmoopObject_id;
				url += '&item_subject='+ShmoopObject_genus;
				url += '&item_section='+ShmoopObject_type;

				if(ShmoopObject_fx != undefined)
					url += '&item_fx='+encodeURIComponent(ShmoopObject_fx);
			}
			new Ajax.Request(url, { onComplete:FinishSaveItemToFolder} );
		}
	}

	function FinishSaveItemToFolder(_response)
	{
		// TODO: error check
		if(_response.responseText == 'error')
		{
		}
		else if(_response.responseText.match(/no\smember/i))
		{
			//REDIRECT TO LOGIN PAGE
			RedirectLogin();
		}
		else
		{
			HideFoldersDialogue(_response.responseText);
		}
	}

	function SaveNewFolder(_name, _id, _tp)
	{
		// don't submit empty or default values
		if(!_name.match(/^\s*$/) && _name != 'Name Your New Folder')
		{
			var url = '/ajax/NewFolder?name='+encodeURIComponent(_name);
			if(_id)
			{
				url += '&item_type='+_tp;
				url += '&item_token='+_id;

				if(_tp == 'clipping')
				{
					url += '&item_id='+ShmoopObject_id;
					url += '&item_subject='+ShmoopObject_genus;
					url += '&item_section='+ShmoopObject_type;
					if(ShmoopObject_fx != undefined)
						url += '&item_fx='+encodeURIComponent(ShmoopObject_fx);
				}

				new Ajax.Request(url, { onComplete:FinishSaveNewFolderContent });
				/*var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
				AjaxResponseMap.mapRequest(xhrcall, FinishSaveNewFolderContent, _name);
				//var xhrcall = new Ajax(url, {onComplete:FinishSaveNewFolderContent}).request();
				xhrcall.request();*/
			}
			else
			{
				//var xhrcall = new Ajax(url, {onComplete:FinishSaveNewFolder}).request();
				new Ajax.Request(url, { onComplete:FinishSaveNewFolder });
			}
		}
	}

	function FinishSaveNewFolderContent(_response)
	{
		_response = _response.responseText;
		// TODO: error && duplicate check
		if(_response == 'error')
		{
		}
		else if(_response == 'redundant')
		{
		}
		else if(_response.match(/no\smember/i))
		{
			//REDIRECT TO LOGIN PAGE
			RedirectLogin();
		}
		else
		{
			HideFoldersDialogue(this);
			document.getElementById('ModalWindow_ChooseFolder_Select').innerHTML = _response;
		}
	}

	function FinishSaveNewFolder(_response)
	{
		// TODO: error && duplicate check
		if(_response == 'error')
		{
		}
		else if(_response == 'redundant')
		{
			HideFoldersDialogue();
		}
		else
		{
			window.location.reload(false);
		}
	}


    function GetMyKitties_Ajax(){
		var url = '/ajax/template/rightblock?fx=get_mykitties';
		//var xhrcall = new Ajax(url, {update:'ModalWindow_AddToKittie_Detail'}).request();
		new Ajax.Updater('ModalWindow_AddToKittie_Detail', url, {});
    }

    function DisplayKittieStartBox(){
    	if(!loggedInObject.getStatus()) {
		//if(ShmoopUser_auth != true){
			//alert('need to auth');
			//open the login window and break
			Modal_Open('Login', null, null, 'btn_Login');
			return;
		}
    	document.getElementById('div_startkittie').style.display = 'block';
    	document.getElementById('div_startkittie_title').innerHTML = 'Enter a name for your new folder...';
    }

    var tmp_startkittie_title = null;
    function StartKittie(){
		var title = document.getElementById('txt_startkittie_title');

		if(title.value == '' || title.value == 'Title'){
			error = true;
			title.style.borderColor = 'red';
			return;
		}

		//now check to see if the name exists for the user
		CheckKittie_Ajax(title.value);
//		StartConversation_Ajax(title.value, body.value);
    }


    function CheckKittie_Ajax(_title){
    	tmp_startkittie_title = _title;
		_title = encodeURI(_title);
		var url = '/ajax/template/rightblock?fx=check_kittie_name&title='+ _title;
		//var xhrcall = new Ajax(url, {onComplete:CheckKittie_Ajax_Response}).request();
		new Ajax.Request(url, { onComplete:CheckKittie_Ajax_Response });
    }


	function CheckKittie_Ajax_Response(_response){
		_response = _response.responseText.replace(/^\s*|\s*$/g, '');
		if(_response == "error"){
			alert("there was an error");
		}else{
			if(_response == 'true'){
				alert('Folder ' + tmp_startkittie_title + ' already exists');
			}else{
//				alert('can add it');
				CreateKittie_Ajax(tmp_startkittie_title);
			}
//			document.getElementById('div_conversation_results').innerHTML = _response + document.getElementById('div_conversation_results').innerHTML;
		}
	}


    function CreateKittie_Ajax(_title){
    	tmp_startkittie_title = _title;
		_title = encodeURI(_title);
		var url = '/ajax/template/rightblock?fx=create_kittie&title='+ _title;
		//var xhrcall = new Ajax(url, {onComplete:CreateKittie_Ajax_Response}).request();
		new Ajax.Request(url, { onComplete:CreateKittie_Ajax_Response });
    }


	function CreateKittie_Ajax_Response(_response){
		if(_response.responseText == "error"){
			alert("there was an error");
		}else{
			//on create success
			//	1:  update the right div
			//SwitchRightBlock('Kitties');

			//	2:  update the pulldown
			GetMyKitties_Ajax();
		}
	}

	//04.016.2008 - npe!
	function CreateUserKittie_Ajax(){
		var _title = document.getElementById('txt_startkittie_title').value;
		tmp_startkittie_title = _title;
		_title = encodeURI(_title);
		var url = '/ajax/template/rightblock?fx=create_kittie&title='+ _title;
		//var xhrcall = new Ajax(url, {onComplete:CreateUserKittie_Ajax_Response}).request();
		new Ajax.Request(url, { onComplete:CreateUserKittie_Ajax_Response });
	}

	//04.016.2008 - npe!
	function CreateUserKittie_Ajax_Response(_response){
		_response = _response.responseText.replace(/^\s*|\s*$/g, '');
		if(_response == "error"){
			alert("There was an error");
		}else if (_response == 'exists'){
			alert('Folder ' + tmp_startkittie_title + ' already exists');
		}
		else{
			//window.location.reload(false);
			GetUserKitties_Ajax();
		}
	}

	//04.016.2008 - npe!
    function GetUserKitties_Ajax(){
		var url = '/ajax/template/rightblock?fx=Kitties';
		//var xhrcall = new Ajax(url, {update:'Rendered_kitties'}).request();
		new Ajax.Updater('Rendered_kitties', url, {});
    }

	function AddItemToKittie(_obj){
		firemodalevent(true);
		AddItemToKittie_Ajax(_obj.value, tmp_addtokittie_id);
	}



    function AddItemToKittie_Ajax(_kittie_id, _item_id){
		var url = '/ajax/template/rightblock?fx=add_item_to_kittie&item_id='+ _item_id +'&item_genus='+ShmoopObject_genus+'&kittie_id='+ _kittie_id;
		//var xhrcall = new Ajax(url, {onComplete:AddItemToKittie_Ajax_Response}).request();
		new Ajax.Request(url, { onComplete:AddItemToKittie_Ajax_Response });
    }


	function AddItemToKittie_Ajax_Response(_response){
		if(_response.responseText == "error"){
			alert("there was an error");
		}else{
			//on create success
			//	1:  update the right div
			//SwitchRightBlock('Kitties');

			//	2:  update the modal window
			//GetMyKitties_Ajax();
			document.getElementById('div_addtokittie_info').innerHTML = _response.responseText;
		}
	}

	var KittieDeleteMouseOver = false;
	function ToggleKitties(){
		if(KittieDeleteMouseOver != true){
			//alert('!true');
		}
	}

	function firekittiedeleteevent(_state){
		KittieDeleteMouseOver = _state;
	}

	function confirmDeleteKittie(_e, _enc)
	{
		var mouse = getPosition(_e);

		var _el = document.getElementById('e'+_enc);
		// dialoge width is 300px, arbitrary additional adjustment
		var lo = (mouse.x-200) + 'px';
		// dialogue height is 120px, bubbles height is 35px
		var to = (mouse.y-120-15) + 'px';
		ShowDeleteDialogue('Folder', DeleteKittie, function(){}, _enc, lo, to);
	}



    function DeleteKittie(_enc){
		var url = '/ajax/DeleteFolder?enc='+ _enc;
		new Ajax.Request(url, { onComplete:DeleteKittie_Response });
/*
		var xhrcall = new Ajax(url, {onComplete:DeleteKittie_Response}).request();
		AjaxResponseMap.mapRequest(xhrcall, DeleteKittie_Response, window);

		xhrcall.request();
*/
    }


	function DeleteKittie_Response(_response){
		if(_response.responseText == "error"){
			alert("there was an error");
		}
		else if(_response.responseText.match(/ok=.+/)){
			var enc = _response.responseText.split('=')[1];
			if ($('s_' + enc))
			{
				$('s_' + enc).remove();
				$('e_' + enc).remove();
			}
		}
	}

	var tmp_deletedetail_node;
    //01.16.2008 - bt
    function DeleteKittieDetail(_kittie_encrypt, _encrypt, _tmp_node){
    	if(confirm('This will remove the item from your folder, can you dig it?'))
    	{
			tmp_deletedetail_node = _tmp_node
			var url = '/ajax/template/rightblock?fx=delete_kittie_detail&ke='+ _kittie_encrypt+'&e='+ _encrypt;
			//var xhrcall = new Ajax(url, {onComplete:DeleteKittieDetail_Response}).request();
			new Ajax.Request(url, { onComplete:DeleteKittieDetail_Response });
		}
    }

    //01.16.2008 - bt
	function DeleteKittieDetail_Response(_response){
		_response = _response.responseText;
		if(_response == "error"){
			alert("there was an error");
		}else{
			var idarr = tmp_deletedetail_node.parentNode.id.split('_');
			var pid = idarr[idarr.length-1];
			document.getElementById('span_item_qty_'+pid).innerHTML = tmp_deletedetail_node.parentNode.childNodes.length-1;
			tmp_deletedetail_node.parentNode.removeChild(tmp_deletedetail_node);
		}
	}

	function DisplayKittieDetailBox(_encrypt){
		ToggleKitties();
    }

    function ToggleDiv(divToToggle, _override){
		if(ModalFunctionFire == false || _override == true){
			var divName = document.getElementById(divToToggle);

			if(divName.style.display == 'none')
			{
				divName.style.display = 'block';
			}
			else  if(divName.style.display == 'block')
			{
				divName.style.display = 'none';
			}
		}
	}
/*  END KITTIE.JS */

/*  START STICKIES.JS */
function refreshStickies(showBox)
{
	//BT:  Needed to add to prevent refresh stickie from processing when page loads.
	//	Behavior that occured was the following:  Page loads, Tool Bar displays
	//	page is redirected to login page.
	if(loggedInObject.getStatus())
	{
		if (ShmoopObject_id)
		{
			var params = 'item_id='+ShmoopObject_id;
			params += '&item_subject='+encodeURIComponent(ShmoopObject_genus);
			params += '&item_section='+encodeURIComponent(ShmoopObject_type);

			if(ShmoopObject_fx != undefined)
				params += '&item_fx='+encodeURIComponent(ShmoopObject_fx);

			var url = '/ajax/Stickies?' + params;
			/*var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
			AjaxResponseMap.mapRequest(xhrcall, finishRefreshingStickies, window);*/

			if (typeof(showBox) == 'boolean' && showBox == true) {
				//$('ModalWindow_CreateStickies').style.display = 'block';
				$('ModalWindow_CreateStickies').show();
			}

			new Ajax.Request(url, { onComplete:finishRefreshingStickies });
		}
	}
}

Event.observe(window, 'load', refreshStickies);

function finishRefreshingStickies(_response)
{
	/*if(_response.match(/no\smember/i))
	{
		// server probably timed out our session, clean up by calling signout() then login again
		signout();
		MOOdalBox.open("javascript:display_auth_panel(false, 'refreshStickies(true)')", "", "");
	}
	else*/

	 if(_response.responseText != 'error')
	{
		// expecting to evaluate an array of stickies called ss
		eval(_response.responseText);
		var c = document.getElementById('stick_container');
		for(var i=0; i<ss.length; ++i)
		{
			// throw response into empty dom element to force parse
			var el = document.createElement('span');
			el.innerHTML = decodeURIComponent(ss[i]);
			el = el.firstChild;
			var f = false;

			// check for stickie existence, update only if found
			for(var j=0; j<c.childNodes.length; j++)
			{
				if(c.childNodes[j].id == el.id)
				{
					c.replaceChild(el, c.childNodes[j]);
					f = true;
					break;
				}
			}

			// if stickie is not found (new), add
			if(!f)
				c.appendChild(el);

			AutoSaveStickie.mapStickie(el.id);
		}
	}
}

function newStickie()
{
	if($('stick_container').visible())
	{
		var params = 'item_id='+ShmoopObject_id;
		params += '&item_subject='+encodeURIComponent(ShmoopObject_genus);
		params += '&item_section='+encodeURIComponent(ShmoopObject_type);

		//if(ShmoopObject_fx != undefined)
		//	params += '&item_fx='+encodeURIComponent(ShmoopObject_fx);

		var url = '/ajax/NewStickie?' + params;

		new Ajax.Request(url, { onComplete:finishNewStickie });

	}
}

function finishNewStickie(_response)
{
	/*if(_response.match(/no\smember/i))
	{
		// server probably timed out our session, clean up by calling signout() then login again
		signout();
		MOOdalBox.open("javascript:display_auth_panel(false, 'newStickie()')", "", "");
	}
	else*/
	if(_response.responseText != 'error' && _response.responseText != 'incomplete')
	{
		var tbl = eval(decodeURIComponent(_response.responseText));
		var el = Builder.node('span', {});
		el.update(tbl);
		el = el.firstChild;
		$('stick_container').appendChild(el);
		//el.place('stick_container');

		// position relative to scroll
		var dim = GetWindowDimensions();
		//el.setStyle({ top:'-10px', left:'-10px'});

		var top = parseInt(el.style.top);
		var left = parseInt(el.style.top);
		var topval = top + dim.scrollY;
		el.style.top = topval + 'px';

		AutoSaveStickie.mapStickie(el.id);
		// adjustment for bubbles over save button on stickie

		var to = (topval - 20) + 'px';
		var lo = (left + 55) + 'px';
		ShowFoldersDialogue(el.id, 'stickie', lo, to);
	}
}

function updateMyFoldersDropdown()
{
	var url = '/ajax/myFoldersDropdown';
	/*var xhrcall = new Ajax(url, {onComplete:AjaxResponseMap.forwardResponse});
	AjaxResponseMap.mapRequest(xhrcall, finishUpdateMyFoldersDropdown, window);

	xhrcall.request();*/
	new Ajax.Request(url, { onComplete: finishUpdateMyFoldersDropdown });
}

function finishUpdateMyFoldersDropdown(_response)
{
	if(_response.responseText.match(/no\smember/i))
	{
		// server probably timed out our session, clean up by calling signout() then login again
		/*signout();
		MOOdalBox.open("javascript:display_auth_panel(false, 'updateMyFoldersDropdown()')", "", "");*/

		return false;
	}

	if (document.getElementById('ModalWindow_ChooseFolder_Select').length > 0) {
		document.getElementById('ModalWindow_ChooseFolder_Select').length = 0;
	}

	if (_response.responseText != 'error' && _response.responseText != 'NO FOLDER') {
		opts = eval('(' + _response.responseText + ')');
		for (i in opts) {
			new_opt = document.createElement("option");
			new_opt.value = i;
			new_opt.text = opts[i];
			try {
				$('ModalWindow_ChooseFolder_Select').add(new_opt);
			} catch(ex) {
				$('ModalWindow_ChooseFolder_Select').add(new_opt, null);
			}
		}
	}

	if ($('ModalWindow_ChooseFolder_Select').length > 1) {
		$('ModalWindow_CreateFolder').style.display = 'none';
		$('ModalWindow_ChooseFolder').style.display = 'block';
	}
}

function saveStickie(_id)
{
	var el = document.getElementById(_id);
	var bin = document.getElementById(_id+'_input');

	if(bin.value != '')
	{
		var params = 'body='+encodeURIComponent(bin.value);
		params += '&px='+parseInt(el.style.left);
		params += '&py='+parseInt(el.style.top);
		params += '&enc='+el.id;

		var url = '/ajax/SaveStickie?' + params;

		document.getElementById(_id+'_saving').innerHTML='Saving...';
		new Ajax.Request(url, { onComplete:function(e)
			{
				finishSavingStickie(e, el.id);
			}
		});
	}
}

function finishSavingStickie(_response, id)
{
	if(_response.responseText.match(/ok=.+/))
	{
		setTimeout('document.getElementById("'+ id +'_saving").innerHTML="Saved at '+currentTime()+'"', 1000);
		AutoSaveStickie.mapStickie(id);
	}
}

function confirmDeleteStickie(_id)
{
	var dim = $(_id).positionedOffset();
	var top = dim['top'] + 'px';
	var left = (dim['left'] + 160) + 'px';
	ShowDeleteDialogue('Stickie', deleteStickie, enableStickieControls, _id, left, top);
	disableStickieControls(_id);
}

function disableStickieControls(_id)
{
	document.getElementById(_id+'_controls').style.visibility = 'hidden';
}

function enableStickieControls(_id)
{
	document.getElementById(_id+'_controls').style.visibility = 'visible';
}

function deleteStickie(_id)
{
	var _el = document.getElementById(_id);
	var params = 'enc='+_el.id;

	var url = '/ajax/DeleteStickie?' + params;
	new Ajax.Request(url, {
		onComplete:function(e) {
			finishDeletingStickie(e, _id);
		}
	});
}

function finishDeletingStickie(_response, id)
{
	if(_response.responseText.match(/ok=[0-9a-zA-Z]+/i))
	{
		$(id).remove();
	}
}

function bringToTop(_el)
{
	var container = document.getElementById('stick_container');
	if(container.lastChild != _el)
	{
		container.removeChild(_el);
		container.appendChild(_el);
	}
}

function makeStickieDraggable(element)
{
	new Draggable(element,
	{
		starteffect:null,
		endeffect:null,
		onEnd:saveStickiePosition
	});
}

function saveStickiePosition(draggable, event)
{
	var s = draggable.element;
	if (s.id != 'stick_new')
	{
		var pos = s.positionedOffset();
		var params = 'enc=' + s.id + '&px=' + pos['left'] + '&py=' + pos['top'];
		var url = '/ajax/SaveStickie?' + params;
		new Ajax.Request(url, {});

		if(Prototype.Browser.IE)
		{
			document.selection.clear();
		}
		else
		{
			window.getSelection().removeAllRanges();
		}
	}
}


function focusOnInput(_e, _id)
{
	var el = document.getElementById(_id);
	AutoSaveStickie.activeStickie(el)
	bringToTop(el);
	showInputState(_id);
}

function blurOnInput(_e, _id)
{
	AutoSaveStickie.scheduleSave(true);
	hideInputState(_id);
}

function showInputState(_id)
{
	var bin = document.getElementById(_id+'_input');
	if(bin.className != 'stickies_field')
	{
		bin.className = 'stickies_field';
		bin.parentNode.className = 'stickies_field_wrapper';
	}
	bin.focus();
}

function hideInputState(_id)
{
	var bin = document.getElementById(_id+'_input');
	if(bin.className != 'stickies_no_field')
	{
		bin.className = 'stickies_no_field';
		bin.parentNode.className = 'stickies_no_field_wrapper';
	}
}

function showAllStickies()
{
	var container = document.getElementById('stick_container');
	for(var i=0; i<container.childNodes.length; ++i)
		container.childNodes[i].style.display = 'block';
	container.style.display = 'block';
	document.getElementById('img_show_all_stickies').src = '/media/07_2008/toolbar/stickies/at/show_all.gif';
	document.getElementById('img_hide_all_stickies').src = '/media/07_2008/toolbar/stickies/un/hide_all.gif';
}

function hideAllStickies()
{
	document.getElementById('stick_container').style.display = 'none';
	document.getElementById('img_show_all_stickies').src = '/media/07_2008/toolbar/stickies/un/show_all.gif';
	document.getElementById('img_hide_all_stickies').src = '/media/07_2008/toolbar/stickies/at/hide_all.gif';
}

function removeAllStickies()
{
	if ($('stick_container'))
	{
		var container = $('stick_container');
		var total_children = container.childNodes.length;
		for (var i = 0; i < total_children; i++) {
			container.removeChild(container.firstChild);
		}
	}
}

function _AutoSaveStickie()
{
	this.lvm = {};
	this.ae = false;
	this.tid = false;
}

_AutoSaveStickie.prototype.mapStickie = function(_id)
{
	var tEl = document.getElementById(_id+'_input');
	// add last value to map
	var f = false;
	for(var i in this.lvm)
	{
		if(i == _id)
		{
			this.lvm[i] = tEl.value;
			f = true;
			break;
		}
	}

	// if element id not found in value map
	if(!f)
	{
		// add to map
		this.lvm[_id] = tEl.value;

		// set events
		$(tEl).observe('onkeyup', this.scheduleSave);
		//EventMap.mapEvent('onkeyup', this.scheduleSave, this, tEl);
	}
}

_AutoSaveStickie.prototype.activeStickie = function(_el)
{
	this.ae = _el;
}

_AutoSaveStickie.prototype.deactiveStickie = function()
{
	this.ae = false;
}

_AutoSaveStickie.prototype.scheduleSave = function(_override)
{
	if(this.ae)
	{
		var tEl = document.getElementById(this.ae.id+'_input');
		for(var i in this.lvm)
		{
			if(i == this.ae.id && this.lvm[i] != tEl.value)
			{
				if(this.tid)
					clearTimeout(this.tid)

				if(_override == true)
					saveStickie(this.ae.id);
				else
					this.tid = setTimeout('saveStickie(\''+this.ae.id+'\')', 2000);
			}
		}
	}
}

var AutoSaveStickie = new _AutoSaveStickie();

/*  END STICKIES.JS */
