//多角度显示图片。
function imgSwitch(id) {
	document.getElementById("zoom").src = id.src;//.replace(/S/,"/B/"); 
	var images=document.getElementsByTagName("img");
	var imgLen=images.length;
	  for(var i=0;i<imgLen;i++){
   	images[i].style.borderColor="#ddd";
  	}
	id.style.borderColor="#f00";
}

 

//floatbox.js
function getElement(aID)
{
  return (document.getElementById) ? document.getElementById(aID)
                                   : document.all[aID];
}
function getAllElement()
{
  return (document.getElementsByTagName) ? document.getElementsByTagName("*")
										 : document.all;
}
function getParentElement(elm)
{
	return (elm.parentElement) ? elm.parentElement : elm.parentNode
}
var Drag={
        "obj":null,
	"init":function(a, aRoot){
			a.onmousedown=Drag.start;
			a.root = aRoot;
			if(isNaN(parseInt(a.root.style.left)))a.root.style.left="0px";
			if(isNaN(parseInt(a.root.style.top)))a.root.style.top="0px";
			a.root.onDragStart=new Function();
			a.root.onDragEnd=new Function();
			a.root.onDrag=new Function();
		},
	"start":function(a){	
			var b=Drag.obj=this;
			a=Drag.fixE(a);
			var c=parseInt(b.root.style.top);
			var d=parseInt(b.root.style.left);
			b.root.onDragStart(d,c,a.clientX,a.clientY);
			b.lastMouseX=a.clientX;
			b.lastMouseY=a.clientY;
			document.onmousemove=Drag.drag;
			document.onmouseup=Drag.end;
			return false;
		},	
	"drag":function(a){
			a=Drag.fixE(a);
			var b=Drag.obj;
			var c=a.clientY;
			var d=a.clientX;
			var e=parseInt(b.root.style.top);
			var f=parseInt(b.root.style.left);
			var h,g;
			h=f+d-b.lastMouseX;
			g=e+c-b.lastMouseY;
			b.root.style.left=h+"px";
			b.root.style.top=g+"px";			
			b.lastMouseX=d;
			b.lastMouseY=c;
			b.root.onDrag(h,g,a.clientX,a.clientY);
			return false;
		},
	"end":function(){			
			document.onmousemove=null;
			document.onmouseup=null;
			Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
			Drag.obj=null;
		},
	"fixE":function(a){
			if(typeof a=="undefined")a=window.event;
			if(typeof a.layerX=="undefined")a.layerX=a.offsetX;
			if(typeof a.layerY=="undefined")a.layerY=a.offsetY;
			return a;
		}
};
function addLightboxMarkup() {

	bod 				= document.getElementsByTagName('body')[0];

	overlay 			= document.createElement('div');
	overlay.id			= 'overlay';

	bod.appendChild(overlay);
}
function hideSelect(visibility){
	selects = document.getElementsByTagName('select');
	for(i = 0; i < selects.length; i++) {
		selects[i].style.visibility = visibility;
	}
}
function preIE(height, overflow){
		bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		bod.style.overflow = overflow;
  
		htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		htm.style.overflow = overflow;
}
function getRange() {
      var top     = document.documentElement.scrollTop;
      var left    = document.documentElement.scrollLeft;
      var height  = document.documentElement.clientHeight;
      var width   = document.documentElement.clientWidth;

      if (top==0 && left==0 && height==0 && width==0) {
        top     = document.body.scrollTop;
        left    = document.body.scrollLeft;
        height  = document.body.clientHeight;
        width   = document.body.clientWidth;
      }

      return  {top:top  ,left:left ,height:height ,width:width } ;
}

function onbodyscroll(){
	var range=getRange();
	WfloatBox.style.top=(range.top+WfloatBox.oy) +"px";
	WfloatBox.style.left=(range.left+WfloatBox.ox) +"px";
	WfloatBox.style.left="5px";
	//alert(WfloatBox.style.left);
}

function closeBox(){
	hideSelect("visible");
	//overlay.style.display="none";
	WfloatBox.style.display="none";
}

function initbox(){	
	var range=getRange();
	WfloatBox=getElement("floatBox");
	WfloatBox.ox=(range.width-680)/2;
	WfloatBox.oy=(range.height-540)/2;

	Drag.init(getElement("draghead"),WfloatBox);

	WfloatBox.onDragEnd=function(x,y){
		WfloatBox.ox=x-getRange().left;
		WfloatBox.oy=y-getRange().top;
	}

	//addLightboxMarkup();

	//overlay.style.height=document.body.clientHeight;

	var all=getAllElement();
	var l=all.length;
	for(var i=0;i<l;i++){
		var o=all[i];
		if(o.className=="lbOn")
		{
			o.attachEvent("onclick",showBox);
		}
	}
}
window.onload=initbox;



var timeout;
/*
* title :主题 
* messageShow : 提示的内容
* type : error-为错误提示   messageShow-正常信息提示
* closeTime 多少秒后关闭
*/
function autoCloseDiv(title,messageShow,type,closeTime) 
{ 	
	timeout = closeTime;
	initbox();		
	openBox(title,messageShow,type);
	document.getElementById("timeBox").style.display = "block";	
	document.getElementById("timeBox").innerHTML = '提示:窗口会在 '+ timeout +' 秒后自己关闭!';	
	setTimeout(infoTimeout, 1000);
}


function infoTimeout() 
{
	document.getElementById("timeBox").innerHTML = '提示:窗口会在 '+ timeout +' 秒后自己关闭!';	
	  timeout--;
	  if (timeout > -1) 
	  {	
		 	setTimeout(infoTimeout, 1000)
		}
	 else
	 {
		closeBox();
	 }
}

/*
* title :主题 
* messageShow : 提示的内容
* type : error-为错误提示   messageShow-正常信息提示
*/
function showBox(title,messageShow,type)
{	
//	document.getElementById("timeBox").style.display = "none";
//	document.getElementById("timeBox").innerHTML = '';
	initbox();		
	openBox(title,messageShow,type);	
}


function openBox(title,messageShow,type)
{
	if(type == 'error')//错误信息提示
	{
		document.getElementById("titleH2").innerHTML = title;
		document.getElementById("content").className = "errorBox";		
		if(messageShow != null && messageShow.length > 1)		
		{
			document.getElementById("contentBox").innerHTML =messageShow;
		}
	}else//信息提示
	{	
		document.getElementById("titleH2").innerHTML =title;
		document.getElementById("content").className = "msgBox";
		if(messageShow != null && messageShow.length > 1)			
		{	
			document.getElementById("contentBox").innerHTML = messageShow;
		}
	}
	
	hideSelect("hidden");	
	WfloatBox.style.display="block";
	var range=getRange();
	WfloatBox.style.top=(range.top+WfloatBox.oy) +"px";
	//WfloatBox.style.left=(range.left+WfloatBox.ox) +"px";
	WfloatBox.style.left="5px";
	window.onscroll=onbodyscroll;
}