﻿$(document).ready(function() {
	// hook for the overlay login works on all anchors with class of cplat-login
	$('a.cplat-login').click(function () {
        
		// The core client Config object literals to configure the Login Overlay object
		var clientConfigParameters = { 
			overlayImgLoader: 'http://www.topgear.com' + applicationRoot + "images/core/ajax-loader.gif",
			userDefinedOverLayDimension: {
				width: 297, 		// 346 width - 25px padding left - 24 padding right
				height: 337			// 383 width - 23 padding top - 23 padding bot
			},
			passionSiteCallBack: {
				successCallBack: TG_CPLAT.clientImplementSuccessCallBack,  
				errorCallBack: TG_CPLAT.clientImplementErrorCallBack,
				overlayCloseCallBack: TG_CPLAT.clientImplementOverlayCloseCallBack
			}
     };

		// set the login URLs to ajax urls
		$(this).attr('href', applicationRoot + 'ajaxlogin');
		
		// Create the login Overlay object
		// note: using AjaxOverLayScreenManager object and the handleLinkClick in order to get an overlay page
		BBCWORLDWIDE_CPLAT.LoginOverlay(BBCWORLDWIDE_CPLAT.AjaxOverLayScreenManager, clientConfigParameters).handleLinkClick(this);
		
		return false;
	});
});
	
// namespace for TG specific CPLAT functions
var TG_CPLAT = TG_CPLAT || {};

TG_CPLAT.clientImplementSuccessCallBack = function(p_param) {
	window.location.reload();
};
TG_CPLAT.clientImplementErrorCallBack = function(p_param) {
	window.location = applicationRoot + 'login';
};
TG_CPLAT.clientImplementOverlayCloseCallBack = function() {

};