// js v 1.0 2008/11/3 created by SHEN.YuShiKi
// www.21fpd.com
// global js for woye

// usercenter_menu begin
function initMenu() {
	Utils.$('my_center').onmouseover= function(){
		Utils.$('my_option').style.display='block';
	} 
	Utils.$('my_center').onmouseout= function(){
		Utils.$('my_option').style.display='none';
	}
	Utils.$('my_option').onmouseover= function(){
		Utils.$('my_option').style.display='block';
	} 
	
	Utils.$('my_cart').onmouseover= function(){
		Utils.$('cart_info').style.display='block';
	} 
	Utils.$('my_cart').onmouseout= function(){
		Utils.$('cart_info').style.display='none';
	}
	Utils.$('cart_info').onmouseover= function(){
		Utils.$('cart_info').style.display='block';
	} 
	
	if (document.all) {
		Utils.$('my_option').onmouseleave= function(){
			Utils.$('my_option').style.display='none';
		}
		Utils.$('cart_info').onmouseleave= function(){
			Utils.$('cart_info').style.display='none';
		}
	} else {
		Utils.$('my_option').onmouseout= function(){
			Utils.$('my_option').style.display='none';
		}
		Utils.$('cart_info').onmouseout= function(){
			Utils.$('cart_info').style.display='none';
		}
	}
}

var browser = navigator.appName;
var b_version = navigator.appVersion;
var version = b_version.split(";"); 
var trim_Version = version[1].replace(/[ ]/g,""); 
if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){ 
//alert("IE 7.0");
} else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0"){ 
//alert("IE 6.0");
	// site_nav begin
	$(document).ready(function(){
	
			$("#main_nav li").hover(
				function(){ $("ul", this).fadeIn("fast"); }, 
				function(){ } 
			);
			
			if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0"){ 
			}else{
				if(document.all){
					$("#main_nav li").hoverClass("sfhover");
				}
			}
	});
			
	$.fn.hoverClass = function(c) {
		return this.each(function(){
			$(this).hover( 
				function() { $(this).addClass(c);  },
				function() { $(this).removeClass(c); }
			);
		});
	};	
} 


function s_menuFix() {
	var sfEls = document.getElementById("s_main_nav").getElementsByTagName("dd");
	for (var i=0; i<sfEls.length; i++){
		sfEls[i].onmouseover=function(){
			this.className+=(this.className.length>0? " ": "") + "s_sfhover";
		}
		
		sfEls[i].onMouseDown=function(){
			this.className+=(this.className.length>0? " ": "") + "s_sfhover";
		}
		
		sfEls[i].onMouseUp=function(){
			this.className+=(this.className.length>0? " ": "") + "s_sfhover";
		}
		
		sfEls[i].onmouseout=function(){
			this.className=this.className.replace(new RegExp("( ?|^)s_sfhover\\b"), "");
		}
	}//end for
}
	
	
// ÎÄ±¾¿òÊäÈë×Ö·û¿ØÖÆ
jQuery.fn.textlimit=function(counter_el, thelimit, speed) {
	var charDelSpeed = speed || 15;
	var toggleCharDel = speed != -1;
	var toggleTrim = true;
	
	var that = this[0];
	updateCounter();
	
	function updateCounter(){
		jQuery(counter_el).text(thelimit - that.value.length);
	};
	
	this.keypress (function(e){ if( this.value.length >= thelimit && e.charCode != '0' ) e.preventDefault() })
	.keyup (function(e){
		updateCounter();
		if( this.value.length >= thelimit && toggleTrim ){
			if(toggleCharDel){
				// first, trim the text a bit so the char trimming won't take forever
				that.value = that.value.substr(0,thelimit+100);
				var init = setInterval
					( 
						function(){ 
							if( that.value.length <= thelimit){ init = clearInterval(init); updateCounter() }
							else{ that.value = that.value.substring(0,that.value.length-1); 
							jQuery(counter_el).text((thelimit - that.value.length)); 
							};
						} ,charDelSpeed 
					);
			}
			else this.value = that.value.substr(0,thelimit);
		}
	});
	
};		

