/*
 * Show/hide all Services
 * Type:	
 * Name:	
 * Date:	2008/10/06
 * @author:	Hien Nguyen <hiennh@von-inc.com>
 */
var flag = false ;
var time2Hide;

function TNShowAllServices(){
	$('.allservices').css('backgroundPosition','right bottom');
	$('#uni_link').slideDown('normal');
}

function TNHideAllServices(){
	$('.allservices').css('backgroundPosition','right top');
	$('#uni_link').slideUp('normal');
}
function TNHideAS(){
	clearTimeout(time2Hide);
	if(!flag){
		time2Hide = setTimeout('TNHideAllServices()',2000);
	}
	else if(flag)	{			
		TNShowAllServices();
	}
}
function TNAS_Show(){
	flag = true;
	TNHideAS();
}
function TNAS_Hide(){
	flag = false;
	TNHideAS();
}//end function

/*
 * Ham thuc hien thay doi icon bo go
 * Type:	onload function
 * Name:	
 * Date:	2008/05/20
 * @author:	Hien Nguyen <hiennh@von-inc.com>
 */
var typing_icon_status = 0;
function typing_change_icon(){
	typing_icon_status++;
	$('.typing_icon').each(function(index)
		{
			$(this).css('background-position', function(){			
			if (typing_icon_status % 2 == 0) { setMethod(0);
			return 'top'; }
			else { setMethod(-1);
			return 'bottom'; }
		})
	});
}//end function

/*
 * Change Tab Search form
 * Type:	
 * Name:	
 * Date:	2008/10/07
 * @author:	Hien Nguyen <hiennh@von-inc.com>
 */
function TNchangeTabSearch(clickTab,box){
	TYPE = clickTab.id;
	var parentTab = clickTab.parentNode;
	$('.'+parentTab.className+' .active').removeClass('active');
	$('.'+parentTab.className+' li').removeClass('active').css('background','url(http://static.timnhanhdev.com/searchv2/css/images/graphics/bg_uppertab_hline.gif) no-repeat right');
	$('.'+parentTab.className+' li:last').css('background','none');
	$('.'+parentTab.className+' li:last').prev().css('background','none');
	$(clickTab).addClass('active');
	$(clickTab).prev().css('background','none');
	if(box==1){
		if($('#topsearch_'+clickTab.id).html()==null)
		{
			var html = $.ajax({ 
				url: SEARCH+'/search/'+clickTab.id, 
				async: false 
				}).responseText;		
				$('#hotTag').append(html);		
		}
		var chi = $("#hotTag").children();		
		$.each(chi,function(i,div){
			$(div).css({ display: "none"});
		});
	}
	else
	{
		if(document.frmSearch.timnhanh.value!='')	
			window.location.href=SEARCH+'/'+TYPE+'/'+TN(document.frmSearch.timnhanh.value);
	}
	$('#topsearch_'+clickTab.id).css({ display: "block"});	
}//end function

/*
 * Show/hide hot Tag
 * Type:	
 * Name:	
 * Date:	2008/10/08
 * @author:	Hien Nguyen <hiennh@von-inc.com>
 */
var hotTagArrow = 'right bottom';
function TNshowHotTag(linkTitle){
	$(linkTitle).css('background-position',function(){
		if (hotTagArrow == 'right top') {
			hotTagArrow = 'right bottom';
			return 'right bottom';
		}
		else {
			hotTagArrow = 'right top';
			return 'right top';
		}
	});
	$(linkTitle).next().slideToggle('fast');
}//end function

/*
 * import flash mp3 player 
 * Type:	
 * Name:	
 * Date:	2008/10/09
 * modifed:	Tri Do <tridn@von-inc.com>
 */
function TNplayerMp3(obj,url){
	$(".playcontrol").html('');
	$(".playbox").removeClass("isplaying");
	$(obj).parent().addClass("isplaying");
	$(obj).parent().children(".playcontrol").html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="230" height="28" id="mp3player" align="middle">' +
		'<param name="allowScriptAccess" value="sameDomain" />' +
		'<param name="movie" value="'+WEBSTATIC+'/searchv2/simple_play.swf?xmlPath='+url+'&mAuto=true" />' +
		'<param name="quality" value="best" />' +
		'<param name="bgcolor" value="#ffffff" />' +
		'<param name="wmode" value="opaque" />' +
		'<embed src="'+WEBSTATIC+'/searchv2/simple_play.swf?xmlPath='+url+'&mAuto=true" quality="best" bgcolor="#ffffff" width="230" height="28" name="simple_play_Flash8" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	return false;
}
function SearchOther()
{
	if(ERROR)
		return;	
	var typeSearch = new Array('web','images','news','music','video','blog');	
	for (var i = 0, length = typeSearch.length; i < length; i++) {
		if(typeSearch[i]==TYPE && TYPE!='images')
		{ continue;}
		$.getJSON
		(
			SEARCH+'/'+typeSearch[i]+'/search?callback=?',	
			{tab:TYPE},
			function(data)
			{				
				var result = data.html;		
				if(result!='')
					$('#result_'+data.tab).html(result);
				else
					$('#result_'+data.tab).css({ display: "none"});
				$('#iconexp_'+data.tab).TNCollapseBox();
				if(data.tab=='images')
				{					
					$('.tooltipcontent').TNPhototip();
				}
					
			}
		)		
	}
}
function SearchTin(obj,tab)
{	
	$.getJSON
	(
		obj.href+'?callback=?',
		{tab:tab},
		function(data)
		{				
			var result = data.html;				
			$('#result_'+data.tab).html(result);	
			$('#iconexp_'+data.tab).TNCollapseBox();
		}
	)
	return false;
}

/*
* dieu khien image tip
* Type:     Function use Jquery
* Name:     tnPhototip 
* date: 	oct 10, 2008
* @author   Tri Do <tridn@von-inc.com >
*/
(function($) {
		$.fn.TNPhototip = function() 
		{	
			function _initialize(e) {
				var arrwsize=_getPageSize();
				var arrscroll=_getPageScroll();
				var objLeft=$(this).offset().left;
				var objWidth=$(this).width();
				var intToolW=0;
				_addPanel();
				if($.browser.msie){ 
					$('#tooltipcontainer').css('top',($(this).offset().top));
				}
				else{
					$('#tooltipcontainer').css('top',($(this).offset().top-70));
				}
				$('#tooltipcontainer').html($(this).children('.tooltipcontent').html());
				$('#tooltipcontainer').width($(this).children('.photobig').width());
				intToolW=$('#tooltipcontainer').width();
				$('#tooltipcontainer .photodes').width(intToolW-10);
				$('#tooltipcontainer .photosize').width(intToolW-10);
				$('#tooltipcontainer').css('left',(objLeft-intToolW-15));
				$('#tooltipcontainer').fadeIn(300);
				if((e.pageY)>=($('#tooltipcontainer').offset().top+40)){
					$('#tooltipconnector').css('top',e.pageY-18);
				}
				else{
					$('#tooltipconnector').css('top',e.pageY+2);
				}
				$('#tooltipconnector').css('left',objLeft-8);
				$('#tooltipconnector').fadeIn(300);									 
				return false;
			};
			function _addPanel(){
				_finish();
				$('body').append('<div id="tooltipcontainer"></div><div id="tooltipconnector"></div>');
				return false;
			};
			function _finish() {
				$('body #tooltipcontainer').html('');
				$('body #tooltipcontainer').hide();
				$('body #tooltipconnector').hide();
				$('body #tooltipconnector').remove();
				$('body #tooltipcontainer').remove();
			};
			function _getPageSize() {
				var xScroll, yScroll;
				if (window.innerHeight && window.scrollMaxY) {	
					xScroll = window.innerWidth + window.scrollMaxX;
					yScroll = window.innerHeight + window.scrollMaxY;
				} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
					xScroll = document.body.scrollWidth;
					yScroll = document.body.scrollHeight;
				} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
					xScroll = document.body.offsetWidth;
					yScroll = document.body.offsetHeight;
				}
				var windowWidth, windowHeight;
				if (self.innerHeight) {	// all except Explorer
					if(document.documentElement.clientWidth){
						windowWidth = document.documentElement.clientWidth; 
					} else {
						windowWidth = self.innerWidth;
					}
					windowHeight = self.innerHeight;
				} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
					windowWidth = document.documentElement.clientWidth;
					windowHeight = document.documentElement.clientHeight;
				} else if (document.body) { // other Explorers
					windowWidth = document.body.clientWidth;
					windowHeight = document.body.clientHeight;
				}	
				var pageHeight, pageWidth;
				// for small pages with total height less then height of the viewport
				if(yScroll < windowHeight){
					pageHeight = windowHeight;
				} else { 
					pageHeight = yScroll;
				}
				// for small pages with total width less then width of the viewport
				if(xScroll < windowWidth){	
					pageWidth = xScroll;		
				} else {
					pageWidth = windowWidth;
				}
				arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);
				return arrayPageSize;
			};
			//ham lay thong so thanh cuon
			function _getPageScroll() {
				var scrOfX = 0, scrOfY = 0;
				if( typeof( window.pageYOffset ) == 'number' ) {
				//Netscape compliant
					scrOfY = window.pageYOffset;
					scrOfX = window.pageXOffset;
				} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
				//DOM compliant
					scrOfY = document.body.scrollTop;
					scrOfX = document.body.scrollLeft;
				} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
				//IE6 standards compliant mode
					scrOfY = document.documentElement.scrollTop;
					scrOfX = document.documentElement.scrollLeft;
				}
				arrayPageScroll = new Array(scrOfX, scrOfY);
				return arrayPageScroll;
			};
			
			return this.parent().unbind('ouseover','mouseout').mouseover(_initialize).mouseout(_finish);
		};
})(jQuery);

/*
* dieu khien box collapse and expand
* Type:     Function use Jquery
* Name:     s20CollapseBox 
* Date:     Oct 07, 2008
* @author   Tri Do <tridn@von-inc.com >
* 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.TNCollapseBox = function() 
	{
		var thisObj=this;
		function _initialize(){
			var boxnode =$(thisObj).parent().parent().parent().siblings();
			$(thisObj).attr("title","Thu gọn");
			$(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);
jQuery(function( $ ){
	$('#gototop').click(function(){
		$.scrollTo( 0, 700);					
		return false;
	});
})