$(document).ready(
    function(){
        //固定的层
        $('.kwicks').kwicks({
            max:225,
            spacing:5
        });
        //jquery插件应用2：
        $("#JQ_s").sBox({
            animated:true
        });
        $("#test").click(function(){
            var value = $("#JQ_S").val();
            var txt = $("#JQ_s_text").val();
            alert( "你本次选择的值和文本分别是：" + value +"  , "+txt );
        });
        //表格样式
        $('#baigou_bags dt:last,#latest_products dt:last').css('border-right',0)
        $('#baigou_bags tr:nth-child(odd)').css('background','#faf6ea');
        //banner轮显
		$('.art_banner ul').cycle({
            fx:'fade'
        });
		$('.exh_instantPic ul').cycle({
            fx:'fade'
        });
        $('#banner div').cycle({
            fx:'fade',
            pager:'#banner ul'
        });
        $('#baigou_business_circle #banner_img div').cycle({
            fx:'fade',
            pager:'#baigou_business_circle #banner_nav'
        });
        $('#latest_information ul').cycle({
            fx:'fade',
            delay: -1000
        });
		//月刊页面更多月刊效果
		$('.promotion h3 #more').click(
			function (){
			    $('.promotion h3 ul').show();
			}
		)
		$('.promotion h3 ul').hover(
			function (){
			    $('.promotion h3 ul').show();
			},
			function () {
				 $('.promotion h3 ul').hide();
			}
		)
        //初始化最新会员
        var new_members = $('#new_members h4')
        new_members.next('p').hide()
        new_members.first().next('p').show()
        //最新会员鼠标经过效果
        new_members.mouseover(
            function (){
                new_members.next('p').hide()
                $(this).next('p').show()
            }
            )
    }
    )

/******************************************************************************/
jQuery.fn.CRselectBox = jQuery.fn.sBox = function(options){
    options = $.extend({
        animated : false
    },options);
    var _self = this;
    /*构建结构*/
    var _parent = _self.parent();
    var wrapHtml = '<div class="CRselectBox"></div>';
    var $wrapHtml = $(wrapHtml).appendTo(_parent);
    var selectedOptionValue = _self.find("option:selected").attr("value");
    var selectedOptionTxt = _self.find("option:selected").text();
    var name = _self.attr("name");
    var id = _self.attr("id");
    var inputHtml = '<input type="hidden" value="'+selectedOptionValue+'" name="'+name+'" id="'+id+'"/>';
    $(inputHtml).appendTo($wrapHtml);
    var inputTxtHtml = '<input type="hidden" value="'+selectedOptionTxt+'" name="'+name+'_CRtext" id="'+id+'_CRtext"/>';
    $(inputTxtHtml).appendTo($wrapHtml);
    var aHtml = '<a class="CRselectValue" href="#">'+selectedOptionTxt+'</a>';
    $(aHtml).appendTo($wrapHtml);
    var ulHtml = '<ul class="CRselectBoxOptions"></ul>';
    var $ulHtml = $(ulHtml).appendTo($wrapHtml);
    var liHtml = "";
    _self.find("option").each(function(){
        if($(this).attr("selected")){
            liHtml += '<li class="CRselectBoxItem"><a href="#" class="selected" rel="'+$(this).attr("value")+'">'+$(this).text()+'</a></li>';
        }else{
            liHtml += '<li class="CRselectBoxItem"><a href="#" rel="'+$(this).attr("value")+'">'+$(this).text()+'</a></li>';
        }
    });
    $(liHtml).appendTo($ulHtml);
    /*添加效果*/
    $( $wrapHtml, _parent).hover(function(){
        $(this).addClass("CRselectBoxHover");
    },function(){
        $(this).removeClass("CRselectBoxHover");
    });
    $(".CRselectValue",$wrapHtml).click(function(){
        $(this).blur();
        if( $(".CRselectBoxOptions",$wrapHtml).is(":hidden") ){
            if(options.animated){
                $(".CRselectBoxOptions").slideUp("fast");
                $(".CRselectBoxOptions",$wrapHtml).slideDown("fast");
            }else{
                $(".CRselectBoxOptions").hide();
                $(".CRselectBoxOptions",$wrapHtml).show();
            }
        }
        return false;
    });
    $(".CRselectBoxItem a",$wrapHtml).click(function(){
        $(this).blur();
        var value = $(this).attr("rel");
        var txt = $(this).text();
        $("#"+id).val(value);
        $("#"+id+"_CRtext").val(txt);
        $(".CRselectValue",$wrapHtml).text(txt);
        $(".CRselectBoxItem a",$wrapHtml).removeClass("selected");
        $(this).addClass("selected");
        if(options.animated){
            $(".CRselectBoxOptions",$wrapHtml).slideUp("fast");
        }else{
            $(".CRselectBoxOptions",$wrapHtml).hide();
        }
        return false;
    });
    $(document).click(function(event){
        if( $(event.target).attr("class") != "CRselectBox" ){
            if(options.animated){
                $(".CRselectBoxOptions",$wrapHtml).slideUp("fast");
            }else{
                $(".CRselectBoxOptions",$wrapHtml).hide();
            }
        }
    });
    _self.remove();
    return _self;
}
/*#############################################################*/
$(function() {
    $(window).scroll(function(){
        var scrollTop = $(window).scrollTop();
        if(scrollTop != 0)
            $('#nav').stop().animate({
                'opacity':'0.2'
            },400);
        else
            $('#nav').stop().animate({
                'opacity':'1'
            },400);
    });
	
    $('#nav').hover(
        function (e) {
            var scrollTop = $(window).scrollTop();
            if(scrollTop != 0){
                $('#nav').stop().animate({
                    'opacity':'1'
                },400);
            }
        },
        function (e) {
            var scrollTop = $(window).scrollTop();
            if(scrollTop != 0){
                $('#nav').stop().animate({
                    'opacity':'0.2'
                },400);
            }
        }
        );
});


SearchUrls = {
    "全部": "",
    "产品": "/company",
    "供求": "/markets",
    "企业": "/company/search",
    "资讯": "/articles/search"
}

$(function(){
    $("#homepage_search").submit(function(){
        $(this).attr("action", SearchUrls[$("#JQ_s").val()])
    })
})