(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();
		
		jQuery("#dialogbacklayer").height(TNCom_getDocumentSize(1));
		jQuery("#dialogbacklayer").width(TNCom_getDocumentSize(0));
		gMsgHtml=jQuery("#"+boxId);
		jQuery(this.msgcontain).html(jQuery("#"+boxId).html());
		jQuery("#"+boxId).remove();
		jQuery(this.dialogcommon).css({left: Math.round(TNCom_getDocumentSize(2)/2-this.intWidth/2) +"px"});
		
		if(jQuery.browser.msie){
		jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/8))+"px"});
		}	
		else
		{
			var ffv=parseInt(jQuery.browser.version.substr(0,1))+ parseInt(jQuery.browser.version.substr(2,1));
			if(ffv<10){
				//jQuery(this.dialogcommon).css({top:100 +"px"});
				jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/8))+"px"});
			}
			else{
				jQuery(this.dialogcommon).css({top: Math.round((TNCom_getDocumentSize(4)+TNCom_getDocumentSize(3)/8))+"px"});	
			}
		}	
		jQuery(this.dialogcommon).fadeIn(300, function()
		{
			jQuery("#dialogbacklayer").show();
			 //jQuery(this.dialogcommon).css({display:'block'}); 
		});		
		window.onresize=this.getpos;
	},
	hide:function(){
		jQuery(this.dialogbacklayer).hide();
		jQuery(this.dialogcommon).hide();
		jQuery('body').append(gMsgHtml);
		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()
	{	
	 	var backobj=document.getElementById('dialogbacklayer');
		if (backobj == null || backobj == 'undefined'){
			jQuery('body').append('<div id="dialogbacklayer"></div><div id="dialogcommon" class="select-free"><!--[if lte IE 6.5]><iframe></iframe><![endif]--><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("#dialogbacklayer").hide();
		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');
/*tridn-------------------*/
function htvactiveTab(){
	$('.tabitem').click(function(){
		var tabID=$(this).attr('rel');
		var obj=$(this);
		$(this).parents('.boxtop').parent().children('.boxcontent').children('.active').fadeOut(300,function(){
			$(this).removeClass('active');
			$('#'+tabID).fadeIn(50,function(){
				$(this).addClass('active');
				$(obj).parents().parents().children('.active').removeClass('active');
				$(obj).parent().addClass('active');
			});
		});
		return false;
	})
}
var g_isplaying=false;
var g_tplaying;
function expanctrl(){
	$('.expbtn').bind('mousemove mouseover',function(){	
			if(!g_isplaying){
				$(this).parent().children('.boxexctrl_out').animate({width:310+'px'},500,function(){
					g_isplaying=false;	
				});
				g_isplaying=true;
				$(this).fadeOut(300);
			}
			
		});
	$('.boxexctrl').bind('mouseout',function(){
			var objpnode=$(this);
			var objexpbtn=$(this).children('.expbtn');
			clearTimeout(g_tplaying);
			g_tplaying=setTimeout(function(){
				if(!g_isplaying){
					$(objpnode).children('.boxexctrl_out').animate({width:65+'px'},500,function(){
						g_isplaying=false;
					});
					$(objexpbtn).fadeIn(300);
					g_isplaying=true;
				}
				
			},100);
	});
	$('.boxexctrl').bind('mousemove mouseover',function(){
			clearTimeout(g_tplaying);
	});
	
}
/*-----------------------*/
/*-----------------------*/
var g_leftflag=true;
var g_rightflag=true;
function getcurnode(imgindex){
	var intindex=0;
	$('#xrangeimg a').each(function(index){
		if($(this).attr('imgindex')==imgindex)	
		{
			intindex=index;
		}
	})
	return parseInt(intindex);
}


function ctrlxslide(imgindex){
	var numimg=$('#xrangeimg a').length;
	var curnode=0;
	var lastindex=imgindex;
	var objslide=$('#xrangeimg');
	objslide.css('width',(numimg+1)*78)
	curnode=getcurnode(imgindex);
	objslide.css({left:-(parseInt(curnode)*78)});
	function moveSlide(way,step){
		if (way==0){
			objslide.stop(false,true);
			objslide.animate({left:"+="+step*78+"px"});
			curnode-=step;
			lastindex=$('#xrangeimg a:eq('+(curnode)+')').attr('imgindex');
		}else{
			objslide.stop(false,true);
			objslide.animate({left:"-="+step*78+"px"});
			curnode+=step;
			lastindex=$('#xrangeimg a:eq('+(curnode)+')').attr('imgindex');
			
		}
	}
	$('.ym4pre').click(function(){
		curnode=getcurnode(lastindex);
		if (curnode<=2){
			if(g_leftflag){
				loadPictureCarouselSyn(lastindex,0);
				curnode=getcurnode(lastindex);
			}
		}
		curnode=getcurnode(lastindex);
		numimg=$('#xrangeimg a').length;
		objslide.css('width',(numimg+1)*78);
		objslide.css({left:-(parseInt(curnode)*78)});
		if(curnode>=2){
			moveSlide(0,2);
		}else if (curnode==1){
			moveSlide(0,1);
		}
	});
	$('.ym4next').click(function(){
		numimg=$('#xrangeimg a').length;
		curnode=getcurnode(lastindex);
		if ((numimg-curnode-2)<2){
			if(g_rightflag){
				loadPictureCarouselSyn(lastindex,1);
				curnode=getcurnode(lastindex);
			}
		}
		curnode=getcurnode(lastindex);
		numimg=$('#xrangeimg a').length;
		objslide.css('width',(numimg+1)*78);
		if((numimg-curnode-2)>=2){
			moveSlide(1,2);
		}else if 
		((numimg-curnode-2)==1){
			moveSlide(1,1);
		}
	});
}
