// JavaScript Document

// 만든이 : 리볼트
// 블로그 주소 : http://wrevolt.tistory.com

function fnNMPhoto_Type() {
	this.GoodsSetTime = null;
	
	this.PicImg = new Array();
	this.PicLink = new Array();
	this.PicTi = new Array();
	
	this.GoodsSetting = function() {
		this.PB = document.getElementById(this.DivName);
		this.PBS = document.getElementById(this.SubName);
		
		this.PBS_Ul = this.PBS.getElementsByTagName("ul")[0];
		this.PBS_Li = this.PBS_Ul.getElementsByTagName("li");
		
		this.PicTotal = this.PBS_Li.length;
		
		this.DateSave();
		this.DefaultInfo();
		
		this.PicShow(0);
	}
	
	this.DateSave = function() {
		for ( var i=0; i<this.PicTotal; i++ ) {
			this.TempLink = this.PBS_Li.item(i).getElementsByTagName("a")[0];
			this.TempImg = this.TempLink.getElementsByTagName("img")[0];

			this.PicLink[i] = this.TempLink.href;
			this.PicImg[i] = this.TempImg.src;
			this.PicTi[i] = this.TempImg.alt;
			
			this.TempLink.i = i;
			this.TempLink.fnName = this.fnName;
			this.TempLink.onmouseover = this.TempLink.onfocus = function() {
				eval( this.fnName +".PicShow("+this.i+")");
			}
		}
	}
	
	this.DefaultInfo = function() {
		this.CurrentHeight = this.PB.offsetHeight;		//  현재 높이;
		this.CurrentWidth = this.PB.offsetWidth;		//  현재 높이;
		this.ModifyHeight = this.CurrentHeight + this.BigImage + this.BigSpace;
		
		this.PB.style.height = this.ModifyHeight + "px";
		
		this.NewDiv = document.createElement('div');
		this.NewDiv.style.position = "absolute";
		this.NewDiv.style.width = "250px";
		this.NewDiv.style.height = "198px";
		this.PB.appendChild(this.NewDiv);
	}
	
	this.PicShow = function(val) {
		this.NewDiv.innerHTML = "";
		this.SubDiv = document.createElement('div');
		$( this.SubDiv ).css("width", "250px" );
		$( this.SubDiv ).css("height", "198px");
		$( this.SubDiv ).css("position", "relative");
		$( this.SubDiv ).css("text-align", "center");
		$( this.SubDiv ).addClass("cursor");
		this.SubDiv.href = this.PicLink[val];
		this.SubDiv.onclick = function() { location.href = this.href }
		this.NewDiv.appendChild(this.SubDiv);

		$(this.NewDiv).css("border", "1px #e0e0e0 solid");

		var newImg = $( "img", $( "#NM_PhotoSub li" )[val] );

		this.NewImg = document.createElement('img');

		if( newImg.attr("src").indexOf( "/images/no_image/" ) > -1 ) {
			this.NewImg.src = "http://web.tradekorea.com/images/no_image/250_198.gif";
		} else {
			this.NewImg.src = this.PicImg[val];
		}
		
		this.NewImg.alt = this.PicTi[val];
		
		// 원본 이미지 사이즈 저장
		var width = $( this.NewImg ).attr("width");
		var height = $( this.NewImg ).attr("height");
		
		// 가로 길이가 최대 가로 사이즈보다 큰경우  
		if( width > 250 ||  height > 198 ) {
			resizeWidth = 250;
			resizeHeight = Math.round((height * resizeWidth) / width);
			topMargin = Math.round((198 - resizeHeight) / 2);
			
			// 재조정된 높이가 제한 높이보다 큰경우.
			if( resizeHeight > 198 ) {
				resizeWidth = Math.round( width * ( 198 / height ));
				resizeHeight = 198;
				topMargin = 0;
			}
		} else {	// 최대사이즈보다 작으면 원본 그대로
			resizeWidth = width;
			resizeHeight = height;
			topMargin = Math.round((198 - resizeHeight) / 2);
		}
		
		$( this.NewImg ).attr("width", resizeWidth );
		$( this.NewImg ).attr("height", resizeHeight);
		$( this.NewImg ).css("margin-top", topMargin);
		this.SubDiv.appendChild(this.NewImg);
	}
}
