var menuSlider=function(){
	var m,e,g,s,q,i; e=[]; q=8; i=8;
	return{
		init:function(j,k){
			m=document.getElementById(j); e=m.getElementsByTagName('li');
			var i,l,w,p; i=0; l=e.length;
			for(i;i<l;i++){
				var c,v; c=e[i]; v=c.value; if(v==1){s=c; w=c.offsetWidth; p=c.offsetLeft}
				c.onmouseover=function(){menuSlider.mo(this)}; c.onmouseout=function(){menuSlider.mo(s)};
			}
			g=document.getElementById(k); g.style.width=w+'px'; g.style.left=p+'px';
		},
		mo:function(d){
			clearInterval(m.tm);
			var el,ew; el=parseInt(d.offsetLeft); ew=parseInt(d.offsetWidth);
			m.tm=setInterval(function(){menuSlider.mv(el,ew)},i);
		},
		mv:function(el,ew){
			var l,w; l=parseInt(g.offsetLeft); w=parseInt(g.offsetWidth);
			if(l!=el||w!=ew){
				if(l!=el){var ld,lr,li; ld=(l>el)?-1:1; lr=Math.abs(el-l); li=(lr<q)?ld*lr:ld*q; g.style.left=(l+li)+'px'}
				if(w!=ew){var wd,wr,wi; wd=(w>ew)?-1:1; wr=Math.abs(ew-w); wi=(wr<q)?wd*wr:wd*q; g.style.width=(w+wi)+'px'}
			}else{clearInterval(m.tm)}
}};}();

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
     var arVersion = navigator.appVersion.split("MSIE")
     var version = parseFloat(arVersion[1])
     if ((version >= 5.5) && (document.body.filters)) 
     {
       for(var j=0; j<document.images.length; j++)
       {
           var img = document.images[j]
           var imgName = img.src.toUpperCase()
           if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
           {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText 
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
             img.outerHTML = strNewHTML
             j = j-1
           }
       }
     }    
}

$(document).ready(function() {
  menuSlider.init('menu','slide');
	$(".btnBack").click(function() {history.go(-1);});			
  correctPNG();
  
  //$(".photo .p img").load(FixRect($("this"),165,220,true));
  //
});


//FixRect Useage:
//s send object img
//h height and w width for a board keep s
//f fullscape set true to keep all
function FixRect(s,h,w,f){ //加入全景支持参数f
  var img = new Image();
  img.onload = function(){
    var r1 = w/h, r2 = img.width/img.height; //注意,C#中w/h总是返回忽略小数,因为是整数算法.
    s.style.position = "relative";
    s.style.left = "0px";
    s.style.top = "0px";
    if(f){
      if(r1>r2){
        s.height = h;
        //s.width = "auto"; //don't work
        s.width = parseInt(h*r2);
        s.style.left = parseInt((w-r2*h)/2) +"px";
      }else{
        //s.height = "auto"; //don't work
        s.height = parseInt(w/r2);
        s.width = w;
        s.style.top = parseInt((h-w/r2)/2) +"px";
      }
      return ;
    }
    if(r1>r2 || r1==r2){
      s.style.width = w + "px";
      s.style.height = w/r2 + "px";
      s.style.top = -parseInt((w/r2 - h)/2) + "px";
    }
    if(r1<r2){
      s.style.height = h + "px";
      s.style.width = h*r2 + "px";
      s.style.left = -parseInt((h*r2-w)/2) + "px";
    }
  };
  img.src = s.getAttribute('nextSrc') || s.src;
}

function ResizeImage(_obj, _width)
{
  //_obj.width = _width;
}