
/**
 * 几个主要的js
 * author :chentao
 **/

/**
 * 收藏和首页
 **/
function addBookmark(title) {
    var url=parent.location.href;
    if (window.sidebar) { 
       window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
       window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
       return true;
    }
}
function SetHome(obj,vrl){
    try{
        obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }catch(e){
        if(window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            } catch (e) { 
                alert("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”，点击“加入收藏”后忽略安全提示，即可设置成功。");            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage',vrl);
         }
   }
}

/**
 * 最新推荐板块的图片轮换
 **/
var atuokey = false;
var ifocus = "pichot";
var focus_piclist = "index_focus_turn_picList";
var focus_btn = "index_focus_turn_btn";
var focus_tx = "index_focus_turn_tx";
function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

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) {
		return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    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 classNormal(iFocusBtnID,iFocusTxID){
	var iFocusBtns= document.getElementById(iFocusBtnID).getElementsByTagName('li');
	var iFocusTxs = document.getElementById(iFocusTxID).getElementsByTagName('li');
	for(var i=0; i<iFocusBtns.length; i++) {
		iFocusBtns[i].className='normal';
		iFocusTxs[i].className='normal';
	}
}

function classCurrent(iFocusBtnID,iFocusTxID,n){
	var iFocusBtns= document.getElementById(iFocusBtnID).getElementsByTagName('li');
	var iFocusTxs = document.getElementById(iFocusTxID).getElementsByTagName('li');
	iFocusBtns[n].className='current';
	iFocusTxs[n].className='current';
}

function iFocusChange() {
	if(!document.getElementById(ifocus)) return false;
	document.getElementById(ifocus).onmouseover = function(){atuokey = true};
	document.getElementById(ifocus).onmouseout = function(){atuokey = false};
	var iFocusBtns = document.getElementById(focus_btn).getElementsByTagName('li');
	var listLength = iFocusBtns.length;
	iFocusBtns[0].onmouseover = function() {
		moveElement(focus_piclist,0,0,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,0);
	}
	if (listLength>=2) {
		iFocusBtns[1].onmouseover = function() {
			moveElement(focus_piclist,0,-204,5);
			classNormal(focus_btn,focus_tx);
			classCurrent(focus_btn,focus_tx,1);
		}
	}
	if (listLength>=3) {
		iFocusBtns[2].onmouseover = function() {
			moveElement(focus_piclist,0,-408,5);
			classNormal(focus_btn,focus_tx);
			classCurrent(focus_btn,focus_tx,2);
		}
	}
	if (listLength>=4) {
		iFocusBtns[3].onmouseover = function() {
			moveElement(focus_piclist,0,-612,5);
			classNormal(focus_btn,focus_tx);
			classCurrent(focus_btn,focus_tx,3);
		}
	}
}

setInterval('autoiFocus()',5000);
function autoiFocus() {
	if(!document.getElementById(ifocus)) return false;
	if(atuokey) return false;
	var focusBtnList = document.getElementById(focus_btn).getElementsByTagName('li');
	var listLength = focusBtnList.length;
	for(var i=0; i<listLength; i++) {
		if (focusBtnList[i].className == 'current') var currentNum = i;
	}
	if (currentNum==0&&listLength!=1 ){
		moveElement(focus_piclist,0,-204,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,1);
	}
	if (currentNum==1&&listLength!=2 ){
		moveElement(focus_piclist,0,-408,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,2);
	}
	if (currentNum==2&&listLength!=3 ){
		moveElement(focus_piclist,0,-612,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,3);
	}
	if (currentNum==3 ){
		moveElement(focus_piclist,0,0,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,0);
	}
	if (currentNum==1&&listLength==2 ){
		moveElement(focus_piclist,0,0,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,0);
	}
	if (currentNum==2&&listLength==3 ){
		moveElement(focus_piclist,0,0,5);
		classNormal(focus_btn,focus_tx);
		classCurrent(focus_btn,focus_tx,0);
	}
}
addLoadEvent(iFocusChange);


/**
 * 特色旅游的滑动门
 */
function secSpecTraitCard(cardName,m,total){
	for (var i=1;i<=total;i++){
		if(i != m){//不是选中的卡
			//图片置为闭合
			document.getElementById(cardName+"_"+i).className = "";
			//内容隐藏
			document.getElementById(cardName+"_"+i+"_div").className = "normal";
		}else{
			//图片置为开
			document.getElementById(cardName+"_"+i).className = "active";
			//内容显示
			document.getElementById(cardName+"_"+i+"_div").className = "current";
		}
	}
}

/**图片滚动**/
function picScroll(contId,contLeftId,contRightId,frameWidth,pageWidth){
	var fwidth = 264;
	var pwidth = 264;
	if(typeof(frameWidth) != "undefined"){
		fwidth = frameWidth;
	}
	if(typeof(pageWidth) != "undefined"){
		pwidth = pageWidth;
	}
    var picScroll = new TencentScrollPic();
	picScroll.scrollContId   = contId; //内容容器ID
	picScroll.arrLeftId      = contLeftId;//左箭头ID
	picScroll.arrRightId     = contRightId; //右箭头ID
	picScroll.frameWidth     = fwidth;//显示框宽度
	picScroll.pageWidth      = pwidth; //翻页宽度
	picScroll.speed          = 40; //移动速度(单位毫秒，越小越快)
	picScroll.space          = 40; //每次移动像素(单位px，越大越快)
	picScroll.autoPlay       = false; //自动播放ture
	picScroll.autoPlayTime   = 5; //自动播放间隔时间(秒)
    picScroll.initialize(); //初始化
}

/**
 *八大板块的滑动门选项卡
 */
function secBoard(elementID,listName,n) {
    var elem = document.getElementById(elementID);
    var elemlist = elem.getElementsByTagName("h3");
    for (var i=0; i<elemlist.length; i++) {
        elemlist[i].className = "normal";
        var m = i+1;
        document.getElementById(listName+"_"+m).className = "normal";
    }
    elemlist[n-1].className = "current";
    document.getElementById(listName+"_"+n).className = "current";
}
