//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
$(document).ready(function()
{
  if(getCookie('show_message')!='no')
  {
      var pos=parseInt($(window).scrollTop())+parseInt($(window).height());
      $('#message_box').css("top",pos-163+"px");
      $('#message_box').show(); //display the message box
   
      //scroll the message box to the top offset of browser's scrool bar
	  $(window).scroll(function()
	  {
  	     var pos=parseInt($(window).scrollTop())+parseInt($(window).height());
        $('#message_box').animate({top:pos-163+"px" },{queue: false, duration: 500});  
	  });
    }
   //when the close button at right corner of the message box is clicked 
	$('#close_message').click(function()
	{
  		//the messagebox gets scrool down with top property and gets hidden with zero opacity 
		$('#message_box').animate({ top:"-=163px",opacity:0 }, "slow");
        setCookie('show_message','no',1); //cookies is set to no value
	});
});

//function to set the cookie name, values and expiry time in hours 
function setCookie(c_name,value,expireHours)
{
  var exhour=new Date(); //create the current date object
  exhour.setHours(exhour.getHours()+1);
  document.cookie=c_name+ "=" +escape(value)+
  ((expireHours==null) ? "" : ";expires="+exhour.toGMTString());
}

//function to get the value from cookie name
function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1; 
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}

