﻿$(function(){

       //字符截断
       $(".side_i .newslist li a").attr("limit", 20)
       $(".news_l .newslist li a").attr("limit", 14)

     //  $("[limit]").limit();
       
  //首页广告图轮换
  var curIndex = 0;
  var picCount = $(".banner img").size();
  var fadeShow;
  $(".banner img:first").show();
  if( picCount <= 1) return;
   autoShow();
   $(".thums span:first").addClass("cur");
   $(".thums span").hover(function(){
     stopShow();
     var thisId = $(".thums span").index($(this));
     if( !$(this).hasClass("cur"))
     {
         $(".banner img:visible").fadeOut();
         $(".banner img").eq(thisId).fadeIn();
         $(".thums span").removeClass();
         $(this).addClass("cur");
     }
   },
   function(){
     autoShow();
   })
  function autoShow(){
     $(".banner img").eq(curIndex - 1).fadeOut();
	 $(".banner img").eq(curIndex).fadeIn();
	 $(".thums span").eq(curIndex).addClass("cur").siblings().removeClass();
	 curIndex++;
	 curIndex = curIndex >= picCount ? 0:curIndex;
	 fadeShow = setTimeout(autoShow,4000);
  }
  function stopShow(){
     clearTimeout(fadeShow);
  }
})

   //字符截断
   $.fn.limit=function(){
	var self = $("[limit]");
	self.each(function(){
		var objString = $(this).text();
		var objLength = $(this).text().length;
		var num = $(this).attr("limit");
		if(objLength > num){
           $(this).attr("title",objString);
			objString = $(this).text(objString.substring(0,num) + "...");
		 }
	})
   }  

function setHomePage() {
    var host = location.href;
    host = host.replace("//", "#");
    host = host.substr(0, host.indexOf("/")).replace("#", "//");
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(host);
    }
    else if (window.sidebar) {
        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', host);
    }
}


function addFavorite() {
    var title = document.title;
    var url = location.href;
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (document.all) {
        window.external.AddFavorite(url, title);
    }
    else {
        return true;
    }
}
