﻿/**
 * rxjh_main.js
 * @author szc
 * @date 2015-09-29
 */
var main = window.main = {
        init: function () {
            var ts = this;
             this.tabs('.new-tab span','cur','.new-con .newlist');
             this.tabs('.tabs span','cur','.each_ind div');
             jQuery(".kv").slide({mainCell:".kv-img",autoPlay:true});
        },
        bookMark: function ( url, title ) {
            $( document ).on( "click", ".bookmark", function ( e ) {
                e.preventDefault();
                var u = url || window.location.href,
                    t = title || document.title;
                try {
                    window.external.AddFavorite( u, t );
                } catch ( e ) {
                    try {
                        window.sidebar.addPanel( t, u, "" );
                    } catch ( e ) {
                        return alert( "请您尝试同时按下Ctrl和D键收藏本页" );
                    }
                }
            });
        },
	tabs: function(ele,cla,con,evt){
		var evt = evt? evt : "mouseenter";
		$(ele).bind(evt,function(){
			var index = $(this).index();
			$(this).addClass(cla).siblings().removeClass(cla);
			$(con).eq(index).show().siblings().hide();
		}).eq(0).trigger(evt)
        },
        hoverSwitch:function(way,hoverThis,hoverClass,switchObject,n,speed,interval){
		var canSwitch = true;
		function switchNow($this,canSwitch){
			var switchObjectLen = switchObject.length,NowIndex = $this.index(),css_z = "z-index";
			$this.addClass(hoverClass).siblings().removeClass(hoverClass);
			for(var i=0;i<switchObjectLen;i++){
				var $nowLi = $(switchObject[i]+":eq("+NowIndex+")"),
						$nowLi_s = $nowLi.siblings(),
						$visible = $(switchObject[i]+":visible"),
						visible_z = parseInt($visible.css(css_z));
				visible_z = visible_z?visible_z:1;
				if(speed){
					if(interval){canSwitch = false};
					$nowLi_s.css(css_z,visible_z-1).stop();
					$nowLi.css(css_z,visible_z).fadeTo(speed,1,function(){
						$nowLi_s.hide();
						if(interval){canSwitch = true};
					});
				}else{
					$nowLi.show();
					$nowLi_s.hide();	
				};
			};
		};
		function autoSwitch(){
			var autoLen = $(hoverThis).length;
			if(canSwitch){
				var i = $(hoverThis).filter(function(index){
				if($(this).hasClass(hoverClass)){
						return $(this);	
					};
				}).index();
				i++;
				if(i>=autoLen){i=0};
				switchNow($(hoverThis).eq(i),canSwitch);
			};
		};
		if(way == "click"){
			$(hoverThis).click(function(){
				switchNow($(this));
			});
			$(hoverThis).eq(n).click();
		}else{
			$(hoverThis).mouseenter(function(){
				switchNow($(this));
			});
			$(hoverThis).eq(n).mouseenter();
		};
		if(interval){
			setInterval(autoSwitch,interval);
			$(hoverThis+","+switchObject[0]).hover(function(){
				canSwitch = false;
			},function(){
				canSwitch = true;
			});
		};
	}
      
};

$(function () {
   
   main.init();
});
