var ie_;
if(navigator.userAgent.indexOf("MSIE")>0){    
	//是否是IE浏览器    
	if(navigator.userAgent.indexOf("MSIE 6.0")>0){    
		//6.0 使用1.CSS    
		ie_=6;   
	}    
	if(navigator.userAgent.indexOf("MSIE 7.0")>0){   
	//7.0 使用2.CSS      
		ie_=7;     
	}     
	if(navigator.userAgent.indexOf("MSIE 8.0")>0){   
	//7.0 使用2.CSS      
		ie_=8;     
	}    
}else {   
	//否则使用3.CSS 还有具体的浏览器 你可以用navigator.userAgent 去获取信息 具体使用 看你自己  
	ie_=10;     
}    

$(document).ready(function () {
       $("img[ajaximage='image_ajax_name']").removeAttr('onmouseover');

       $("img[ajaximage='image_ajax_name']").removeAttr('onmouseout');

	   $(".product_options").each(function(i){
			$(this).prepend('<option value="0">Please Select</option>');
			this.options[0].selected=true;	
		});

    

	   $(".product_options").change(function(){
		   var id=$(this).attr('path').replace(/[^\w\-]/g,"");
		   var n=true;
		   $('#'+id).find('.product_options').each(function(){
			  if(this.value==0){
				   n=false;
			  }			
			});
			if(!n){
				return;
			}
		   $('#a'+id).click();
		   $('#'+id).css('display','none');
	   
	   });

        $("a[ajaxname='button_add_small']").hover(function(event){

			var divId=$(this).attr('name');
/*
if(ie_==10){
	var getEPlace=$(this).find('img').offset();
}else{
	var getEPlace=$(this).find('img').position();
}
*/
var notImg=false;//有没有图片
var addTops=0;//指定加上top高度
if($(this).attr('_addTop_')>0){
	addTops=parseInt($(this).attr('_addTop_'));
}

if(ie_==10){//火狐
	if($(this).find('img').attr('src')){//连接中有图片
		//var getEPlace=$(this).find('img').offset();
		var getEPlace=$(this).find('img').position();
	}else{//连接中没有图片
		var getEPlace=$(this).offset();
		notImg=true;
	}

}else{//ie
	if($(this).find('img').attr('src')){//连接中有图片
		var getEPlace=$(this).find('img').position();
	}else{//连接中没有图片
		var getEPlace=$(this).offset();
		notImg=true;
	}
}

//var top=getEPlace.top+$(this).find('img').height();

if(notImg==true){
	//如果没有图片，
			//1。left位置 取连接上级指定父元素的位置（id为空 或者 id=_addCartWidth_）
			//2。取不到，取本身left位置


	var top2=getEPlace.top+$(this).height()-3;
	var addCartWidth=this.offsetWidth;///模板上 addcart 连接宽度

	var getEP=false;//是否取到

	var ii=0;
	//var eP=this.offsetParent;
	//var eP=this.parentElement;///////////获得父元素
	var eP=this.parentNode ;

	var ePW=0;////连接的父元素

	while(eP){
		if(ii>6){
			break;
		}

		ii++;
      
		if(!eP.id){
			getEP=true;
			break;
		}else if(eP.id=='_addCartWidth_'){
			getEP=true;
			break;
		}else{
			//eP=eP.offsetParent;
			//eP=eP.parentElement;
			eP=eP.parentNode ;
		}
	}

	if(getEP==true){//取到了
		var getEPlace2=$(eP).offset();
		var left2=getEPlace2.left;
	}else{//取不到
		var left2=getEPlace.left;
	}
}else{
	//var top2=getEPlace.top+$(this).height()-5;
	var top2=getEPlace.top+$(this).find('img').height()-2;
	var left2=getEPlace.left;
}

top2=top2-addTops;

		var style='display:\'\'; z-Index:99; position: absolute;top: ' +top2 + 'px; left: ' +left2 + 'px;';
		    $('#'+divId).attr('style',style);
             if(!($('#'+divId).find('select').length>0)){
				 $('#'+divId).hide();
			 }
			 $('#'+divId).hover(
				 function(){
			   $('#'+divId).show();
			   
			   //$('#'+divId).css('dispaly','');

			 },
				 function(e){

				 if (!e) var e = window.event;
					var relTarg = e.relatedTarget || e.fromElement; 
					if(relTarg.tagName!="SELECT"){
						//alert(relTarg.tagName);
						$('#'+divId).hide();
						//$('#'+divId).css('dispaly','none');
					}
			 });
		
		},function(){
              var divId=this.name;
			  $('#'+divId).hide();

			  //$('#'+divId).css('dispaly','none');
		});

});

function _getEPlace(e){
	var offset={'t':e.offsetTop,'l':e.offsetLeft};

	if(e.offsetParent!=null) {
		var tl=_getEPlace(e.offsetParent);

		offset['t']+=tl['t'];
		offset['l']+=tl['l'];
	}
	return offset;
}



/**
* @鼠标当前位置
* @例子：_mousePosition(event)
*/
function _mousePosition(ev){
    ev = ev || window.event;
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop  - document.body.clientTop
}
}

