(function(jQuery) {
		  
	var self = null;
 
	jQuery.fn.autogrow = function(o)
	{	
		return this.each(function() {
			new jQuery.autogrow(this, o);
		});
	};
	jQuery.autogrow = function (e, o)
	{
		this.options		  	= o || {};
		this.divCloneTextArea	= null;
		this.interval	 	  	= null;
		this.line_height	  	= this.options.lineHeight || parseInt(jQuery(e).css('line-height'));
		this.min_height		  	= this.options.minHeight || parseInt(jQuery(e).css('min-height'));
		this.max_height		  	= this.options.maxHeight || parseInt(jQuery(e).css('max-height'));
		this.init_height		= this.options.initHeight || parseInt(jQuery(e).css('height'));
		this.textarea		  	= jQuery(e);
		if (this.line_height == NaN)
		{
			this.line_height = 0;
		}
		if (this.min_height == NaN || this.min_height == 0)
		{
			this.min_height = this.textarea.height();
		}
		if (this.init_height == NaN || this.init_height == 0)
		{
			this.init_height = this.textarea.height();
		}
		this.init();
	};
	
	jQuery.autogrow.fn = jQuery.autogrow.prototype={};
 	jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend;
	jQuery.autogrow.fn.extend({						 
		init: function(){			
				var self = this;			
				this.textarea.css({overflow: 'hidden', display: 'block'});
				this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand()});
		},				 
		startExpand: function() {				
		  	var self = this;
			this.interval = window.setInterval(function() {self.checkExpand()},100);
		},
		stopExpand: function(){
			try{
				if(this.divCloneTextArea.html()=='') 
				{
					this.textarea.css({'height':this.init_height});
					$(this.divCloneTextArea).remove();
				}
				clearInterval(this.interval);
			}
			catch(e){};
		},
		checkExpand: function() {
			if (this.divCloneTextArea == null)
			{
				this.divCloneTextArea = jQuery('<div></div>');
				var strPadding=this.textarea.css('padding-top')+' '+this.textarea.css('padding-right')+' '+this.textarea.css('padding-bottom')+' '+this.textarea.css('padding-left');
				this.divCloneTextArea.css({'font-size': this.textarea.css('font-size'),'font-family': this.textarea.css('font-family'),'width': this.textarea.css('width'),'padding':strPadding,'display':'none'}).appendTo('body');
			}
			var html = this.textarea.val().replace(/(<|>)/g, '');
			if (jQuery.browser.msie)
			{
				html = html.replace(/\n/g, '<BR>new');
			}
			else
			{
				html = html.replace(/\n/g, '<br>new');
			}
			if ((this.divCloneTextArea.html() != html))
			{
				this.divCloneTextArea.html(html);	
				
				if (this.max_height > 0 && (this.divCloneTextArea.height() + this.line_height > this.max_height))
				{
					this.textarea.css('overflow-y', 'auto');	
				}
				else
				{
					this.textarea.css('overflow-y', 'hidden');
					if (this.textarea.height() < this.divCloneTextArea.height() + this.line_height || (this.divCloneTextArea.height() < this.textarea.height()))
					{	
						if((this.divCloneTextArea.height() + this.line_height)<(this.min_height))
						{
							this.textarea.css({'height': (this.min_height) + 'px'});
						}	
						else
						{
							this.textarea.css({'height': (this.divCloneTextArea.height()+ this.line_height) + 'px'});
						}
					}
				}
			}
			else{
				if((this.divCloneTextArea.height() + this.line_height)<(this.min_height))
				{
					this.textarea.css({'height': (this.min_height) + 'px'});
				}	
				else
				{
					this.textarea.css({'height': (this.divCloneTextArea.height()+ this.line_height) + 'px'});
				}
			}
		}
						 
	 });
})(jQuery)
/*--------------------------------------------------------------------*/
var gObjGrow,gObjAreaComment;
function ym2_txtAreaComment(strSel){
	
	jQuery(strSel).bind('focus',function(){
		if(jQuery(this).val()=='Viết tiếp bình luận hoặc trả lời ...'){
			jQuery(this).val('')
			jQuery(this).parents('.temp').addClass('active');
		}
	});
	jQuery(strSel).blur(function(){
		if(jQuery(this).val()=='') 
		{
			jQuery(this).val('Viết tiếp bình luận hoặc trả lời ...');
			jQuery(this).parents('.temp').removeClass('active');
		}
	});
	jQuery(strSel).autogrow({minHeight:32});
}
/*--------------------------------------------------------------------------*/
var g_toutmnulink;

function TNLib_ym2TopMenu(TopMenuID){
	jQuery('#'+TopMenuID+' #ymTopmenu_bar > a').not(':last').after('<span class="ymTopMenu_vline ymTopMenu_fakeBorderC"></span>');
	jQuery('#'+TopMenuID+' a.ymTopMenu_selected').next().css('background','none');
	jQuery('#'+TopMenuID+' a.ymTopMenu_selected').prev().css('background','none');
	if ((jQuery('#'+TopMenuID+' #ymTopmenu_bar a:first').attr('class') != null) && (jQuery('#ymTopmenu_bar a:first').attr('class').match("selected"))) {	
		jQuery('#'+TopMenuID+' #left_menu_bar div').not(':first').addClass('ymTopMenu_selected');
	}
	else { jQuery('#'+TopMenuID+' #left_menu_bar div').not(':first').removeClass('ymTopMenu_selected'); }
	jQuery('#'+TopMenuID+' #ymTopmenu_bar > a:last').hover(
		function(){
			jQuery('#'+TopMenuID+' #right_menu_bar div').not(':last').addClass('ymTopMenu_selected');
			jQuery(this).addClass('ymTopMenu_selected');
			jQuery(this).prev().removeClass('ymTopMenu_fakeBorderC');
			jQuery('#menu_olink').show();
		},
		function(){
			var othis=this;
			g_toutmnulink=setTimeout(function(){
				jQuery('#'+TopMenuID+' #right_menu_bar div').not(':last').removeClass('ymTopMenu_selected');
				jQuery(othis).removeClass('ymTopMenu_selected');
				jQuery(othis).prev().addClass('ymTopMenu_fakeBorderC');
				jQuery('#menu_olink').hide();
			},100);
									 
		}
	)
	jQuery('#menu_olink').hover(
		function(){
			clearTimeout(g_toutmnulink);
		},
		function(){
			jQuery('#'+TopMenuID+' #right_menu_bar div').not(':last').removeClass('ymTopMenu_selected');
			jQuery('#'+TopMenuID+' #ymTopmenu_bar > a:last').removeClass('ymTopMenu_selected');
			jQuery('#'+TopMenuID+' #ymTopmenu_bar > a:last').prev().addClass('ymTopMenu_fakeBorderC');
			jQuery('#menu_olink').hide();
		}
	)
	// Setup arrow position
	if (jQuery('#'+TopMenuID+' a.ymTopMenu_selected').attr('class') != null){
		jQuery('#'+TopMenuID+' #ymTopmenu_bar').append('<div id="menu_arrow">'+
				'<div id="arrow"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div style="width:1px;"></div></div></div>');
		jQuery('#'+TopMenuID+' #arrow div').addClass('ymTopMenu_selected ymTopMenu_borderC');
		jQuery('#'+TopMenuID+' #arrow div:last').removeClass('ymTopMenu_selected ymTopMenu_borderC').addClass('ymTopMenu_fakeBorderC').css('border','none');
		jQuery('#'+TopMenuID+' #arrow div:first').css('border','none');
		
		var widArrow = jQuery('#'+TopMenuID+' #menu_arrow').innerWidth();
		var step = widArrow;
		jQuery('#'+TopMenuID+' #arrow div').each(function(){
		   jQuery(this).width(step+'px');
		   step = step-2;
		});	
		left_width_actBtn =  jQuery('#'+TopMenuID+' #ymTopmenu_bar').offset().left - jQuery('#'+TopMenuID+' a.ymTopMenu_selected').offset().left;
		width_actBtn = Math.round((jQuery('#'+TopMenuID+' a.ymTopMenu_selected').outerWidth() - widArrow) / 2 ) ;	
		jQuery('#'+TopMenuID+' #menu_arrow').css('left',width_actBtn - left_width_actBtn );
	}
};


var gMsgHtml=null;
var ym2msgbox = {		
	intWidth:1,
	dialogcommon:"#dialogcommon",
	msgcontain:"#msgcontain",
	dialogbacklayer:"#dialogbacklayer",
	show:function(boxId,msgWidth)
	{	
		if(gMsgHtml!=null) jQuery('body').append(gMsgHtml);
		this.intWidth=msgWidth;
		this.init();
		gMsgHtml=jQuery("#"+boxId);
		jQuery(this.msgcontain).html(jQuery("#"+boxId).html());
		jQuery("#"+boxId).remove();
		
		jQuery(this.dialogcommon).fadeIn(500, function()
		{
			 jQuery(this.dialogcommon).css({display:'block'}); 
		});
		var pageHeight=$('#uni_wrapper').height();
		jQuery(this.dialogcommon).css({left: Math.round(TNCom_getDocumentSize(2)/2-this.intWidth/2) +"px"});
		jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/5))+"px"});
		jQuery(this.dialogbacklayer).height(pageHeight);
		jQuery(this.dialogbacklayer).width(TNCom_getDocumentSize(2));
		window.onresize=this.getpos;
		if(jQuery.browser.msie)
		{
			if(parseInt(jQuery.browser.version)==6) jQuery('#uni_page').css('overflow-y','hidden');
			else jQuery('html').css('overflow-y','hidden');
		}
		else{
		jQuery('body').css('overflow-y','hidden');
		}
	},
	hide:function(){
		jQuery(this.dialogbacklayer).remove();
		jQuery(this.dialogcommon).remove();
		jQuery('body').append(gMsgHtml);
		if(jQuery.browser.msie)
		{
			if(parseInt(jQuery.browser.version)==6) jQuery('#uni_page').css('overflow-y','auto');
			else jQuery('html').css('overflow-y','auto');
		}
		else{
		jQuery('body').css('overflow-y','auto');
		}		
		gMsgHtml=null;			
	},	
	getpos: function(){
		jQuery(ym2msgbox.dialogcommon).css({left: Math.round((TNCom_getDocumentSize(2)-ym2msgbox.intWidth)/2)+"px"});
		jQuery(ym2msgbox.dialogcommon).css({top: Math.round(TNCom_getDocumentSize(3)/5 + TNCom_getDocumentSize(4))+"px"});
	},
	init:function()
	{		
		jQuery('body').append('<div id="dialogbacklayer"></div><div id="dialogcommon"><div class="rowtop"><div class="lb_top_border_cl"></div><div class="wdialog"></div><div class="lb_top_border_cr"></div></div><div class="rowmid"><div class="wdialog"><div id="msgcontain"></div></div></div><div class="rowbot"><div class="lb_bot_border_cl"></div><div class="wdialog"></div><div class="lb_bot_border_cr"></div></div></div>');
		jQuery('#dialogcommon').css('width',this.intWidth+20+'px');
		jQuery('#msgcontain').css('width',this.intWidth+'px');
		jQuery('#dialogcommon .wdialog').css('width',(this.intWidth)+'px');
	}
}

/*-------------------------------------------------------*/
function ym2btnUnder(){
	var inthidetip;
	var objtiphide;
	jQuery('.ym2subitem').hover(
		function(){
			if(Number(jQuery(this).attr('value'))==1) 
			{
				jQuery(this).find('.delsubicon').show();
				jQuery(this).find('.hidesubicon').show();
			}
		},
		function(){
			jQuery(this).find('.delsubicon').hide();
			jQuery(this).find('.hidesubicon').hide();
		});
	jQuery('.hidesubicon').hover(
		function(){
			objtiphide=jQuery(this).parent().parent().children('.tiphidesub');
			if(jQuery(objtiphide).css('display')!='none')
			{
				clearTimeout(inthidetip);
			}
			else{
				jQuery(objtiphide).show();
			}
		},
		function(){
			inthidetip=setTimeout(function(){
				jQuery(objtiphide).hide();
			},100);
		});
	jQuery('.tiphidesub').hover(
		function(){
			if(jQuery(this).css('display')!='none')
			{
				clearTimeout(inthidetip);
			}
		},
		function(){
			if(jQuery(this).css('display')=='block')
			{
				inthidetip=setTimeout(function(){
				jQuery('.tiphidesub').hide();
				},100);
			}
		});
};
/*-------------------------------------------------------*/
function ym2Settab(boxid){
	try{
		jQuery('#'+boxid+' .tablist .tabactive').show();
		jQuery('#'+boxid+' .toplink a').click(function(){
			var strtabid=jQuery(this).attr('rel');
			if(!jQuery(this).hasClass('active'))
				{
					jQuery('#'+boxid+' .toplink .active').removeClass('active');
					jQuery(this).addClass('active');
					jQuery('#'+boxid+' .tablist .tabactive').removeClass('tabactive').fadeOut(400,function(){
						jQuery('#'+strtabid).fadeIn().addClass('tabactive');
					});
					
				}
				return false;
			});
		}
	catch(err)
	{
		ym2debug.innerHTML='<p>'+err+'</p>';
	}
}
function ym2checkImg(strSelector){
	jQuery(strSelector).click(function(){
		jQuery(strSelector).removeClass('active');
		jQuery(this).addClass('active');
		id = jQuery(this).attr('rev');		
		jQuery('#'+id).val(jQuery(this).attr('rel'));		
		return false;
	});		
}
function showfillter(obj){
	jQuery('#ym2funwindow .boxfilter').css('left',jQuery(obj).parent().offset().left);
	jQuery('#ym2funwindow .boxfilter').css('top',jQuery(obj).parent().offset().top+20+$('#uni_page').scrollTop()).slideDown();
}
function hidefillter(){
	jQuery('#ym2funwindow .boxfilter').slideUp();
}
function ym2_setwalllink(){
	jQuery('.atitem .closeicon').click(function(){
		$('.btnsend').show();
		Wall.symbol = '';
		jQuery(this).parents('.atitem').slideUp(400,function(){
			jQuery('#mainitem').fadeIn();
		});
		return false;
	});
	jQuery('#mainitem .ym_link').click(function(){
		if($(this).hasClass('isfail')) return false;
		var othis=jQuery('#'+jQuery(this).attr('rel'));
		jQuery('#mainitem').fadeOut(100,function(){
			jQuery(othis).slideDown();
		});
		return false;
	});	
}
function ymGoNext(){
	if((jQuery('#funfillmenu ul').position().top+jQuery('#funfillmenu ul').height())>0) 
	{
		if((jQuery('#funfillmenu ul').position().top+jQuery('#funfillmenu ul').height())>280){
			jQuery('#funfillmenu ul').animate({top:(jQuery('#funfillmenu ul').position().top-140+'px')},400);
		}
		else{
			jQuery('#funfillmenu ul').animate({top:(140-jQuery('#funfillmenu ul').height())},400);
		}
	}
}
function ymGoPre(){
	if(jQuery('#funfillmenu ul').position().top<0) 
	{
		if(jQuery('#funfillmenu ul').position().top<(-140)){
			jQuery('#funfillmenu ul').animate({top:(jQuery('#funfillmenu ul').position().top+140+'px')},400);
		}
		else{
			jQuery('#funfillmenu ul').animate({top:0+'px'},400);
		}
	}
}
ym2_txtAreaComment('textarea.txtcomment');
jQuery('textarea.tarealink').autogrow({minHeight:30});
ym2btnUnder();
ym2_setwalllink();
ym2Settab('attphoto');
ym2Settab('attvideo');
ym2Settab('attmusic');