// JavaScript Document
function docactiveTab(){
	$('.tabitem').click(function(){
		var tabID=$(this).attr('rel');
		var obj=$(this);
		var objtab=$(this).parents('.boxtop').find('.boxcontent').children('.active');
		if(tabID!=objtab.attr('id'))
{
			objtab.fadeOut(300,function(){
				$(this).removeClass('active');
				$('#'+tabID).fadeIn(50,function(){
					$(this).addClass('active');
					$(obj).parent().parent().children('.active').removeClass('active');
					$(obj).parent().addClass('active');
				});
			});
		}
		return false;
	})
}
$('.dropdownitem').hover(function()
{
  	$(this).children('.dropdown').show();
  },function(){
  	$(this).children('.dropdown').hide();
	});
/*-----------------------------------------------------------*/
function getDocumentSize(val)
{
	var xScroll,yScroll,value;
	var hasInner = typeof(window.innerWidth) == 'number';
	var hasElement = document.documentElement && document.documentElement.clientWidth;
	var numShiftY = hasInner?pageYOffset:hasElement?document.documentElement.scrollTop:document.body.scrollTop;
	var numShiftX = hasInner?pageXOffset:hasElement?document.documentElement.scrollLeft:document.body.scrollLeft;
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	var windowWidth,windowHeight;

	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}

	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight,numShiftY,numShiftX)
	return arrayPageSize[val]
}// end function



/*
 * Ham thuc hien chuc nang tab
 * Type:	function
 * Name:	TNProfile_activeTabFriend
 * Date:	2008/05/21
 * @author:	Thanh Bui <thanhbt@von-inc.com>
 * @param int obj la tab duoc active
 */
function TNCom_getDocumentSize(val)
{
	var xScroll,yScroll,value;

	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}

	var windowWidth,windowHeight;

	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}

	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}

	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}

	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize[val]
}// end function

 function TNProfile_activeTabFriend(obj){
	for (var i=1; i<4; i++){
		var content = "cont_0"+i;
		var content_header = "tab"+i;
		document.getElementById(content).style.display='none';
		document.getElementById(content_header).className='tab_title ym_border_module ym_link'
		if (content_header==obj){
			document.getElementById(content).style.display='block';
			document.getElementById(content_header).className='tab_title ym_border_module ym_text'
		}
	}
}

/*
 * Ham thuc hien chuc nang tab box BanBe trang Profile
 * Type:	function
 * Name:	TNPro_actTabFriend
 * Date:	2008/05/21
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param obj la ID cua tab
 */
function TNPro_actTabFriend(obj){
	for (var i=1; i<4; i++){
		var content = "ym_banbe_con"+i;
		var content_header = "ym_banbe_tab"+i;
		$('#'+content).hide();
		$('#'+content_header).removeClass('active_icon');
		if (content_header==obj){
			$('#'+content).fadeIn('normal');
			$('#'+content_header).addClass('active_icon');
		}
	}
}
/*
 * Ham thuc hien chuc nang them link box Blogroll
 * Type:	function
 * Name:	TNPro_blogroll
 * Date:	2008/06/02
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param obj la ID cua tab
 */
function TNPro_blogroll(obj){
	$('#'+obj).fadeIn('slow');
	if (obj=="ym_blogrollB") selfDiv = obj.replace('B','A');
	else selfDiv = obj.replace('A','B');
	$('#'+selfDiv).hide();
}
/*
 * Ham thuc hien chuc nang copylink cua cac box playlist
 * Type:	function
 * Name:	TNPro_HighlightAll
 * Date:	2008/06/02
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param obj la ID cua tab
 */
function HighlightAll(theField)
{
	var tempval = document.getElementById(theField).select();
	var txtCopy = document.getElementById(theField).value;
	$.copy(txtCopy);
}

/*
 * Ham thuc hien chuc nang back to top
 * Type:	function
 * Name:	GoToTop
 * Date:	2008/06/025
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param
 */
jQuery(function( $ ){
	$('#gototop').click(function(){
		$.scrollTo( 0, 700);
		return false;
	});
	$('#gotocm').click(function(){
	$.scrollTo('#ym_writebl_inner', 700);
		return false;
	});
})

function IsNumeric(ch){
	if(ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9"||ch=="A"||ch=="B"||ch=="C"||ch=="D"||ch=="E"||ch=="F"||ch=="a"||ch=="b"||ch=="c"||ch=="d"||ch=="e"||ch=="f")
		return 1
	else
		return 0
}

function isHex(str){
	var i,ch
	if(str.length>6)
		return false

	for(i=0;i<str.length;i++){
		ch=str.substring(i,i+1)
		if(!IsNumeric(ch))
			return false
	}
	return true
}
function TNScrollTo(intX,intY)
{
	intDefaultWidth=1280;
	intDefaultHeight=1024;
	intNewX=parseInt(intX*screen.width/intDefaultWidth);
	intNewY=parseInt(intY*screen.height/intDefaultHeight);
	scrollTo(intNewX,intNewY);
}
//----------------------------------------------------------------------------------------------------
function docactiveTab(){
	$('.tabitem').click(function(){
		var tabID=$(this).attr('rel');
		var obj=$(this);
		var objtab=$(this).parents('.boxtop').find('.boxcontent').children('.active');
		if(tabID!=objtab.attr('id'))
		{
			objtab.fadeOut(300,function(){
				$(this).removeClass('active');
				$('#'+tabID).fadeIn(50,function(){
					$(this).addClass('active');
					$(obj).parent().parent().children('.active').removeClass('active');
					$(obj).parent().addClass('active');
				});
			});
		}
		return false;
	})
}
$('.dropdownitem').hover(function()
{
  	$(this).children('.dropdown').show();
  },function(){
  	$(this).children('.dropdown').hide();
  });
/*-----------------------------------------------------------*/
docslidetop = function()
{
	var tsec;
	var curindex=0;
	var maxindex=0;
	maxindex=$(".topvid li").length;
	$('.prenode').click(function(){
		if(curindex>0){
			$(".topvid li").stop(true,true);
			curindex--;
			pixchange($(".topvid li:eq("+curindex+")"));
		}
	});
	$('.nextnode').click(function(){
		if(curindex<maxindex-1){
			$(".topvid li").stop(true,true);
			curindex++;
			pixchange($(".topvid li:eq("+curindex+")"));
		}
	});
	$('.stopnode').toggle(
		function(){
			$(this).addClass('pause');
				$(".topvid .active").stop(true,true);
				clearTimeout(tsec);
		},
		function(){
			$(this).removeClass('pause');
			if(curindex<maxindex-1) curindex++;
			else curindex=0;
			autochange($(".topvid li:eq("+curindex+")"));
		}
	);
	autochange($(".topvid li:eq("+curindex+")"));
	function autochange(obj){
		clearTimeout(tsec);
		$('.topvid .active').removeClass('active');
		$(obj).addClass('active').fadeIn(500,function(){
			tsec=setTimeout(function(){
				curindex++;
				if(curindex==maxindex) curindex=0;
				$(obj).removeClass('active').fadeOut(200,function(){
					autochange($(".topvid li:eq("+curindex+")"));
				});
			},8000);
		});
	}
	function pixchange(obj){
		$('.topvid .active').removeClass('active').fadeOut(200,function(){
			$(obj).addClass('active').fadeIn(500)
		});
	}
};
/*--------------------------------------------------------*/
function ImageSlideShow(){
	var numImagesLoad=3;
	var speedScroll=1000;
	var numPageIndex=1;
	var numItems=$('.listitem li').length;
	var numImgBlockWidth=$('.listitem li').width()+14;
	$('.contvid .listitem').width(numItems * numImgBlockWidth);
	$(".nextvid .next").click(function(){
							if(numPageIndex<(numItems/numImagesLoad)){
								$(".contvid .listitem").animate({left:'-='+numImgBlockWidth*numImagesLoad+'px'}, speedScroll);
								numPageIndex++;
							}
					});
	$(".previd .pre").click(function(){
							if(numPageIndex>1){
								$(".contvid .listitem").animate({left:'+='+numImgBlockWidth*numImagesLoad+'px'}, speedScroll);
								numPageIndex--;
							}
					});
}
/*
* dieu khien box collapse and expand
* Cau truc box
	<div class="box_size">
		<div class="comtitle">
			<div class="ttright">
				<p class="ttmid">
					<span class="iconexp"></span>
					<span class="textleft">Video</span>
					<span  class="textright"><a href="#">Xem thÃªm</a></span>
				</p>
			</div>
		</div>
		<div class="content_size">

		</div>
	</div>
*/
var g_speedSlide=400;
(function($) {
	$.fn.DocCollapseBox = function()
	{
		var thisObj=this;
		function _initialize(){
			var boxnode =$(thisObj).parent().parent().parent().siblings();
			$(thisObj).attr("title","Thu gọn");
			if($(thisObj).hasClass('iconcoll'))
			{
				boxnode.hide();
				$(thisObj).toggle(
					function(){
						$(this).removeClass("iconcoll");
						$(this).attr("title","Thu gọn");
						boxnode.slideDown(g_speedSlide);
					},
					function(){
						$(this).addClass("iconcoll");
						$(this).attr("title","Mở rộng");
						boxnode.slideUp(g_speedSlide);
					}
				);
			}
			else{
				$(thisObj).toggle(
					function(){
						$(this).addClass("iconcoll");
						$(this).attr("title","Mở rộng");
						boxnode.slideUp(g_speedSlide);
					},
					function(){
						$(this).removeClass("iconcoll");
						$(this).attr("title","Thu gọn");
						boxnode.slideDown(g_speedSlide);
					}
				);
			}
		};
		return _initialize();
	};
})(jQuery);
function setlinktab(){
		$('.listlink a').click(function(){
			if($(this).attr('rel'))
			{
				$('.listlink li').removeClass('active');
				$(this).parent().addClass('active');
				$('.conde05').hide();
				$('#'+$(this).attr('rel')).show();
			}
			return false;
		});
}
(function($) {
		$.fn.mdtTooltip = function()
		{
			function _initialize(e) {
				$(this).addClass('over');
				$('#tooltipcontainer').html($(this).attr('msghtml'));
				var tipw=300;
				var sh=getDocumentSize(4);
				var wh=getDocumentSize(3);
				var ww=getDocumentSize(2);
				var sw=getDocumentSize(5);
				var tiph=Math.round($('#mytooltip').height()/2);
				var ttop=0;
				var tleft=0;
				if((e.pageX+(tipw/2))>ww){
					tleft=ww+sw-tipw-30;
				}
				else{
					tleft=e.pageX-Math.round(tipw/3);
				}
				if((e.pageY+2*tiph)>(sh+wh))
				{
					ttop=e.pageY-(2*tiph);
				}
				else{
					ttop=e.pageY+10;
				}
				$('#tooltipconnector').css('left',e.pageX-tleft);
				$('#mytooltip').css('top',ttop+10);
				$('#mytooltip').css('left',tleft);
				$('#mytooltip').show();
				return false;
			};
			function _finish(){
				$(this).removeClass('over');
				$('#mytooltip').hide();
			};
			if($(this).attr('msghtml') && $(this).attr('msghtml')!=''){
				this.mousemove(_initialize);
				this.mouseout(_finish);
			}
		};
})(jQuery);
function addPanel(){
	$('body').append('<div id="mytooltip"><div id="contbox"><div id="tooltipcontainer" class="select-free"><!--[if lte IE 6.5]><iframe></iframe><![endif]--></div><div id="tooltipconnector"></div></div></div>');
	return false;
};
function showguidetip(obj,tiptext,tipwidth){
		var tipnotediv=document.getElementById('tipnote');
   		if(tipnotediv==null)
	   {
		  $('body').append('<div class="tipnote" id="tipnote"><div class="tiparr"><div class="tipcon"></div></div></div>')
	  	}
		var intleft=$(obj).parents('li').offset().left+$(obj).parents('li').width()+5;
		var inttop=$(obj).offset().top;
		$('.tipnote').css('top',inttop+'px');
		$('.tipnote').css('left',intleft+'px');
		$('.tipnote').css('width',tipwidth+'px');
		$('.tipnote .tipcon').html(tiptext);
		$('.tipnote').fadeIn();
}
function hideguidetip(){
	$('.tipnote').hide();
}
function showtabbox(objid){
	$('.ptabbox').hide();
	$('#'+objid).show();
}
function setcactivesearch(){
	$('.contsfrm li a').click(function(){
		$('.contsfrm .active').removeClass('active');
		$(this).parent().addClass('active');
	})
}
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();
		var dialogTop=Math.round(getDocumentSize(4)+(getDocumentSize(3)-jQuery(this.dialogcommon).height())/2);
		jQuery(this.dialogcommon).css({left: Math.round(getDocumentSize(2)/2-this.intWidth/2) +"px"});
		jQuery(this.dialogcommon).css({top:dialogTop +"px"});
		jQuery(this.dialogcommon).fadeIn(300, function()
		{
			jQuery("#dialogbacklayer").show();
			 jQuery(this.dialogcommon).css({display:'block'});
		});
		jQuery("#dialogbacklayer").click(function(){
			ym2msgbox.hide();
		});
		window.onresize=this.getpos;
		window.onscroll=this.getpos;
	},
	hide:function(){
		jQuery(this.dialogbacklayer).hide();
		jQuery(this.dialogcommon).hide();
		jQuery('body').append(gMsgHtml);
		gMsgHtml=null;
	},
	getpos: function(){
		var dialogTop=Math.round(getDocumentSize(4)+(getDocumentSize(3)-jQuery(this.dialogcommon).height())/2);
		jQuery(ym2msgbox.dialogcommon).css({left: Math.round((getDocumentSize(2)-ym2msgbox.intWidth)/2)+"px"});
		jQuery(ym2msgbox.dialogcommon).css({top: dialogTop+"px"});
	},
	init:function()
	{
	 	var backobj=document.getElementById('dialogbacklayer');
		if (backobj == null || backobj == 'undefined'){
			jQuery('body').append('<div id="dialogbacklayer">&nbsp;</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('#dialogcommon').css('width',this.intWidth+20+'px');
		jQuery('#msgcontain').css('width',this.intWidth+'px');
		jQuery('#dialogcommon .wdialog').css('width',(this.intWidth)+'px');
	}
}
function changposbox(){

	$('.pcontgo .go1').click(function(){
			try{
				var objmove01=$(this).parents('.pmovebox');
				var objmove02=$(this).parents('.pmovebox').prev('.pbox');
				if(objmove02.hasClass('pmovebox'))
				{
					var obj1top=objmove01.height();
					var obj2top=-objmove02.height()-10;
					$(objmove01).fadeTo(100, 0.5)
						.animate({
							top:obj2top
						},1000,function(){
							$(objmove01).css({top: 0})
							$(objmove01).fadeTo(200, 1.0);
						});
					$(objmove02)
						.fadeTo(100, 0.5)
						.animate({
							top:obj1top
						},1000,function(){
							$(objmove02).before($(objmove01));
							$(objmove02).css({top: 0})
							$(objmove02).fadeTo(200, 1.0);
						});
				}else
				{
					return false;
				}

			}
			catch(err){
				return false;
			}
	});
	$('.pcontgo .go2').click(function(){
			try{
				var objmove01=$(this).parents('.pmovebox');
				var objmove02=$(this).parents('.pmovebox').next('.pbox');
				if(objmove02.hasClass('pmovebox'))
				{
					var obj1top=-objmove01.height()-10;
					var obj2top=objmove02.height();
					$(objmove01).fadeTo(100, 0.5)
						.animate({
							top:obj2top
						},1000,function(){
							$(objmove01).css({top: 0})
							$(objmove01).fadeTo(200, 1.0);
						})

					$(objmove02)
						.fadeTo(100, 0.5)
						.animate({
							top:obj1top
						},1000,function(){
							$(objmove02).css({top: 0})
							$(objmove01).before($(objmove02));
							$(objmove02).fadeTo(200, 1.0);
						})
				}else
				{
					return false;
				}

			}
			catch(err){
				return false;
			}
	});
}
$(document).ready(function(){
	docactiveTab();
	docslidetop();
	setlinktab();
	ImageSlideShow();
	addPanel();
	changposbox();
	setcactivesearch();
	$('.hicon').each(function(){
		$(this).mdtTooltip();
	});
	$('.iconexp').each(function(){
			$(this).DocCollapseBox();
	});
});

function setScriptBanner(strIdBoxBanner,strIdBoxTarget)
{
	if(parseInt($("#"+strIdBoxBanner+" object").attr('width'))>0)
	{
		$("#"+strIdBoxTarget).append($("#"+strIdBoxBanner+" object"));
	}
	else{
		$("#"+strIdBoxTarget).append($("#"+strIdBoxBanner+" a"));
	}
}