﻿/*****************************************************************************************
' @File : /include/js/util_clipimg.js
' @Description	 : 클립이미지 사용 함수
' @Author by		 : 유성훈
' @Date				 : 2011 - 07 - 06
' ********************************************************************************************/


/****************************************************************************
	Clip Img Control
*****************************************************************************/

mnetClipImg = function(){
}
mnetClipImg.prototype={
	url : {
		ALBUM		: "http://cmsimg.mnet.com/clipimage/" ,
		ARTIST		: "http://cmsimg.mnet.com/clipimage/" ,
		VOD			: "http://cmsimg.mnet.com/clipimage/" ,
		PHOTO		: "http://pds.mnet.com/" ,
		UPLOAD	: "http://mnetimg.mnet.com/L_uimg/",
		NONE		: "http://cmsimg.mnet.com/clipimage/default/"

    },

	getClipURL : function(){

			var nMediaID		= arguments[0];
			var strMediaType	= arguments[1];
			var nSizeType		= arguments[2];

			var strDummyClipName	= "";
			var strClipImgHost			= "";
			var strTmpSize					= "";
			
			
			//***** MediaType 을 변경한다.
			switch( strMediaType.toUpperCase() ) {

					case "ALBUM"		:	strMediaType	= "album";
													strClipImgHost = this.url.ALBUM;
													strTmpSize		= 160;
													break;

					case "ARTIST"		:	strMediaType	= "artist";
													strClipImgHost	= this.url.ARTIST;
													strTmpSize		= 160;
													break;

					case "VOD"			:	strMediaType	= "vod";
													strClipImgHost = this.url.VOD;
													strTmpSize		= 174;
													break;

					case "PHOTO"		:	strMediaType	 = "photo";
													strClipImgHost	 = this.url.PHOTO;
													break;
					
					case "PLAYLIST"	:	strMediaType	 = "playlist";
													strClipImgHost	 = this.url.UPLOAD + "userupload/";
													break;
			}

			if( nMediaID == null || ( strMediaType == null &&  nSizeType == null && strTmpSize == null ) ) {

				return clipImg.getClipURLnone(strMediaType, nSizeType, "")
			}
			else if( strMediaType == "playlist" ){

				// 이미지 없는 경우
				if( nMediaID == "0" ){
					return clipImg.getClipURLnone("album", nSizeType, "");
				}
				// 앨범 기본 이미지 선택인 경우
				else if( nMediaID.replace('.jpg','').length == 3 || nMediaID.replace('.jpg','').length == 4 ){
					nMediaID = clipImg.Right("00" + nMediaID.replace('.jpg',''), 4)
					return	strClipImgHost + strMediaType + "/" +"other/"+ nSizeType +"/"+ clipImg.Left(nMediaID,2) + "/" + clipImg.Right(nMediaID.replace('.jpg',''),2) +".jpg";
				}
				// 앨범 사용자가 이미지를 올린 경우
				else if( clipImg.Right(nMediaID,4) == ".jpg" ){
					return	strClipImgHost + strMediaType + "/" + nSizeType +"/"+ clipImg.Left(nMediaID,4) +"/"+ clipImg.Mid(nMediaID,5,2) +"/"+ clipImg.Mid(nMediaID,7,2) +"/"+ nMediaID;
				}
				else if( clipImg.Right(nMediaID,4) == ".gif" ){
					return	strClipImgHost + strMediaType + "/origin/"+ clipImg.Left(nMediaID,4) +"/"+ clipImg.Mid(nMediaID,5,2) +"/"+ clipImg.Mid(nMediaID,7,2) +"/"+ nMediaID;
				}
				else{
					return clipImg.getClipURLnone("album", strTmpSize, "");
				}
			}
			else {

				strDummyClipName	= clipImg.Right("0000000000" + nMediaID, 9)
				return strClipImgHost + strMediaType + "/" + nSizeType + "/" +  clipImg.Left(strDummyClipName, 3) + "/" +  clipImg.Mid(strDummyClipName, 4, 3) + "/" + nMediaID + ".jpg";
			}

	},
	
	getClipURLnone : function(){
			
			var strMediaType	= arguments[0];
			var nSizeType		= arguments[1];
			var strArtType		= arguments[2]+"";
			var tempURL		= "";
			
			var strDummyClipName	= "";

			//***** MediaType 을 변경한다.
			strMediaType = strMediaType.toLowerCase()

			//***** 기본값이 없을경우
			if( strArtType == null ) {strArtType = "";}

			//***** 아티스트의 경우 아티스트 타입에 따라 분기
			if( strMediaType == "artist" ) {

				switch( strArtType ) {

					case "0302"		:	strArtType = "_02_woman";	break;
					case "0102"		:	strArtType = "_03_group";		break;
					case "0109"		:	strArtType = "_04_VA";			break;
					default 			:	strArtType = "_01_man";			break;
				}
				tempURL = this.url.NONE + strMediaType + strArtType + "_" + nSizeType  + ".jpg";
			}
			else {
				tempURL = this.url.NONE + strMediaType + "_" + nSizeType + strArtType  + ".jpg";
			}

			return tempURL;
	},

    Left : function(){
		var str	= arguments[0];
		var n	= arguments[1];
		if (n <= 0){return "";}
		else if (n > String(str).length){return str;}
		else {return String(str).substring(0,n);}
	},

	Right : function(){
		var str	= arguments[0];
		var n	= arguments[1];
	   if (n <= 0){return "";}
	   else if (n > String(str).length){return str;}
	   else{var iLen = String(str).length; return String(str).substring(iLen, iLen - n);}
	},

	Mid : function(){
		var str	= arguments[0];
		var n	= arguments[1];
		var m	= arguments[2];

		var iEnd, iLen = String(str).length;

		if (n < 0 || m < 0)	return "";
		if (n + m > iLen){ iEnd = iLen; }
		else{ iEnd = n + m; }

		return String(str).substring(n-1,iEnd-1);
	}
}


var clipImg = new mnetClipImg();
