/* ajax_img 080926 clear loadpage  */
/* ajax_img 080926 updateposition fix  */
/* ajax_img 080926 short animation  */
/* ajax_img 080818  */
/* ajax_img 080816b  */
	// gmail code
	var isIE=(window.attachEvent && !window.opera);
	var Ka=navigator.userAgent.toLowerCase();
	var rt=Ka.indexOf("opera")!=-1;
	var r=Ka.indexOf("msie")!=-1&&(document.all&&!rt);
	
	function myAttachEvent(a,b,c){if(r){a.attachEvent("on"+b,c)}else{a.addEventListener(b,c,false)}}


function getXCoord(el) {
	x = 0;
	while(el){
		x += el.offsetLeft;
		el = el.offsetParent;
	}
	return x;
}

function getYCoord(el) {
	y = 0;
	while(el){
		y += el.offsetTop;
		el = el.offsetParent;
	}
	return y;
}



/*
function $(id) {
	return document.getElementById(id);
}
*/




/* ===================================== */
var divPageMask;
var divPopContainer;

function OpenMask()
{


	if(!$('divPageMask')){
		divPageMask = document.createElement('div');
		divPageMask.id = "divPageMask";
		divPageMask.style.display = "none";
		document.body.appendChild(divPageMask);
	}

	divPageMask.innerHTML='';
	


	// set opacity
	/*if(isIE){
			divPageMask.style.filter= ' alpha(opacity=70); ';
	
	}else{
			divPageMask.style.opacity=0.7;
	}*/
	
	

	divPageMask.style.backgroundColor ="#000000";
	divPageMask.style.position = 'absolute';
	divPageMask.style.left =0+'px';
	divPageMask.style.top = 0+'px';		
	divPageMask.style.zIndex = "1";
	
	
	myAttachEvent(divPageMask,'click', CloseMask); 
	

	
	  //select
	  DispalySelect(0);  
	  
	  //?Bnh
	  /*divPageMask.style.display="block";*/	  
	  
	  if(divPageMask.style.display=="none"){
		Effect.Appear(divPageMask, {   from: 0.0, to: 0.8,duration: 0.6});
	  }
	  
	 //BzBnh
	  resizeMask();
	  myAttachEvent(window,'resize', resizeMask); 
	  /*myAttachEvent(window,'scroll', resizeMask); */
	  
	  
	  
	/* clear loadpage */
	var loc=document.location+"";
	var selfpath=loc.substring(0,loc.lastIndexOf("/")+1);
	var url_key=loc.replace(selfpath,"");

	if(url_key.indexOf("loadpage=")>0){
			document.location="#";
	}
	/* ========== */
	

}

function DispalySelect(val)
{  //?Mselect
 var dispalyType;
  var arrdispalyType=["hidden","visible"];
  var arrObjSelect=document.getElementsByTagName("select");
  for (i=0;i<arrObjSelect.length;i++)
  {
    arrObjSelect[i].style.visibility=arrdispalyType[val];
  }
}



function CloseMask()
{
	//select
	DispalySelect(1);
	

	
	window.onResize = null;
	window.onScroll = null;
	
	
	
	if($('divPopContainer')){
		/*divPopContainer.style.display="none";*/
		new Effect.Fade(divPopContainer, { duration: 0.6});
	}
	
	if($('divTempArea')){
		/*divPopContainer.style.display="none";*/
		new Effect.Fade(divTempArea, { duration: 0.6});
	}	
	
	//BzBnh
	if(divPageMask){
		/*divPageMask.style.display="none";*/
		
		Effect.Fade(divPageMask, { duration: 0.6} );
	}
	
	
	
	




}


function resizeMask()
{

  var myWidth = 0, myHeight = 0;
  if(window.innerWidth) {

    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
	  
	if(document.body.scrollWidth!=""){
		myWidth=Math.max(document.body.scrollWidth, myWidth);
	}
	
	
	if(document.body.scrollHeight!=""){
		myHeight=Math.max(document.body.scrollHeight, myHeight);
	}
	
	divPageMask.style.height=myHeight+'px';
	divPageMask.style.width=myWidth+'px';

/*
	if($("divPopContainer")){
		
		divPopContainer=$("divPopContainer");
		getViewPoint(); // DL DT
		getViewport(); //  viewportwidth viewportheight
		divPopContainer.style.left=DL+(viewportwidth/2)-(divPopContainer.offsetWidth/2) +'px';
		divPopContainer.style.top =DT+(viewportheight/2)-(divPopContainer.offsetHeight/2)+'px';
	
	}*/
}

var DL, DT;
function getViewPoint(){
  if(window.pageXOffset){DL=window.pageXOffset;}
  else if(document.documentElement&&document.documentElement.scrollLeft){
    DL=document.documentElement.scrollLeft;}
  else if(document.body){DL=document.body.scrollLeft;}
  
  if(window.pageYOffset){DT=window.pageYOffset;}
  else if(document.documentElement&&document.documentElement.scrollTop){
    DT=document.documentElement.scrollTop;}
  else if(document.body){DT=document.body.scrollTop;}
}


var viewportwidth;
 var viewportheight;
 function getViewport(){
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth;
      viewportheight = window.innerHeight;
	
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 else if (typeof document.documentElement != 'undefined'    && typeof document.documentElement.clientWidth !=     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth;
       viewportheight = document.documentElement.clientHeight;	

 }
 
 // older versions of IE
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
       viewportheight = document.getElementsByTagName('body')[0].clientHeight;
 }
/* ===================================== */

 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


function jspop(obj_id){
	var obj=$(obj_id);
	


	/*CloseMask();*/
	OpenMask();
	
	
	if(!$('divPopContainer')){
		divPopContainer = document.createElement('div');
		divPopContainer.id = "divPopContainer";
		document.body.appendChild(divPopContainer);
	}
	
	divPopContainer.innerHTML=obj.innerHTML;
	

	
	divPopContainer.style.position = 'absolute';
	


	divPopContainer.style.display="";
	divPopContainer.style.visibility="hidden"; /* for cal  offsetWidth */
	
		
	getViewPoint(); // DL DT
	getViewport(); //  viewportwidth viewportheight
	divPopContainer.style.left =DL+(viewportwidth/2)-(divPopContainer.offsetWidth/2) +'px';
	divPopContainer.style.top =DT+(viewportheight/2)-(divPopContainer.offsetHeight/2)+'px';
		
	divPopContainer.style.display="none";
	divPopContainer.style.visibility=""; 
	

	new Effect.Appear(divPopContainer, { duration: 0.6});
	
	divPopContainer.style.zIndex = "2";

	return false;
}
 
 




var delaytimer2;
function funUpdatePosition2(){

	divTempArea=$("divTempArea");
	getViewPoint(); // DL DT
	getViewport(); //  viewportwidth viewportheight
	posy=getYCoord(divTempArea) ;
	posx=DL+(viewportwidth/2)-(divTempArea.offsetWidth/2) ;


	clearTimeout(delaytimer);
	
	if(divTempArea.style.display==""){
		delaytimer=setTimeout(function(){

		new Effect.Move (divTempArea,{ x: posx, y: posy, mode: 'absolute'});
			
		},200);
	}
}




function funShowPopContainer(){

	
	getViewPoint(); // DL DT
	getViewport(); //  viewportwidth viewportheight

	divTempArea=$("divTempArea");

	
	divTempArea.style.display="";
	divTempArea.style.visibility="hidden"; 
	
	var  temp_top=DT+(viewportheight/2)-(divTempArea.offsetHeight/2);

	if(temp_top<=0){
		temp_top=30;
	}

	divTempArea.style.left = DL+(viewportwidth/2)-(divTempArea.offsetWidth/2) +'px';
	divTempArea.style.top = temp_top+'px';
		

		
	divTempArea.style.display="none";
	divTempArea.style.visibility=""; 



	new Effect.Appear(divTempArea, { duration: 0.6});




}


myAttachEvent(window,'load', function(){


	var loc=document.location+"";

	if(loc.indexOf("loadpage=")>0){
		var start=loc.indexOf("loadpage=")+9;
		var end=loc.length;
		var value=loc.substring(start,end);
		funLoadPage(value);
	}
	
	
}); 


function funLoadPage(obj){
	var url;
	if(obj.length){
		url=obj;

	}else{
		url=obj.href;

	}
	
	var loc=document.location+"";
	var selfpath=loc.substring(0,loc.lastIndexOf("/")+1);

	var url_key=url.replace(selfpath,"");
	if(url_key.indexOf("loadpage=")>0){
		var start=url_key.indexOf("loadpage=")+9;
		var end=url_key.length;
		var value=url_key.substring(start,end);
		url_key=value;
	}
	

	document.location="#loadpage="+url_key;


	/*CloseMask();*/
	OpenMask();
	
	if(!$('divTempArea')){
		divTempArea = document.createElement('div');
		divTempArea.id = "divTempArea";

		divTempArea.style.position = 'absolute';
		divTempArea.style.zIndex="1";
		divTempArea.style.left="0px";
		divTempArea.style.top="0px";
		divTempArea.style.display="";
		divTempArea.style.visibility="hidden";
	
		document.body.appendChild(divTempArea);
	}
	



	
	
	new Ajax.Updater('divTempArea', url, {
		onComplete:funShowPopContainer

	});
	


	myAttachEvent(window,'resize', funUpdatePosition2); 

	return false;
}



/* img box */



  function FadeEffect(element){
       new Effect.Fade(element, 
       { duration:0.3});
   }
   function ShowEffect(element){
       new Effect.Appear(element, 
       {duration:0.3, from:0, to:1.0});
   }
   
   



 
var lastWidth=0;
var lastHeight=0;
function funShowInfoBar(){

var divPopInfo=$("divPopInfo");

			percent_y=(($("divPopContainer").getHeight()+divPopInfo.getHeight())/$("divPopContainer").getHeight()*100);
					
					new Effect.Scale($("divPopContainer"), percent_y, 
			{scaleX:false,
			scaleY:true,
			duration: 0.5,
			scaleContent: false
			}
			);
		
				window.setTimeout(function(){
				
						new Effect.Appear($('divPopInfo'), 	{duration:0.3, from:0, to:1.0});
			 
					
				},500);
			
							
								
}


function funShowImage(){
		/* show image*/		
		/*
		imgLarge.style.display="";*/
		
		ShowEffect($('imgLarge'));
}



var resize_speed_init=800;
var padding_size=6;
function resizeContainer(){

	$('imgLarge').src=$('imgPreLoad').src;
	$('divLoading').style.display= "none";
	


	var divPopContainer=$("divPopContainer");




	/*document.title="OK "+$('imgPreLoad').getWidth();*/
	
	lastWidth =padding_size*2+($('imgPreLoad').getWidth());
	lastHeight=padding_size*2+($('imgPreLoad').getHeight());


	/* for cal  divPopContainer position offsetWidth */
	getViewPoint(); // DL DT
	getViewport(); //  viewportwidth viewportheight
	
	var divPopContainer_top=DT+20;
	if(divPopContainer_top=DT+20){ divPopContainer_top=DT+20};
	
	divPopContainer.style.left =DL+(viewportwidth/2)-(divPopContainer.getWidth()/2) +'px';
	divPopContainer.style.top =divPopContainer_top+'px';
	




	var percent_x=(lastWidth/$("divPopContainer").getWidth()*100);
	var percent_y=(lastHeight/$("divPopContainer").getHeight()*100);

	var showEffect=1;
	resize_speed=resize_speed_init;
	if(percent_x >=80 && percent_x<=120){
		/*resize_speed=0;*/
		showEffect=0;
	}else{
		showEffect=1;
		/*resize_speed=resize_speed_init;*/
	}



	
	/*  resize_speed */
	if(showEffect==1){
			
			/* ================= */
			
				var speed_effect=resize_speed/1000;
				new Effect.Scale(divPopContainer, percent_x, 
				{scaleX:true,
				scaleY:false,
				scaleFromCenter:true,
				duration: speed_effect,
				scaleContent: false
				}
				);
			
				window.setTimeout(function(){
				
					new Effect.Scale(divPopContainer, percent_y, 
					{scaleX:false,
					scaleY:true,
					duration: speed_effect,
					scaleContent: false
					}
					);
					
			
								
					
						window.setTimeout(function(){
							/*document.title=" lastWidth "+lastWidth+" , my width:"+$("divPopContainer").getWidth();*/
							
							
							funShowImage();
							
							funShowInfoBar();
								
					 
							
						},resize_speed);
			
					
					
				},resize_speed);
			
				
				
	}else{
				
					resize_speed=100;
			/* ================= */		
	/* ================= */
			
				var speed_effect=resize_speed/1000;
				new Effect.Scale(divPopContainer, percent_x, 
				{scaleX:true,
				scaleY:false,
				scaleFromCenter:true,
				duration: speed_effect,
				scaleContent: false
				}
				);
			
				window.setTimeout(function(){
				
					new Effect.Scale(divPopContainer, percent_y, 
					{scaleX:false,
					scaleY:true,
					duration: speed_effect,
					scaleContent: false
					}
					);
					
			
								
					
						window.setTimeout(function(){
							/*document.title=" lastWidth "+lastWidth+" , my width:"+$("divPopContainer").getWidth();*/
							
							
							funShowImage();
							
							funShowInfoBar();
								
					 
							
						},resize_speed);
			
					
					
				},resize_speed);
	
	}
	
			
		
		
}
var delaytimer;
function funUpdatePosition(){
	getViewPoint(); // DL DT
	getViewport(); //  viewportwidth viewportheight
	posy=getYCoord(divPopContainer) ;
	posx=DL+(viewportwidth/2)-(divPopContainer.offsetWidth/2) ;

	clearTimeout(delaytimer);
	
	if(divPopContainer.style.display==""){
		delaytimer=setTimeout(function(){

		new Effect.Move (divPopContainer,{ x: posx, y: posy, mode: 'absolute'});
			
		},200);
	}

}
function jsImgBox(obj){

if(obj.length){
	img=obj;
}else{
	img=obj.href;

}





	if($('imgLarge')){
		$('imgLarge').style.display="none";
		
	}	


	if(!$('divEmpty')){
		divEmpty = document.createElement('div');
		divEmpty.id = "divEmpty";
		divEmpty.style.display = "none";
		divEmpty.innerHTML +='<img style="margin:80px" src="images/ajax-loader.gif">';
		document.body.appendChild(divEmpty);
	}else{
	
		var divEmpty=$('divEmpty');
	}
	divEmpty.innerHTML +='<img width="20" src="'+img+'">';
	
	
if(divPageMask && divPageMask.style.display=="" ){
		var show_Container=0;
}else{
	var show_Container=1;
		OpenMask();
}
	/*CloseMask();*/

	
	
	if(!$('divPopContainer')){
		divPopContainer = document.createElement('div');
		divPopContainer.id = "divPopContainer";
		divPopContainer.style.backgroundColor = "#ffffff";
		document.body.appendChild(divPopContainer);
	}
	
	
	if(lastWidth!=0){
		divPopContainer.style.width=lastWidth+"px";
		divPopContainer.style.height=lastHeight+"px";
	}else{
		divPopContainer.style.width="300px";
		divPopContainer.style.height="300px";
	}
	
/*divPopContainer.innerHTML="asddas<BR>asddas";*/


	if(!$('divLoading')){
		var divLoading = document.createElement('div');
		divLoading.id = "divLoading";
		divLoading.style.backgroundColor = "#ffffff";
		divLoading.style.textAlign = "center";
		divLoading.style.textAlign = "center";
		
		divPopContainer.appendChild(divLoading);
	}else{
		divLoading=$("divLoading");
	}
	divLoading.innerHTML = '<img style="margin:0px" src="images/ajax-loader.gif">';
	/*divLoading.style.display="";*/
	
	



	/* add divPopBorder */
	if(!$('divPopBorder')){
		var divPopBorder = document.createElement('div');
		divPopBorder.id = "divPopBorder";
		divPopBorder.style.padding = padding_size+"px";
		divPopBorder.style.backgroundColor = "#ffffff";

		
		$("divPopContainer").appendChild(divPopBorder);
	
	}else{
		divPopBorder=$("divPopBorder");
	}	


	
	 /* add image */
	if(!$('imgLarge')){
		var imgLarge = document.createElement('img');
		imgLarge.id = "imgLarge";
		imgLarge.style.display= "none";

		
		$("divPopBorder").appendChild(imgLarge);
	
	}else{
		
		imgLarge=$("imgLarge");
	}	

	imgLarge.src="";
	





	
	 /* add divPopInfo */
	if(!$('divPopInfo')){

		var divPopInfo = document.createElement('div');
		divPopInfo.id = "divPopInfo";
		
		divPopInfo.innerHTML='<div style="text-align:center;padding-top:3px;padding-left:5px;color:#0A1030;  padding-right:5px;cursor:pointer;font-size:12px;"  onclick="CloseMask();">[Close]</a>';


		
		$("divPopBorder").appendChild(divPopInfo);
	
	/*
		var btnPrev = document.createElement('span');
		btnPrev.id = "btnPrev";
		btnPrev.href= "#btnPrev";
		btnPrev.innerHTML = "xxbtnPrev";
		
		$("divPopInfo").appendChild(btnPrev);
	
		var btnNext = document.createElement('span');
		btnNext.id = "btnNext";
		btnNext.href= "#btnNext";

		
		$("divPopInfo").appendChild(btnNext);
		*/
	}else{
		
		
		/*btnNext=$("btnNext");
		btnPrev=$("btnPrev");*/


		divPopInfo=$("divPopInfo");
	}	



	divPopInfo.style.display = "none";



	

	


	divPopContainer.style.position = 'absolute';
	divPopContainer.style.display="";
	divPopContainer.style.visibility="hidden"; /* for cal  offsetWidth */
	
		
	getViewPoint(); // DL DT
	getViewport(); //  viewportwidth viewportheight
	divPopContainer.style.left =DL+(viewportwidth/2)-(divPopContainer.offsetWidth/2) +'px';
	

	divPopContainer.style.top =(DT+20)+'px';

	/*divPopContainer.style.top =DT+(viewportheight/2)-(divPopContainer.offsetHeight/2)+'px';*/
		
		divPopContainer.style.visibility=""; 
	


if(show_Container==1){
	divPopContainer.style.display="none";

	new Effect.Appear(divPopContainer, { duration: 0.6});
}else{

	divPopContainer.style.display="";
	
}	
	divPopContainer.style.zIndex = "2";
	





	if(!$('imgPreLoad')){
		imgPreLoad = document.createElement('img');
		imgPreLoad.id = "imgPreLoad";
		
		imgPreLoad.style.visibility="hidden"; 		
		imgPreLoad.style.position = 'absolute';
		imgPreLoad.style.left="0px"; 
		imgPreLoad.style.top="0px"; 
		imgPreLoad.style.zIndex = "1";
		
		document.body.appendChild(imgPreLoad);
		
		myAttachEvent(imgPreLoad,"load",resizeContainer);
	}

	imgPreLoad.src = img;	
		
	
	
	 myAttachEvent(window,'resize', funUpdatePosition); 
	return false;
}




