// JavaScript Document
$(function(){		 
		//下拉菜单  （三种效果show_hide、fadeIn_fadeOut、slideDown_slideUp）
		$("#nav > li").hover(
			function(){
				$(this).find(".nav_menu").show();
				$(this).addClass("curr2");
				},
			function(){
				$(this).find(".nav_menu").hide();
				$(this).removeClass("curr2");
				}
		);
		
});

(function($){
		
		//导航当前项
		$.fn.currentMenu=function(settings){
			st=$.extend({
				text: "ホーム",
				style: "curr"
			},settings);		
			st.text=st.text.toLowerCase();
			$(this).each(function(n){
				tmpText=$(this).find("a").eq(0).text().toLowerCase();
				tmpText=tmpText.replace(/ /,"");

				if(tmpText==st.text){
					$(this).addClass(st.style);
				}
			});
		}
		
		//Banner切换
		$.fn.bannerSlide=function(settings){
			st=$.extend({
				width: 1000,
				height: 300,
				numStyle: "numStyle",
				numCurr: "numCurr",
				effect: "slide",
				interval: 4000,
				speed: 800
			},settings);
			st.currIndex=0;		
			st.thisObj=$(this);
			st.actionTime=null;
			$(this).css({	position:"relative", width:st.width+"px", height:st.height+"px", overflow:"hidden", zoom:1 });
			$(this).find("ol,ul,li").css({listStyle:"none", padding:"0px", margin:"0px"});
			$(this).find("li").css({width:st.width+"px", height:st.height+"px", overflow:"hidden"});
			$(this).find("img").css({border:"none"});
			$("."+st.numStyle).children().each( function(n){$(this).attr("index",n)} );
			if(st.effect=="slide"){
				$(this).children("ul").css({ position:"absolute", top:"0px", left:"0px"});
				$("."+st.numStyle).children().click(function(){
					clearTimeout(st.actionTime);
					thisIndex=parseInt($(this).attr("index"));
					slideImage(thisIndex);
				});
				slideImage(0);
			}
			if(st.effect=="fade"){
				$(this).children("ul").css({position:"relative", height:st.height+"px"})
				.children("li").css({position:"absolute", width:st.width+"px", left:"0px", top:"0px" })
				.eq(0).css({zIndex:1});	
				$("."+st.numStyle).children().click(function(){
					clearTimeout(st.actionTime);
					thisIndex=parseInt($(this).attr("index"));
					fadeImage(thisIndex);
				});
				fadeImage(0);
			}
			function slideImage(index){
				if(index==st.thisObj.find("ul > li").length) st.currIndex=0;
				else st.currIndex=index;
				ulPos=-st.currIndex*st.height+"px";
				st.thisObj.children("ul").stop().animate({top:ulPos},st.speed);
				$("."+st.numStyle).children().eq(st.currIndex).addClass(st.numCurr).siblings().removeClass(st.numCurr);
				st.currIndex++;
				st.actionTime=setTimeout(function(){slideImage(st.currIndex)},st.interval);
			}
			function fadeImage(index){
				if(index==st.thisObj.find("ul > li").length) st.currIndex=0;
				else st.currIndex=index;
				st.thisObj.find("ul > li").eq(st.currIndex).fadeIn(st.speed).siblings().fadeOut(st.speed);
				$("."+st.numStyle).children().eq(st.currIndex).addClass(st.numCurr).siblings().removeClass(st.numCurr);
				st.currIndex++;
				st.actionTime=setTimeout(function(){ fadeImage(st.currIndex) },st.interval);
			}
		}
		
		//Tab切换
		$.fn.tabSwitch=function(settings){
			settings=$.extend({
				tabContent: "tab_cont",
				currentClass: "curr",
				firstShow: 1
			},settings);
			$(this).children().eq(settings.firstShow-1).addClass(settings.currentClass);
			$("."+settings.tabContent).hide().eq(settings.firstShow-1).show();
			$(this).children().each(function(n){ $(this).attr("index",n);	});			
			$(this).children().click(function(){
					var currIndex=parseInt($(this).attr("index"));
					$(this).addClass(settings.currentClass).siblings().removeClass(settings.currentClass);
					$("."+settings.tabContent).eq(currIndex).show().siblings("."+settings.tabContent).hide();
			});
			return this;
		}
		
				//弹出内容
		$.fn.showContent=function(settings){
			st=$.extend({
				closeStyle:"#close"			
			},settings);	
			st.oTarget=null;
			$($(this).attr("href")).css({display:"none"});
			$(this).click(function(){
				showBg();
				st.oTarget=$(this).attr("href");
				sTop=document.documentElement.clientHeight-$(st.oTarget).height();				
				sTop=sTop/2+document.documentElement.scrollTop;				
				sLeft=($("body").width()-$(st.oTarget).width())/2;				
				$(st.oTarget).css({
					position:"absolute",
					left:sLeft+"px",
					top:sTop+"px",
					zIndex:200
				}).fadeIn();
				return false;
			});
			function showBg(){
				$("body").append("<div id='showBg'></div>");
				$("#showBg").css({
					display:"none",
					position:"absolute",
					top:"0px",
					left:"0px",
					zIndex:1,
					width:$(document).width()+"px",
					height:$(document).height()+"px",
					background:"#000",
					opacity:0.5
				}).fadeIn();
				$("#showBg").click(function(){
					$(this).fadeOut();
					$(st.oTarget).fadeOut();
				});				
			}
			$(st.closeStyle).css({cursor:"pointer"}).click(function(){
					$("#showBg").fadeOut();
					$(st.oTarget).fadeOut();
				});			
		}
		
		
})(jQuery);

//sidebar brand roll
(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 = Math.ceil($wrapper.innerWidth() / singleWidth),
                currentPage = 1,
                pages = Math.ceil($items.length / visible);
                
            /* TASKS */
            
            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }
            
            // 2. create the carousel padding on left and right (cloned)
            $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
            $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
            $items = $slider.find('> li');
            
            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);
            
            // 4. paging function
            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth * dir * visible * n;
                
                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft : '+=' + left
                }, 500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth * visible * pages);
                    }
                    
                    currentPage = page;
                });
            }
                        
            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });
            
            // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
            $(this).bind('next', function () {
                gotoPage(currentPage + 1);
            });
        });
    };
})(jQuery);

(function($){
//预览文本信息
		$.fn.textPreview=function(settings){
			st=$.extend({
				width: 160,
				height: 45,
				xOffset: 10,
				yOffset: -30,
				speed: 500
			},settings);
			$(this).find("span").hide();
			$(this).hover(function(e){
				$("body").append("<p id='preview'>"+$(this).find("span").text()+"</p>")	;
				$("#preview").css({
					position: "absolute",
					background: "url(style/style_img/tips_bg.gif) no-repeat",
					top: (e.pageY+st.yOffset)+"px",
					left: (e.pageX+st.xOffset)+"px",
					color: "#f19149",
					padding: "5px 5px 0px 15px",
					width: st.width+"px",
					height: st.height+"px",
					display: "none"
				}).fadeIn(st.speed);
			},function(){
				$("#preview").remove();
			});
			$(this).mousemove(function(e){
				$("#preview").css({
					top: (e.pageY+st.yOffset)+"px",
					left: (e.pageX+st.xOffset)+"px"		
				});					   
			});
		}
})(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(){
	//国家地区语言选择项
	$("#language").hover(function(){
			$(this).find(".language_list").show();								  
		},function(){
			$(this).find(".language_list").hide();	
		});	
});

