//Configuration is provided by store-specific Config.js
/*
function lpAddMonitorTag(src) {
    if (typeof(src) == 'undefined' || typeof(src) == 'object') {
        src = lpMTagConfig.lpMTagSrc ? lpMTagConfig.lpMTagSrc: '/hcp/html/mTag.js';
    }
    if (src.indexOf('http') != 0) {
        src = lpMTagConfig.lpProtocol + "://" + lpMTagConfig.lpServer + src + '?site=' + lpMTagConfig.lpNumber;
    } else {
        if (src.indexOf('site=') < 0) {
            if (src.indexOf('?') < 0) src = src + '?';
            else src = src + '&';
            src = src + 'site=' + lpMTagConfig.lpNumber;
        }
    };
    var s = document.createElement('script');
    s.setAttribute('type', 'text/javascript');
    s.setAttribute('charset', 'iso-8859-1');
    s.setAttribute('src', src);
    s.setAttribute('id', 'livePersonMonitorTag');
    document.getElementsByTagName('head').item(0).appendChild(s);
}
if (window.attachEvent) window.attachEvent('onload', lpAddMonitorTag);
else window.addEventListener("load", lpAddMonitorTag, false);

if (typeof(lpMTagConfig) == "undefined") {
    lpMTagConfig = {};
}
if (typeof(lpMTagConfig.sessionVar) == "undefined") {
    lpMTagConfig.sessionVar = [];
}
//lpMTagConfig.sessionVar[lpMTagConfig.sessionVar.length] = '${roomName}';
*/
/* **************** START Invitation Events **************************/
/*
lpMTagConfig.inviteChatShown = function(invitename) {

    try {
        //Add web analytics code here to capture the Invitation Shown event
        if (salmonChatHelper) {
            salmonChatHelper.showInvitation();
        }

    } catch(e) {}

    return true;

}


lpMTagConfig.inviteChatTimeout = function(invitename) {

    try {
        //Add web analytics code here to capture the Invitation Timed Out ("ignored") event
        } catch(e) {}

    return true;

}

lpMTagConfig.inviteChatAccept = function(invitename) {

    try {
        //Add web analytics code here to capture the Invitation Accepted event
        var img = new Image();
        img.src = document.location.protocol + '//view.atdmt.com/iaction/mmislp_ChatOpenChatWindow_1';
    } catch(e) {}

    return true;

}

lpMTagConfig.inviteChatDeclined = function(invitename) {

    try {
        //Add web analytics code here to capture the Invitation Declined event
        } catch(e) {}
    return true;
}*/

/* **************** END Invitation Events **************************/

Initialiser.modules.clickToCall = function(){

	//Enable the proxy click to chat and click to call links
	$('a.clickToChatLink, button.ClickToChatLink, a.clickToCallLink, button.ClickToCallLink, area.clickToChatLink, area.clickToCallLink').live('click', function(){
		var targetReference = $(this).attr('rel')
		
		if (targetReference) {
		//	console.log('#' + $(this).attr('rel') + ' a', $('#' + $(this).attr('rel') + ' a'))
			if ($('#' + targetReference + ' a').length) {
				
				
				var clickTarget = $('#' + targetReference + ' a');
				
				//If this is a voice link, and it's offline, show a message:
				if ((targetReference.indexOf('voice') > -1) && clickTarget.is('.offline')) {
					alert('We\'re sorry, our call back service is currently unavailable.');
					$(this).addClass('offline');
				} else if ((targetReference.indexOf('chat') > -1) && clickTarget.is('.offline')) {
  					alert('We\'re sorry, our live chat service is currently unavailable.');
  					$(this).addClass('offline');
  				
				} else {
					//When you pack javascript inside the href attribute, normal click events don't work on it.
					//This work around extracts the javascript and evals it - which is horrible, but works:

					var clickOperationText = $('#' + targetReference + ' a').attr('href'),
						clickOperation = clickOperationText.split('javascript:')[1];
						eval(clickOperation); //Ugh - I know this looks horrible, but it's really no different to packing javascript into your href's
				
				}
				
			
			} else {
					//console.log("Couldn't find an element for the rel target:" +  targetReference); //Debug only
			}
			return false;
		}
	});


}
