	/*
		dependencies:
			common.js
	*/

		var ActiveModalWindow = '';
		var ModalFunctionFire = false;
		var ModalEscape = false;

		//moved this from dictionary - 12.12.2007 - jw!
		function FireKeyEvent(e){
			keycode = GetKeyCode(e);
//			alert(keycode);
			if(ModalFunctionFire == false){
				//dictionary
				/*if(keycode == 68){
					OpenDictionary(e);
				}

				//search
				if(keycode == 83){
					if(ModalFunctionFire == false){
						OpenSearch();
					}
				}

				//help
				if(keycode == 72){
					if(ModalFunctionFire == false){
						Modal_Open('Help', null, null, 'btn_Help');
					}
				}*/

				//notes
				//if(keycode == 78){
				//	MakeNote(e);
				//}

				//login
				//02.14.2008 - bt
				if(keycode == 76 && ShmoopUser_auth != true){
					if(ModalFunctionFire == false){
						Modal_Open('Login', null, null, 'btn_Login');
					}
				}

				//conversations
				/*if(keycode == 67){
					if(SwitchRightBlock_target != 'Conversations'){
						SwitchRightBlock('Conversations');
					}
				}*/

				//kitties
				/*if(keycode == 75){
					if(SwitchRightBlock_target != 'Kitties'){
						SwitchRightBlock('Kitties');
					}
				}*/
			}

			//escape -- exit
			if(keycode == 27){
				ReturnToRest();
			}
		}


		//new OpenWindow function 10.19.2007 - jw!
		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);

	document.getElementById('ModalWindow_ShmoopTip_Content').innerHTML = _tip;

	var df = document.getElementById('ModalWindow_ShmoopTip');
	// dialogue height is 120px, bubbles height is 35px
	df.style.top = (mouse.y-120-35) + 'px';
	// dialoge width is 300px, arbitrary additional adjustment
	if(mouse.x-150 > 0)
		df.style.left = (mouse.x-150) + 'px';
	else
		df.style.left = '10px';
	df.style.display = 'block';
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/*
function LoadLikeThisLikeThat_Ajax(_moduleID, _shortTitle, _subject, _synSubject, _showhide)
{
	if(_moduleID != undefined || _moduleID != null)
	{
		//alert(ShmoopObject_type);
		//alert(_synSubject);
		if(_synSubject == undefined || _synSubject == null)
			_synSubject = "";
		if(_showhide == undefined || _showhide == null)
			_showhide = "none";
			//var ajaxUrl = '/ajax/LikeThis/LikeThis?fx=rightside&subject='+_subject+'&id='+_moduleID+'&shorttitle='+_shortTitle+'&subject='+_subject;
			//var myRequest = new Request({url: ajaxUrl, onSuccess: LoadLikeThisLikeThat_Ajax_Response, method: 'post', data: {subject: _subject}}).send(); // Fire it

		var url = '/ajax/LikeThis/LikeThis?fx=rightside&type='+ShmoopObject_type+'&subject='+_subject+'&id='+_moduleID+'&shorttitle='+_shortTitle+'&modSyn='+_synSubject+'&showhide='+_showhide;
		var xhr = new Ajax(url, {onComplete:LoadLikeThisLikeThat_Ajax_Response, method: 'get' }).request();
	}
}

function LoadLikeThisLikeThat_Ajax_Response(_response)
{
	if(_response== "no member")
		alert("You're not signed in!!!")
	else if(_response == "error"){
		//document.getElementById('divImageError').innerHTML = "<div style=\"background:white;font-size:10pxborder:1px red solid;padding:10px;margin-top:10px;\">Error Approving Image.  Please contact Tech Team.</div>";
	}
	else
	{
		//alert(_response);
		document.getElementById('divLikeThisContent').innerHTML = _response;
	}
}

function DisplayAllGenreModules(_synSubject)
{

	document.getElementById("spin").style.display = 'block';
	if(ShmoopModuleID != undefined || ShmoopModuleID != null)
	{
		if(document.getElementById(_synSubject) == null)
		{
			LoadLikeThisLikeThat_Ajax(ShmoopModuleID, ShmoopShortTitle, ShmoopSubject, _synSubject, 'block');
		}
		else
		{
			LoadLikeThisLikeThat_Ajax(ShmoopModuleID, ShmoopShortTitle, ShmoopSubject, _synSubject, 'none');
		}
	}
}
window.addEvent('domready', function(){
	if(ShmoopModuleID != undefined || ShmoopModuleID != null)
	{
		//LOAD RIGHT IF  YOU LIKE THIS
		LoadLikeThisLikeThat_Ajax(ShmoopModuleID, ShmoopShortTitle, ShmoopSubject);
	}
});*/

function CitationStyle_OnChange(value, title, subject, euroDate, usDate, url){
	//urlMarkup = "&lt;" + url + "&gt;";
	urlMarkup = url;
	wrkURL = "";
	//trim all spaces
	//alert(title)
	title = title.trim();
	subject = subject.trim();
	//alert(title.replace(/%/ig, "\'"));
	//alert(subject);
	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;

	}
}

function ShowShareLinkContent(title, url, type)
{
	var _tip = "";
	title = title.trim();
	title = title.replace(/%/ig, "\'");

	var link = '&lt;a href=\"' + url +  '\" title=\"' + title.trim() + '\"&gt;' + title + '&lt;/a&gt;';

	//get len of url plus markup
	var urlMarkupLen = link.length;

	//get len of url
	var urlLen = url.length;

	var numberOfURLMarkupRows = Math.round(urlMarkupLen / 30);
	var numberOfURLRows = Math.round(urlLen / 30);

	var startingValue = 0;
	var endingValue = 30;
	var wrkURL = "";
	/*for(z=1; z<= numberOfURLMarkupRows; z++)
	{
		wrkURL += link.substring(startingValue, endingValue);
		wrkURL += "\n";
		startingValue = endingValue;
		endingValue += 30;
	}*/

	//ad 2 extra lines to the num
	numberOfURLMarkupRows = numberOfURLMarkupRows+2;
	numberOfURLRows = numberOfURLRows + 2;
	wrkURL += link.substring(startingValue);
	var combinedURL = wrkURL;

	if(type == 'link'){
		_htmlTip = '<table id="ModuleWindow_LinkPage_TableCitation" style="border: 0px solid black;" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr>';
		_htmlTip +=	'<tr style="text-align: left;"><td><textarea class="textAdjust"  wrap="off" onclick="this.select();" style="border: 0px;margin:0px;overflow:hidden;font-size:12px;font-weight:normal;">' + link + '</textarea></td></tr>';
		_htmlTip += '</table>';

		document.getElementById('divGrabHTML').innerHTML = _htmlTip;

	}
	else{
		_htmlTip = '<table id="ModuleWindow_SharePage_TableCitation" style="border: 0px solid black;" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr>';
		_htmlTip +=	'<tr style="text-align: left;"><textarea class="textAdjust" wrap="off" onclick="this.select();" style="border: 0px;margin:0px;overflow:hidden;font-size:12px;font-weight:normal;">' + url + '</textarea></td></tr>';
		_htmlTip += '</table>';
		document.getElementById('divCopyLink').innerHTML = _htmlTip;
	}


	if(type == 'link'){
		_urlTip = '<table id="ModuleWindow_LinkPage_TableCitation" style="border: 0px solid black;" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr>';
		_urlTip +=	'<tr style="text-align: left;"><td><textarea class="textAdjust" wrap="off" onclick="this.select();" style="border: 0px;margin:0px;overflow:hidden;font-size:12px;font-weight:normal;">' + url + '</textarea></td></tr>';
		_urlTip += '</table>';
		document.getElementById('divGrabURL').innerHTML = _urlTip;
	}
	//else{
	//	_urlTip = '<table id="ModuleWindow_SharePage_TableCitation" style="border: 0px solid black;" cellpadding="0" cellspacing="0" border="0"><tr><td></td></tr>';
	//	_urlTip +=	'<tr style="text-align: left;"><td>' + url + '</td></tr>';
	//	_urlTip += '</table>';
	//}


}

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_SharePage').style.display = 'none';
	document.getElementById('ModalWindow_LinkPage').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 LinkPageDialogEvent;
function ShowLinkPageDialogue(title, url, type)
{
	document.getElementById('ModalWindow_SharePage').style.display = 'none';
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_LinkPage').style.display = 'block';
	document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';
	ShowShareLinkContent(title, url, type);
}

var SharePageDialogEvent;
function ShowSharePageDialogue(title, url, type)
{
	document.getElementById('ModalWindow_LinkPage').style.display = 'none';
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_SharePage').style.display = 'block';
	document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';
	ShowShareLinkContent(title, url, type);
}

var CreateStickiesDialogEvent;
function ShowCreateStickiesDialogue(title, url, type)
{
	// hide all other boxes but display 'create stickies' only if user logged in
	document.getElementById('ModalWindow_LinkPage').style.display = 'none';
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_SharePage').style.display = 'none';
	if (ShmoopUser_auth == true) {
		document.getElementById('ModalWindow_CreateStickies').style.display = 'block';
	}
	document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';
	ShowCreateStickiesContent(title, url, type);
}

function ShowCreateStickiesContent(title, url, type)
{
	if (ShmoopUser_auth == false) {
		MOOdalBox.open("javascript:display_auth_panel(false, 'refreshStickies(true)')", "", "");
	} else {
		refreshStickies(false);
	}
}

var DictionaryDialogEvent;
function ShowDictionaryDialogue(e)
{
	document.getElementById('ModalWindow_LinkPage').style.display = 'none';
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_SharePage').style.display = 'none';
	document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'block';
	document.getElementById('ModalWindow_MyFolders').style.display = 'none';
	ShowDictionaryContent(e);
}

function ShowDictionaryContent(e)
{
	if (e) {
		var me = new Event(e);
	} else {
		var me = new Event(window.event);
	}
	me.stopPropagation();

	OpenDictionary(e);
}

var MyFoldersDialogEvent;
function ShowMyFoldersDialogue(title, url, type)
{
	// don't show the box unless user logged in
	document.getElementById('ModalWindow_LinkPage').style.display = 'none';
	document.getElementById('ModalWindow_CiteShmoop').style.display = 'none';
	document.getElementById('ModalWindow_SharePage').style.display = 'none';
	document.getElementById('ModalWindow_CreateStickies').style.display = 'none';
	document.getElementById('ModalWindow_Dictionary').style.display = 'none';
	if (ShmoopUser_auth == true) {
		document.getElementById('ModalWindow_MyFolders').style.display = 'block';
	}
	ShowMyFoldersContent(title, url, type);
}

function ShowMyFoldersContent(title, url, type)
{
	if (ShmoopUser_auth == false) {
		MOOdalBox.open("javascript:display_auth_panel(false, 'refreshMyFolders()')", "", "");
	} else {
		refreshMyFolders();
	}
}

var u=location.href;
var t=document.title;
var c= "Look at what I found on Shmoop :-)";


function social_network_click(_group)
{
	switch(_group)
	{
		case "facebook":
			window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t),"sharer","toolbar=0,status=0,width=626,height=436");
			break;
		case "delicious":
			window.open("http://del.icio.us/post?v=4&noui&jump=close&url="+encodeURIComponent(u)+"&title="+encodeURIComponent(t), "delicious","toolbar=no,width=700,height=400");
			break;
		case "stumbleupon":
			window.open("http://stumbleupon.com/submit?url="+encodeURIComponent(u)+"&title="+encodeURIComponent(t), "stumbleupon","toolbar=no,width=700,height=400");
			break;
		case "myspace":
			window.open("http://www.myspace.com/Modules/PostTo/Pages/?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t)+"&c="+encodeURIComponent(c), "myspace","toolbar=no,width=700,height=400");
			break;
		case "digg":
			window.open("http://digg.com/submit?phase=2&url="+encodeURIComponent(u)+"&title="+encodeURIComponent(t)+"&bodytext=Look at what I found on Shmoop today!! :-)" , "Digg","toolbar=no,width=700,height=400");
			break;
		case "twitter":
			//get the bit.ly call
			GetBitly_Ajax(u);
			break;
	}

	return false;
}
function GetBitly_Ajax(u)
{
		var url = "/ajax/ShortenURL/?long_url="+u;
		var xhr = new Ajax(url, {onComplete:GetBitly_Ajax_Response, method: "get"}).request();
}

function GetBitly_Ajax_Response(_response)
{
	if(_response== "no member")
		alert("You\'re not signed in!!!")
	else if(_response == "error"){
	}
	else
	{
		//alert(_response);
		var twitterURL = "http://twitter.com/home?status=Reading " + encodeURIComponent(t) + " - " + _response;
		window.open(twitterURL, "twitter","toolbar=no,width=700,height=400");
	}
}

function fbs_click()
{
	var u=location.href;
	var t=document.title;
	window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t),"sharer","toolbar=0,status=0,width=626,height=436");
	return false;
}
function del_click()
{
	var u= location.href;
	var t= document.title;
	window.open("http://del.icio.us/post?v=4&noui&jump=close&url="+encodeURIComponent(u)+"&title="+encodeURIComponent(t), "delicious","toolbar=no,width=700,height=400");
	return false;
}
function stumble_click()
{

	var u= location.href;
	var t= document.title;
	window.open("http://stumbleupon.com/submit?url="+u+"&title="+encodeURIComponent(t), "stumbleupon","toolbar=no,width=700,height=400");
	return false;
}

function digg_click()
{
	var u=location.href;
	var t=document.title;
	window.open("http://digg.com/submit?phase=2&url="+encodeURIComponent(u)+"&title="+encodeURIComponent(t)+"&bodytext=Look at what I found on Shmoop today!! :-)" , "Digg","toolbar=no,width=700,height=400");
	return false;
}

function myspace_click()
{
	var u= location.href;
	var t= document.title;
	var c= "Look at what I found while shmooping today!! :-)";
	window.open("http://www.myspace.com/Modules/PostTo/Pages/?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t)+"&c="+encodeURIComponent(c), "myspace","toolbar=no,width=700,height=400");
	return false;
}

function ReturnToRest(e){
	if($('ModalWindow_Dictionary') == undefined)
		return;
	if ($('ModalWindow_Dictionary').style.display == 'block') {
		if (window.ie) {
			target = event.srcElement;
			if (typeof(target.onclick) != 'function') {
				// IE (at lease IE6) needs this much time to combine
				// a double click and send us the selected text;
				// without the setTimeout we will go to
				// OpenDictionaru() right after the first click
				setTimeout("OpenDictionary('')", 300);
			}
		} else {
			target = e.target;
			if (typeof(target.onclick) != "function") {
				OpenDictionary('');
			}
		}
	}
}
