﻿//阻止冒泡
function stopBubble(e){
    if(e && e.stopPropagation){
        e.stopPropagation();
    }else{
        window.event.cancelBubble = true;
    }
}
//获取flash对象
function thisMovie(movieName) {
     if (navigator.appName.indexOf("Microsoft") != -1) {
         return window[movieName];
     } else {
         return document[movieName];
     }
}
var clickNum = 0;
var hideLogoFlash = function(){
    $('.logoSwf').css('visibility','hidden');
    clickNum = 0;
}
//flash关闭
function hideMsg() {
    if( typeof(thisMovie("aipai4").hideMsg) == 'function'){
        thisMovie("aipai4").hideMsg();
    }
}
//flash重播
function replayMsg() {
    $('.logoSwf').addClass('showSwf').css('visibility','visible');
    if(typeof(thisMovie("aipai4").replayMsg) == 'undefined'){
        return;
    }
    thisMovie("aipai4").replayMsg();
}

//关键词轮换
function scrollable(){
    this.index           = 0;
    this.num             = 1;
    this.timeline		 = 4000; //自动轮换时间
    this.intervalProcess = null;
    this.init();
}
scrollable.prototype.init = function(){
    var size = $('.keyZiList li').size();
    if(size <= 1){
        $('.keyZiList').show();
        return;
    }
    var fisrt = parseInt(Math.random()*size); //随机数
    $('.keyZiList li').eq(fisrt).prependTo('.keyZiList ul').clone().appendTo('.keyZiList ul')
    $('.keyZiList').show();
    this.num = size;
    this.change_handle();
    this.start();
    this.bind();
}
scrollable.prototype.bind = function(){
    var _this = this;
    $('.keyZiList').hover(function(){
        _this.stop();
    },function(){
        _this.start();
    });
}
scrollable.prototype.start = function(){
    var _this = this;
    clearInterval(_this.intervalProcess);
    this.intervalProcess = setInterval(function(){
        _this.change_handle();
    },this.timeline);
}
scrollable.prototype.stop = function(){
    clearInterval(this.intervalProcess);
}
scrollable.prototype.change_handle = function(){
    this.change(this.index)
    this.index += 1;
}
scrollable.prototype.change = function(index){
    var _this = this;
	$('.keyZiList ul').animate( { top:-(16*this.index)+'px' } , 1000,'',function(){
        if(index == _this.num){
            _this.index = 1;    
            $('.keyZiList ul').css('top','0px');
        }
    } )
}

$(function(){
    //Logo Flash start
    hideMsg();
    var hideTimer = null;
    var showTimer = null;
    function clearTimer(){
        if(showTimer){clearTimeout(showTimer);}
        if(hideTimer){clearTimeout(hideTimer);}
    }
    function clickBody(){
        if(clickNum == 0){
            clickNum = 1;
            clearTimer();
            hideMsg();    
        }
    }
    $('.logo a').hover(function(e){
        stopBubble(e);
        showTimer=setTimeout(function(){
            replayMsg();
            $('body').bind('click',clickBody);
        },200);
    },function(e){
        stopBubble(e);
        clearTimer();
        hideTimer=setTimeout(function(){
            hideMsg();
            $('body').unbind('click',clickBody);
        },600);
    });
    $('.logoSwf').click(stopBubble).hover(function(e){
        stopBubble(e);
        clearTimer();
    },function(e){
        stopBubble(e);
        clearTimer();
        hideTimer=setTimeout(function(){
            hideMsg();
            $('body').unbind('click',clickBody);
        },600);
    });
    //Logo Flash end


    //游戏选择
    $('.hotArea .hoTop li a').click(function(){
        $('.hotArea .hoTop li a').removeClass('current');    
        $(this).addClass('current');
        $(this).blur();
        var index = $('.hotArea .hoTop li a').index(this);
        $('.hotArea .hotCon .gl').hide();
        $('.hotArea .hotCon .gl').eq(index).show();
    });

    //图片切换
    $('.focus').dsTab({
		changeTime : 3000,
		maxSize         : 10,
		itemEl          : '.focusPic a',
		btnElName       : 'focusBtns',
		btnItem         : 'li a',
		currentClass    : 'onFocus', 
        action : 'click'        //动作：点击
    });

	//初始化
	$(".inputBox input[name='key']").focus();
	
    //搜索
    $('.seabnt .sbtn a').click(function(){
        $('.seabnt .sbtn').removeClass('current');
        $(this).blur().parent().addClass('current');
        var type = $(this).attr('type');
        //$('.area .search .seaform .seainput').hide();
        //$('#seaType'+type).show();
		if(type == '1')
		{
			$("#form1").attr("action","http://so.aipai.com/search");
			$(".inputBox input[name='type']").attr("value",'card');
			$(".inputBox input[name='key']").removeClass("input466");
			$("#seaType1").show();
			$("#seaType2").hide();
			$("#seaType3").hide();
			$("#seaType4").hide();
			$(".selectValue").text('按内容');
		}
		else if(type == '2')
		{
			$("#form1").attr("action","http://so.aipai.com/search");
			$(".inputBox input[name='type']").attr("value",'book');
			$(".inputBox input[name='key']").removeClass("input466"); 
			$("#seaType1").hide();
			$("#seaType2").show();
			$("#seaType3").hide();
			$("#seaType4").hide();
			$(".selectValue").text('按内容');
		}
		else if(type == '3')
		{
			$("#form1").attr("action","http://so.aipai.com/searchUser.php");
			$(".inputBox input[name='type']").attr("value",'all');
			$(".inputBox input[name='key']").removeClass("input466"); 
			$("#seaType1").hide();
			$("#seaType2").hide();
			$("#seaType3").show();
			$("#seaType4").hide();
			$(".selectValue").text('综合');
		}
		else if(type == '4')
		{
			$("#form1").attr("action","http://so.aipai.com/searchGroup.php");
			$(".inputBox input[name='type']").attr("value",'game');
			$(".inputBox input[name='key']").removeClass("input466"); 
			$("#seaType1").hide();
			$("#seaType2").hide();
			$("#seaType3").hide();
			$("#seaType4").show();
			$(".selectValue").text('按游戏');
		}
		$(".inputBox input[name='key']").focus();
    });
    //为空时提示
    $('form[name="search"]').submit(function(){
        var key = $.trim($(this).find('input.seainputKey').val());
		var type = $("input[name='type']").val();

        if(key == ''){
            alert('搜索内容不能为空哦.');
			$(".inputBox input[name='key']").focus();
            return false;
        }
	//搜宝宝号时判断
		if($(".selectValue").text().indexOf('宝宝号') != -1 && parseInt(key) != key)
		{
			alert('宝宝号只能是数字哦');
			return false;
		}
	//搜组织号时判断	
		if($(".selectValue").text().indexOf('组织号') != -1 && parseInt(key) != key)
		{
			alert('组织号只能是数字哦');
			return false;
		}
	
	var url = document.getElementById("form1").action+"?key="+encodeURI(key)+'&type='+type;
	document.getElementById("form1").action = url;
	document.getElementById("form1").submit();
	
	return false;
		
    });

    //限制输入框字符
    $('.seainputKey').keyup(function(){
        var maxcount = 30;  //字符数
        var _this = $(this).get(0);
        if (_this.value.length > maxcount) {
            _this.value = _this.value.substr(0, maxcount);
        }
    });

    //关键词轮换
    var Sa = new scrollable();

    //更多精彩切换
    $('.jingcaiCon .jingcaiNav span').hover(function(){
        $(this).addClass('nobline');
    },function(){
        $(this).removeClass('nobline');
    });
    $('.jingcaiCon .jingcaiNav span').click(function(){
        if($(this).hasClass('current')){
            return false;
        }
        var index = $('.jingcaiCon .jingcaiNav span').removeClass('current').index(this);
        $(this).addClass('current').blur();
        $('.jingcaiCon .jingcaiC').hide().eq(index).show();
        return false;
    });

});
    
    
    function game_Choose2(tabID){
		document.getElementById(tabID).style.display = "block";
		var hpTabs = new Array();
		hpTabs[6] = "hot_game";hpTabs[7] = "a_d";
		hpTabs[8] = "e_h";hpTabs[9] = "i_l";
		hpTabs[10] = "m_p";hpTabs[11] = "q_t";	
		hpTabs[12] = "u_x";hpTabs[13] = "y_z";	
		var i;
		for (i=6;i<hpTabs.length;i++){
			if(tabID != hpTabs[i]){
				document.getElementById(hpTabs[i]).style.display = "none";
			}
		}
	}
	

	function AddFavorite(sURL,sTitle)
	{
		try
		{
			window.external.addFavorite(sURL,sTitle);
		}
		catch (e)
		{
			try
			{
				window.sidebar.addPanel(sTitle,sURL,"");
			}
			catch (e)
			{
				alert("加入收藏失败，请使用Ctrl+D进行添加");
			}
		}
	}


	function bookmark(title, url) {
	  if (document.all)
		window.external.AddFavorite(url, title);
	  else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
	}
	
	
//	function search_type_choose(search_type){
//		document.getElementById(search_type).style.display = "block";
//		var searchType = new Array();
//		searchType[0] = "card";
//		searchType[1] = "book";
//		searchType[2] = "user";
//	
//		var i;
//		for (i=0;i<searchType.length;i++){
//			if(search_type != searchType[i]){
//				document.getElementById(searchType[i]).style.display = "none";
//				document.getElementById('type').value = search_type;
//			}
//		}
//	}
function space()
{
window.open ("http://www.aipai.com/space.php");
}
	

$(function(){
	$(".selectBox").hover(function(){
		$(this).addClass("selectBoxHover");
	},function(){
		$(this).removeClass("selectBoxHover");
	});
	$(".selectValue").click(function(){
		$(this).blur();
		$(".selectBoxOptions").show();
		return false;
	});
	$(".selectBoxItem a").click(function(){
		$(this).blur();
		var value = $(this).attr("rel");
		var txt = $(this).text();
		if(txt.indexOf('按作者') != -1)
		{
			$("#form1").attr("action","http://so.aipai.com/searchUser.php");
		}
		else if(txt.indexOf('按内容') != -1)
		{
			$("#form1").attr("action","http://so.aipai.com/search");
		}
		$(".selectValue").text(txt);
		$(".inputBox input[name='type']").attr("value",value);
		$(".selectBoxItem a").removeClass("selected");
		$(this).addClass("selected");
		$(".selectBoxOptions").hide();
		return false;
	});
	/*点击任何地方关闭层*/
	$(document).click(function(event){
		if( $(event.target).attr("class") != "selectBox" ){
			$(".selectBoxOptions").hide();
		}
	});

})

