// 头部搜索切换



function check() {

	var content = $("#feedbackContenId").attr('value');

	var contact = $("#feedbackEmailId").attr('value');

	var code = $("#code").attr('value');

	var url = 'http://www.gtobal.com/?m=ajax&c=idea&a=index';	

	if(trim(content) != '' && trim(contact) != '' && trim(code) != '' && content != '您有任何意见或建议均可在此留言，我们将虚心接受与改进，谢谢！' && contact != '请输入您的EMAIL') {

		     var email = $("#feedbackEmailId").val();

             var pattern =  /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;

             chkFlag = pattern.test(email);

		     if(chkFlag)

			 {

				  $.post(url, {content:content,contact:contact,type:4,title:'首页建议',is_email:2,code:code}, function(data){

				  if(data == 1) {

					$("#feedbackContenId").attr('value', '您有任何意见或建议均可在此留言，我们将虚心接受与改进，谢谢！');

					$("#feedbackContenId").css('color', '#999');

					$("#feedbackEmailId").attr('value', '请输入您的EMAIL');

					$("#feedbackEmailId").css('color', '#999');

					$("#code").attr('value', '');

					alert('您提交成功！');

					modiP();

				} else if(data == -2) {

					alert('验证码错误!');

				}

		        });

			 }

			 else

			 {

				 alert("您输入EMAIL格式不正确！");

			     $("#feedbackEmailId").focus();

		     }

	} else {

		if(trim(content) == '' || content == '您有任何意见或建议均可在此留言，我们将虚心接受与改进，谢谢！') {

			alert('请输入见议内容!');

		} else {

			if(trim(contact) == '' || contact == '请输入您的EMAIL') {

				alert('请输入email地址!');

			}

		}

	}

}

function trim(msg) {

		return msg.replace(/(^\s*)|(\s*$)/g, "");

}

function modiP(){

    var b=Math.floor(Math.random() * 1000);

    var picRel=$('#codeId').attr('rel')+'&'+b;

    $('#codeId').attr('src',picRel);

}



$("document").ready(function(){   	

	$("#catalog dl").mouseover(function(){

		$(this).addClass("curr");

	}).mouseout(function(){

		$(this).removeClass("curr");

	});

	var l_n=0;

	$("#soll_top .up").click(function(){

	  l_n=0;

	  //sollMyTime=setInterval(function(){sollTime()} , 3000);

	  $("#soll_top dl").css("top","30px");

	  var aa=$("#soll_top dl.curr");

	  aa.css("top","0px")

	  if(aa.next("dl").length>0)

	  {

	   aa.next("dl").filter(':not(:animated)').animate({top: '0px'}, "slow");

	   aa.next("dl").addClass("curr");

	  }

	  else

	  {$("#soll_top dl:first").addClass("curr");

	  $("#soll_top dl:first").filter(':not(:animated)').animate({top: '0px'}, "slow"); 

	  }

	  aa.removeClass("curr");

	  aa.css("top","30px");

	})

	$("#soll_top .next").click(function(){

	  l_n=0;

	  //sollMyTime=setInterval(function(){sollTime()} , 3000);

	  $("#soll_top dl").css("top","-30px");

	  var aa=$("#soll_top dl.curr");

	  aa.css("top","0px")

	  if(aa.prev("dl").length>0)

	  {

	   aa.prev("dl").filter(':not(:animated)').animate({top: '0px'}, "slow");

	   aa.prev("dl").addClass("curr");

	  }

	  else

	  {$("#soll_top dl:last").addClass("curr");

	  $("#soll_top dl:last").filter(':not(:animated)').animate({top: '0px'}, "slow"); 

	  }

	  aa.removeClass("curr");

	  aa.css("top","-30px");	  

	})

	

	

	$('#soll_top').hover(function(){

		if(sollMyTime){

		   clearInterval(sollMyTime);

		}

	 },function(){

		sollMyTime=setInterval(function(){sollTime();} , 3000);

	 });

	

	var sollMyTime=setInterval(function(){sollTime();} , 3000);

	

	

	function sollTime()

{

	var li_n=Math.ceil($("#soll_top dl.curr dd ul li").length/2);

	var l_w=0;	

	  if(l_n==li_n-1)

	    l_n=0;

	  else

	    l_n++;

	  l_w=l_n*(-350);

	  $("#soll_top dl.curr dd ul").animate({left: l_w}, "slow");

}

})







// 输入框focus,blur

function textInputFocus(thisID,sText){

	 $(thisID).css("color","#333");

     if($(thisID).val()==sText)

		$(thisID).val("");

}

function textInputBlur(thisID,sText){	

     if($(thisID).val()=="")

		{$(thisID).val(sText); $(thisID).css("color","#999");}

	 else{$(thisID).css("color","#333");}

}

//TAB切换

function setTabAll_1(name,cursel,n){

	for(i=1;i<=n;i++){

	   if(cursel==i)

	   {

		  $("#"+name+"_"+i).removeClass("disNone");

		  $("#"+name+i).addClass("curr");

	   } 

	   else{

	   $("#"+name+"_"+i).addClass("disNone");

	   $("#"+name+i).removeClass("curr");}

	}

}

//广告滚动图片

$(function(){

	 var index = 0;

	 $("#btn li").mouseover(function(){

		index  =  $("#btn li").index(this);

		showImg(index);

	});	 

	 //滑入 停止动画，滑出开始动画.

	 $('#imgnav').hover(function(){

			  if(MyTime){

				 clearInterval(MyTime);

			  }

	 },function(){

			  MyTime = setInterval(function(){

			    showImg(index)

				index++;

				if(index==5){index=0;}

			  } , 5000);

	 });	 

	 //自动开始

	 var MyTime = setInterval(function(){

		showImg(index)

		index++;

		if(index==5){index=0;}

	 } , 5000);

})

//关键函数：通过控制i ，来显示不通的幻灯片

function showImg(i){

   $("#img img").eq(i).stop(true,true).fadeIn(800).parent().siblings().find("img").hide();

   $("#btn li").eq(i).addClass("hov").siblings().removeClass("hov");

   $("#btn").find("p a").html($("#img img").eq(i).parent().find("img").attr("alt"));

   $("#btn").find("p a").attr("href",$("#img img").eq(i).parent("a").attr("href"));

}

//文字滚动

(function($){

$.fn.extend({

        Scroll:function(opt,callback){

                //参数初始化

                if(!opt) var opt={};

                var _this=this.eq(0).find("ul:first");

                var        lineH=_this.find("li:first").height(), //获取行高

                        line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10),

                        speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度，数值越大，速度越慢（毫秒）

                        timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）

                if(line==0) line=1;

                var upHeight=0-line*lineH;

                //滚动函数

                scrollUp=function(){

                        _this.animate({

                                marginTop:upHeight

                        },speed,function(){

                                for(i=1;i<=line;i++){

                                        _this.find("li:first").appendTo(_this);

                                }

                                _this.css({marginTop:0});

                        });

                }

                //鼠标事件绑定

                _this.hover(function(){

                        clearInterval(timerID);

                },function(){

                        timerID=setInterval("scrollUp()",timer);

                }).mouseout();

        }       

})

})(jQuery);



$(document).ready(function(){

        $("#sell_scroll").Scroll({line:1,speed:800,timer:4500});

});

// 图片滚动

(function ($) {

    $.fn.infiniteCarousel = function () {

        function repeat(str, n) {

            return new Array( n + 1 ).join(str);

        }

        

        return this.each(function () {

            // magic!

            var $wrapper = $('> div', this).css('overflow', 'hidden'),

                $slider = $wrapper.find('> ul').width(9999),

                $items = $slider.find('> li'),

                $single = $items.filter(':first')

                

                singleWidth = $single.outerWidth(),

                visible = 4,

				currentPage =1,

                pages = Math.ceil($items.length / visible); 

            /* TASKS */       

            // 3. reset scroll

            $wrapper.scrollLeft(0);

			if($items.length>visible)

			{$("#leftSoull").addClass("arrow leftNone");$("#rightSoull").addClass("arrow rightBg");}

			else{$("#rightSoull").hide();$("#leftSoull").hide();}

//            // 4. paging function

            function gotoPage(page) {	

                var left = singleWidth * page;									

					$wrapper.filter(':not(:animated)').animate({

                    scrollLeft : '+=' + left

                });	

            }

			function gotoBg(page) {

			    $("#rightSoull").removeClass("arrow rightNone");

				$("#leftSoull").removeClass("arrow leftNone");

				$("#rightSoull").removeClass("arrow rightBg");

				$("#leftSoull").removeClass("arrow leftBg");

				

				if(page==1)

				{ $("#leftSoull").addClass("arrow leftNone");$("#rightSoull").addClass("arrow rightBg");}

				else if(page-1==$items.length-visible)

				{$("#rightSoull").addClass("arrow rightNone");$("#leftSoull").addClass("arrow leftBg");}

				else

				{$("#rightSoull").addClass("arrow rightBg");$("#leftSoull").addClass("arrow leftBg");}

				currentPage = page;				

			}			        

            // 5. insert the back and forward link            

            // 6. bind the back and forward links

            $('#rightSoull.rightBg').live('click', function () {

			    gotoBg(currentPage +1);

                gotoPage(1);				

                return false;

            });           

            $('#leftSoull.leftBg').live('click', function () {		

				gotoBg(currentPage -1);

                gotoPage(-1);				

				return false;

            });

            

            

        });

    };

})(jQuery);



$(document).ready(function () {

    // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL

    var autoscrolling = true;

    

    $('.infiniteCarousel').infiniteCarousel().mouseover(function () {

        autoscrolling = false;

    }).mouseout(function () {

        autoscrolling = true;

    });

    

    setInterval(function () {

        if (autoscrolling) {

            $('.infiniteCarousel').trigger('next');

        }

    }, 2000);

});



// 图片滚动

(function ($) {

    $.fn.infiniteCarousela = function () {

        function repeat(str, n) {

            return new Array( n + 1 ).join(str);

        }

        

        return this.each(function () {

            // magic!

            var $wrapper = $('> div', this).css('overflow', 'hidden'),

                $slider = $wrapper.find('> ul').width(9999),

                $items = $slider.find('> li'),

                $single = $items.filter(':first')

                

                singleWidth_1 = $single.outerWidth(),

                visible_1 = Math.ceil($wrapper.innerWidth() / singleWidth_1), // note: doesn't include padding or border//,

				currentPage_1 =1,

                pages_1 = Math.ceil($items.length / visible_1);

            /* TASKS */       

            // 3. reset scroll

            $items.filter(':first').before($items.slice(-visible_1).clone().addClass('cloned'));

            $items.filter(':last').after($items.slice(0, visible_1).clone().addClass('cloned'));

            $items = $slider.find('> li');

            

            // 3. reset scroll

            $wrapper.scrollLeft(singleWidth_1 * visible_1);

            if(pages_1!=1)

			{

				if(currentPage_1==1)

				{ $("#leftSoull_1").addClass("arrow leftNone");$("#rightSoull_1").addClass("arrow rightBg");}

				else

				{$("#rightSoull_1").addClass("arrow rightBg");$("#leftSoull_1").addClass("arrow leftBg");}

			}

			else

			{$("#rightSoull_1").addClass("arrow leftNone");$("#leftSoull_1").addClass("arrow rightNone");}

            // 4. paging function

            function gotoPage(page) {				

				

                var dir = page < currentPage_1 ? -1 : 1,

                    n = Math.abs(currentPage_1 - page),

                    left = singleWidth_1 * dir * visible_1 * n;									

					$wrapper.filter(':not(:animated)').animate({

                    scrollLeft : '+=' + left

                }, 500, function () {

                    // if page == last page - then reset position

                    if (page > pages_1) {

                        $wrapper.scrollLeft(singleWidth_1 * visible_1);

                        page = 1;

                    } else if (page == 0) {

                        page = pages_1;

                        $wrapper.scrollLeft(singleWidth_1 * visible_1 * pages_1);

                    }                    

                    currentPage_1 = page;					

                });	

				

					

            }

			function gotoBg(page) {

			    $("#rightSoull_1").removeClass("arrow rightNone");

				$("#leftSoull_1").removeClass("arrow leftNone");

				$("#rightSoull_1").removeClass("arrow rightBg");

				$("#leftSoull_1").removeClass("arrow leftBg");

				if(page==pages_1)

				{ $("#rightSoull_1").addClass("arrow rightNone");$("#leftSoull_1").addClass("arrow leftBg");}

				else if(page==1){$("#rightSoull_1").addClass("arrow rightBg");$("#leftSoull_1").addClass("arrow leftNone");}

				else{$("#rightSoull_1").addClass("arrow rightBg");$("#leftSoull_1").addClass("arrow leftBg");}

				

				

			}			        

            // 5. insert the back and forward link            

            // 6. bind the back and forward links

            $('#rightSoull_1.rightBg').live('click', function () {	

			    gotoBg(currentPage_1 +1);

                gotoPage(currentPage_1 +1);				

                return false;

            });           

            $('#leftSoull_1.leftBg').live('click', function () {		

				gotoBg(currentPage_1 -1);

                gotoPage(currentPage_1 -1);				

				return false;

            });

                       

        });

    };

})(jQuery);



$(document).ready(function () {

    // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL

    var autoscrolling_1 = true;

    

    $('.infiniteCarousel_1').infiniteCarousela().mouseover(function () {

        autoscrolling_1 = false;

    }).mouseout(function () {

        autoscrolling_1 = true;

    });

    

    setInterval(function () {

        if (autoscrolling_1) {

            $('.infiniteCarousel_1').trigger('next');

        }

    }, 2000);

});