function getPS(node) {
  if (typeof(node)=="string") {
    node=document.getElementById(node);
  }
  var topValue=node.offsetTop;
  var leftValue=node.offsetLeft;
  var widthValue=node.offsetWidth;
  var heightValue=node.offsetHeight;
  while (node=node.offsetParent) {
    topValue+=node.offsetTop;
    leftValue+=node.offsetLeft;
  }
  if($.browser.msie){
	  return {
	    left: leftValue,
	    top: topValue,
	    width: widthValue,
	    height: heightValue
	  }
  } else if($.browser.mozilla){
	  return {
	    left: leftValue,
	    top: topValue,
	    width: widthValue,
	    height: heightValue
	  }
  } else {
	  return {
	    left: leftValue,
	    top: topValue,
	    width: widthValue,
	    height: heightValue
	  }
  }
}

var flasWallLastCid="";

function showDetail(obj, cid) {
	flasWallLastCid=cid;
	$(".cflashwall_detailtable").hide();
	setTimeout(function(){doShowDetail(obj, cid);},200);
}

function doShowDetail(obj, cid) {
	if(flasWallLastCid != cid){
		return false;
	}
  $(".cflashwall_detailtable").hide();
  if (document.getElementById("flashWallDetail"+cid)) {
    $("#iflashtable li").find("div").addClass("cflashwall_tdfilter");
    $(obj).find("div").removeClass("cflashwall_tdfilter");
    $("#flashWallDetail"+cid).show();
  } else {
    var tableObj=document.getElementById("iflashtable");
    var tdJSON=getPS(obj);
    var tableJSON=getPS(tableObj);
    $("#iflashtable li").find("div").addClass("cflashwall_tdfilter");
    $(obj).find("div").removeClass("cflashwall_tdfilter");
	var jobCount=0;
    var htmlStr="";
    if ((tdJSON.left+tdJSON.width+200) <= (tableJSON.left+tableJSON.width)) {
      htmlStr+="<table  class='cflashwall_detailtable' border=0 cellpadding=0 cellspacing=0 id='flashWallDetail"+cid+"' style='top:"+(tdJSON.top - 2)+"px;left:"+(tdJSON.left-2)+"px;'>";
      htmlStr+="<tr>";
      if($.browser.msie){
      	htmlStr+="<td class='cflashwall_blank' style='border-left:3px solid #1896e2;border-top:3px solid #1896e2;border-bottom:3px solid #1896e2;height:"+(tdJSON.height-1)+"px;width:"+(tdJSON.width-1)+"px;'><a href=\""+flashWallJson[cid].curl+"\" target=\"_blank\" onfocus=\"blur()\"><div style=\"cursor:pointer;height:"+(tdJSON.height-3)+"px;width:"+(tdJSON.width-3)+"px;\">&nbsp;</div></a></td>";
      } else {
      	htmlStr+="<td class='cflashwall_blank' style='border-left:3px solid #1896e2;border-top:3px solid #1896e2;border-bottom:3px solid #1896e2;height:"+(tdJSON.height+3)+"px;width:"+(tdJSON.width-2)+"px;'><a href=\""+flashWallJson[cid].curl+"\" target=\"_blank\" onfocus=\"blur()\"><div style=\"cursor:pointer;height:"+(tdJSON.height-3)+"px;width:"+(tdJSON.width-3)+"px;\">&nbsp;</div></a></td>";
      }
      htmlStr+="<td valign='top' class='cflashwall_company_and_job' nowrap style='border-right:3px solid #1896e2;border-top:3px solid #1896e2;border-bottom:3px solid #1896e2;'>";
      htmlStr+="<div class='cflashwall_company'><a href='"+flashWallJson[cid].curl+"' target='_blank' class='ccompany' onfocus=\"blur()\">"+flashWallJson[cid].cname+"</a></div>";	      
      if(flashWallJson[cid].job!=null&&flashWallJson[cid].job.length!=null&&flashWallJson[cid].job.length>0){
      for(var i=0;i<flashWallJson[cid].job.length;i++){
      	if($.trim(flashWallJson[cid].job[i].joburl) != "" && $.trim(flashWallJson[cid].job[i].jobname) != ""){
      	  htmlStr+="<div class='cflashwall_job'>กค<a href='"+flashWallJson[cid].job[i].joburl+"' target='_blank' class='cjob' onfocus=\"blur()\">"+flashWallJson[cid].job[i].jobname+"</a></div>";
      	  jobCount++;
      	}
      }
      }
      if(jobCount==0){
    	htmlStr+="<div class='cflashwall_job'></div>";
      }
	  htmlStr+="</td>";
	  htmlStr+="<td class='cshadowright'>&nbsp;</td>";
	  htmlStr+="</tr>";
      htmlStr+="<tr><td colspan=2 class='cshadowbottom'>&nbsp;</td><td class='cshadowrightbottom'>&nbsp;</td></tr>";      
      htmlStr+="</table>";
    } else if ((tdJSON.left+tdJSON.width+200) > (tableJSON.left+tableJSON.width)) {
    	if((tableJSON.width<tdJSON.width+200) && ($.browser.version=="6.0" && $.browser.msie)){
      	htmlStr+="<table class='cflashwall_detailtable' border=0 cellpadding=0 cellspacing=0 id='flashWallDetail"+cid+"' style='top:"+(tdJSON.top - 2)+"px;left:"+(tdJSON.left - 199)+"px;'>";
    	} else {
      	htmlStr+="<table class='cflashwall_detailtable' border=0 cellpadding=0 cellspacing=0 id='flashWallDetail"+cid+"' style='top:"+(tdJSON.top - 2)+"px;left:"+(tdJSON.left - 2 - 200)+"px;'>";
    	}
      htmlStr+="<tr>";
      htmlStr+="<td valign='top' class='cflashwall_company_and_job' nowrap style='border-left:3px solid #1896e2;border-top:3px solid #1896e2;border-bottom:3px solid #1896e2;'>";
      htmlStr+="<div class='cflashwall_company'><a href='"+flashWallJson[cid].curl+"' target='_blank' class='ccompany' onfocus=\"blur()\">"+flashWallJson[cid].cname+"</a></div>";
      if(flashWallJson[cid].job!=null&&flashWallJson[cid].job.length!=null&&flashWallJson[cid].job.length>0){
      for(var i=0;i<flashWallJson[cid].job.length;i++){
      	if($.trim(flashWallJson[cid].job[i].joburl) != "" && $.trim(flashWallJson[cid].job[i].jobname) != ""){
      		htmlStr+="<div class='cflashwall_job'>กค<a href='"+flashWallJson[cid].job[i].joburl+"' target='_blank' class='cjob' onfocus=\"blur()\">"+flashWallJson[cid].job[i].jobname+"</a></div>";
      		jobCount++;
      	}
    	}
      }
      if(jobCount==0){
    	htmlStr+="<div class='cflashwall_job'></div>";
      }
      htmlStr+="</td>";
      if($.browser.msie){
      	htmlStr+="<td class='cflashwall_blank' style='border-right:3px solid #1896e2;border-top:3px solid #1896e2;border-bottom:3px solid #1896e2;height:"+(tdJSON.height-2)+"px;width:"+(tdJSON.width-2)+"px;'><a href=\""+flashWallJson[cid].curl+"\" target=\"_blank\" onfocus=\"blur()\"><div style=\"cursor:pointer;height:"+(tdJSON.height-3)+"px;width:"+(tdJSON.width-3)+"px;\">&nbsp;</div></a></td>";
      } else {
      	htmlStr+="<td class='cflashwall_blank' style='border-right:3px solid #1896e2;border-top:3px solid #1896e2;border-bottom:3px solid #1896e2;height:"+(tdJSON.height+3)+"px;width:"+(tdJSON.width-2)+"px;'><a href=\""+flashWallJson[cid].curl+"\" target=\"_blank\" onfocus=\"blur()\"><div style=\"cursor:pointer;height:"+(tdJSON.height-3)+"px;width:"+(tdJSON.width-3)+"px;\">&nbsp;</div></a></td>";
      }
      htmlStr+="<td class='cshadowright'>&nbsp;</td>";
      htmlStr+="</tr>";
      htmlStr+="<tr><td colspan=2 class='cshadowbottom'>&nbsp;</td><td class='cshadowrightbottom'>&nbsp;</td></tr>";
      htmlStr+="</table>";
    }
    $("#new51pd").append(htmlStr);
    if($.browser.version=="6.0" && $.browser.msie ){
	  $(".cflashwall_detailtable").find("*").each(function(){
	  var bgIMG=$(this).css('background-image');
	  if(bgIMG.indexOf(".png")!=-1){
	  var iebg=bgIMG.split('url("')[1].split('")')[0];
	  $(this).css('background-image', 'none');
	  $(this).get(0).runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+iebg+"',sizingMethod='scale')";
	}
	});
	}	
    $("#flashWallDetail"+cid).fadeIn(500);
  }
}

function hideDetail(evt,obj) {
	evt=(evt)?evt:window.event;
	var tableObj=document.getElementById("new51pd");
  var toElementObj;
  if($.browser.msie){
  	toElementObj=evt.toElement;
  } else if($.browser.mozilla){
  	toElementObj=evt.relatedTarget;
  } else {
  	toElementObj=evt.relatedTarget;
  }
  if (!tableObj.contains(toElementObj)) {
  	flasWallLastCid="";
    $("#iflashtable li").find("div").removeClass("cflashwall_tdfilter");
    $(".cflashwall_detailtable").fadeOut(500);
  }
}

if(typeof(HTMLElement) != "undefined"){
	HTMLElement.prototype.contains=function(obj) {
	while(obj != null &&  typeof(obj.tagName) != "undefind"){
		if(obj==this)
			return true;
			obj=obj.parentNode;
		}
		return false;
	};
}
