

//if (!docshotsWidth) { var docshotsWidth = 500; }else{if (docshotsWidth>document.body.clientWidth)docshotsWidth=document.body.clientWidth-100}
//if (!docshotsHeight) { var docshotsHeight = 350; }else{if (docshotsHeight>document.body.clientHeight)docshotsHeight=document.body.clientHeight-100}
if (!docshotsWidth) { 
	var docshotsWidth = 500; 
}else{
	if (docshotsWidth>1200)docshotsWidth=700;
	if (docshotsWidth<450)docshotsWidth=450;
}
if (!docshotsHeight) {
	var docshotsHeight = 350; 
}else{
	if (docshotsHeight>800)docshotsHeight=500;
	if (docshotsHeight<300)docshotsHeight=300;
}


function docshotsAttachScript(url) {
	var head = document.getElementsByTagName('head').item(0);
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', url);
	head.appendChild(js);
	return false;
}
if (docshotsIsInited!=true){
var docshotsOldOnload = window.onload; 
window.onload = function() { if (docshotsOldOnload) docshotsOldOnload(); DocShots.Init(); }
}
var docshotsLinkClicked = false;
var docshotsMouseovered = false;
var docshotsEls;
var docshotsBindableEls = new Array();
var docshotsQS = '';
var docshotsQSprecheck = '';
var docshotsCounter = 0;
var docshotsTotalCounter = 0;
var docshotsStartIndex = 0;
var JSONreturn;
var docshotsIsInited=false;

var DocShots = {
	mo: null,
	dsWin: null,
	dsIcon: null,
	fadeInt: null,
	fscInt: null,
	currOp: null,
	currHeight: null,
	currWidth: null,
	currX: null,
	currY: null,
	userX: null,
	userY: null,
	el: null,
	lastEl: null,
	elX: null,
	elY: null,
	parentX: null,
	regHeight: docshotsHeight,
	regWidth: docshotsWidth,
	leftCalib: docshotsWidth,
	fullScreened: false,
	winWidth: null,
	winHeight: null,
	tweenXdone: null,
	tweenYdone: null,
	tweenHdone: null,
	tweenWdone: null,
	tweenOpacdone: null,
	tweenScrollYdone: null,
	tweenScrollXdone: null,
	frameInterval: 20,
	animDelta: 60,
	opacDelta: .2,
	dsWinBottom: null,
	dsWinRight: null,
	currScrollY: null,
	currScrollX: null,
	IE: null,
	IEfactor: 4,
	isSame: false,
	elMouse: null,
	lastEL: null,
	moveLeft: false,
	docID: null,
	docUrl: null,
	allowDownloads: 0,
	showRelated: 0,
	showOther: 0,
	moveLeftOffset: 48,
	moveUp: false,
	midTransition: false,
	bodyClickEv: document.onclick,
	oTimeout:0,
	PreloadImages: function() {

		var i = 0;

		imageObj = new Image();

		images = new Array();
		images[0]="BC.png"
		images[1]="BL.png"
		images[2]="BR.png"
		images[3]="btn_fullscn.png"
		images[4]="btn_X.png"
		images[5]="btn-border.gif"
		images[6]="btn-download.png"
		images[7]="docshots.gif"
		images[8]="L_dk_B.png"
		images[9]="L_dk_T.png"
		images[10]="L_lt.png"
		images[11]="R_dk_B.png"
		images[12]="R_dk_T.png"
		images[13]="R_lt.png"
		images[14]="status-bg.png"
		images[15]="TC.png"
		images[16]="title-bg.png"
		images[17]="TL.png"
		images[18]="useDocShots.png"
		images[19]="btn-rss.gif";
		images[20]="btn-print.png";

		for(i=0; i<=20; i++) 
		{
		  imageObj.src="http://i.docstoccdn.com/ds/" + images[i];
		}
	},
	Init: function() {
		setTimeout('DocShots.PreloadImages()',1000);
		isInited = true;
		docshotsEls = document.getElementsByTagName('a');

		var preString = 'http://rest.docstoc.com/upload/UploadFilesFromUrlUniqueGet?Key=' + docshotsKey.replace(/\+/g,"%2B") + '&Ticket=' + docshotsTicket.replace(/\+/g,"%2B");
		var postString = '&ReturnType=JSON&count=';
		var pch='xxxZxxx';
		// find a tags, send info to server
		for (var i = 0; i < docshotsEls.length; i++) {
			fileExtPlus = docshotsEls[i].href.substring(docshotsEls[i].href.lastIndexOf('.'), docshotsEls[i].href.length);
			if (fileExtPlus.lastIndexOf('?') != -1) { fileExtPure = fileExtPlus.substring(0, fileExtPlus.lastIndexOf('?')); } else { fileExtPure = fileExtPlus; }
			fileExtPure = fileExtPure.toLowerCase()

			var title = '';
			if (docshotsEls[i].title) {
				title = escape(docshotsEls[i].title);
			} else { // strip tags from link innerHTML
				title += escape(docshotsEls[i].innerHTML.replace(/(<([^>]+)>)/ig, ''));
			}
			title = title.replace(/\+/g,"%2B");
			var className = docshotsEls[i].className.toLowerCase();
			var extFromClassName = this.GetExtension("docshots-", className);
			if (extFromClassName!='')
			{
				fileExtPure = "." + extFromClassName;
				if (docshotsEls[i].href.indexOf("?")>-1){docshotsEls[i].href += "&"}else{docshotsEls[i].href += "?"}
				docshotsEls[i].href += "docshotsFilename=" + title + fileExtPure;
			}
			if (this.GetExtension(".",fileExtPure)!='') {
				// href is a document -- bind events later -- this is just for sending to server

				docshotsQSprecheck = '&Url_' + pch + '=' + escape(docshotsEls[i].href.replace(/\+/g,"%2B")) + '&Title_' + pch + '=' + title;
				docshotsQSprecheck += '&IsPrivate_' + pch + '=' + docshotsIsPrivate + '&TemplateID_' + pch + '=' + docshotsTemplateID;

				docshotsBindableEls[docshotsTotalCounter] = docshotsEls[i];
				docshotsBindableEls[docshotsTotalCounter].fileType = fileExtPure;
				docshotsBindableEls[docshotsTotalCounter].url = docshotsEls[i].href;

				// querystring limit
				if (docshotsQSprecheck.length + preString.length + docshotsQS.length + postString.length > 2000) {
					docshotsQSprecheck = docshotsQSprecheck.replace(/xxxZxxx/g,"0")
					//alert('SENDING BATCH: ' + preString + docshotsQS + postString + docshotsCounter);
					docshotsAttachScript(preString + docshotsQS + postString + docshotsCounter + '&startIndex=' + docshotsStartIndex);
					docshotsQS = docshotsQSprecheck;
					docshotsCounter = 0;
					docshotsStartIndex = docshotsTotalCounter;
				} else
				{
					docshotsQS += docshotsQSprecheck.replace(/xxxZxxx/g,docshotsCounter);				
				}
				docshotsCounter++;
				docshotsTotalCounter++;
			}
		}

		if (docshotsQS.length > 0) {
			docshotsAttachScript(preString + docshotsQS + postString + docshotsCounter + '&startIndex=' + docshotsStartIndex);			
		}


		this.IE = window.ActiveXObject;
		if (this.IE) {
			this.animDelta = this.animDelta * this.IEfactor;
			this.leftCalib = this.leftCalib + 62;
			this.moveLeftOffset = 24;
		}



	},
	GetExtension: function(prefix, stringToCheck){
		var items= new Array('doc' ,'xls' ,'ppt' ,'pps' ,'pdf' ,'rtf' ,'txt' ,'docx' ,'xlsx' ,'ppts');
		for (var i=0; i<items.length;i++){
			if (stringToCheck.indexOf(prefix+items[i])>-1){
				return items[i];
			}
		}
		return '';
	},

	CheckAJAXReturn: function(result) {
		docshotsJSONreturn = eval("(" + result + ")");
		var ix=0;
		// after response, apply events AND params, beginning at startIndex and going for COUNT items
		for (var i = docshotsJSONreturn.startIndex; i < docshotsJSONreturn.startIndex + docshotsJSONreturn.items.length; i++) {
			if (docshotsJSONreturn.items[ix].docConverted) this.BindEvents(docshotsBindableEls[i], docshotsJSONreturn.items[ix]);
			ix++;
		}

	},
	BodyClick: function(el) {
		if (!DocShots.isChild(el, DocShots.dsWin)){
			setTimeout('DocShots.BodyClickHelper()', 1);
		}
	},

	BodyClickHelper: function() {
		if (DocShots.dsWin) DocShots.Hide();
		if (this.el) this.RebindMouseover(this.el);
		this.RebindMouseover(this.lastEL);
	},

	BindEvents: function(el, item) {
		if (el) {
			el.docshotsUrl = item.url;
			el.docshotsTitle = item.title;
			el.docshotsID = item.id;

			if (el.className.toLowerCase().indexOf('docshotsembed')>-1) // toggle mode
			{ // embed
				var w=docshotsWidth;
				var h=docshotsHeight;
				if (el.className.indexOf("-")>-1){
					var s=el.className.split("-");
					w=s[1];
					h=s[2];
				}
				embedHTML = '<object id="docshotsViewer_' + item.id + '" name="docshotsViewer_' + item.id + '" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" data="http://viewer.docstoc.com/"><param name="FlashVars" value="doc_id=' + el.docshotsID + '&mem_id=' + docshotsMemID + '&doc_type=' + el.fileType + '&fullscreen=0&showrelated=' + docshotsShowRelated + '&showotherdocs=' + docshotsShowOther + '" /><param name="movie" value="http://viewer.docstoc.com/"/><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object>';
				embedDiv = document.createElement('div');
				embedDiv.innerHTML = embedHTML;
				el.parentNode.insertBefore(embedDiv, el.nextSibling)

			} else if (el.className!='docshotsPL'){ // docshots window

				el.onmouseover = function(e) {DocShots.Mouseover(this);}
				el.onmouseout = function(e) {DocShots.Mouseout(this);}
				el.onclick = function(e) {DocShots.StartOpenAnime(this);return false;}

				
				var ico = document.createElement('img');
				ico.src='http://i.docstoccdn.com/ds/docshots.gif';
				ico.style.border="0";
				ico.style.width = '17px';
				ico.style.height = '14px';
				ico.style.display = 'inline';
				el.appendChild(ico);		
			}
		
		}


	},

	ToggleWin: function(el) {
		clearTimeout(this.oTimeout);
		//this.Mouseout(el);
		//alert('toggle');
		this.isSame = (this.el == el);
		//el.onmouseover = 'el.style.backgroundColor = "#c1e6f6";';
		this.lastEL = this.el;
		if (this.lastEL && !this.isSame);this.RebindMouseover(this.lastEL);
		this.el = el;
		if (this.dsWin) {
			//this.Hide();
		} else {
			this.Show();
		}
		
	},

	RebindMouseover: function(el) {
		if (el && el.className!='docshotsPL') {
			el.onmouseover = function(e) {
				DocShots.Mouseover(this);
			}
			el.onmouseout = function(e) {
				DocShots.Mouseout(this);
			}
		}
	},

	Mouseover: function(el) {
		this.oTimeout = setTimeout(function(){DocShots.StartOpenAnime(el)}, 1000);
	},

	Mouseout: function(el) {
		clearTimeout(this.oTimeout);
		this.oTimeout =0;
		el.style.backgroundColor = 'transparent';
		docshotsMouseovered = false;
	},

	StartOpenAnime: function(el) {
		if (!this.midTransition) {
			el.style.backgroundColor = '#c1e6f6';
			docshotsLinkClicked = false;
			docshotsMouseovered = true;
			this.elMouse = el;
		}

		// docshotsLinkClicked prevents the mouse time out from firing ToggleWin if the user has already clicked
		if (docshotsMouseovered && !docshotsLinkClicked) {
			DocShots.ToggleWin(this.elMouse, true);
		}
	},

	FindXY: function() {
		this.elX = this.FindPosX(this.el) - 15; // calibrate
		this.parentX = this.FindPosX(this.el.parentNode);
		this.elY = this.FindPosY(this.el) + 15;
	},

	ResetTweens: function() {
		this.tweenXdone = false;
		this.tweenYdone = false;
		this.tweenHdone = false;
		this.tweenWdone = false;
		this.tweenOpacdone = false;
		this.tweenScrollYdone = false;
		this.tweenScrollXdone = false;
	},

	GetWinSize: function() {
		this.winWidth = this.GetWinWidth();
		this.winHeight = this.GetWinHeight();
	},

	DisableSelect: function(el) {
		var element = document.getElementById(el);
		element.onselectstart = function() { return false; } // ie
		element.onmousedown = function() { return false; } // mozilla
	},

	GetCurrXY: function() {
		this.currX = this.dsWin.style.left.replace('px', '');
		this.currY = this.dsWin.style.top.replace('px', '');
	},

	HideViewer: function() {
		this.$('docshotsViewer').style.visibility = 'hidden';
	},

	ShowViewer: function() {
		this.$('docshotsViewer').style.visibility = 'visible';
	},

	FullScreen: function() {

		this.$('docshotsHandle').onmousedown = null;
		this.$('docshotsHandle').style.cursor = 'default';

		this.GetWinSize();
		this.GetCurrXY();
		
		
		if (!this.fullScreened) {
			this.$('docshotsViewer').ChangeFullScreenButton(true);
			this.currHeight = this.regHeight;
			this.currWidth = this.regWidth;
			this.fullScreened = true;
			this.userX = this.currX;
			this.userY = this.currY;
			this.FScnUpStart();	
		} else {
			this.$('docshotsViewer').ChangeFullScreenButton(false);
			this.HideViewer();
			this.fullScreened = false;
			this.FScnDownStart();
		}
	},

	FScnUpStart: function() {
		this.HideViewer();
		this.ResetTweens();

		this.fscnInt = setInterval("DocShots.FScnUp()", this.frameInterval);
	},

	FScnDownStart: function() {
		this.ResetTweens();
		this.FindXY();

		this.fscnInt = setInterval("DocShots.FScnDown()", this.frameInterval);
	},

	GetScrollTop: function() {

		if (document.compatMode == 'CSS1Compat' && (navigator.appVersion.indexOf("Safari") == -1)) { // transitional
			return document.documentElement.scrollTop;
		} else { // strict and/or safari
			return document.body.scrollTop;
		}
	},

	GetScrollLeft: function() {
		if (document.compatMode == 'CSS1Compat' && (navigator.appVersion.indexOf("Safari") == -1)) { // transitional
			return document.documentElement.scrollLeft;
		} else { // strict and/or safari
			return document.body.scrollLeft;
		}
	},

	FScnUp: function() {
		if ((this.currX > this.GetScrollLeft()) && !this.tweenXdone) {
			this.currX = this.currX - this.animDelta;
			this.dsWin.style.left = this.currX + 'px';
		} else { this.dsWin.style.left = this.GetScrollLeft() + 'px'; this.tweenXdone = true; }

		if ((this.currY > this.GetScrollTop()) && !this.tweenYdone) {
			this.currY = this.currY - this.animDelta;
			this.dsWin.style.top = this.currY + 'px';
		} else { this.dsWin.style.top = this.GetScrollTop() + 'px'; this.tweenYdone = true; }

		if ((this.currHeight < this.winHeight - this.animDelta) && !this.tweenHdone) {
			this.currHeight = this.currHeight + this.animDelta;
			this.$('docshotsMidCell').style.height = this.currHeight + 'px';
		} else { this.tweenHdone = true; this.$('docshotsMidCell').style.height = this.winHeight + 'px'; }

		if ((this.currWidth < this.winWidth - this.animDelta * 1.4) && !this.tweenWdone) {
			this.currWidth = this.currWidth + this.animDelta * 1.4;
			this.dsWin.style.width = this.currWidth + 'px';
		} else { this.tweenWdone = true; this.dsWin.style.width = this.winWidth + 'px'; }

		if (this.tweenXdone && this.tweenYdone && this.tweenHdone && this.tweenWdone) {
			clearInterval(this.fscnInt);
			this.ShowViewer();
		}

	},

	FScnDown: function() {
		if ((this.currX < this.userX) && !this.tweenXdone) {
			this.currX = parseInt(this.currX) + this.animDelta;
			this.dsWin.style.left = this.currX + 'px';
		} else { this.dsWin.style.left = this.userX + 'px'; this.tweenXdone = true; }

		if ((this.currY < this.userY) && !this.tweenYdone) {
			this.currY = parseInt(this.currY) + this.animDelta;
			this.dsWin.style.top = this.currY + 'px';
		} else { this.dsWin.style.top = this.userY + 'px'; this.tweenYdone = true; }

		if ((this.currHeight > this.regHeight) && !this.tweenHdone) {
			this.currHeight = this.currHeight - this.animDelta;
			this.$('docshotsMidCell').style.height = this.currHeight + 'px';
		} else { this.$('docshotsMidCell').style.height = this.regHeight + 'px'; this.tweenHdone = true; }
		if ((this.currWidth > this.regWidth) && !this.tweenWdone) {
			this.currWidth = this.currWidth - this.animDelta * 1.4;
			this.dsWin.style.width = this.currWidth + 'px';
		} else { this.dsWin.style.width = this.regWidth + 'px'; this.tweenWdone = true; }

		if (this.tweenXdone && this.tweenYdone && this.tweenHdone && this.tweenWdone) {
			this.$('docshotsHandle').onmousedown = DocShotsDrag.start;
			this.$('docshotsHandle').style.cursor = 'move';
			clearInterval(this.fscnInt);
			this.ShowViewer();
		}

	},

	Hide: function() {
		this.fullScreened = false;
		this.FadeOutStart();
		this.ShowHide('object','visible');
		this.ShowHide('embed','visible');
		
		this.detachBodyClick();
	},


	GetWinHeight: function() {
		height = window.innerHeight;

		if (document.compatMode == 'CSS1Compat') {
			height = document.documentElement.clientHeight;
		} else {
			height = document.body.clientHeight;
		}

		return height - 86;
	},

	GetWinWidth: function() {
		width = window.innerWidth;

		if (document.compatMode == 'CSS1Compat') {
			width = document.documentElement.clientWidth;
		} else {
			width = document.body.clientWidth;
		}

		return width - 6;
	},

	FadeStart: function() {
		this.ResetTweens();
		this.GetCurrXY();
		this.dsWin.style.opacity = 0;
		//this.dsWin.style.filter = "alpha(opacity='0')";
		this.dsWin.style.display = 'block';
		this.currOp = 0;
		this.currHeight = 20;
		this.currWidth = 20;
		this.$('docshotsMidCell').style.height = '20px';
		this.dsWin.style.width = '20px';

		// appear on left side if more space
		this.tweenXdone = !((this.winWidth - this.currX) < this.leftCalib + 10);
		this.moveLeft = (((this.winWidth - this.currX) < this.regWidth) && (this.currX - this.regWidth > -100));

		// appear above if better
		this.moveUp = (document.body.clientHeight < (this.elY + this.regHeight)) && (this.currY - this.regHeight > 0) && (this.elY - this.regHeight > this.GetScrollTop() + 18);

		if (this.moveUp) {
			this.currY = this.currY - this.regHeight - 28;
			this.dsWin.style.top = this.currY + 'px';
		}

		clearInterval(this.fadeInt);
		this.fadeInt = setInterval("DocShots.FadeUp()", this.frameInterval);
	},
	
	Show: function() {
		this.GetWinSize();
		this.FindXY();

		this.dsWin = document.createElement('div');
		this.dsWin.style.position = 'absolute';
		this.dsWin.style.fontSize = '12px';
		this.dsWin.style.fontFamily = 'Verdana';
		this.dsWin.style.top = this.elY + 'px';
		this.dsWin.id = 'dsWin';

		// X aligned with element
		this.dsWin.style.left = this.elX + 'px';
		// left justified to parent
		//parentX
		//this.dsWin.style.left = this.parentX + 'px';

		this.dsWin.style.display = 'none';
		this.dsWin.style.zIndex = '9999999';

		innerContent = '<object id="docshotsViewer" name="docshotsViewer" width="100%" height="100%" type="application/x-shockwave-flash" data="http://viewer.docstoc.com/"><param name="FlashVars" value="fsp=DocShots.FullScreen()&doc_id=' + this.el.docshotsID + '&mem_id=' + docshotsMemID  + '&doc_type=' + this.el.fileType + '&fullscreen=0&showrelated=' + docshotsShowRelated + '&showotherdocs=' + docshotsShowOther + '" /><param name="movie" value="http://viewer.docstoc.com/"/><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /></object>';
		this.dsWin.innerHTML = '<table cellspacing=0 style="width:100%"><tr><td style="overflow:hidden;padding:0;vertical-align:top;width:12px;height:14px;background: url(http://i.docstoccdn.com/ds/TL.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/TL.png, sizingMethod=crop);"></td><td style="height:14px;overflow:hidden;padding:0;vertical-align:top;background: url(http://i.docstoccdn.com/ds/TC.png) repeat-x 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/TC.png, sizingMethod=scale);"></td><td style="height:14px;overflow:hidden;padding:0;vertical-align:top;width:14px;background: url(http://i.docstoccdn.com/ds/TR.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/TR.png, sizingMethod=crop);"></td></tr><tr style="cursor:move;" id=docshotsHandle ondblclick="DocShots.FullScreen()"><td style="overflow:hidden;padding:0;vertical-align:top;width:12px;height:23px;background: url(http://i.docstoccdn.com/ds/L_dk_T.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/L_dk_T.png, sizingMethod=crop);"></td><td style="overflow:hidden;padding:0;vertical-align:top;height:23px;background: url(http://i.docstoccdn.com/ds/title-bg.png) repeat-x 0 0;">' +
		'<table cellspacing="0" cellpadding="0" border="0" style="width:100%"><tr><td id=docshotsTitle noselect=true>'+
		'<div style="width:100% !important;overflow:hidden; height:16px;text-align:left"><div style="display:inline;width:100%;height:18px;overflow:hidden;font-size: 12px; font-weight:bold" noselect=true>'+
		'<b style="color:#5992c4">DocShots - </b><a href="' + this.el.docshotsUrl + '" target="_blank" style="color:#000">' + this.el.docshotsTitle + '</a>'+
		'</div></div></td><td width=236>'+
		'<a style="width: 16px; height: 16px; display: block; background: url(http://i.docstoccdn.com/ds/btn_X.png) no-repeat 0 0; cursor: pointer; float: right; margin: 1px 2px 0 4px; outline: none;" href="javascript:DocShots.Hide()"></a>' +
		'<div style="float:right;padding:0 4px 0 6px;height:19px"><div style="position:absolute;top:9px;background: url(http://i.docstoccdn.com/ds/btn-border.gif) repeat-y 0 0;width:3px;height:29px;"></div></div>'+
		'<a style="width: 83px; height: 18px; display: block; background: url(http://i.docstoccdn.com/ds/btn-download.png) no-repeat 0 0; cursor: pointer; float: right; outline: none" href="' + this.el.href + '"></a>' +
		'<div style="float:right;padding:0 4px 0 6px;height:19px"><div style="position:absolute;top:9px;background: url(http://i.docstoccdn.com/ds/btn-border.gif) repeat-y 0 0;width:3px;height:29px;"></div></div>'+
		'<a style="width: 64px; height: 19px; display: block; background: url(http://i.docstoccdn.com/ds/btn-print.png) no-repeat 0 0; cursor: pointer; float: right; outline: none" href="javascript:DocShots.Print()"></a>' +
		'<div style="float:right;padding:0 9px 0 4px;height:19px"><div style="position:absolute;top:9px;background: url(http://i.docstoccdn.com/ds/btn-border.gif) repeat-y 0 0;width:3px;height:29px;"></div></div><a style="width: 16px; height: 18px; display: block; background: url(http://i.docstoccdn.com/ds/btn-rss.gif) no-repeat 0 2px; cursor: pointer; float: right;outline: none;" href="http://www.docstoc.com/Feeds/rss.ashx?id=3&memid=' + docshotsMemID + '"></a>' + 

		'</td></tr></table>'+
		'</td><td style="overflow:hidden;padding:0;vertical-align:top;width:14px;height:23px;background: url(http://i.docstoccdn.com/ds/R_dk_T.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/R_dk_T.png, sizingMethod=crop);"></td></tr><tr><td style="overflow:hidden;padding:0;vertical-align:top;width:12px;background: url(http://i.docstoccdn.com/ds/L_lt.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/L_lt.png, sizingMethod=crop);"></td><td style="background: #d8e0e4; overflow: visible;padding:0;vertical-align:top;" id=docshotsMidCell>' + innerContent + '</td><td style="overflow:hidden;padding:0;vertical-align:top;width:14px;background: url(http://i.docstoccdn.com/ds/R_lt.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/R_lt.png, sizingMethod=crop);"></td></tr><tr><td style="overflow:hidden;padding:0;vertical-align:top;width:12px;height: 24px; background: url(http://i.docstoccdn.com/ds/L_dk_B.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/L_dk_B.png, sizingMethod=crop);"></td><td style="border-top:1px solid #9a9a9a;overflow:hidden;padding:0;vertical-align:top;text-align:right;height: 24px; background: url(http://i.docstoccdn.com/ds/status-bg.png) repeat-x 0 0;"><a style="width: 189px; height: 21px; display:block; float:right; background: url(http://i.docstoccdn.com/ds/useDocShots.png) no-repeat 0 0; padding-right:6px; cursor: pointer" href="http://www.docstoc.com/DocShots/"></a></td><td style="overflow:hidden;padding:0;vertical-align:top;width:14px;height: 24px; background: url(http://i.docstoccdn.com/ds/R_dk_B.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/R_dk_B.png, sizingMethod=crop);"></td></tr><tr><td style="height: 21px; background: url(http://i.docstoccdn.com/ds/BL.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/BL.png, sizingMethod=crop);overflow:hidden;padding:0;vertical-align:top;width:12px;"></td><td style="height: 21px; background: url(http://i.docstoccdn.com/ds/BC.png) repeat-x 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/BC.png, sizingMethod=scale);overflow:hidden;padding:0;vertical-align:top;"></td><td style="height: 21px; background: url(http://i.docstoccdn.com/ds/BR.png) no-repeat 0 0; -background: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=http://i.docstoccdn.com/ds/BR.png, sizingMethod=crop);overflow:hidden;padding:0;vertical-align:top;width:14px;"></td></tr></table>';

		document.body.appendChild(this.dsWin);
		
		this.ShowHide('object','hidden');
		this.ShowHide('embed','hidden');
		  
		this.HideViewer();
		this.DisableSelect('docshotsTitle');

		this.FadeStart();
		

	},
	Print: function(){
		this.$('docshotsViewer').Print();
	},
	ShowHide: function(tag,display){
		return;
		var els = document.body.getElementsByTagName(tag);
		for (var i=0;i<els.length;i++){
			els[i].style.visibility=display;
		}
	},
	FadeUp: function() {

		if ((this.currOp != 1) && !this.tweenOpacdone) {
			this.currOp = this.currOp + this.opacDelta;
			this.dsWin.style.opacity = this.currOp;
			// this.dsWin.style.filter = "alpha(opacity='" + currOp*100 + "')";
		} else { this.currOp = 1; this.dsWin.style.opacity = this.currOp; this.tweenOpacdone = true; }

		if ((this.currHeight < this.regHeight - this.animDelta) && !this.tweenHdone) {
			this.currHeight = this.currHeight + this.animDelta;
			this.$('docshotsMidCell').style.height = this.currHeight + 'px';
		} else { this.$('docshotsMidCell').style.height = this.regHeight; this.tweenHdone = true; }

		if ((this.currWidth < this.regWidth - this.animDelta * 1.4) && !this.tweenWdone) {
			this.currWidth = this.currWidth + this.animDelta * 1.4;
			this.dsWin.style.width = this.currWidth + 'px';
		} else { this.dsWin.style.width = this.regWidth; this.tweenWdone = true; }

		// appear on left side if more space
		if ((this.currX > this.elX - this.animDelta) && !this.tweenXdone) {
			this.currX = this.currX - this.animDelta;
			this.dsWin.style.left = this.currX + 'px';
		} else {
			if (this.moveLeft) {
				this.dsWin.style.left = (this.elX - this.regWidth + this.el.offsetWidth + this.moveLeftOffset) + 'px';
			}
			this.tweenXdone = true;
		}

		if (this.tweenOpacdone && this.tweenHdone && this.tweenWdone && this.tweenXdone) {

			clearInterval(this.fadeInt);
			this.fadeInt = null;
			this.ScrollWin();
			DocShotsDrag.init(this.$('docshotsHandle'), this.dsWin);
			this.ShowViewer();

			this.attachBodyClick();
		}
	},

	ScrollWin: function() {
		this.ResetTweens();
		this.dsWinBottom = parseInt(this.currY) + parseInt(this.currHeight);
		this.dsWinRight = parseInt(this.currX) + parseInt(this.currWidth);

		if (this.dsWinBottom > this.winHeight + this.GetScrollTop() || this.dsWinRight > this.winWidth + this.GetScrollLeft()) {
			this.currScrollY = this.GetScrollTop();
			this.currScrollX = this.GetScrollLeft();
			this.scrollInt = setInterval("DocShots.ScrollInc()", this.frameInterval);
		}
	},

	ScrollInc: function() {

		if (this.currScrollY < this.dsWinBottom - this.winHeight) {
			this.currScrollY = this.currScrollY + this.animDelta;
		} else {
			this.tweenScrollYdone = true;
			this.currScrollY = this.dsWinBottom - this.winHeight;
			if (this.IE) {
				this.currScrollY += 80
			} else if (document.compatMode != 'CSS1Compat') {
				this.currScrollY += 20;
			}
		}

		if (this.currScrollX < this.dsWinRight - this.winWidth) {
			this.currScrollX = this.currScrollX + this.animDelta;
		} else {
			this.tweenScrollXdone = true;
			this.currScrollX = this.dsWinRight - this.winWidth;
		}

		window.scrollTo(this.currScrollX, this.currScrollY);

		if (this.tweenScrollYdone && this.tweenScrollXdone) clearInterval(this.scrollInt);
	},

	FadeOutStart: function() {
		this.midTransition = true;
		this.HideViewer();
		this.ResetTweens();
		clearInterval(this.fadeInt);
		this.fadeInt = setInterval("DocShots.FadeDown()", this.frameInterval);
	},

	FadeDown: function() {

		if (this.currOp > 0) {
			this.currOp = this.currOp - this.opacDelta;
			this.dsWin.style.opacity = this.currOp;
			// this.dsWin.style.filter = "alpha(opacity='" + currOp*100 + "')";
		}
		if (this.currHeight > this.animDelta) {
			this.currHeight = this.currHeight - this.animDelta;
			this.$('docshotsMidCell').style.height = this.currHeight + 'px';
		}
		if (this.currWidth > this.animDelta * 1.4) {
			this.currWidth = this.currWidth - this.animDelta * 1.4;
			this.dsWin.style.width = this.currWidth + 'px';
		} else {

			clearInterval(this.fadeInt);
			this.removeChildren(this.dsWin);
			this.dsWin.parentNode.removeChild(this.dsWin);
			this.dsWin = null;

			docshotsLinkClicked = false;
			if (this.el) this.RebindMouseover(this.el);
			if (this.lastEL) this.RebindMouseover(this.lastEL);

			this.midTransition = false;
		}
	},
	removeChildren: function (el){
		if (!el) return;
		while (el.hasChildNodes()) {
			this.removeChildren(el.firstChild);
			el.removeChild(el.firstChild);
		}
	},
	// utility
	$: function(el) {
		return document.getElementById(el);
	},
	isChild: function (parent,child){
		while (parent.parentNode != null) {
			if (parent==child){return true;}
			parent= parent.parentNode;
		}
		return false;
	},
	attachBodyClick:function(){
		document.onclick = function(e) {
			var el;
			if (window.event)
			{
				e=window.event;
				el = e.srcElement;
			}else{
				el = e.target;
			}
			if (DocShots.bodyClickEv) DocShots.bodyClickEv(); 
			DocShots.BodyClick(el);
		}
		return;
		if (window.addEventListener) {
			window.addEventListener('click', DocShots.BodyClick, false);
		} else {
			document.attachEvent('onclick', DocShots.BodyClick);
		}
	},
	detachBodyClick:function(){
		document.onclick = this.bodyClickEv;
		return;
		if (window.addEventListener) {
			window.removeEventListener('click', DocShots.BodyClick, false);
		} else {
			document.detachEvent('onclick', DocShots.BodyClick);
		}
	},

	FindPosX: function(obj) {
		var curleft = 0;
		if (obj.offsetParent)
			while (1) {
			curleft += obj.offsetLeft;
			if (!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	},

	FindPosY: function(obj) {
		var curtop = 0;
		if (obj.offsetParent)
			while (1) {
			curtop += obj.offsetTop;
			if (!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
};


var DocShotsDrag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= DocShotsDrag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top	= "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		if (DocShots.IE) DocShots.HideViewer();
		
		var o = DocShotsDrag.obj = this;
		e = DocShotsDrag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= DocShotsDrag.drag;
		document.onmouseup		= DocShotsDrag.end;

		return false;
	},

	drag : function(e)
	{
		e = DocShotsDrag.fixE(e);
		var o = DocShotsDrag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		DocShotsDrag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		DocShotsDrag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		DocShotsDrag.obj.lastMouseX	= ex;
		DocShotsDrag.obj.lastMouseY	= ey;

		DocShotsDrag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		DocShotsDrag.obj.root.onDragEnd(	parseInt(DocShotsDrag.obj.root.style[DocShotsDrag.obj.hmode ? "left" : "right"]), 
									parseInt(DocShotsDrag.obj.root.style[DocShotsDrag.obj.vmode ? "top" : "bottom"]));
		DocShotsDrag.obj = null;
		
		if (DocShots.IE) DocShots.ShowViewer();
	},
	
	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};