﻿function DrawImage(ImgD,FitWidth,FitHeight) 
{ 
  var image=new Image(); 
  image.src=ImgD.src; 
  if(image.width>0 && image.height>0) 
  { 
    if(image.width/image.height>= FitWidth/FitHeight) 
    { 
      if(image.width>FitWidth) 
      { 
        ImgD.width=FitWidth; 
        ImgD.height=(image.height*FitWidth)/image.width;
      } 
      else 
      {
        ImgD.width=image.width; 
        ImgD.height=image.height; 
      } 
    } 
    else 
    { 
      if(image.height>FitHeight) 
      { 
        ImgD.height=FitHeight; 
        ImgD.width=(image.width*FitHeight)/image.height; 
      } 
      else 
      { 
        ImgD.width=image.width; 
        ImgD.height=image.height; 
      } 
    } 
  }
}

//焦点图片js脚本
function HtmlDecode(text){return text.replace(/&amp;/g,'&').replace(/&quot;/g,'\"').replace(/&lt;/g,'<').replace(/&gt;/g,'>')}

function TopImgItem (strUrl,imgMaxUrl,imgMinUrl,strText){
	this.strUrl = strUrl;
	this.imgMaxUrl = imgMaxUrl;
	this.imgMinUrl = imgMinUrl;	
	this.strText = HtmlDecode(strText);
}

function opCard(objName,htmlContainer){
	this.obj = objName;
	this.container = htmlContainer || 'focusImg';
	this.bind = new Array();
	this.index = 0;
	this.style = new Array();
	this.overStyle = false;
	this.overChange = false;
	this.menu = false;
	this.nesting = [false,false,"",""];
	this.auto = [false, 1000];
	this.timerID = null;
	this.menutimerID = null;
	this.m_TopImgs = new Array();
	this.completed = false;
}

opCard.prototype.AddImgItem = function (strUrl,imgMaxUrl,imgMinUrl,strText){
	this.m_TopImgs[this.m_TopImgs.length] = new TopImgItem(strUrl,imgMaxUrl,imgMinUrl,strText);
}

opCard.prototype.show = function(){
	var str='<ul id="'+ this.obj +'_s" class="ul">';
	for (var i=0;i<this.m_TopImgs.length;i++){
		str += '<li';
		if (i!=0){str += ' style="display:none"'}
		str += '><a href="'+ this.m_TopImgs[i].strUrl +'" target="_blank"><img src="'+ this.m_TopImgs[i].imgMaxUrl +'" alt="'+this.m_TopImgs[i].strText+'" /></a><p class="titbg"></p><p class="tita"><a href="'+ this.m_TopImgs[i].strUrl +'" title="'+ this.m_TopImgs[i].strText +'" target="_blank">'+ this.m_TopImgs[i].strText +'</a></p></li>';
	}
	str +='</ul><ul id="'+ this.obj +'_a" class="ul">';
	for (var i=0;i<this.m_TopImgs.length;i++){
		str += '<li><a href="'+ this.m_TopImgs[i].strUrl +'" target="_blank"><img src="'+ this.m_TopImgs[i].imgMinUrl +'" alt="'+ this.m_TopImgs[i].strText +'" /></a></li>';
	}
	str +='</ul>';
	this.completed = true;
	document.getElementById(this.container).innerHTML=str;
	//return str;
}
opCard.prototype.creat = function(func){
	var _arrMenu = document.getElementById(this.bind[0]).getElementsByTagName(this.bind[1]);
	var _arrInfo = document.getElementById(this.bind[2]).getElementsByTagName(this.bind[3]);
	var my = this, i;
	var argLen = arguments.length;
	var arrM = new Array();
	if(this.nesting[0] || this.nesting[1]){
		var arrMenu = this.nesting[0]?getChilds(_arrMenu,this.bind[0],2):_arrMenu;
		var arrInfo = this.nesting[1]?getChilds(_arrInfo,this.bind[2],3):_arrInfo;
	}else{
		var arrMenu = _arrMenu;
		var arrInfo = _arrInfo;
	}
	var l = arrMenu.length;
	if(l!=arrInfo.length){alert("菜单和内容必须拥有相同的数量\n如果需要，你可以放一个空的在那占位。")}
	if(this.menu){this.auto=false;this.overChange=true;}
	for(i=0;i<l;i++){
		arrMenu[i].cName = arrMenu[i].className;
		arrMenu[i].className = (i!=this.index || this.menu)?getClass(arrMenu[i],this.style[0]):getClass(arrMenu[i],this.style[1]);
		if(arrMenu[i].getAttribute("skip")){
			if(this.overStyle || this.overChange){
				arrMenu[i].onmouseover = function(){changeTitle(this, 2);autoStop(this, 0);}
				arrMenu[i].onmouseout = function(){changeTitle(this, 0);autoStop(this, 1);}
			}
			arrMenu[i].onclick = function(){if(argLen==1){func()}}
			arrInfo[i].style.display = "none";
			continue;
		}
		if(i!=this.index || this.menu){arrInfo[i].style.display="none"};
		arrMenu[i].index = i;
		arrInfo[i].index = i;
		if(this.overChange){
			arrMenu[i].onmouseover = function(){changeOption(this);my.menu?changeMenu(1):autoStop(this, 0);}
			arrMenu[i].onmouseout = function(){changeOption(this);my.menu?changeMenu(0):autoStop(this, 1);}
		}else{
			arrMenu[i].onclick = function(){changeOption(this);autoStop(this, 0);if(argLen==1){func()}}
			if(this.overStyle){
				arrMenu[i].onmouseover = function(){changeTitle(this, 2);autoStop(this, 0);}
				arrMenu[i].onmouseout = function(){changeTitle(this, 0);autoStop(this, 1);}
			}else{
				if(this.auto[0]){
					arrMenu[i].onmouseover = function(){autoStop(this, 0);}
					arrMenu[i].onmouseout = function(){autoStop(this, 1);}
				}
			}
		}
		if(this.auto[0] || this.menu){
			arrInfo[i].onmouseover = function(){my.menu?changeMenu(1):autoStop(this, 0);}
			arrInfo[i].onmouseout = function(){my.menu?changeMenu(0):autoStop(this, 1);}
		}
	}
	if(this.auto[0]){
		this.timerID = setTimeout(autoMove,this.auto[1])
	}

	function autoMove(){
		var n;
		n = my.index + 1;
		if(n==l){n=0};
		while(arrMenu[n].getAttribute("skip")){
			n += 1;
			if(n==l){n=0};
		}
		changeOption(arrMenu[n]);
		my.timerID = setTimeout(autoMove,my.auto[1]);
	}
	function autoStop(obj, num){
		if(!my.auto[0]){return;}
		num == 0 ? clearTimeout(my.timerID) : my.timerID = setTimeout(autoMove,my.auto[1]);
	}
	function changeOption(obj){
		arrMenu[my.index].className = getClass(arrMenu[my.index],my.style[0]);
		arrInfo[my.index].style.display = "none";
		obj.className = getClass(obj,my.style[1]);
		arrInfo[obj.index].style.display = "";
		my.index = obj.index;
	}
	function changeTitle(obj, num){
		if(!my.overStyle){return;};
		if(obj.index!=my.index){obj.className = getClass(obj,my.style[num])}
	}
	function changeMenu(num){
		if(!my.menu){return;}
		num==0?my.menutimerID = setTimeout(menuClose,1000):clearTimeout(my.menutimerID)
	}
	function menuClose(){
		arrInfo[my.index].style.display = "none";
		arrMenu[my.index].className = getClass(arrMenu[my.index],my.style[0]);
	}
	function getClass(o, s){
		if(o.cName==""){return s}
		else{return o.cName + " " + s}
	}
	function getChilds(arrObj, id, num){
		var depth = 0;
		var firstObj = my.nesting[num]==""?arrObj[0]:document.getElementById(my.nesting[num]);
		do{
			if(firstObj.parentNode.getAttribute("id")==id){break}else{depth+=1}
			firstObj = firstObj.parentNode;
		}while(firstObj.tagName.toLowerCase()!="body")
		var t;
		var arr = new Array();
		for(i=0;i<arrObj.length;i++){
			t = arrObj[i], d = 0;
			do{
				if(t.parentNode.getAttribute("id")==id && d == depth){
					arr.push(arrObj[i]);break;
				}else{
					if(d==depth){break};d+=1;
				}
				t = t.parentNode;
			}
			while(t.tagName.toLowerCase()!="body")
		}
		return arr;
	}
}

if (!Array.prototype.push) {
	Array.prototype.push = function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
};
if (!Array.prototype.pop) {
	Array.prototype.pop = function array_pop() {
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
};

//上下间隔性滚动js
function Marquee()
{
 this.ID = document.getElementById(arguments[0]);
 if(!this.ID)
 {
  alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
  this.ID = -1;
  return;
 }
 this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.Correct = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
 this.Step = 1;
 this.Timer = 30;
 this.DirectionArray = {"top":0 , "bottom":1 , "left":2 , "right":3};
 if(typeof arguments[1] == "number")this.Direction = arguments[1];
 if(typeof arguments[2] == "number")this.Step = arguments[2];
 if(typeof arguments[3] == "number")this.Width = arguments[3];
 if(typeof arguments[4] == "number")this.Height = arguments[4];
 if(typeof arguments[5] == "number")this.Timer = arguments[5];
 if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
 if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
 if(typeof arguments[8] == "number")this.ScrollStep = arguments[8]
 this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
 this.ID.noWrap = true;
 this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
 if(arguments.length >= 7)this.Start();
}

Marquee.prototype.Start = function()
{
 if(this.ID == -1)return;
 if(this.WaitTime < 800)this.WaitTime = 800;
 if(this.Timer < 20)this.Timer = 20;
 if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
 if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
 if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
 this.HalfWidth = Math.round(this.Width / 2);
 this.BakStep = this.Step;
 this.ID.style.width = this.Width;
 this.ID.style.height = this.Height;
 if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
 var msobj = this;
 var timer = this.Timer;
 var delaytime = this.DelayTime;
 var waittime = this.WaitTime;
 msobj.StartID = function(){msobj.Scroll()}
 msobj.Continue = function()
    {
     if(msobj.MouseOver == 1)
     {
      setTimeout(msobj.Continue,delaytime);
     }
     else
     { clearInterval(msobj.TimerID);
      msobj.CTL = msobj.Stop = 0;
      msobj.TimerID = setInterval(msobj.StartID,timer);
     }
    }

 msobj.Pause = function()
   {
    msobj.Stop = 1;
    clearInterval(msobj.TimerID);
    setTimeout(msobj.Continue,delaytime);
   }

 msobj.Begin = function()
  {
   msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth : msobj.ID.scrollHeight;
   if((msobj.Direction <= 1 && msobj.ClientScroll <msobj.Height) || (msobj.Direction > 1 && msobj.ClientScroll <msobj.Width))return;
   msobj.ID.innerHTML += msobj.ID.innerHTML;
   msobj.TimerID = setInterval(msobj.StartID,timer);
   if(msobj.ScrollStep < 0)return;
   msobj.ID.onmousemove = function(event)
      {
       if(msobj.ScrollStep == 0 && msobj.Direction > 1)
       {
        var event = event || window.event;
        if(window.event)
        {
         if(msobj.IsNotOpera)
         {
          msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
         }
         else
         {
          msobj.ScrollStep = null;
          return;
         }
        }
        else
        {
         msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;
        }
        msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
        msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
        msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
       }
      }
   msobj.ID.onmouseover = function()
      {
       if(msobj.ScrollStep == 0)return;
       msobj.MouseOver = 1;
       clearInterval(msobj.TimerID);
      }
   msobj.ID.onmouseout = function()
      {
       if(msobj.ScrollStep == 0)
       {
        if(msobj.Step == 0)msobj.Step = 1;
        return;
       }
       msobj.MouseOver = 0;
       if(msobj.Stop == 0)
       {
        clearInterval(msobj.TimerID);
        msobj.TimerID = setInterval(msobj.StartID,timer);
       }
      }
  }
 setTimeout(msobj.Begin,waittime);
}

Marquee.prototype.Scroll = function()
{
 switch(this.Direction)
 {
  case 0:
   this.CTL += this.Step;
   if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
   {
    this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
    this.Pause();
    return;
   }
   else
   {
    if(this.ID.scrollTop >= this.ClientScroll)
    {
     this.ID.scrollTop -= this.ClientScroll;
    }
    this.ID.scrollTop += this.Step;
   }
  break;

  case 1:
   this.CTL += this.Step;
   if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
   {
    this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
    this.Pause();
    return;
   }
   else
   {
    if(this.ID.scrollTop <= 0)
    {
     this.ID.scrollTop += this.ClientScroll;
    }
    this.ID.scrollTop -= this.Step;
   }
  break;

  case 2:
   this.CTL += this.Step;
   if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
   {
    this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
    //this.Pause();
    //return;
   }
   else
   {
    if(this.ID.scrollLeft >= this.ClientScroll)
    {
     this.ID.scrollLeft -= this.ClientScroll;
    }
    this.ID.scrollLeft += this.Step;
   }
  break;

  case 3:
   this.CTL += this.Step;
   if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
   {
    this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
    //this.Pause();
    //return;
   }
   else
   {
    if(this.ID.scrollLeft <= 0)
    {
     this.ID.scrollLeft += this.ClientScroll;
    }
    this.ID.scrollLeft -= this.Step;
   }
  break;
 }
}

//focus_width:图片宽度
//focus_height:图片高度
//pics:新闻图片字符串
//links:新闻链接字符串
//texts:新闻文本字符串
function image_news(focus_width, focus_height, pics, links, texts) {
    var interval_time = 5;

    var text_height = 23;

    var text_mtop = 3;

    var text_lm = 0;

    var textmargin = text_mtop + "|" + text_lm;

    var textcolor = "#000000|0x000000";

    var text_align = 'center';

    var swf_height = focus_height + text_height + text_mtop;

    var text_size = 13;

    var borderStyle = "0|0xffffff|100";

    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + focus_width + '" height="' + swf_height + '">');

    document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="/port/include/powerpoint.swf"> <param name="quality" value="high"><param name="Wmode" value="transparent">');

    document.write('<param name="menu" value="false"><param name=wmode value="opaque">');

    document.write('<param name="FlashVars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '&textmargin=' + textmargin + '&textcolor=' + textcolor + '&borderstyle=' + borderStyle + '&text_align=' + text_align + '&interval_time=' + interval_time + '&textsize=' + text_size + '">');

    document.write('<embed src="/port/include/powerpoint.swf" wmode="opaque" FlashVars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + focus_width + '&borderheight=' + focus_height + '&textheight=' + text_height + '&textmargin=' + textmargin + '&textcolor=' + textcolor + '&borderstyle=' + borderStyle + '&text_align=' + text_align + '&interval_time=' + interval_time + '&textsize=' + text_size + '" menu="false" bgcolor="ffeeff" quality="high" width="' + focus_width + '" height="' + swf_height + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>');
}
