//--選單的圖片替換特效 --------------------------------------------------------------------------------//

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//--排行榜 --------------------------------------------------------------------------------// 
var multiBillboard = new Array("01","02","03");
    // 各區項目 0:新品　1:暢銷　2:熱門
	
    function showTabMultiBillboard(id) {
        for(i=0;i<multiBillboard.length;i++){
            document.getElementById(multiBillboard[i]).style.display = "none";

        }
        document.getElementById(multiBillboard[id]).style.display = "block";
    }

var multiBillboardTab = new Array("tab01","tab02","tab03");
	function showMultiBillboardTab(id) 
	{
		var prefix = "images/bg-multiBillboard-";
		for(i=0;i<multiBillboardTab.length;i++)
		{
			//document.getElementById(multiBillboardTab[i]).style.display = "none";
			document.getElementById(multiBillboardTab[i]).src = "images/bg-multiBillboard-"+ multiBillboard[i] +"-off.jpg";
		}
		document.getElementById(multiBillboardTab[id]).src = "images/bg-multiBillboard-"+ multiBillboard[id] +"-on.jpg";
		//document.getElementById(theImgTab).style.display = "block";            
		//var imgTabSrc = theImgTab.src;        
		//theImgTab.src = imgTabSrc.substring(0,imgTabSrc.length-7) + "-off.jpg";     
	}

//--左邊選單的收闔功能 --------------------------------------------------------------------------------// 
function display(y){$(y).style.display=($(y).style.display=="none")?"block":"none";}
function $(s){return document.getElementById(s);}



//--去除超連結的虛線 --------------------------------------------------------------------------------// 
function hideFocus(){
	if(document.all){    
	var tags=document.all.tags('a')    
	for (var i=0;i<tags.length;i++)    
	tags(i).outerHTML=tags(i).outerHTML.replace('/>',' onfocus="if(this.blur)this.blur()"')}  
};
window.onload = hideFocus;


//--讓產品圖等比例縮小到限定的長寬以內, 版面美化專用 --------------------------------------------------------------------------------//
function resizeImg(oriImg,limitWidth,limitHeight){

	var w = document.getElementById(oriImg).width;
	var h = document.getElementById(oriImg).height;
	var newImgH =  h * limitWidth / w;
	var newImgW =  w * limitHeight / h;
	var ratio = limitWidth/limitHeight;

	if(document.getElementById(oriImg).height >= limitHeight && document.getElementById(oriImg).width >= limitWidth){
		//圖檔長寬都大於限制區的長寬時, 再去判斷長寬比跟限制區的長寬比 的大小, 來決定要跟著限制區的寬還是高縮放
		if( w/h < ratio ){
			document.getElementById(oriImg).width = newImgW; 
			document.getElementById(oriImg).height = limitHeight;		
		}else{
			document.getElementById(oriImg).width = limitWidth; 
			document.getElementById(oriImg).height = newImgH;
		}
	}else if(document.getElementById(oriImg).height <= limitHeight && document.getElementById(oriImg).width >= limitWidth){
		document.getElementById(oriImg).width = limitWidth; 
		document.getElementById(oriImg).height = newImgH;
	}else if(document.getElementById(oriImg).height >= limitHeight && document.getElementById(oriImg).width <= limitWidth){
		document.getElementById(oriImg).width = newImgW; 
		document.getElementById(oriImg).height = limitHeight;
	}
	
	if(document.getElementById(oriImg).height <= limitHeight && document.getElementById(oriImg).width <= limitWidth){
		w = document.getElementById(oriImg).width;
		h = document.getElementById(oriImg).height;
	}//圖檔長寬都小於我們要的長寬時, 就不更動原圖的長寬

};

