
var fileLoadingImage = "images/loading.gif";		
var fileBottomNavCloseImage = "images/closelabel.gif";

var resizeSpeed = 7;	// controls the speed of the image resizing (1=slowest and 10=fastest)
var borderSize = 10;	//if you adjust the padding in the CSS, you will need to update this variable

var imageArray = new Array;
var activeImage;

if(resizeSpeed > 10){ resizeSpeed = 10;}
if(resizeSpeed < 1){ resizeSpeed = 1;}
resizeDuration = (11 - resizeSpeed) * 0.15;

Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});

Array.prototype.removeDuplicates = function () {
	for(i = 1; i < this.length; i++){
		if(this[i][0] == this[i-1][0]){
			this.splice(i,1);
		}
	}
}

// -----------------------------------------------------------------------------------

Array.prototype.empty = function () {
	for(i = 0; i <= this.length; i++){
		this.shift();
	}
}

var Lightbox = Class.create();

Lightbox.prototype = {

	initialize: function() {	
		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// loop through all anchor tags
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			
			var relAttribute = String(anchor.getAttribute('rel'));
			
			// use the string.match() method to catch 'lightbox' references in the rel attribute
			if (anchor.getAttribute('href') && (relAttribute.toLowerCase().match('lightbox'))){
				anchor.onclick = function () {myLightbox.start(this); return false;}
			}
		}
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		objOverlay.style.display = 'none';
		objOverlay.onclick = function() { myLightbox.end(); return false; }
		objBody.appendChild(objOverlay);
		
		var objLightbox = document.createElement("div");
		objLightbox.setAttribute('id','lightbox');
		objLightbox.style.display = 'none';
		objBody.appendChild(objLightbox);
	
		var objOuterImageContainer = document.createElement("div");
		objOuterImageContainer.setAttribute('id','outerImageContainer');
		objLightbox.appendChild(objOuterImageContainer);
		
		 var objLoadingLink = document.createElement("a");
		objLoadingLink.setAttribute('id','loadingLink');
		objLoadingLink.setAttribute('href','#');
		 objLoadingLink.innerHTML = "关闭";
		objLoadingLink.onclick =closedwid;
		objOuterImageContainer.appendChild(objLoadingLink);//添加一个关闭的 按钮
		  
		  
		var myself = document.createElement("div");
		myself.setAttribute('id','myself');
		myself.setAttribute('class','topborder');
		objOuterImageContainer.appendChild(myself);
		
		var data = new Array();
        data.push('  <table width=400 border=0 cellpadding=0 cellspacing=0 height=110 align=center>');
						 data.push('	<tr>');
							 data.push('  <td>&nbsp;</td>');
							  data.push(' <td colspan=3 class=LanMu align=left>天才工作室欢迎您登录网站</td>');
			   data.push('  </tr>');
							 data.push('<tr>');
								 data.push('<td width=79>用户名：</td>');
								 data.push('<td colspan=3 align=left><input type=text name=username1 id=username1>');
							    data.push(' <br></td>');
							 data.push('</tr>');
							 data.push('<tr>');
								 data.push('<td align=center>密&nbsp; 码：</td>');
								 data.push('<td colspan=3 align=left><input type=password name=password1 id=password1>');
							    data.push(' <br></td>');
							 data.push('</tr>');
							 data.push('<tr>');
							 data.push('	<td align=center>验证码：</td>');
							  data.push(' <td width=70 class=iup><input id=yanzheng1 type=text size=10>');
						      data.push(' <a href=#></a>								</td>');
							 data.push('<td width=15 class=iup>');
								 data.push('<strong id=divCode>&nbsp;</strong></td>');
								 data.push('<td width=59 class=iup>&nbsp;&nbsp;<a href=javascript:ChangeValidateCode()>看不清?<br>');
								 data.push('</a></td>');
							 data.push('</tr>');
							 data.push('<tr>');
								 data.push('<td height=35>&nbsp;</td>');
								 data.push('<td colspan=3 align=center valign=bottom><div align=left>');
								 data.push('<INPUT class=WebButtonStyle type=button value="登 陆" name=membersubmit onclick=checklogined()>');
								  data.push('	<div id=error1 style=color:red></div>');
							    data.push(' </div></td>');
							 data.push('</tr>');
						 data.push('</table> ');
            document.getElementById('myself').innerHTML = data.join('');
            document.onload = ChangeValidateCode();
      
	},

	start: function(imageLink) {	

		hideSelectBoxes();

		// stretch overlay to fill page and fade in
		var arrayPageSize = getPageSize();
		Element.setHeight('overlay', arrayPageSize[1]);
		new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });

		imageArray = [];
		imageNum = 0;		

		if (!document.getElementsByTagName){ return; }
		var anchors = document.getElementsByTagName('a');

		// if image is NOT part of a set..
		if((imageLink.getAttribute('rel') == 'lightbox')){
			// add single image to imageArray
			imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));			
		} else {
		// if image is part of a set..

			// loop through anchors, find other images in set, and add them to imageArray
			for (var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel')))
				{
					imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
				}
			}
			imageArray.removeDuplicates();
			while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
		}

		// calculate top offset for the lightbox and display 
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);

		Element.setTop('lightbox', lightboxTop);
		Element.show('lightbox');
		
		this.changeImage(imageNum);
	},


	end: function()
	 {
		this.disableKeyboardNav();
		Element.hide('lightbox');
		new Effect.Fade('overlay', { duration: 0.2});
		showSelectBoxes();
	}
}
   function closedwid()//解除主窗口的锁定
   {
        Element.hide('lightbox');
		new Effect.Fade('overlay', { duration: 0.2});
		showSelectBoxes();
		 document.getElementById("username1").value="";
       document.getElementById("password1").value="";
       document.getElementById("yanzheng1").value="";
       document.getElementById("error1").innerHTML="";
   }
   
   //////////////////////////////////////////////////////////////////////////////////////////登录的验证
   var xmlHttp;//创造xmlHttpRequest对象
   var username;
 function createXMLHttpRequest()
   {
      if(window.ActiveXObject)
          {
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
             
          }
          else if(window.XMLHttpRequest)
             {
               xmlHttp=new XMLHttpRequest();
             }
     }
   function checklogined()
   { 
     username=document.getElementById("username1").value;
     var password=document.getElementById("password1").value;
     var yanzheng=document.getElementById("yanzheng1").value;
    if(username.length==0)
       {  
         document.getElementById("error1").innerText="温馨提示:请输入用户名.";
         window.event.returnValue=false;
         return false;
        }
        else
          {
              if(password.length==0)
                {
                     document.getElementById("error1").innerText="温馨提示:请输入密码.";
                     window.event.returnValue=false;
                      return false;
                }
                else
                {
                    if(yanzheng.length==0)
                        {
                           document.getElementById("error1").innerText="温馨提示:请输入验证码.";
                            window.event.returnValue=false;
                            return false;
                        }
                        else
                        {
                            var yz=document.getElementById("divCode").innerText;
                            if(yanzheng!=yz)
                                 {
                                     document.getElementById("error1").innerText="温馨提示:验证码错误.";
                                     window.event.returnValue=false;
                                     return false;
                                 }
                        }
                }
          }
        createXMLHttpRequest();//创建对象
        var url="Admin/ajax.aspx?username="+username+"&password="+password+"&types=45";
        xmlHttp.open("GET",url,true);
        xmlHttp.onreadystatechange=callback;
        xmlHttp.send(null);
   }
   function logined(username)
      {
        document.getElementById("login").innerHTML="<div>"+username+":您已经成功登陆"+"  "+"<a href=javascript:loginout() title=点击退出本注销登录网站.>退出</div><div><a href=seereg.htm title=欢迎您注册成本站的会员.>注册</a>"+"   "+"<a href=getpwd.html title=忘记密码取回您的密码.>忘记密码</a></div>";
      }
   ///////////////////////验证用户的回调函数
   function callback()
    {
       document.getElementById("error1").innerText="系统正在登陆中,请稍候...";
       if(xmlHttp.readyState==4)
           {
           
              if(xmlHttp.status==200)
                  {
                     if(xmlHttp.responseText=="true")
                      {
                         closedwid();
                        document.getElementById("login").innerHTML="<div>"+username+":您已经成功登陆"+"  "+"<a href=javascript:loginout() title=点击退出本注销登录网站.>退出</div><div><a href=seereg.htm title=欢迎您注册成本站的会员.>注册</a>"+"   "+"<a href=getpwd.html title=忘记密码取回您的密码.>忘记密码</a></div>";
                      }
                     if(xmlHttp.responseText=="false")
                      {
                         ChangeValidateCode();
                         document.getElementById("error1").innerText="温馨提示:用户名或密码错误.";
                         window.event.returnValue=false;
                     }
                  }
                 
            }
             window.event.returnValue=false;
      }
      ////////////////验证码
 function ChangeValidateCode()
    {   
        document.getElementById("divCode").innerHTML="";
		var codeLength = 6
		var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
		for(var i=0;i<codeLength;i++)
		{
			var charIndex = Math.floor(Math.random()*36);
			document.getElementById("divCode").innerHTML=document.getElementById("divCode").innerHTML+selectChar[charIndex];
		}
}
//////////////////////////退出登录
 function loginout()
 {
         createXMLHttpRequest();//创建对象
        var url="Admin/ajax.aspx?types=46";
        xmlHttp.open("GET",url,true);
        xmlHttp.onreadystatechange=callback1;
        xmlHttp.send(null);
 }
  function callback1()
    {
       if(xmlHttp.readyState==4)
           {
           
              if(xmlHttp.status==200)
                  {
                     if(xmlHttp.responseText=="true")
                      {
                        document.getElementById("login").innerHTML="<div align=center id=login>您还末<a href=# rel=lightbox>登录</a> <a href=seereg.htm title=欢迎您注册成本站的会员.>注册</a></div>";
                      }
                  }  
            }
            window.event.returnValue=false;
      }
 
 
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	
	if(key == 'x'){
	}
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {	document.onkeypress = getKey; }
	
// ---------------------------------------------------

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

// ---------------------------------------------------

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

// ---------------------------------------------------



function initLightbox() { myLightbox = new Lightbox(); }
Event.observe(window, 'load', initLightbox, false);