var SkinEmbbed = {
	totalIcon: 10,
	firstID:1,
	totalIconDisplay:6,
	currentID:1,
	width:350,
	height:180,
	autoPlay:'false',
	chose:'',
	txtForumID:'LinkPlayMp3',
	txtBlogID: 'txtEmbedCode',
    imageServer : 'http://static.karaoke.com.vn/',
	createIcon: function(id,display,chose){
		var type_skin = jQuery('#hiddenTypeSkin').val( );
		if (type_skin === 'music') {
			var template = '<li class="' + chose + '" style="display:' + display + '" id="lnkSkin' + id + '" onclick="SkinEmbbed.changeSkin(' + id + ');return false;"><img src="' + this.imageServer + 'img/flash/skin/sk' + id + '.png" /></li>';
		}else{
			var template = '<li class="' + chose + '" style="display:' + display + '" id="lnkSkin' + id + '" onclick="SkinEmbbed.changeSkin(' + id + ');return false;"><img src="' + this.imageServer + 'img/flash/playlist/pl' + id + '.png" /></li>';
		}
		jQuery('#lnkSkin'+id).css('cursor','pointer');
		return template;
	},

	createEmbbedCodeBlog: function( auto ){
		var id = jQuery('#hiddenIdMusic').val( );
		var secu = jQuery('#hiddenSecu').val( );
		var type_skin = jQuery('#hiddenTypeSkin').val( );
		if( type_skin === 'music'){
			var tpl = '<embed src="'+this.imageServer+'flash/skin/MiniPlayer'+this.currentID+'.swf"  FlashVars="domain=karaoke.com.vn&id=' + id + '&autoplay='+ auto +'&secu=' + secu + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="'+this.width+'" height="'+this.height+'" name="MiniPlayer" align="middle" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		}else{
			var tpl = '<embed src="'+this.imageServer+'flash/skin/playlist/PlaylistPlayer'+this.currentID+'.swf"  FlashVars="domain=karaoke.com.vn&id=' + id + '&autoplay='+ auto +'&secu=' + secu + '&type='+ type_skin +'" quality="high" bgcolor="#ffffff" wmode="transparent" width="'+this.width+'" height="'+this.height+'" name="MiniPlayer" align="middle" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		}
		jQuery('#divChiaSeBlog').html( tpl );
		jQuery('#yBlogDiv').html( tpl );
		return tpl;
	},
	createEmbbedCodeForum: function( auto ){
		var id = jQuery('#hiddenIdMusic').val( );
		var secu = jQuery('#hiddenSecu').val( );
		var imageServer = 'http://static.karaoke.com.vn/';
		var type_skin = jQuery('#hiddenTypeSkin').val( );
		if (type_skin === 'music') {
			var tpl = '[FLASH]' + this.imageServer + 'flash/skin/MiniPlayer' + this.currentID + '.swf?id=' + id + '&secu=' + secu + '&autoplay=' + auto + '[/FLASH]';
		}else{
			var tpl = '[FLASH]' + this.imageServer + 'flash/skin/playlist/PlaylistPlayer' + this.currentID + '.swf?id=' + id + '&secu=' + secu + '&autoplay=' + auto + '&type='+ type_skin +'[/FLASH]';
		}
		jQuery('#divChiaSeForum').html( tpl );
		return tpl;
	},

	createListIcon: function(){
		var html = '';
		var display = '';
		var last = '';
		for(i=1;i<=this.totalIcon;i++ ){
			if( i == this.firstID ){
				this.chose = 'Chose';
			}else{
				this.chose = '';
			}
			if((i>=this.firstID) && (i<=this.firstID+this.totalIconDisplay-1)){
				display = '';
			}else{
				display = 'none';
			}
			html=html+this.createIcon(i,display,this.chose);
		}
		return html;
	},

	changeSkin: function(id){
		var type_skin = jQuery('#hiddenTypeSkin').val( );
		if( type_skin === 'music'){
			var src = this.imageServer + 'img/flash/skin/fullskin/full'+id+'.png';
			this.width = 350;
			this.height = 180;
		}else{
			var src = this.imageServer + 'img/flash/playlist/fullskin/playlist'+id+'.png';
			this.width = 350;
			this.height = 320;
		}

		jQuery('#imgSkinPlayer').attr('src',src);

		this.currentID = id;


		jQuery('#chkAutoPlay').attr('checked','');
		jQuery('#chkBackGround').attr('checked', '');
		this.setEmbededCode('false');

		// danh dau icon dang chon
		for(j=1;j<=this.totalIcon;j++ ){
			if( j === id){
				this.chose = 'Chose';
			}else{
				this.chose = '';
			}

			jQuery('#lnkSkin'+j).attr('class', this.chose);
		}
	},

	createMain: function(){
		var list = this.createListIcon();
		var main = '<p class="BodyAlbumDetail2"><span class="New4">Skin:</span></p><p class="Day"><img id="imgSkinPlayer" src="' + this.imageServer + 'img/flash/skin/fullskin/full1.png" /></p><p><input id="chkAutoPlay" class="GoodExcelent" type="checkbox" onclick="SkinEmbbed.changeAutoPlay()"  />Tự động Play</p><p><input id="chkBackGround" class="GoodExcelent" type="checkbox" onclick="return SkinEmbbed.changeBackGround();"  />Nhạc nền</p><input class="NextButton" onclick="return SkinEmbbed.moveLeft();" type="button"/><div class="Skin"><ul>'+list+'</ul></div><input class="BackSkin" onclick="SkinEmbbed.moveRight()" type="button"/><div class="ClearSpace"></div>';
		return main;
	},

	setEmbededCode: function( auto ){
		var forumCode = this.createEmbbedCodeForum( auto );
		var blogCode = this.createEmbbedCodeBlog( auto );
		jQuery('#lblShareLocation').html('Blog');
		jQuery('#lblLinkSong').html('Forum');
		jQuery('#'+this.txtForumID).val(forumCode);
		jQuery('#'+this.txtBlogID).val(blogCode);
	},

	changeAutoPlay: function(){
		var chkAutoPlay = jQuery('#chkAutoPlay').attr('checked');
		if(chkAutoPlay){
			this.autoPlay = 'true';
			//this.xmlUrl = jQuery('#xmlUrlAuto').val();
		}else{
			this.autoPlay = 'false';
			//this.xmlUrl = jQuery('#xmlUrlNoAuto').val();
		}
		this.setEmbededCode( this.autoPlay );
	},
	changeBackGround: function(){
		var chkBackGround = jQuery('#chkBackGround').attr('checked');
		var type_skin = jQuery('#hiddenTypeSkin').val( );
		if(chkBackGround){
			jQuery('#chkAutoPlay').attr('checked','checked');
			this.changeAutoPlay();
			jQuery('#chkAutoPlay').attr('disabled','disabled');
			this.width = 1;
			this.height = 1;
		}else{
			jQuery('#chkAutoPlay').attr('disabled','');
			if( type_skin === 'music'){
				this.width = 350;
				this.height = 180;
			}else{
				this.width = 350;
				this.height = 320;
			}

		}
		this.setEmbededCode(this.autoPlay);
	},

	show: function(id){
		jQuery('#lnkSkin'+id).show();
	},

	hide: function(id){
		jQuery('#lnkSkin'+id).hide();
	},

	moveLeft: function(){
		var firstID_new = this.firstID-1;
		if(firstID_new>=1){
			this.hide(firstID_new+this.totalIconDisplay);
			this.show(firstID_new);
			this.firstID = firstID_new;
		}
		return false;
	},

	moveRight: function(){
		var lastID_new = this.firstID+this.totalIconDisplay;
		if(lastID_new<=this.totalIcon){
			this.hide(this.firstID);
			this.show(lastID_new);
			this.firstID +=1;
		}
		return false;
	}
}
