$(document).ready(function () {
  // Set up the live person listener
   inviteTimer = setInterval ( "checkInvite()", 5000 );

  // Cufon Replace Time
  Cufon.set('fontFamily', 'ITC Kabel');
  Cufon.replace('#footer h3, .tnc_header, #live_chat h1');
  Cufon.set('fontFamily', 'ShagExpert-Lounge');
  Cufon.replace('h2, .tnc_header strong');

// 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");
  });
});

// Open link in new window
// Adapted from http://www.thefutureoftheweb.com/blog/target-blank-xhtml11
window.onload = function() {
    var links = document.getElementsByTagName('a');
    for (var i=0;i < links.length;i++) {
        if (links[i].className == 'new-window' || links[i].className == 'new-window hide') {
            links[i].onclick = function() {
                window.open(this.href);
                return false;
            }
        }
    }
}
function showChatAlert() {
  // show live chat
  $('body').prepend("<div id='live_chat'><div id='live_chat_container'><h1>Instant Help</h1><p>Chat live with one of our Casino representatives and we'll be happy to help you.</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');
	}
}



  function popup(url) {
    var width = 800;
    var height = 600;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    var params = 'width=' + width + ', height=' + height;
    params += ', top=' + top + ', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=no';
    params += ', status=no';
    params += ', toolbar=no';
    newwin = window.open(url, 'windowname5', params);
    //if (window.focus) {newwin.focus()}
    return false;
  }

