$(document).ready(function () {
// Set up the live person listener
   inviteTimer = setInterval ( "checkInvite()", 5000 );
  
  // hide the live chat of a button
  $('#live_chat_close').live('click', function() {
  hideChatAlert();
});

  $('#live_chat_accept').live('click', function() {
  hideChatAlert();
});

  // IF JS is Enabled (most cases) Initiate the Terms and Conditions and add the toggle class to the header bar
  $("#tnc_text").hide();
  $(".tnc_header").addClass("tnc_toggle_header");
  // Toggle Function for the Terms and COnditions
  $(".tnc_header").toggle(
  function () {
    $("#tnc_text").slideDown("fast");
    $(this).addClass("tnc_toggle_header_collapse");
  },
  function () {
    $("#tnc_text").slideUp("fast");
    $(this).removeClass("tnc_toggle_header_collapse");
  });
});

function showChatAlert() {
  // show live chat
  $('body').prepend("<div id='live_chat'><div id='live_chat_container'><h1>&pound;1,000 Welcome Bonus</h1><p>Claim up to &pound;1,000 in casino bonuses when you deposit now!</p><a href='#' id='live_chat_accept''>Chat Now</a></div><div id='live_chat_close'>close</div></div>");

 var lpAccept = $('.chatInvite').attr('ia');
 var lpReject = $('.chatInvite').attr('ir');

  $('#live_chat_accept').attr('onClick', lpAccept);
  $('#live_chat_close').attr('onClick', lpReject);

$('#live_chat').slideDown();

}

function hideChatAlert() {
  // hide live chat
  $('#live_chat').slideUp(function () {
    $(this).remove();
  });
}

function checkInvite ( )
{
	//alert('checking');
  if ($('.chatInvite').length)
  	{
           showChatAlert();
	  clearInterval(inviteTimer);
    }
    else
    {
     // alert('not found');
	}
}

