/*
 * ¹ÂÁ÷ ÇÃ·¹ÀÌ¾î ±¸µ¿ ÀÚ¹Ù½ºÅ©¸³Æ®
 *
 * ¿øº»: http://music.cyworld.nate.com/player/music_player.js
 * ÀÛ¼ºÀÚ : À½¾ÇTF °­µ¿Çõ
 * ÀÛ¼ºÀÏ : 2005-11-12
 * ¼öÁ¤ :
 *     2005-11-16, °­µ¿Çõ, CMListControl.List ¿ÀºêÁ§Æ® Ãß°¡
 *     2005-11-17, °­µ¿Çõ
 *         CMListControl.List °¡ null ÀÏ ¶§, param Ãß°¡ÇØ¼­ ÇÃ·¹ÀÌ¾î¸¦ ¶ç¿ìµµ·Ï ¼öÁ¤
 *     2005-11-19, °­µ¿Çõ
 *         ÇÃ·¹ÀÌ¾î¸¦ cyplayer2 ·Î ±¸µ¿
 *     2006-01-19, °­µ¿Çõ
 *         NDR Åë°è ÄÚµå Ãß°¡
 *     2006-06-08, °­µ¿Çõ
 *         ¿¬¼ÓÀûÀ¸·Î °î Ãß°¡ÇÏ¿© ÇÃ·¹ÀÌ¾î°¡ ´Ù½Ã ±¸µ¿µÇ´Â °Í ¹æºñ
 *     2006-06-19, °­µ¿Çõ
 *         ¼±¹°°¡°Ô Å¬¸¯ ¾ÆÀÌÅÛ °ü·Ã ¼öÁ¤
 *		2006-12-15, °­µ¿Çõ
 *				¹è³Ê heigth ¸¸Å­ ÇÃ·¹ÀÌ¾î Å©±â ´ÃÀÓ
 *		2007-06-01, °­µ¿Çõ
 *				music µµ¸ÞÀÎ º¯°æ
 *		2007-09-11, °­µ¿Çõ
 *				ÆÄÀÌ¾îÆø½º Áö¿ø
 *		2007-11-28, °­µ¿Çõ
 *				È®Àå¼ºÀ» À§ÇØ ¸ðµâÈ­
 *		2007-12-06, °­µ¿Çõ
 *				ndr ÄÚµå¸¦ À§ÇØ referer ¸¦ ÆÄ¶ó¹ÌÅÍ·Î Ãß°¡
 *		2008-03-14, °­µ¿Çõ
 *				¹ÂÁ÷¾Ù¹ü Ãß°¡
 *		2008-04-03, °­µ¿Çõ
 *				ÆÄÀÌ¾îÆø½º¿¡¼­ playerListControl.Add ½ÇÆÐ ½Ã ÇÑ¹ø ´õ È£ÃâÇÏµµ·Ï ¼öÁ¤
 *		2008-11-17, °­µ¿Çõ
 *				¹ÂÁ÷¾Ù¹ü SEQ Ãß°¡
 */

var MUSIC_PLAYER_URL = "http://music.cyworld.com/player/jukebox/player.asp";
//var MUSIC_PLAYER_WIDTH = 374;  // 354
var MUSIC_PLAYER_WIDTH = 650;
var MUSIC_PLAYER_HEIGHT = 662;  // 63Àº ¹è³Ê height
var WAIT_TIME = 500;
var semaphore = true;
var playerListControl = null;
var isBrowserFirefox = (navigator.userAgent.indexOf('Gecko') != -1);

var MusicPlayerControl = {
	ndr : '',
	param : '',
	initialized : false,

	init : function () {
	    if (playerListControl == null) {
			if (isBrowserFirefox) {
				var mimetype = navigator.mimeTypes["application/x-skcomms-cymusic"];
				if (mimetype) {
				   var plugin = mimetype.enabledPlugin;
				   if (plugin) {
						try {
							if (document.getElementById('_lc') == null) {
								var body = document.getElementsByTagName('body')[0];
								var embed = document.createElement('embed');
								embed.setAttribute('id','_lc');
								embed.setAttribute('type','application/x-skcomms-cymusic');
								embed.setAttribute('style','width:0; height:0;');
								body.appendChild(embed);
							}
							playerListControl = document.getElementById('_lc');
							this.initialized = true;
						} catch (error) {
							alert(error);
						}
				   }
				}
			} else {
				try {
					    playerListControl = new ActiveXObject("CMListControl.List");
						this.initialized = true;
				} catch (error) {}
			}
		}
	},

	addToPlayerListFF : function () {
		semaphore = true;
		this.addToPlayerList(this.param, this.ndr);
	},

	addToPlayerList : function (param, ndr) {
		if (!this.initialized) {
			this.init();
		}

	    if (semaphore) {
	        semaphore = false;
	        if (playerListControl != null) {
	            if (typeof ndr == 'undefined' || ndr == null) {
					ndr = '';
				}
				this.ndr = ndr;

				if (param != '')
					param += '&';
				param += "ndr_url=" + ndr;

				try {
					var add = playerListControl.Add(param);
				} catch (error) {
					if (isBrowserFirefox) {
						this.param = param;
						setTimeout("MusicPlayerControl.addToPlayerListFF()", 100);
					}
					return;
					//alert(document.getElementById('_lc')+','+error);
				}
	            setTimeout('MusicPlayerControl.checkPlayList()', WAIT_TIME);
	        } else {
	            this.openMusicPlayer(param,ndr);
	        }
	    }
	},

	checkPlayList : function () {
	    semaphore = true;
		if (isBrowserFirefox) {
			var fileExt = playerListControl.FileExt();
			//alert('FileExt:'+fileExt);
			if (fileExt) {
				MusicPlayerControl.openMusicPlayer('');
			}
		} else {
			if (playerListControl.FileExt() == 1) {
				MusicPlayerControl.openMusicPlayer('');
			}
		}
	},

	openMusicPlayer : function (param) {
		semaphore = true;

		if (param != '')
			param += '&';

		param += "ndr_url=" + MusicPlayerControl.ndr;
		param += '&referer=' + encodeURIComponent(document.location);

		this.windowOpen(MUSIC_PLAYER_URL + "?" + param);
	},

	windowOpen : function (url) {
		window.open(url, 'cyplayer2','width=' + MUSIC_PLAYER_WIDTH + ',height=' + MUSIC_PLAYER_HEIGHT);
	}
}

/*
function OnCheck(param) {
	alert('[OnCheck]'+param);
	openMusicPlayer(param);
}
*/

/*
 * °î µè±â¸¦ À§ÇØ ÇÃ·¹ÀÌ¾î¸¦ ±¸µ¿ÇÑ´Ù.
 *
 * @author À½¾ÇTF °­µ¿Çõ
 * @param asx °î »óÇ°ÀÇ link_code ¸®½ºÆ®.
 *             link_code ¸¦ "." À¸·Î ±¸ºÐÇÑ´Ù.
 *             ¿¹) 12334.5678.901234
 * @param ndr NDR Åë°è¸¦ À§ÇÑ ÄÚµå
 *    ÁêÅ©¹Ú½º - 'juke'
 *    ¼±¹°°¡°Ô - 'm_item'
 *    ¹ÂÁ÷ - 'cymusic'
 *    C_Tab _¹ÂÁ÷°Ë»ö - 'ctab_search'
 *    ¼½¼Ç_¹ÂÁ÷°Ë»ö - 'smusic_search'
 *    ¼±¹°°¡°Ô_À½¾Ç°Ë»ö - 'gmusic_search'
 *    ±âÅ¸ - 'etc'
 */
function playMusicLinkCode(asx,ndr) {
	MusicPlayerControl.addToPlayerList('asx=' + asx,ndr);
}

/*
 * °î µè±â¸¦ À§ÇØ ÇÃ·¹ÀÌ¾î¸¦ ±¸µ¿ÇÑ´Ù.
 *
 * @author À½¾ÇTF °­µ¿Çõ
 * @param productSeq °î »óÇ°ÀÇ product_seq ÀÇ ¸®½ºÆ®.
 *             product_seq ¸¦ "." À¸·Î ±¸ºÐÇÑ´Ù.
 *             ¿¹) 12334.5678.901234
 * @param ndr NDR Åë°è¸¦ À§ÇÑ ÄÚµå
 *    ÁêÅ©¹Ú½º - 'juke'
 *    ¼±¹°°¡°Ô - 'm_item'
 *    ¹ÂÁ÷ - 'cymusic'
 *    C_Tab _¹ÂÁ÷°Ë»ö - 'ctab_search'
 *    ¼½¼Ç_¹ÂÁ÷°Ë»ö - 'smusic_search'
 *    ¼±¹°°¡°Ô_À½¾Ç°Ë»ö - 'gmusic_search'
 *    ±âÅ¸ - 'etc'
 */
function playMusicSong(productSeq,ndr) {
	MusicPlayerControl.addToPlayerList('product_seq=' + productSeq,ndr);
}

/*
 * ¾Ù¹ü µè±â¸¦ À§ÇØ ÇÃ·¹ÀÌ¾î¸¦ ±¸µ¿ÇÑ´Ù.
 *
 * @author À½¾ÇTF °­µ¿Çõ
 * @param themaSeq ¾Ù¹ü »óÇ°ÀÇ product_seq ÀÇ ¸®½ºÆ®.
 *             product_seq ¸¦ "." À¸·Î ±¸ºÐÇÑ´Ù.
 *             ¿¹) 12334.5678.901234
 * @param ndr NDR Åë°è¸¦ À§ÇÑ ÄÚµå
 *    ÁêÅ©¹Ú½º - 'juke'
 *    ¼±¹°°¡°Ô - 'm_item'
 *    ¹ÂÁ÷ - 'cymusic'
 *    C_Tab _¹ÂÁ÷°Ë»ö - 'ctab_search'
 *    ¼½¼Ç_¹ÂÁ÷°Ë»ö - 'smusic_search'
 *    ¼±¹°°¡°Ô_À½¾Ç°Ë»ö - 'gmusic_search'
 *    ±âÅ¸ - 'etc'
 */
function playMusicAlbum(themaSeq,ndr) {
	MusicPlayerControl.addToPlayerList('thema_seq=' + themaSeq,ndr);
}

/*
 * ¹ÂÁ÷¾Ù¹ü µè±â¸¦ À§ÇØ ÇÃ·¹ÀÌ¾î¸¦ ±¸µ¿ÇÑ´Ù.
 *
 * @author À½¾ÇTF °­µ¿Çõ
 * @param ¹ÂÁ÷¾Ù¹üID
 * @param ¹ÂÁ÷¾Ù¹ü SEQ. SEQ °ªÀÌ ¾øÀ¸¸é ³ÖÁö ¾Ê¾Æµµ µÊ.
 */
function playMyMusicAlbum(musicAlbum, albumSeq) {
	var param = 'music_album=' + musicAlbum;
	if (typeof albumSeq != 'undefined' && albumSeq != null)
		param += '&album_seq=' + albumSeq

	MusicPlayerControl.addToPlayerList(param);
}

/*
 * ¹Ì´ÏÈ¨ÇÇBGMÀ» µè±â À§ÇØ ÇÃ·¹ÀÌ¾î¸¦ ±¸µ¿ÇÑ´Ù.
 * ¹Ì´ÏÈ¨ÇÇ¿¡¼­ »ç¿ë
 * @author ±è»ó¼ö
 */
function playMinihpBgm(minihp_id, minihp_seq, link_code, play_time) {
	var param = 'minihp_id=' + minihp_id+"&minihp_seq="+minihp_seq+"&link_code="+link_code+"&play_time="+play_time;
	MusicPlayerControl.addToPlayerList(param, 'minihp');
}

/**
 * popUpBlockCheck()
 * ÆÄÀÌ¾îÆø½º¿¡¼­ ÆË¾÷Ã¢ Â÷´ÜÇØÁö¸¦ À§ÇØ¼­ »ý¼º
 */
function popUpBlockCheck() {
	window.open('http://music.cyworld.com/');
}

