var gDelay      = 2;
var x           = 0;
var msn_width   = 201;
var msn_height  = 116;
var css         = 'position:fixed;';
var html_code   = '';
 
if(document.all && window.XMLHttpRequest && !window.opera){
  if( ( window.document.childNodes[0].text == undefined ) || ( window.document.childNodes[0].text.search(/DOCTYPE\s+HTML\s+PUBLIC.+\.dtd/i) == -1) ){
    css = 'position:absolute; top:expression( eval( document.compatMode && document.compatMode == \'CSS1Compat\' ) ? documentElement.scrollTop + (documentElement.clientHeight-this.clientHeight) : document.body.scrollTop + ( document.body.clientHeight-this.clientHeight ) ); ';
  }
 
}
if(document.all && !window.XMLHttpRequest){
  css = 'position:absolute; top:expression( eval( document.compatMode && document.compatMode == \'CSS1Compat\' ) ? documentElement.scrollTop + (documentElement.clientHeight-this.clientHeight) : document.body.scrollTop + ( document.body.clientHeight-this.clientHeight ) ); ';
}

html_code += '<div id="msn_banner" style="' + css + ' display:block; z-index:99999;; bottom:3px; right:3px; position:fixed; width:' + msn_width + 'px; height:' + msn_height +'px; overflow:hidden;">';
html_code += '<div id="msn_contents" style="width:100%;position:relative; top:' +msn_height +'px; z-index:99998; height:' + msn_height + 'px;float:left;"><div style="width:100%;float:left;word-break:break-all;" id="msn_title" style="width:100%;"></div><div style="width:100%;height:100%;float:left;word-break:break-all;" id="msn_in"></div></div>';
html_code += '</div>';
 
document.write(html_code);

$.ajax({
	type: "POST",
	dataType:'json',
	url: _Web_Url + "/index.php/web/msn_banner/",
	success: function(data){
		try{
		html = '<div align="left" style="width:80%;float:left;">'+data.title+'</div>';
		html = html +  '<div align="right" style="width:20%;float:left;font-weight:bolder;font-size:12px"><a href="#" onclick="phmg_move('+'\'msn_contents\''+','+'\'down\''+');return false;">X</a></div>';
		$('#msn_title').html(html);
		$('#msn_in').html(data.contents);
		$("#msn_title").css({"background":data.titleColor});
		$("#msn_in").css({"background":data.ContentsColor});
		}catch(err){}
	}		

});

check_run();
var phmg_timer;

function auto_run(){
	try{
  	phmg_timer = setTimeout(phmg_move('msn_contents','up'),500);
	}catch(error){
	}
}


function check_run(){
	x = x + 1;
	if (x<=gDelay){
		TmpTime = setTimeout("check_run()",1000);
	}else{
		auto_run();
		clearTimeout(TmpTime);
	}
}
 
function phmg_move(elmID,direction){
	
  var supported = (document.getElementById);
  if (!supported){
    return;
  }
  var x;
  var divPath = document.getElementById(elmID);
  var currPos = parseInt(divPath.style.top);
  var holderDisplay = document.getElementById('msn_banner');
  holderDisplay.style.display = ''; 
  if(direction === 'down'){
    x = divPath.offsetHeight;
    if(currPos <= x){
      currPos += (currPos + 5) > x? ( (x - currPos) +1 ):5;
      divPath.style.top = currPos + 'px';
      phmg_timer = setTimeout("phmg_move('" + elmID + "','down')",30);
    }else{
      // Antimation completed clear timeout
      clearTimeout(phmg_timer);
      holderDisplay.style.display = 'none';       
    }
  }else{
    x = 0;
    if(currPos > x){
      currPos -= currPos < 5? currPos:5;
      divPath.style.top = currPos + 'px';                                              
      phmg_timer = setTimeout("phmg_move('" + elmID + "','')",30);
    }else{
      clearTimeout(phmg_timer);
    }
  }
}
