/**
 * 쇼룸이 다른 컨텍스트, 다른 메뉴에서도 사용가능하도록 하기 위해 관련된 javascript를 따로 구성한다.
 */
ShowRoom = function() {
	// 플래시 파일의 경로
	this.flashURL = "/img/Flash/newcar/showroom.swf";
	// 파라미터를 구성할때 아래의 이름으로된 프로퍼티는 파라미터 구성에서 제외된다.
	this.ignoreParam = '|parseParam|flashURL|ignoreParam|printEmbed|flashWidth|flashHeight|flashObjId|targetObjId|displayFlash|';
	
	
	// 명령어 구분
	this.cmd = '';
	// 현재 페이지 번호
	this.curPage = '';
	// 목록갯수
	this.listLines = '';
	// 이미지 구분
	this.imgDiv = '';
	// 카테고리 코드
	this.cateCode = '';
	// 검색 시작일
	this.startDay = '';
	// 검색 종료일
	this.endDay = '';
	// 태그명
	this.tagName = '';
	// 호출할 데이터URL
	this.dataURL = '';
	// 선택한 이미지 ID
	this.imageId = '';
	
	// 노출될 Flash의 가로
	//this.flashWidth = 1000;
	this.flashWidth = '100%';
	// 노출될 Flash의 세로
	//this.flashHeight = 723;
	this.flashHeight = '100%';
	// 노출될 Flashd의 오브젝트ID
	this.flashObjId = 'shrFlashObj';
	// Flash의 HTML이 노출될 DIV ID
	this.targetObjId = 'shrFlashDiv';
	
	/**
	 * 파라미터 구성을 한다.
	 * 위에 정의된 ignoreParam에 포함된 프로퍼티는 제외한다.
	 */
	this.parseParam = function() {
		var paramUrl = this.flashURL + "?";
		for(var i in this) {
			if(this.ignoreParam.indexOf("|"+i+"|")>=0) continue;
			if(this[i] != '')
				paramUrl += i +"=" +this[i]+ "&";
		}
		return paramUrl;
	}
};

/*
 * Flash 객체의 HTML 코드를 설정하고 대상 DIV에 노출되도록 한다.
 */
ShowRoom.prototype.printEmbed = function() {
	var flashStr = "<object id=\""+this.flashObjId+"\" name=\""+this.flashObjId+"\" width=\""+this.flashWidth+"\" height=\""+this.flashHeight+"\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ";
	flashStr +=	   "		codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0\" id=\"V000133454\"> ";
	flashStr +=	   "	<param name=\"movie\" id=\"movie\" value=\"$MOVIE_URL$\" /> ";
	flashStr +=	   "	<param name=\"allowScriptAccess\" value=\"sameDomain\" /> ";
	flashStr +=	   "	<param name=\"allowFullScreen\" value=\"true\" /> ";
	flashStr +=	   "	<embed width=\""+this.flashWidth+"\" height=\""+this.flashHeight+"\" name=\"plugin\" src=\"$MOVIE_URL$\" type=\"application/x-shockwave-flash\"/> ";
	flashStr +=	   "</object> ";
	
	var replaceStr = this.parseParam();
	flashStr = flashStr.replaceAllWithLoop("$MOVIE_URL$", replaceStr); 
	$(this.targetObjId).innerHTML = flashStr;
};


/*
 * Flash의 IF 명령구분에 따라 기본값을 설정하고 노출되는 처리를 한다.
 */
ShowRoom.prototype.displayFlash = function() {
	var SHR_DOMAIN = "/showroom";
	if (document.domain.indexOf("enclean") >= 0) {
		SHR_DOMAIN = "http://www.enclean.com/showroom";
	}
	
	if('if1' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
		this.curPage = 1;
		this.listLines = 20;
	} else if('if2' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
		if(this.curPage==""){this.curPage=1;}
		if(this.listLines==""){this.listLines=20;}
	} else if('if3' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
		if(this.curPage==""){this.curPage=1;}
		if(this.listLines==""){this.listLines=20;}
	} else if('if4' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
		if(this.curPage==""){this.curPage=1;}
		if(this.listLines==""){this.listLines=20;}
		this.tagName = encodeURIComponent(this.tagName);
	} else if('if5' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
	} else if('if6' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
		if(this.listLines==""){this.listLines=20;}
	} else if('if7' == this.cmd) {
		this.dataURL = SHR_DOMAIN+'/flash/';
	} else {
		//alert("잘못된 파라미터입니다.");
		this.cmd = "if2";
		this.dataURL = SHR_DOMAIN+'/flash/';
		if(this.curPage==""){this.curPage=1;}
		if(this.listLines==""){this.listLines=20;}
		//return;
	}
	
	this.printEmbed();
};

/*
 * 쇼룸 플래쉬 호출하기
 */
function showroomPop(ifId, imgDiv, imgId, startDay, endDay, tagName, cateCode){
	if(!ifId) ifId = '';
	if(!imgDiv) imgDiv = '';
	if(!imgId) imgId = '';
	if(!startDay) startDay = '';
	if(!endDay) endDay = '';
	if(!tagName) tagName = '';
	if(!cateCode) cateCode = '';
	
	tagName = encodeURIComponent(tagName);
	var SHR_DOMAIN = "/showroom";
	if (document.domain.indexOf("enclean") >= 0) {
		SHR_DOMAIN = "http://www.enclean.com/showroom";
	}
	
	//alert(window.screenTop);
	//alert(window.screenLeft);
	
	if(!ifId)
		ifId = 'if2';
	//wopen(SHR_DOMAIN+"/flash/view.pop.do?cmd="+ifId+"&imgDiv="+imgDiv+"&imgId="+imgId+"&startDay="+startDay+"&endDay="+endDay+"&tagName="+tagName+"&cateCode="+cateCode , "shrImageView" ,1000,720,0);
	window.open(SHR_DOMAIN+"/flash/view.pop.do?cmd="+ifId+"&imgDiv="+imgDiv+"&imgId="+imgId+"&startDay="+startDay+"&endDay="+endDay+"&tagName="+tagName+"&cateCode="+cateCode , "shrImageView", 'menubar=yes, toolbar=yes, status=yes, scrollbars=yes,width='+(window.screen.width-10)+',height='+(window.screen.height-100)+',top='+window.screenTop+',left='+window.screenLeft);
}