//thumbnailviewer
var thumbnailviewer={
	divID: null,
	enableTitle: true,
	enableAnimation: true,
	defineLoading: '<img src=\'loading.gif\' /> Đang tải ảnh...',

	scrollbarwidth: 16,
	opacitystring: 'filter:progid:DXImageTransform.Microsoft.alpha(opacity=10); -moz-opacity: 0.1; opacity: 0.1',
	targetlinks:[],

	createthumbBox:function(divId)
	{
		this.divID=document.getElementById(divId);
		this.divID.innerHTML='<div id=\'thumbBox\'><div id=\'thumbImage\'></div></div>';
		
		this.divID.innerHTML+='<div id=\'thumbLoading\'>'+this.defineLoading+'</div>';
		this.thumbBox=document.getElementById('thumbBox')
		this.thumbImage=document.getElementById('thumbImage')
		this.thumbLoading=document.getElementById('thumbLoading')
		this.standardbody=(document.compatMode=='CSS1Compat')? document.documentElement : document.body
	},


	centerDiv:function(divobj)
	{ 
		var ie=document.all && !window.opera
		var dom=document.getElementById
		var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
		var scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
		var docwidth=this.divID.offsetWidth;
		var docheight=this.divID.offsetHeight;
		var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight 
		var objwidth=divobj.offsetWidth 
		var objheight=divobj.offsetHeight 
		var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+'px' : scroll_top+10+'px'

		//divobj.style.left=docwidth/2-objwidth/2+'px'
		//divobj.style.top=Math.floor(parseInt(topposition))+'px'
		divobj.style.visibility='visible'
	},

	showthumbBox:function(){ 
		this.centerDiv(this.thumbBox)
		if (this.enableAnimation){ 
			this.currentopacity=0.1 
			this.opacitytimer=setInterval('thumbnailviewer.opacityanimation()', 20)
		}
	},


	loadimage:function(link)
	{
		if (this.thumbBox.style.visibility=='visible')
		this.closeit()
		var imageHTML='<img src="'+link.getAttribute("href")+'" style="'+this.opacitystring+'" />'
		if (this.enableTitle && link.getAttribute("title"))
		imageHTML+='<br />'+link.getAttribute("title")
		this.centerDiv(this.thumbLoading) 
		this.thumbImage.innerHTML=imageHTML 
		this.featureImage=this.thumbImage.getElementsByTagName("img")[0] 
		this.featureImage.onload=function()
		{
			thumbnailviewer.thumbLoading.style.visibility="hidden"
			thumbnailviewer.showthumbBox()
		}
		if (document.all && !window.createPopup)
		this.featureImage.src=link.getAttribute("href")
		this.featureImage.onerror=function(){
			thumbnailviewer.thumbLoading.style.visibility="hidden"
		}
	},

	setimgopacity:function(value){
		var targetobject=this.featureImage
		if (targetobject.filters && targetobject.filters[0]){
			if (typeof targetobject.filters[0].opacity=="number")
			targetobject.filters[0].opacity=value*100
			else 
			targetobject.style.filter="alpha(opacity="+value*100+")"
		}
		else if (typeof targetobject.style.MozOpacity!="undefined")
		targetobject.style.MozOpacity=value
		else if (typeof targetobject.style.opacity!="undefined")
		targetobject.style.opacity=value
		else
		this.stopanimation()
	},

	opacityanimation:function(){
		this.setimgopacity(this.currentopacity)
		this.currentopacity+=0.1
		if (this.currentopacity>1)
		this.stopanimation()
	},

	stopanimation:function(){
		if (typeof this.opacitytimer!="undefined")
		clearInterval(this.opacitytimer)
	},


	closeit:function()
	{
		this.stopanimation()
		this.thumbBox.style.visibility="hidden"
		this.thumbImage.innerHTML=""
		this.thumbBox.style.left="-2000px"
		this.thumbBox.style.top="-2000px"
	},

	cleanup:function(){
		this.thumbLoading=null
		if (this.featureImage) this.featureImage.onload=null
		this.featureImage=null
		this.thumbImage=null
		for (var i=0; i<this.targetlinks.length; i++)
		this.targetlinks[i].onclick=null
		this.thumbBox=null
	},

	dotask:function(target, functionref, tasktype)
	{
		var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
		if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
	},

	init:function()
	{
		if (!this.enableAnimation)
		this.opacitystring=""
		var pagelinks=document.getElementsByTagName("a")
		for (var i=0; i<pagelinks.length; i++)
		{
			if (pagelinks[i].getAttribute("rel") && pagelinks[i].getAttribute("rel")=="thumbnail")
			{
				pagelinks[i].onclick=function(){
					thumbnailviewer.stopanimation()
					thumbnailviewer.loadimage(this)
					return false
				}
				this.targetlinks[this.targetlinks.length]=pagelinks[i]
			}
		}
		this.dotask(window, function(){if (thumbnailviewer.thumbBox.style.visibility=="visible") thumbnailviewer.centerDiv(thumbnailviewer.thumbBox)}, "resize")
	}
}
//thumbnailviewer

//File hiển thị toolTip kiểu Text hoặc Ảnh.
//script phong to thu nho anh
// De chay duoc nhat thiet phai chen mot the div vao cuoi trang
//<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>

//////////////////////
var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

// resize fix for ns4
var origWidth, origHeight;
if (ns4) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

///////////////////////  CUSTOMIZE HERE   ////////////////////
// settings for tooltip
// Do you want tip to move when mouse moves over link?
var tipFollowMouse= true;

var tipWidth= 400;
var offX= 20;	// how far from mouse to show tip
var offY= 12;

var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";

var tipFontColor= "#000000";
var tipBgColor= "#DDECFF";
var tipBorderColor= "#000080";
var tipBorderStyle= "ridge";
var tipBorderWidth= 1;
var tipPadding= 4;

var tooltip, tipcss;
function initTip() {
	if (nodyn) return;
	tooltip = (ns4)? document.tipDiv.document: (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = (ns4)? document.tipDiv: tooltip.style;
	if (ie4||ie5||ns5) {	// ns4 would lose all this on rewrites
		tipcss.fontFamily = tipFontFamily;
		tipcss.fontSize = tipFontSize;
		tipcss.color = tipFontColor;
		tipcss.backgroundColor = tipBgColor;
		tipcss.borderColor = tipBorderColor;
		tipcss.borderWidth = tipBorderWidth+"px";
		tipcss.padding = tipPadding+"px";
		tipcss.borderStyle = tipBorderStyle;
	}
	if (tooltip&&tipFollowMouse) {
		if (ns4) document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = trackMouse;
	}
}

window.onload = initTip;

/////////////////////////////////////////////////
//  doTooltip function
//			Assembles content for tooltip and writes
//			it to tipDiv
/////////////////////////////////////////////////
var t1,t2;	// for setTimeouts
var tipOn = false;	// check if over tooltip link
var midStr = ' border="0"></td></tr><tr><td valign="top" align="center">';
var endStr = '</td></tr></table>';

function doTooltip(evt,imgName, Text,width)
{
	if(typeof(tipcss)=='undefined')
	return;
	
	tipcss.borderWidth = tipBorderWidth+"px";
	tipcss.padding = tipPadding+"px";
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	// set colors if included in messages array
	/*if (messages[num][2])	var curBgColor = messages[num][2];
	else curBgColor = tipBgColor;
	if (messages[num][3])	var curFontColor = messages[num][3];
	else curFontColor = tipFontColor;
	*/
	var curBgColor ="#ffffff";
	var curFontColor ="#000000";
	//imgName='image/sanpham/'+ imgName;
	if (ie4||ie5||ns5) {
		var tip = '<table width="' + width + '" border=0><tr><td align="center" width="100%"><img src="' + imgName + ' " width=' + width + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">'+Text+'</span>' + endStr;
		tipcss.backgroundColor = curBgColor;
		tooltip.innerHTML = tip;
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);
}

function doTooltipText(evt,Text,width)
{
	if(typeof(tipcss)=='undefined')
	return;
	
	tipcss.borderWidth = tipBorderWidth+"px";
	tipcss.padding = tipPadding+"px";
	if (!tooltip) return;
	if (t1) clearTimeout(t1);
	if (t2) clearTimeout(t2);
	tipOn = true;

	var curBgColor ="#FFFFCC";
	var curFontColor ="#000000";

	if (ie4||ie5||ns5)
	{
		if(width)
		{
			var tip = '<table width="' + width + '" border=0><tr><td align="left" width="100%"><span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">'+Text+'</span>' + endStr;
		}
		else
		{
			var tip = '<table border=0><tr><td align="left" width="100%"><span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">'+Text+'</span>' + endStr;
		}
		tipcss.backgroundColor = curBgColor;
		tooltip.innerHTML = tip;
	}

	if (!tipFollowMouse)
	positionTip(evt);
	else
	t1=setTimeout("tipcss.visibility='visible'",100);
}

function doTooltipHTML(evt, tipHTML, image_id)
{
	if(typeof(tipcss)=='undefined')
	return;
	
	tipcss.borderWidth ='0px';
	tipcss.padding = "0px";
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;
	var curBgColor ="";
	var curFontColor ="#000000";

	if (ie4||ie5||ns5)
	{
		var tip = tipHTML ;
		tipcss.backgroundColor = curBgColor;
		tooltip.innerHTML = tip;
//		document.getElementById('tooltipIMG').innerHTML='àkj';
		if(image_id)
		{
			thumbnailviewer.createthumbBox('tooltipIMG');
			thumbnailviewer.dotask(window, function(){thumbnailviewer.init()}, "load")
			thumbnailviewer.dotask(window, function(){thumbnailviewer.cleanup()}, "unload")
			thumbnailviewer.loadimage(document.getElementById('mage_id'+image_id+''));
		}
	}

	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);

}

var mouseX, mouseY;
function trackMouse(evt) {
	mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
	mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	if (tipOn) positionTip(evt);
}

///////////////////////////////////////////////////////////////
//  positionTip function									 //
//		If tipFollowMouse set false, so trackMouse function	 //
//		not being used, get position of mouseover event.	 //
//		Calculations use mouseover event position, 			 //
//		offset amounts and tooltip width to position		 //
//		tooltip within window.								 //
///////////////////////////////////////////////////////////////
function positionTip(evt) {
	if (!tipFollowMouse) {
		mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
		mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
	}
	// tooltip width and height
	var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	// document area in view (subtract scrollbar width for ns)
	var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
	var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
	// check mouse position against tip and window dimensions
	// and position the tooltip
	if ((mouseX+offX+tpWd)>winWd)
	tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
	else tipcss.left = (ns4)? mouseX+offX: mouseX+offX+"px";
	if ((mouseY+offY+tpHt)>winHt)
	tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
	else tipcss.top = (ns4)? mouseY+offY: mouseY+offY+"px";
	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}

function hideTip() {
	if (!tooltip) return;
	t2=setTimeout("tipcss.visibility='hidden'",100);
	tipOn = false;
}




//Script khi di chuot hien dong` chu~ phuc vu quang cao tren text
//De chay duoc nhat thiet phai chen doan ma sau vao cuoi trang
//<div id="GALBox" style="text-align: left; position: absolute; z-index: 100; visibility: hidden; left: 202px; top: 6962px;" onmouseover="this.style.visibility='visible';" onmouseout="this.style.visibility='hidden';"></div>


///////////
//  %%product_title%% %%version%%
//	Copyright ©2005-%%current_year%% All rights reserved by www.thevbgeek.com
//	Code may not be used in whole or part without written permission.
//  You may not distribute this or any of files in whole or significant part
//	without explicit written permission.
// ---------------- %%product_title%% IS NOT FREE SOFTWARE ----------------
// http://www.thevbgeek.com
// Licensed to %%domain%% %%email%%
// License key: %%licensekey%%
// Downloaded: %%download_date%%

// change to gal_opens=1; for RTL
var gal_opens=0;

//change timeout
var gal_timeout=1000;

var posx = 0;
var posy = 0;

document.documentElement.onmousemove = mousexy;

var tempX = 0;
var tempY = 0;

var gleftpx;
var gtoppx;
var grightpx;
var gheightpx;
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = ((userAgent.indexOf('opera') != -1) || (typeof(window.opera) != 'undefined'));
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac    = (userAgent.indexOf('mac') != -1);

// Catch possible bugs with WebTV and other older browsers


function fetch_object(idname)
{
	if (document.getElementById)
	{
		return document.getElementById(idname);
	}
	else if (document.all)
	{
		return document.all[idname];
	}
	else if (document.layers)
	{
		return document.layers[idname];
	}
	else
	{
		return null;
	}
}
function mousexy(e)
{
	if (is_ie)
	{
		tempX = event.clientX;
		tempY = event.clientY;
	}
	else
	{
		tempX = e.clientX ;
		tempY = e.clientY;
	}
	tempY = tempY + document.documentElement.scrollTop;
	tempX = tempX + document.documentElement.scrollLeft;
	//window.status = tempX + " " + tempY;
}


function GAL_watch()
{

	e = fetch_object("GALBox");
	if (e.style.visibility == 'visible')
	{
		var leftpx  = e.offsetLeft;
		var toppx   = e.offsetTop;
		var rightpx = e.offsetWidth;
		var heightpx = e.offsetHeight;

		while ((e = e.offsetParent) != null)
		{
			leftpx  += e.offsetLeft;
			toppx   += e.offsetTop;
		}
		//status = leftpx;
		if ((tempX > leftpx) && (tempX < (leftpx + rightpx)) && (tempY > toppx) && (tempY < (heightpx + toppx)))
		{
			setTimeout("GAL_watch()", gal_timeout);
			gal_opens = 1;

		}
		else
		{
			if ((tempX > gleftpx) && (tempX < (gleftpx + grightpx)) && (tempY > gtoppx) && (tempY < (gheightpx + gtoppx)))
			{
				setTimeout("GAL_watch()", gal_timeout);
				gal_opens = 1;
			}
			else
			{
				gal_opens = 0;
				fetch_object("GALBox").style.visibility = 'hidden';
			}
		}

	}

}

function GAL_popup(e,offset,width, box_style, value,value_style, title, title_style)
{

	var anchorright = 0;
	if (!offset)
	{
		offset = 1;
	}

	gleftpx 	= e.offsetLeft;
	gtoppx 	= e.offsetTop;
	grightpx = e.offsetWidth;
	gheightpx = e.offsetHeight;

	while ((e = e.offsetParent) != null)
	{
		gleftpx 	+= e.offsetLeft;
		gtoppx	+= e.offsetTop;
	}

	var toppx = gtoppx;
	var leftpx = gleftpx;
	var rightpx = grightpx;

	if (is_ie)
	{
		toppx	+= 15;
	}
	else
	{
		toppx 	+=12;
	}

	var dest = fetch_object("GALBox");
	toppx=toppx-offset;

	if (width)
	{
		width = " Width='" + width + "' ";
	}
	else
	{
		width = " Width='300px' ";
	}
	var innerhtml="<table border='0' cellpadding='0' cellspacing='0' " + width + "><tr><td onmouseover=\"GAL_keepopen();\" onmouseout=\"GAL_hidepopup();\"><div " + box_style + width + " >";
	if (title)
	{
		innerhtml=innerhtml + "<div " + title_style + " >" + title + "</div>";
	}
	innerhtml= innerhtml + "<div " + value_style + " >" + value + "</div></div></td><tr></table>";
	dest.innerHTML=innerhtml;

	//alert(innerhtml);


	if (anchorright == 1)
	{
		rightpx = leftpx - dest.offsetWidth + rightpx;
		if (rightpx<0)
		{
			rightpx = 0;
		}
		var anchor = rightpx + "px";
	}
	else
	{
		if (document.documentElement)
		{
			if (document.documentElement.clientWidth < (leftpx + dest.offsetWidth))
			{
				leftpx = document.documentElement.clientWidth - dest.offsetWidth;
			}
		}
		var anchor = leftpx + "px";
	}

	dest.style.left = anchor;
	dest.style.top  = toppx + "px";

	dest.style.visibility='visible';
	gal_opens = 2;
	setTimeout("GAL_watch()", 1000);
}

function GAL_hidepopup()
{
	gal_opens--;
}
function GAL_keepopen(){
	gal_opens++;
}