/**
调用格式调用参数
    uid : 数字,联盟ID,必填
	minw : 数字(20),最小宽度
	minh : 数字(20),最小高度
	maxw : 数字(200),最大宽度
	maxh : 数字(200),最大高度
	showrightmenu: 布尔值(true),是否显示左侧菜单
**/
var uid=10009,minw=5,minh=5,maxw=3000,maxh=2000,showrightmenu=false;
var XCMenu = null;
var Publisher = "IEPhotoshop";
var XCMinWidth = 5;
var XCMinHeight = 5;
var XCMaxWidth = 2000;
var XCMaxHeight = 2000;
var XCCuteCheckImgSrc = true;
var XCTimerID = -1;
var bEnter = 0

//2007-11-22 支持设置最小宽度和最小高度
if(typeof(minw) == "number") XCMinWidth = minw;
if(typeof(minh) == "number") XCMinHeight = minh;
//2008-3-20 支持设置最大宽度和最大高度
if(typeof(maxw) == "number") XCMaxWidth = maxw;
if(typeof(maxh) == "number") XCMaxHeight = maxh;
//2007-11-23 支持设置是否显示右侧菜单
var ShowRightMenu;
ShowRightMenu = true;
if(typeof(showrightmenu) == "boolean") ShowRightMenu = showrightmenu; 

//Specifies the loading status of a document. It has one of the following four string values: 
//
//uninitialized 
//The document has not started loading.
//
//loading 
//The document is loading.
//
//interactive 
//The document has loaded sufficiently for the user to interact with it.
//
//complete 
//The document is completely loaded

if(document.readyState=="complete")
{
	XCSetupMenu(document);
}
else
{
	XCSetupMenu(document);
	XCTimerID = setTimeout("funSetup();", 3*1000);

	document.onreadystatechange = function()
	{
		if(document.readyState=="complete")
		{
			XCSetupMenu(document);
			clearTimeout(XCTimerID);
		}
	}
}

function funSetup()
{
	XCSetupMenu(document);
}


function XCSetupMenu(doc)
{
	try { 
		if (bEnter != 0)
		{
			return;
		}
		bEnter = 1;
		if(typeof(doc.XCMenu)=="undefined")
		{
			doc.XCMenu = null;
			doc.XCMinWidth = XCMinWidth;
			doc.XCMinHeight = XCMinHeight;
			doc.XCMaxWidth = XCMaxWidth;
			doc.XCMaxHeight = XCMaxHeight;	
			doc.XCCuteCheckImgSrc = XCCuteCheckImgSrc;
		}
		for(var i = 0; i<doc.images.length; ++i)
		{
			var img = doc.images[i]; //An array of Image objects that represent 
                                     //the <img> elements in the document
			if (img.onmouseover != XCRollOver)
			{
					if( img.width>doc.XCMinWidth && img.height>doc.XCMinHeight) {
						if( typeof(img.orig_onmouseover)=="undefined" ) {
							img.orig_onmouseover = img.onmouseover;
							img.orig_onmouseout = img.onmouseout;
						}			
			
						img.onmouseover = XCRollOver;
						img.onmouseout = XCRollOut;				
					}					
			}
            
            if( img.width>=doc.XCMaxWidth && img.height>=doc.XCMaxHeight && ShowRightMenu )
			  {
				XCSetupImgMenu(img);
			  }

		}
		var objs = doc.all.tags("INPUT");
		for(var j = 0; j < objs.length; ++j)
		{
			var img = objs[j];
			if (img.onmouseover != XCRollOver)
			{
				if(typeof(img.type)=="string" && img.type.toLowerCase()=="image")
				{
					if(typeof(img.XCMenu)=="undefined")
					{
						if( img.width>doc.XCMinWidth && img.height>doc.XCMinHeight ) {
							if( typeof(img.orig_onmouseover)=="undefined" ) {
								img.orig_onmouseover = img.onmouseover;
								img.orig_onmouseout = img.onmouseout;
							}			
			
							img.onmouseover = XCRollOver;
							img.onmouseout = XCRollOut;							
						}
						if( img.width>=doc.XCMaxWidth && img.height>=doc.XCMaxHeight && ShowRightMenu )
						{
							XCSetupImgMenu(img);
						}
					}
				}
			}
		}

		bEnter = 0;
	} 
	catch(er) {
	} 
}

function XCSetupImgMenu(img)
{
	if(img.width>=document.XCMinWidth&&img.height>=document.XCMinHeight)
	{
		if(typeof(img.XCMenu)=="undefined")
		{
			img.XCMenu = document.createElement("DIV");
			img.XCMenu.style.zIndex = 5000;
			img.XCMenu.style.color = "black";
			img.XCMenu.style.fontFamily = "宋体";
			img.XCMenu.style.fontSize  = "9pt";
			img.XCMenu.style.border = "solid 1px black";
			img.XCMenu.style.backgroundColor = "#DADBDC";
			img.XCMenu.innerHTML = "";
			img.XCMenu.style.padding = "3px";
			img.XCMenu.target = "_blank";
			img.XCMenu.style.position = "absolute";
			img.XCMenu.style.visibility = "hidden";

			var t=document.createElement('table');  	// - start by creating the table element
			var tb=document.createElement('tbody');  	// - create a tbody element 

			t.style.border='0px  ridge';
			t.style.width='0px';
			t.style.textAlign='left';
			t.style.padding='0px';

			var tr=document.createElement('tr');  	// - now create the tr and td elements
			var td=document.createElement('td');
			var tdMovie=document.createElement('td');
			//td.style.textAlign='right';
			//td.style.padding='5px';

			img.XCMenu.SendPic = document.createElement("A");
			//img.XCMenu.SendPic.id = "XCSendPic";
			img.XCMenu.SendPic.style.color = "black";
			img.XCMenu.SendPic.style.fontFamily = "宋体";
			img.XCMenu.SendPic.style.fontSize  = "9pt";
			img.XCMenu.SendPic.style.backgroundColor = "#DADBDC";
			img.XCMenu.SendPic.style.textDecoration="none";
			img.XCMenu.SendPic.innerHTML = "←-<br>&nbsp;在&nbsp;<br>&nbsp;线&nbsp;<br>&nbsp;PS&nbsp;<br>&nbsp;此&nbsp;<br>&nbsp;图&nbsp;<br>&nbsp;片";
			img.XCMenu.SendPic.target = "_blank";

			/**img.XCMenu.SendMovie = document.createElement("A");
			img.XCMenu.SendMovie.id = "XCSendMovie";
			img.XCMenu.SendMovie.style.color = "#B400FF";
			img.XCMenu.SendMovie.style.fontFamily = "宋体";
			img.XCMenu.SendMovie.style.fontSize  = "9pt";
			img.XCMenu.SendMovie.style.backgroundColor = "#F1FF77";
			img.XCMenu.SendMovie.style.textDecoration="none";
			img.XCMenu.SendMovie.innerHTML = "--<br>查<br>看<br>相<br>关<br>电<br>影<br>&nbsp;<br>&nbsp;";
			img.XCMenu.SendMovie.target = "_blank";**/

			td.appendChild(img.XCMenu.SendPic );
			//tdMovie.appendChild(img.XCMenu.SendMovie );
			tr.appendChild(td); 						// - put the cell into the row
			//tr.appendChild(tdMovie); 						// - put the cell into the row
			tb.appendChild(tr); 						// - put the row into the tbody
			t.appendChild(tb);						// - put the tbody into the table

			img.XCMenu.appendChild(img.XCMenu.SendPic);
			//img.XCMenu.appendChild(t);

			document.body.insertAdjacentElement("afterBegin", img.XCMenu);
		}

		var x = 0, y = 0;
		for(var obj = img; obj; obj = obj.offsetParent)
		{
			x += parseInt(obj.offsetLeft);
			y += parseInt(obj.offsetTop);
		}	
		
		img.XCMenu.SendPic.href = "http://www.iephotoshop.com/index.asp?img=" + ValueEncode(XCCalcSrc(img,document.XCCuteCheckImgSrc));
		img.XCMenu.SendPic.target = "_blank";

		//img.XCMenu.style.left = x; //Math.max(x, stgcl(doc));
		//img.XCMenu.style.top = y; //Math.max(y, stgct(doc));
		img.XCMenu.style.left = x+img.width;
		img.XCMenu.style.top = y+img.height/2;
		img.XCMenu.style.visibility = "";

	}
}

function XCRollOver()
{
	if(this.orig_onmouseover)
	{
		this.orig_onmouseover();
	}
	var doc = this.document;
	if(!doc.XCMenu)
	{
		doc.XCMenu = doc.createElement("DIV");
		doc.XCMenu.id = "XCSendIMG";
		doc.XCMenu.style.zIndex = 5000;
		doc.XCMenu.style.color = "black";
		doc.XCMenu.style.fontFamily = "宋体";
		doc.XCMenu.style.fontSize  = "9pt";
		doc.XCMenu.style.border = "solid 1px black";
		doc.XCMenu.style.backgroundColor = "DADBDC";
		doc.XCMenu.innerHTML = "";
		doc.XCMenu.style.padding = "3px";
		doc.XCMenu.target = "_blank";
		doc.XCMenu.style.position = "absolute";
		doc.XCMenu.style.visibility = "hidden";
		doc.XCMenu.onmouseout = function()
		{
			var e = this.document.parentWindow.event;
			if(e.toElement)
			{
				if (e.toElement.id == "XCSendIMG" || e.toElement.id == "XCViewMovie"  || e.toElement.id == "XCSendPic")
					return;
			}

			this.style.visibility = "hidden";
		}

		doc.XCMenu.SendPic = doc.createElement("A");
		doc.XCMenu.SendPic.id = "XCSendPic";
		doc.XCMenu.SendPic.style.color = "black";
		doc.XCMenu.SendPic.style.fontFamily = "宋体";
		doc.XCMenu.SendPic.style.fontSize  = "9pt";
		doc.XCMenu.SendPic.style.backgroundColor = "#DADBDC";
		doc.XCMenu.SendPic.innerHTML = "在线PS此图片";
		doc.XCMenu.SendPic.target = "_blank";
		doc.XCMenu.appendChild(doc.XCMenu.SendPic);

		/**doc.XCMenu.ViewMovie = doc.createElement("A");
		doc.XCMenu.ViewMovie.id = "XCViewMovie";
		doc.XCMenu.ViewMovie.style.color = "black";
		doc.XCMenu.ViewMovie.style.fontFamily = "宋体";
		doc.XCMenu.ViewMovie.style.fontSize  = "9pt";
		doc.XCMenu.ViewMovie.style.backgroundColor = "yellow";
		doc.XCMenu.ViewMovie.innerHTML = "<br>查看相关电影";
		doc.XCMenu.ViewMovie.target = "_blank";
		
			doc.XCMenu.appendChild(doc.XCMenu.ViewMovie);**/
		
		doc.body.insertAdjacentElement("afterBegin", doc.XCMenu);
	}
	//doc.body.insertAdjacentElement("BeforeEnd", doc.XCMenu);
	
	if(this.width>=doc.XCMinWidth&&this.height>=doc.XCMinHeight)
	{
		var x = 0, y = 0;
		for(var obj = this; obj; obj = obj.offsetParent)
		{
			x += parseInt(obj.offsetLeft);
			y += parseInt(obj.offsetTop);
		}	
		
		doc.XCMenu.SendPic.href = "http://www.iephotoshop.com/index.asp?img=" + ValueEncode(XCCalcSrc(this,document.XCCuteCheckImgSrc));
		
		doc.XCMenu.SendPic.target = "_blank";

		doc.XCMenu.style.left = x; //Math.max(x, stgcl(doc));
		doc.XCMenu.style.top = y; //Math.max(y, stgct(doc));
		
		//如果图片高度大于150,在右上角显示 
		if(this.height >= 150)
		{
			doc.XCMenu.style.left = Math.max(x+this.width/2, stgcl(doc)); //x+this.width/2;
			doc.XCMenu.style.top = Math.max(y, stgct(doc)); //y+this.height/2;
		}
		doc.XCMenu.style.visibility = "";
	}
}
function XCRollOut()
{
	var doc = this.document;
	if(doc.XCMenu)
	{
		if(this.orig_onmouseout)
		{
			this.orig_onmouseout();
		}
		var e = this.document.parentWindow.event;
		if(e.toElement)
		{
			if (e.toElement.id == "XCSendIMG"  || e.toElement.id == "XCSendPic")
				return;
		}
		doc.XCMenu.style.visibility = "hidden";
	}
}
function XCCalcSrc(img,CuteCheckImgSrc)
{
	var ext = "";
	var href = "";
	for(var obj=img; obj&&CuteCheckImgSrc; obj = obj.parentElement)
	{
		if(obj.tagName=="A")
		{
			href = obj.href;
			ext = getextension(href).toLowerCase();
			break;
		}
	}
	return ext==".jpg"||ext==".jpeg"||ext==".jpe"||ext==".gif"||ext==".png" ? href : img.src;
}
function getextension(s)
{
	var n=s.lastIndexOf('.');
	return n<0 ? "" : s.substring(n,s.length);
}
function ValueEncode(s)
{
	var r =s;
	r = r.replace(/%/gi, "%25");
	r = r.replace(/ /gi, "%20");
	r = r.replace(/\+/gi, "%2B");
	r = r.replace(/\t/gi, "%09");
	r = r.replace(/#/gi, "%23");
	r = r.replace(/\{/gi, "%7B");
	r = r.replace(/\}/gi, "%7D");
	r = r.replace(/\^/gi, "%5E");
	r = r.replace(/~/gi, "%7E");
	r = r.replace(/\[/gi, "%5B");
	r = r.replace(/\]/gi, "%5D");
	r = r.replace(/;/gi, "%3B");
	r = r.replace(/@/gi, "%40");
	r = r.replace(/=/gi, "%3D");
	r = r.replace(/&/gi, "%26");
	r = r.replace(/`/gi, "%60");
	return r;
}
function stgcl(doc)
{
	if (doc == null)
		return 0;
	if (doc.body == null)
		return 0;

	//if (typeof(doc.documentElement) == 'undefined' || doc.documentElement == null)

	return doc.body.scrollLeft;
	return doc.documentElement.scrollLeft;
}
function stgct(doc)
{
	if (doc == null)
		return 0;
	if (doc.body == null)
		return 0;
	//if (typeof(doc.documentElement) == 'undefined' || doc.documentElement == null)
	return doc.body.scrollTop;
	return doc.documentElement.scrollTop;
}
