var m_link;
var c_waitSec = 3;
var m_sec;
var countInt;
function CloseDialog()
{
	StopCountSec();
	$('#dialog-overlay').fadeOut(300);
	$('#alert-dialog').fadeOut(300);
}
function OuterLink(a_str)
{
	m_link = a_str;
	window.open(m_link);
	//DisplayOverlay();
}

function GotoBooking()
{
	//location.href=m_link;
	window.open(m_link);
}

function UpdateBrowser()
{
	var h = $(document).height()+"px";
	$('#dialog-overlay').css("height", h);
}

function UpdateScroll()
{
	var scrollTop = $(window).scrollTop()-50;
	$('#alert-dialog').css("margin-top", scrollTop+'px');
}

function onDialogDisplayComplete()
{
	setTimeout(DisplayAlert,0);
}

function DisplayAlert()
{
	m_sec = c_waitSec;
	$('#alert-dialog .cont #alert-dialog-content .buttonCon').html("<span class='second'>in</span> "+m_sec+" <span class='second'>secs</span>");
	StopCountSec();
	$('#alert-dialog').fadeIn(300,onAlertDisplayComplete);
}

function onAlertDisplayComplete()
{
	CountSec();
	countInt = setInterval(CountSec,1000);	
}

function DisplayOverlay()
{
	UpdateBrowser();
	$('#dialog-overlay').fadeIn('fast',onDialogDisplayComplete);
}

function CountSec()
{
	$('#alert-dialog .cont #alert-dialog-content .buttonCon').html("<span class='second'>in</span> "+m_sec+" <span class='second'>secs</span>")
	m_sec-=1;
	if(m_sec<0)
	{
		GotoBooking();
		StopCountSec();
	}
}

function StopCountSec()
{
	clearInterval(countInt);
}
function InitDialog()
{
	$('#dialog-overlay').bind("click", function(e){
      CloseDialog();
	});
	
	$().bind("resize", function(e){
		UpdateBrowser();
	});
	
	$().bind("scroll", function(e){
		UpdateScroll();
	});
	//
	m_sec = c_waitSec;
	$('#alert-dialog .cont #alert-dialog-content .hint').html('You are now being redirected to <br/>a partner hotel website.');
}
	
$(document).ready(function()
						   {
							   InitDialog();
						   }
				  )
