﻿jQuery.noConflict(); 
//Nav
jQuery(function(){
				
				
	var pageURL = window.location.toString().toLowerCase();
    if (pageURL.indexOf("/products/") > -1) {
        jQuery("#menu_li1").addClass("nav_link_open");
    }
    else if (pageURL.indexOf("/buy/") > -1) {
        jQuery("#menu_li2").addClass("nav_link_open");
    }
    else if (pageURL.indexOf("/support/") > -1) {
        jQuery("#menu_li3").addClass("nav_link_only_open2");
    }
    else if (pageURL.indexOf("/imageland/") > -1) {
        jQuery("#menu_li4").addClass("nav_link_only_open3");
    }
    else if (pageURL.indexOf("/corp/") > -1) {
        jQuery("#menu_li5").addClass("nav_link_open");
    }
	else if (pageURL.indexOf("/news/") > -1 || pageURL.indexOf("/newsoverview/") > -1) {
        jQuery("#menu_li6").addClass("nav_link_open");
    }
		
	var vNav_list = jQuery("ul#Nav_List > li");
	var vSetTimeover;
	var vSetTimeout;
	var _index;
	vNav_list.hover(
		function(){
			_index = vNav_list.index(this);
			var _this = jQuery(this);
			var vDiv_list = jQuery("ul#Nav_List > li > div");
			clearTimeout(vSetTimeout);
			if(_index == 3){
				vDiv_list.css("display","none");
				vNav_list.removeClass("current");
				clearTimeout(vSetTimeout);
				return;	
			}
			if(_index == 4){
					_index = 3;
			}
			if(_index == 5){
					_index = 4;
			}
			vNav_list.removeClass("current");
			_this.addClass("current");
			vDiv_list.css("display","none");
			vSetTimeover = window.setTimeout(
				function(){
					vDiv_list.eq(_index).fadeIn(300);
				},100
			)
		},
		function(){
			_index = vNav_list.index(this);
			var vDiv_list = jQuery("ul#Nav_List > li > div");
			var _this = jQuery(this);
			clearTimeout(vSetTimeover);
			if(_index == 4){
					_index = 3;
			}
			if(_index == 5){
					_index = 4;
			}
			vSetTimeout = window.setTimeout(function(){vDiv_list.eq(_index).css("display","none");_this.removeClass("current");},50);		
		}
	);
	//Search
	var vSearchBox = jQuery(".search_box");
	var vSearchIpt = jQuery("#MF_form_phrase");
	vSearchIpt.focusin(function(){
		jQuery(".search_box").animate({left: '-46px'}, 300);
	});
	vSearchIpt.focusout(function(){
		var aaa = vSearchIpt[0].value
		if(aaa == ""){
			jQuery(".search_box").animate({left: '0px'}, 300);
		}
	});
	jQuery("#goTop").mouseover(function(event){
		jQuery(this).addClass("hover");
	});	
	jQuery("#goTop").mouseout(function(event){
		jQuery(this).removeClass("hover");
	});	
	jQuery("#goTop").click(function(event){
		jQuery(window).scrollTop(0);
		return;
	});
	//LeftNav
	var vFstLayerLink = jQuery("ul#SideNav a");
	vFstLayerLink.click(function(event){
		var num = (jQuery(this).parent("li")).find("ul");
		var len = num.length;
		if(len > 0){
			var vClassName = (jQuery(this).parent("li")).attr("class");
			var flag = vClassName.indexOf("dis");
			if(flag > 0){
				(jQuery(this).parent("li")).removeClass("dis");
			}
			else{
				(jQuery(this).parent("li")).addClass("dis").siblings().removeClass("dis");
			}
			return false;
		}
	});
});
//Banner
function teaserURLFun(teaserURLArray){
	jQuery.imgpreload(teaserURLArray,
		{
			each: function()
			{
				jQuery("li#teaser1 img").attr("src",teaserURLArray[0]);
			},
			all: function()
			{
				var li_len = jQuery("#BannerBox li").length;
				for(i=1;i<li_len;i++){
					jQuery("li#teaser"+ (i+1)+" img").attr("src",teaserURLArray[i]);	
				}
				if(li_len == 1){
					jQuery("ul#BannerBtn").hide();
					jQuery("div#BannerBtnBj").hide();		
				}
				if(li_len > 1){
					if(li_len == 2){
						jQuery("ul#BannerBtn").show();
						jQuery("div#BannerBtnBj").show();
						jQuery("ul#BannerBtn").addClass("scroll_btn_two")	
				}
				if(li_len == 3){
						jQuery("ul#BannerBtn").show();
						jQuery("div#BannerBtnBj").show();
						jQuery("ul#BannerBtn").addClass("scroll_btn_three")	
				}
				if(li_len == 4){
					jQuery("ul#BannerBtn").show();
					jQuery("div#BannerBtnBj").show();
					jQuery("ul#BannerBtn").addClass("scroll_btn_four")	
				}
				if(li_len == 5){
					jQuery("ul#BannerBtn").show();
					jQuery("div#BannerBtnBj").show();
					jQuery("ul#BannerBtn").addClass("scroll_btn_five")	
				}
				if(li_len == 6){
					jQuery("ul#BannerBtn").show();
					jQuery("div#BannerBtnBj").show();
				}
					jQuery("ul#BannerBtn").show();
					jQuery("div#BannerBtnBj").show();
					jQuery("#Banner").Slide({
						effect : "scroolX",
    				speed : "normal",
						timer : 6000
					});
				}
			}
	});
}
//Tab
jQuery(function(){  
	jQuery.fn.Tab = function (options) {
			jQuery.fn.Tab.deflunt={
				_tab: "ul.tabnav > li", 
				_box: ".tabbox > div" 
			};
			var opts = jQuery.extend({},jQuery.fn.Tab.deflunt,options);
			var _cTab = jQuery(opts._tab, jQuery(this));
			var _cBox = jQuery(opts._box, jQuery(this));
			var _index;
			return this.each(function() {
				_cTab.mouseover(function(event){
					_index = _cTab.index(this);
					_cTab.eq(_index).addClass(opts._mouse).siblings().removeClass(opts._mouse);
				});	
				_cTab.mouseout(function(event){
					_index = _cTab.index(this);
					_cTab.eq(_index).removeClass(opts._mouse);
				});	
				_cTab.click(function(event){
					_index = _cTab.index(this);
					_cTab.eq(_index).addClass(opts._hover).siblings().removeClass(opts._hover);
					_cBox.eq(_index).show().siblings().hide();
				});	
			});	
		}
});
//Tab
jQuery(function(){ 
	jQuery("#tab").Tab({
		_tab: "ul.sub_one_nav_tab > li",
		_box: ".sub_one_tab_box > div" ,
		_hover: "current",
		_mouse: "hover"
	});
});
//Scroll
(function($){
	jQuery.fn.Slide=function(options){
		var opts = jQuery.extend({},jQuery.fn.Slide.deflunt,options);
		var index=1;
		var targetLi = jQuery("." + opts.claNav + " li", jQuery(this));
		var clickNext = jQuery("." + opts.claNav + " .next", jQuery(this));
		var clickPrev = jQuery("." + opts.claNav + " .prev", jQuery(this));
		var ContentBox = jQuery("." + opts.claCon , jQuery(this));
		var ContentBoxNum=ContentBox.children().size();
		var slideH=ContentBox.children().first().height();
		var slideW=ContentBox.children().first().width();
		var autoPlay;
		var slideWH;
		if(opts.effect=="scroolY"||opts.effect=="scroolTxt"){
			slideWH=slideH;
		}else if(opts.effect=="scroolX"||opts.effect=="scroolLoop"){
			ContentBox.css("width",ContentBoxNum*slideW);
			slideWH=slideW;
		}else if(opts.effect=="fade"){
			ContentBox.children().first().css("z-index","1");
		}
		
		return this.each(function() {
			var $this=jQuery(this);
			var doPlay=function(){
				jQuery.fn.Slide.effect[opts.effect](ContentBox, targetLi, index, slideWH, opts);
				index++;
				if (index*opts.steps >= ContentBoxNum) {
					index = 0;
				}
			};
			clickNext.click(function(event){
				jQuery.fn.Slide.effectLoop.scroolLeft(ContentBox, targetLi, index, slideWH, opts,function(){
					for(var i=0;i<opts.steps;i++){
	                    ContentBox.find("li:first",$this).appendTo(ContentBox);
	                }
	                ContentBox.css({"left":"0"});
				});
				event.preventDefault();
			});
			clickPrev.click(function(event){
				for(var i=0;i<opts.steps;i++){
	                ContentBox.find("li:last").prependTo(ContentBox);
	            }
	          	ContentBox.css({"left":-index*opts.steps*slideW});
				jQuery.fn.Slide.effectLoop.scroolRight(ContentBox, targetLi, index, slideWH, opts);
				event.preventDefault();
			});
			if (opts.autoPlay) {
				autoPlay = setInterval(doPlay, opts.timer);
				ContentBox.hover(function(){
					if(autoPlay){
						clearInterval(autoPlay);
					}
				},function(){
					if(autoPlay){
						clearInterval(autoPlay);
					}
					autoPlay=setInterval(doPlay, opts.timer);
				});
			}
			
			targetLi.hover(function(){
				if(autoPlay){
					clearInterval(autoPlay);
				}
				index=targetLi.index(this);
				window.setTimeout(function(){jQuery.fn.Slide.effect[opts.effect](ContentBox, targetLi, index, slideWH, opts);},200);
				
			},function(){
				if(autoPlay){
					clearInterval(autoPlay);
				}
				autoPlay = setInterval(doPlay, opts.timer);
			});
    	});
	};
	jQuery.fn.Slide.deflunt={
		effect : "scroolY",
		autoPlay:true,
		speed : "normal",
		timer : 1000,
		defIndex : 0,
		claNav:"scroll_btn",
		claCon:"scroll_content",
		steps:1
	};
	jQuery.fn.Slide.effectLoop={
		scroolLeft:function(contentObj,navObj,i,slideW,opts,callback){
			contentObj.animate({"left":-i*opts.steps*slideW},opts.speed,callback);
			if (navObj) {
				navObj.eq(i).addClass("on").siblings().removeClass("on");
			}
		},
		
		scroolRight:function(contentObj,navObj,i,slideW,opts,callback){
			contentObj.stop().animate({"left":0},opts.speed,callback);
			
		}
	}
	jQuery.fn.Slide.effect={
		fade:function(contentObj,navObj,i,slideW,opts){
			contentObj.children().eq(i).stop().animate({opacity:1},opts.speed).css({"z-index": "1"}).siblings().animate({opacity: 0},opts.speed).css({"z-index":"0"});
			navObj.eq(i).addClass("on").siblings().removeClass("on");
		},
		scroolTxt:function(contentObj,undefined,i,slideH,opts){
			contentObj.animate({"margin-top":-opts.steps*slideH},opts.speed,function(){
                for( var j=0;j<opts.steps;j++){
                	contentObj.find("li:first").appendTo(contentObj);
                }
                contentObj.css({"margin-top":"0"});
            });
		},
		scroolX:function(contentObj,navObj,i,slideW,opts,callback){
			contentObj.stop().animate({"left":-i*opts.steps*slideW},opts.speed,callback);
			if (navObj) {
				navObj.eq(i).addClass("on").siblings().removeClass("on");
			}
		},
		scroolY:function(contentObj,navObj,i,slideH,opts){
			contentObj.stop().animate({"top":-i*opts.steps*slideH},opts.speed);
			if (navObj) {
				navObj.eq(i).addClass("on").siblings().removeClass("on");
			}
		}
	};
})(jQuery);

//Scroll pic
function moveFrames(stFrameID, iFrameWidth, stDirection, iTotalQuantity, iMoveAmount, iCurrentEdgeElement){
	if(stDirection == 'right'){
		iFeaturesLeft = iTotalQuantity-(iCurrentEdgeElement);
		
		if(iFeaturesLeft <= 0){
			return iCurrentEdgeElement;
		}
		
		if(iMoveAmount >= iFeaturesLeft){
			iMoveAmount = (iFeaturesLeft);
		}
		
		iCurrentEdgeElement += iMoveAmount;
		if(iCurrentEdgeElement >= iTotalQuantity){
			iCurrentEdgeElement = iTotalQuantity;
		}
		
		iFullMove = iMoveAmount*iFrameWidth;
		jQuery(stFrameID).animate({"left": "-="+iFullMove+"px"}, "slow");
		
		
		
	}else if(stDirection == 'left'){
		
		if(iCurrentEdgeElement == iMoveAmount){
			return iCurrentEdgeElement;
			
		}else if((iCurrentEdgeElement-iMoveAmount) > iMoveAmount){
			iShiftAmount = iMoveAmount;
			
		}else{
			iShiftAmount = (iCurrentEdgeElement-iMoveAmount);
		}

		iFullMove = iShiftAmount*iFrameWidth;
		jQuery(stFrameID).animate({"left": "+="+iFullMove+"px"}, "slow");

		iCurrentEdgeElement -= iShiftAmount;
				
		
	}else if(stDirection == 'up'){
		
		iFeaturesLeft = iTotalQuantity-(iCurrentEdgeElement);
		
		if(iFeaturesLeft <= 0){
			return iCurrentEdgeElement;
		}
		
		if(iMoveAmount >= iFeaturesLeft){
			iMoveAmount = (iFeaturesLeft);
		}
		
		iCurrentEdgeElement += iMoveAmount;
		if(iCurrentEdgeElement >= iTotalQuantity){
			iCurrentEdgeElement = iTotalQuantity;
		}

		
		iFullMove = iMoveAmount*iFrameWidth;

		jQuery(stFrameID).animate({top: "-="+iFullMove+"px"}, "slow");
		
		iCurrentEdgeElement;
		
	}else if(stDirection == 'down'){
		
		if(iCurrentEdgeElement == iMoveAmount){
			return iCurrentEdgeElement;
			
		}else if((iCurrentEdgeElement-iMoveAmount) > iMoveAmount){
			iShiftAmount = iMoveAmount;
			
		}else{
			iShiftAmount = (iCurrentEdgeElement-iMoveAmount);
		}
		
		iFullMove = iShiftAmount*iFrameWidth;
		
		jQuery(stFrameID).animate({top: "+="+iFullMove+"px"}, "slow");

		iCurrentEdgeElement -= iShiftAmount;
		
	}else{
		iCurrentEdgeElement = 3;
		jQuery(stFrameID).animate({"left": "0px"}, "slow");
	}
	
	return iCurrentEdgeElement;
	
}

function checkButtons(isHorizontal, stLeftArrowID, stRightArrowID, iRightFeature, iTotalFeatures, iQuantityVisible){
	jQuery(stLeftArrowID +','+ stRightArrowID).each(function() {
		this.blur();
	});
	if(isHorizontal){
		if(iRightFeature >= iTotalFeatures){
			jQuery(stRightArrowID).removeClass('on').addClass('off');
		}else{
			jQuery(stRightArrowID).removeClass('off').addClass('on');
		}
		
		if((iRightFeature-iQuantityVisible) > 0){
			jQuery(stLeftArrowID).removeClass('off').addClass('on');
		}else{
			jQuery(stLeftArrowID).removeClass('on').addClass('off');
		}
	}else{
		if(iRightFeature > (iTotalFeatures-1)){
			jQuery(stRightArrowID).removeClass('on').addClass('off');
		}else{
			jQuery(stRightArrowID).removeClass('off').addClass('on');
		}
		if((iRightFeature-iQuantityVisible) > 0){
			jQuery(stLeftArrowID).removeClass('off').addClass('on');
		}else{
			jQuery(stLeftArrowID).removeClass('on').addClass('off');
		}
	}
}

function highlightLeftNav(LeftNavItem,openItem,highlightItem){
		var LeftNavFirst = jQuery("li.first_layer");
		var nItem = (LeftNavItem - 1);
		var oItem = (openItem - 1);
		var hItem = (highlightItem - 1);
		
		var fstNav = LeftNavFirst.eq(nItem);
		var secNav = fstNav.find("li.second_layer").eq(oItem);
		var trdNav = secNav.find("li.third_layer").eq(hItem);
		
		if(LeftNavItem == 0){
			return false;	
		}
		
		if(openItem == 0){
			var num_1 = fstNav.find("ul");
			var len_1 = num_1.length;
			if(len_1 > 0){
				fstNav.addClass("dis");
			}
			fstNav.find("a").eq(0).addClass("current");
			return false;	
		}
		if(highlightItem == 0){
			fstNav.addClass("dis");
			var num_2 = secNav.find("ul");
			var len_2 = num_2.length;
			if(len_2 > 0){
				secNav.addClass("dis");
			}
			secNav.find("a").eq(0).addClass("current");
			return false;		
		}
		fstNav.addClass("dis");
		secNav.addClass("dis");
		trdNav.find("a").addClass("current");
}

function checkButtons(isHorizontal, stLeftArrowID, stRightArrowID, iRightFeature, iTotalFeatures, iQuantityVisible){
	jQuery(stLeftArrowID +','+ stRightArrowID).each(function() {
		this.blur();
	});
	if(isHorizontal){
		if(iRightFeature >= iTotalFeatures){
			jQuery(stRightArrowID).removeClass('on').addClass('off');
		}else{
			jQuery(stRightArrowID).removeClass('off').addClass('on');
		}
		
		if((iRightFeature-iQuantityVisible) > 0){
			jQuery(stLeftArrowID).removeClass('off').addClass('on');
		}else{
			jQuery(stLeftArrowID).removeClass('on').addClass('off');
		}
	}else{
		if(iRightFeature > (iTotalFeatures-1)){
			jQuery(stRightArrowID).removeClass('on').addClass('off');
		}else{
			jQuery(stRightArrowID).removeClass('off').addClass('on');
		}
		if((iRightFeature-iQuantityVisible) > 0){
			jQuery(stLeftArrowID).removeClass('off').addClass('on');
		}else{
			jQuery(stLeftArrowID).removeClass('on').addClass('off');
		}
	}
}
jQuery(document).ready(function(){
	jQuery('#share_button').mouseover(function() {
		jQuery("#at15s").css("right", "-38px");
		jQuery("#at20mc").show();
	});
	
	jQuery('#share_button').mouseout(function() {
		jQuery("#at20mc").hide();
	});
});

var pageUrl = encodeURIComponent(document.location);
var pageTitle = encodeURIComponent(document.title);

//douban
function openDouban() {
    var d = document,
		e = encodeURIComponent,
		s1 = window.getSelection,
		s2 = d.getSelection,
		s3 = d.selection,
		s = s1 ? s1() : s2 ? s2() : s3 ? s3.createRange().text : "",
		r = "http://www.douban.com/recommend/?url=" + pageUrl + "&amp;title=" + pageTitle + "&amp;sel=" + e(s) + "&amp;v=1",
		x = function() {
		    if (!window.open(r)) {
		        location.href = r + "&amp;r=1";
		    }
		};
    if (/Firefox/.test(navigator.userAgent)) {
        setTimeout(x, 0);
    } else {
        x();
    }
}

//baidu
function openBaidu() {
    window.open("http://cang.baidu.com/do/add?it=" + pageTitle + "&iu=" + pageUrl + "&fr=ien#nw=1");
}

//sina
function openSina() {
    window.open('http://v.t.sina.com.cn/share/share.php?url=' + pageUrl + '&title=' + pageTitle);
}

//kaixin
function openKaixin() {
    window.open('http://www.kaixin001.com/repaste/share.php?rurl=' + pageUrl + '&rtitle=' + pageTitle + '&rcontent=' + pageTitle);
}

//renren
function openRenren() {
    window.open('http://share.renren.com/share/buttonshare.do?link=' + pageUrl + '&title=' + pageTitle, '_blank');
}

//email
function openEmail() {
	document.location="mailto:?body="+pageUrl;
}

//Tencent
function openTencent(){
	var _t = encodeURI(document.title);
	var _url = encodeURI(document.location);
	var _appkey = encodeURI("appkey");
	var _pic = encodeURI('');
	var _site = '';
	var _u = 'http://v.t.qq.com/share/share.php?title='+_t+'&url='+_url+'&appkey='+_appkey+'&site='+_site+'&pic='+_pic;
	 
	window.open( _u,'Tencent', 'width=700, height=680, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, location=yes, resizable=no, status=no' );
}
