var floatad = floatad || {}
floatad.automove = function automove(id) {
 var xPos = 300;
 var yPos = 200;
 var step = 1;
 var delay = 30;
 var width = document.body.clientWidth;
 var height = document.body.clientHeight;
 var Hoffset = 0;
 var Woffset = 0;
 var yon = 0;
 var xon = 0;
 var pause = true;
 var interval;
 var img1=document.getElementById(id);
 img1.style.top = yPos;

 function changePos()
 {
  Hoffset = img1.offsetHeight;
  Woffset = img1.offsetWidth;
  img1.style.left = xPos + document.body.scrollLeft;
  img1.style.top = yPos + document.body.scrollTop;
  if (yon)
  {
   yPos = yPos + step;
  }
  else
  {
   yPos = yPos - step;
  }
  if (yPos < 0)
  {
   yon = 1;yPos = 0;
  }
  if (yPos >= (height - Hoffset))
  {
   yon = 0;yPos = (height - Hoffset);
  }
  if (xon)
  {
   xPos = xPos + step;
  }
  else
  {
   xPos = xPos - step;
  }
  if (xPos < 0)
  {
   xon = 1;xPos = 0;
  }
  if (xPos >= (width - Woffset))
  {
   xon = 0;xPos = (width - Woffset);
  }
 }

 function start()
 {
  if(interval == null) {
   img1.visibility = "visible";
   interval = setInterval(changePos, delay);
  }
 }
 function pauseit()
 {
  if(pause)
  {
   clearInterval(interval);
   pause = false;
  }
 }
 function resumeit()
 {
  if(!pause)
  {
   interval = setInterval(changePos,delay);
   pause = true;
  }
 }
 function pause_resume()
 {
  if(pause)
  {
   clearInterval(interval);
   pause = false;
  }
  else
  {
   interval = setInterval(changePos,delay);
   pause = true;
  }
 }
 start();
 img1.onmouseover = function() { pauseit(); }
 img1.onmouseout = function() { resumeit(); }
}
function hide(id) {
	var e = document.getElementById(id);
    e.style.display = 'none';
}
function setMenuListSize(menubarId,width) {
 var menubar=document.getElementById(menubarId);
 var menulist = menubar.getElementsByTagName("ul")[0];
 var style = "width:" + menulist.children.length * width + "px;";
 menulist.setAttribute('style', style);
 menulist.style.width = menulist.children.length * width;
}
function autoSizeImg(id, maxWidth, maxHeight) {
 var abc=document.getElementById(id);
 var imgs=abc.getElementsByTagName("img");
 for (var i=0,g;g=imgs[i];i++)
  g.onload=function(){
   if (this.width>maxWidth){
    this.width=maxWidth
   }else{
    if (this.height>maxHeight)
     this.height=maxHeight
   }
  }
}
function enableDropDownMenu(id) {
 var handler = attachDropDownMenuHandler(id);
 //if (window.attachEvent) window.attachEvent("onload", handler);
}
function attachDropDownMenuHandler(id) {
   var sfEls = document.getElementById(id).getElementsByTagName("LI");
   for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
     this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
     this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
   }
}
function switchTab(id,num,count)
{
  ClearTabClass(id,count);
  document.getElementById("tabname_" + id + num).className = "tabf";
  var box = document.getElementById(id + num);
  if(typeof box !== "undefined") {
    box.style.display = "";
  }
}
function swicthTab(id,num,count)
{
  ClearTabClass(id,count);
  document.getElementById("tabname_" + id + num).className = "tabf";
  var box = document.getElementById(id + num);
  if(typeof box !== "undefined") {
    box.style.display = "";
  }
}
function ClearTabClass(id,count)
{
  for(i=1;i<=count;i++)
  {
    document.getElementById("tabname_" + id + i).className = "tabn";
    var box = document.getElementById(""+id + i);
    if(typeof box !== "undefined") {
      box.style.display = "none";
     }
  }
}
var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
    
}
/**
 * util
 */
var util = util || {}
util.applySelectOptionColor = function applySelectOptionColor(id) {
  var select = document.getElementById(id);
  var nodes = select.children;
  var color;
  var option;
  var i;
  for(i=1; i<nodes.length; i++) {
    option = nodes[i];
    color = option.value;
    style = 'background:'+color+'; color:'+color+';';
    option.setAttribute('style', style);
    option.style.cssText = style;
  }
}
util.applySelectOptionFont = function applySelectOptionFont(id) {
  var select = document.getElementById(id);
  var nodes = select.children;
  var fontFamily;
  var option;
  var i;
  for(i=1; i<nodes.length; i++) {
    option = nodes[i];
    fontFamily = option.value;
    style = 'font-family:'+fontFamily;
    option.setAttribute('style', style);
    option.style.cssText = style;
  }
}
util.changeStyle = function changeStyle(id, colorSelectId, fontSelectId) {
  var colorSelect = document.getElementById(colorSelectId);
  var fontSelect = document.getElementById(fontSelectId);
  var color = colorSelect.options[colorSelect.selectedIndex].value;
  var fontFamily = fontSelect.options[fontSelect.selectedIndex].value;
  var style = 'color:'+color + '; font-family:'+fontFamily;
  var element = document.getElementById(id);
  element.setAttribute('style', style);
  element.style.cssText = style;
}
/**
 * focus photo
 */
var focusPhoto = focusPhoto || {};
focusPhoto.n=0;
focusPhoto.autoStart;

focusPhoto.setBg = function setBg(value){
  for(var i=0;i<5;i++)
    document.getElementById("t"+i+"").className="bbg0";
  document.getElementById("t"+value+"").className="bbg1";
};
focusPhoto.plays = function plays(value){
  try
  {
    with (au){
      filters[0].Apply();
      for(i=0;i<5;i++)i==value?children[i].style.display="block":children[i].style.display="none";
      filters[0].play();
      }
  }
  catch(e)
  {
    var d = document.getElementById("au").getElementsByTagName("div");
    for(i=0;i<5;i++)i==value?d[i].style.display="block":d[i].style.display="none";
  }
};
focusPhoto.conaus = function conaus(value){
  try
  {
    with (conau){

      for(i=0;i<5;i++)i==value?children[i].style.display="block":children[i].style.display="none";

      }
  }
  catch(e)
  {
    var d = document.getElementById("conau").getElementsByTagName("div");
    for(i=0;i<5;i++)i==value?d[i].style.display="block":d[i].style.display="none";
  }
};
focusPhoto.Mea = function Mea(value){
  focusPhoto.n=value;
  focusPhoto.setBg(value);
  focusPhoto.plays(value);
  focusPhoto.conaus(value);
};
focusPhoto.clearAuto = function clearAuto(){
  clearInterval(focusPhoto.autoStart)
};
focusPhoto.setAuto = function setAuto(){
  focusPhoto.autoStart=setInterval("focusPhoto.auto()", 3000)
};
focusPhoto.auto = function auto(){
  var n = focusPhoto.n;
  n++;
  if(n>4)n=0;
  focusPhoto.Mea(n);
  focusPhoto.conaus(n);
  focusPhoto.n = n;
};

/**
 * marquee
 * 速度数值越大速度越慢
 */
var marquee = marquee || {};
marquee.startHorizontal= function startHorizontal(boxId, box1Id, box2Id, speed) {
  if(speed === null || typeof speed === "undefined") {
    speed = 25;
  }
  var box = document.getElementById(boxId);
  var box1 = document.getElementById(box1Id);
  var box2 = document.getElementById(box2Id);
  box2.innerHTML=box1.innerHTML;
  function Marquee(){
    if(box2.offsetWidth-box.scrollLeft<=0)
      box.scrollLeft-=box1.offsetWidth;
    else{
      box.scrollLeft++;
    }
  }
  var MyMar=setInterval(Marquee,speed);
  box.onmouseover=function() {
    clearInterval(MyMar);
  }
  box.onmouseout=function() {
    MyMar=setInterval(Marquee,speed);
  }
}
marquee.startVertical = function startVertical(boxId, box1Id, box2Id, speed) {
  if(speed === null || typeof speed === "undefined") {
    speed = 100;
  }
  var box = document.getElementById(boxId);
  var box1 = document.getElementById(box1Id);
  var box2 = document.getElementById(box2Id);
  box2.innerHTML=box1.innerHTML;
  function Marquee(){
    if(box2.offsetTop-box.scrollTop<=0)
      box.scrollTop-=box1.offsetHeight;
    else{
      box.scrollTop++;
    }
  }
  var MyMar=setInterval(Marquee,speed);
  box.onmouseover=function() {
    clearInterval(MyMar);
  }
  box.onmouseout=function() {
    MyMar=setInterval(Marquee,speed);
  }
}
/**
 * theme
 */
var theme = theme || {};
theme.cookieName = 'theme';
theme.linkId = 'link';
theme.selectId = 'select';
theme.resetTheme = function resetTheme() {
  var select = document.getElementById(theme.selectId);
  select.selectedIndex = 0;
  theme.selectTheme();
};
theme.applyTheme = function applyTheme() {
  var t = cookie.readCookie(theme.cookieName);
  if(t === null || typeof t === "undefined") {
    return;
  }
  var link = document.getElementById(theme.linkId);
  link.href='../'+t+'/style.css';
};
theme.adjustSelect = function adjustSelect() {
  var t = cookie.readCookie(theme.cookieName);
  if(t === null || typeof t === "undefined") {
    return;
  }
  var select = document.getElementById(theme.selectId);
  for(var i =0; i<select.length; i++) {
    var option = select.options[i];
    if(option.value == t) {
      option.selected = true;
    }
  }
}
theme.selectTheme = function selectTheme() {
  var select = document.getElementById(theme.selectId);
  var t = select.options[select.selectedIndex].value;
  cookie.createCookie(theme.cookieName, t, 365);
  theme.applyTheme();
}
/**
 * cookie function
 * http://www.quirksmode.org/js/cookies.html
 */
var cookie = cookie || {};
cookie.createCookie = function createCookie(name,value,days) {
  var expires;
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    expires = "; expires="+date.toGMTString();
  }
  else  {
    expires = "";
  }
  document.cookie = name+"="+value+expires+"; path=/";
}

cookie.readCookie = function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

cookie.eraseCookie = function eraseCookie(name) {
  cookie.createCookie(name,"",-1);
}

/**
 * plain, simple, advance
 * editor
 */
function initEditor(t,id,lan) {
 initEditor2(t,id,lan,"TINYMCE");
}
function initEditor2(t,id,lan,editorType) {
 if(t === null || typeof t === "undefined" || t == "plain") {
  return;
 }
 if(editorType == "TINYMCE") {
  if(t == "simple") {
   tinyMCE.init({
    //mode : "textareas",
    mode : "exact",
    elements : id,
    theme : "simple",
    language : lan,
    debug : false
   });
   return;
  }
  if(t == "simple2") {
   tinyMCE.init({
    //mode : "textareas",
    mode : "exact",
    elements : id,
    theme : "advanced",
    language : lan,
    plugins : "paste",
    theme_advanced_buttons1_add_before : "fontselect,fontsizeselect,separator,forecolor,backcolor",
    theme_advanced_buttons2_add_before : "pastetext,pasteword,selectall",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_disable: "styleselect",
    paste_auto_cleanup_on_paste : true,
    paste_retain_style_properties: "text-indent,font-size,color",
    debug : false
   });
  }
  if(t == "advance") {
   tinyMCE.init({
    //mode : "textareas",
    mode : "exact",
    elements : id,
    theme : "advanced",
    language : lan,
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    extended_valid_elements : "a[href|target|name]",
    plugins : "table,media,paste",
    theme_advanced_buttons1_add_before : "fontselect,fontsizeselect,separator,forecolor,backcolor",
    theme_advanced_buttons2_add_before : "pastetext,pasteword,selectall",
    theme_advanced_buttons3_add_before : "tablecontrols,separator",
    theme_advanced_buttons3_add : "media",
    paste_auto_cleanup_on_paste : true,
   paste_retain_style_properties: "text-indent,font-size,color",
   //invalid_elements : "a",
   //theme_advanced_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1", // Theme specific setting CSS classes
   theme_advanced_disable: "styleselect",
   debug : false,
   media_wmp6_compatible : true
  });
  return;
 }
 } else if(editorType == "CKEDITOR") {
  CKEDITOR.replace(id,
   {language : lan }
   );
 }
}

function jmpURLonSelect(select) {
 var jmpURL=select.options[select.selectedIndex].value;
 if(jmpURL === null || typeof jmpURL === "undefined") {
  return;
 } else {
  window.open(jmpURL);
  select.selectedIndex=0;
 }
}