//图片滑动
var moveing = false;
function $(id) { return document.getElementById(id); }
function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
  if (!elem.style.top) {
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (xpos == final_x && ypos == final_y) {
	moveing=false;
    return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);//Math.ceil求最小的整数，但不小于本身
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}
function next(previousBtn,nextBtn,scrollID,highlightID) {
	if(moveing) return;
	moveing = true;
	var vTop = parseInt($(scrollID).style.top);
	var vLeft = parseInt($(scrollID).style.left);
	if (vLeft <= -1776) return moveing=false;
	if(vLeft == -1184) {
		$(nextBtn).className = 'last_btn';
	}
	var finalLeft = vLeft - 592;
	moveElement(scrollID,finalLeft,vTop,5);
	$(previousBtn).className = 'previous';
	var highLightList = $(highlightID).getElementsByTagName('span');
	for (var i=0; i<highLightList.length; i++) {
		if (highLightList[i].className == 'current') {
			 var currentNum = i;
		}		
	}
	highLightList[currentNum].className = '';
	highLightList[currentNum+1].className = 'current';
}
function previous(previousBtn,nextBtn,scrollID,highlightID) {
	if(moveing) return;
	moveing = true;
	var vTop = parseInt($(scrollID).style.top);
	var vLeft = parseInt($(scrollID).style.left);
	if (vLeft >= 0) return moveing=false;
	if(vLeft == -592) {
		$(previousBtn).className = 'first_btn';
	}
	var finalLeft = vLeft + 592;
	moveElement(scrollID,finalLeft,vTop,5);
	$(nextBtn).className = 'next';
	var highLightList = $(highlightID).getElementsByTagName('span');
	for (var i=0; i<highLightList.length; i++) {
		if (highLightList[i].className == 'current') {
			 var currentNum = i;
		}		
	}
	highLightList[currentNum].className = '';
	highLightList[currentNum-1].className = 'current';
}

//login伸缩效果
var $ = function (id) {
    return "string" == typeof id ? document.getElementById(id) : id;
};
var $C = function (id) {
	return $(id).style;
};
var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}
Object.extend = function(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
    return destination;
}
var CurrentStyle = function(element){
	return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}
var FlexDiv = Class.create();
FlexDiv.prototype = {
  initialize: function(idDiv, options) {
    var oDiv = $(idDiv);
	oDiv.style.overflow = "hidden";
    this.oDiv = oDiv;
    this.borderWidth = parseInt(CurrentStyle(oDiv).borderTopWidth) + parseInt(CurrentStyle(oDiv).borderBottomWidth) || 0;
	
	
    this.SetOptions(options);
	
	if(this.options.Show){
		this.show = 1;//1显示，-1隐藏
		this.oDiv.style.height = this.options.maxHeight + "px";
	} else {
		this.show = -1;
		this.oDiv.style.height = "0px";
	}
	
    this.timer = null;
  },
  //设置默认属性
  SetOptions: function(options) {
    this.options = {//默认值
      Show:			true,//默认打开状态
	  iStep:        4,//每次变化的px量
      iTime:        10,//每隔多久循环一次
      minHeight:    0,//最小高度
      maxHeight:    this.oDiv.offsetHeight - this.borderWidth//最大高度
    };
    Object.extend(this.options, options || {});
  },
  //触发
  Flex: function() {
    clearTimeout(this.timer); this.show *= -1; this.SetFlex();
  },
  //执行
  SetFlex: function() {
    var iHeight = this.oDiv.offsetHeight - this.borderWidth, op = this.options;
    if ((this.show > 0 && iHeight < op.maxHeight) || (this.show < 0 && iHeight > op.minHeight)) {
        iHeight += this.show * op.iStep;
        this.oDiv.style.height = ((iHeight > 0) ? iHeight : 0) + "px";
        var oFlex = this;
        this.timer = setTimeout(function(){ oFlex.SetFlex(); }, op.iTime);
    }
  }
};


//---中英文切换菜单特效--
var DDSPEED = 10;
var DDTIMER = 15;
// 处理鼠标动作的主函数 //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// 回缩菜单 //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// 如果有用户将鼠标放置在菜单上则取消回溯 //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// 展开/回缩菜单，并设置透明度 //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

// 分栏显示 //
function switchmodTag(modtag,modcontent,modk) {
    for(i=1; i <3; i++) {
      if (i==modk) {
        document.getElementById(modtag+i).className="menuOn";document.getElementById(modcontent+i).className="SlidingList";}
      else {
        document.getElementById(modtag+i).className="menuNo";document.getElementById(modcontent+i).className="SlidingList_none";}
    }
  }
  
  //层模拟的窗口
  var Obj=''
document.onmouseup=MUp
document.onmousemove=MMove
function MDown(Object){
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y-document.all(Obj).style.pixelTop;
}

function MMove(){
if(Obj!=''){
  document.all(Obj).style.left=event.x-pX;
  document.all(Obj).style.top=event.y-pY;
  }
}

function MUp(){
if(Obj!=''){
  document.all(Obj).releaseCapture();
  Obj='';
  }
}
