$(function() {
  $('#downArrowBox').click(function() {
      if($(document).height() > $(this).offset().top) {
        var _t = document.documentElement.scrollTop + 200;
        $(document.documentElement).animate({scrollTop: _t}, 400);
      }
    });
  doOnScrollTimer = null;
  window.onscroll = function() { window.clearTimeout(doOnScrollTimer); doOnScrollTimer = window.setTimeout('doOnScroll()', 100); };
  doOnScroll();
});
function doOnScroll() {
  if( document.documentElement.clientHeight + document.documentElement.scrollTop > document.body.scrollHeight - 80 ) {
    $('#downArrowBox').fadeTo('slow', 0);
  } else {
    var top = document.documentElement.clientHeight + document.documentElement.scrollTop - 80;
    var left = document.documentElement.clientWidth + document.documentElement.scrollLeft -  70;
    $('#downArrowBox').animate({ top: top }, 400)
      .fadeTo('fast', 1);
  }
}

/* 更换产品
*/
function showProduct(sid) {
  if($('.rightpart')) {
    var par = {
      _rn: Math.random(),
      sid: sid
    };
    $('.rightpart').html('<img src="common/loading/loading28.gif" align="absmiddle" /> 正在加载内容......')
      .load('act.php?getProduct', par, function() {  });
  } else {
  }
}
/* 更换图片
*/
function swiPhoto(e) {
  if($('.flashbox_2') && $('img', e)) {
    var src = $('img', e).attr('src');
    $('.flashbox_2 img:eq(0)').attr('src', src);
    $('.flashbox_2 a:eq(0)').attr('href', src);
    window.scrollTo(0, 265);
  }
}
/* 更换图片
 * 应用于搜索结果页面
*/
function swiPhoto2(i, e) {
  if($('#bigPhotoBox_'+i) && $('img', e)) {
    var src = $('img', e).attr('src');
    $('#bigPhotoBox_'+i+' img:eq(0)').attr('src', src);
    $('#bigPhotoBox_'+i+' a:eq(0)').attr('href', src);
  }
}

/* Window functions
*/
var winFunc = {
  toString: function() {
    return location;
  },
  /* 获取锚点
  */
  get_anchor: function() {
    var href = location.href;
    var anchor = href.indexOf('#') == -1 ?
      false :
      href.substring(href.indexOf('#')+1);
    return anchor;
  },
  /* 设置锚点
  */
  set_anchor: function($var) {
    //alert($var);
    var href = location.href;
    if(href.indexOf('#') == -1) {
      location = href + '#' + $var;
    } else {
      location = href.substring(0, href.indexOf('#')) + '#' + $var;
    }
  },
  reload: function() {
    location.reload();
    //location = location;
  },
  go: function(sUrl, sTarget) {
    if(typeof sTarget=='undefined') {
      location = sUrl;
    } else {
      sTarget.location = sUrl;
    }
    if($.browser.msie) event.srcElement.href = '#';
    return;
  },
  top: function() {
    window.scrollTo(0, 0);
  },
  bottom: function() {
    window.scrollTo(0, 9999);
  },
  open: function(sUrl) {
    window.open(sUrl);
  },
  /* 切换数据语言
  */
  sl: function(lang, onComplete) {
    var par = {
      _rn: Math.random(),
      lang: lang
    }
    $.post('act.php?sl', par, function() {
      if(onComplete == undefined) {
        winFunc.reload();
      } else {
        __LP = lang;
        onComplete();
      }
    });
  },
  /* 获取文件扩展名
   * dellker.com 2007-10-31
  */
  getExt: function(sFile) {
    if(!sFile) return;
    else{
      var a = sFile.split('.');
      if(a.length>0) return a[a.length-1].toLowerCase();
      else return false;
    }
  }
}/* end winFunc*/

/* 加入收藏夹方法
 * 兼容 FF & IE
*/
function addFavorite(sURL, sTitle) {
  try {
    window.external.addFavorite(sURL, sTitle);
  } catch(e) {
    try {
      window.sidebar.addPanel(sTitle, sURL, "");
    } catch(e) {
      alert("加入收藏失败，请使用Ctrl+D进行添加");
    }
  }
}

/**
 * 展开 "更多案例" 列表
 * reference: case.html
 *
 */
function expandCaseList() {
  $('.sidenav').animate( { height: getHeight()}, null, null, function() {
      $('#content .left1 .more').fadeOut('fast', function() { $(this).remove(); });
  });
}

function getHeight() {
  var height = 0;
  $('.sidenav li').each(function() {
    height += $(this).height();
  });
  return height;
}

/**
 * 禁止右键
 *
 */
document.oncontextmenu = function(e){
     return !((e||event).cancelBubble = true);
}

$(function() {
  var ht = $('.sidenav').height();
  if(getHeight() > ht) {
    $('#content .left1 .more').show();
  }
});