if (typeof Cobalt == "undefined") { var Cobalt = {}; };
if (typeof Cobalt.partners == "undefined") { Cobalt.partners = {}; };
if (typeof Cobalt.partners.ContactAtOnce == "undefined") { Cobalt.partners.ContactAtOnce = {}; };

Cobalt.partners.ContactAtOnce.liveChat = {
	
	IMAGE_ID: 'CAOLiveChat' + '_' + SITE_VERSION.CURRENT.DESIGN
	
	,IMAGE_CLASS: 'CAOLiveChat'
	
	,providerId: 'NNN'
	
	,merchantId: 'NNN'
	
	,lookup: { 
		design: { color: 100 },
		Lexus_Endorsed5: { black: 501, blue: 502, dark_blue: 503, green: 504, grey: 505, grey_blue: 506, light_blue: 507, red: 508 },
		Lexus_Endorsed6: { black: 601, blue: 602, dark_blue: 603, green: 604, grey: 605, grey_blue: 606, light_blue: 607, red: 608 },
		Lexus_Endorsed7: { black: 701, blue: 702, dark_blue: 703, green: 704, grey: 705, grey_blue: 706, light_blue: 707, metallic_black: 708, red: 709 },
		Lexus_Endorsed8: { black: 801, blue: 802, dark_blue: 803, green: 804, grey: 805, grey_blue: 806, light_blue: 807, red: 808 },
		Lexus_Endorsed9: { sapphire: 901, onyx: 902, jade: 903, granite: 904, chocolate: 905 },
        Lexus_Endorsed10: { sapphire: 1001, onyx: 1002, jade: 1003, granite: 1004, chocolate: 1005 }
	}
	
	,init: function() {
		var my = this;
		var img = this.getImage();
		jQuery('#headerWrapper').append(img);
		jQuery('#' + this.IMAGE_ID).bind('click', function() { my.handleClickEvent(); return false; });
		jQuery('#' + this.IMAGE_ID).bind('error', function() { my.handleErrorEvent(); });
	}
	
	,getImage: function() {
		var html = '<img id="'+ this.IMAGE_ID +'" class="' + this.IMAGE_CLASS + '" alt="Click to instant message a representative now!" ';
		html += 'src="http://lexus.contactatonce.com/getagentstatusimage.aspx?';
		html += 'ProviderId=' + this.providerId;
		html += '&MerchantId=' + this.merchantId;
		html += '&PlacementId=' + this.getPlacementId(SITE_VERSION.CURRENT.DESIGN, SITE_VERSION.CURRENT.COLOR);
		html += '"/>';
		return html;
	}
	
	,getPopupUrl: function() {
		var str = 'http://lexus.contactatonce.com/caoclientcontainer.aspx?';
		str += 'ProviderId=' + this.providerId;
		str += '&MerchantId=' + this.merchantId;
		str += '&PlacementId=' + this.getPlacementId();
		str += '&PageLocation=Masthead';
		str += '&OriginationUrl=' + encodeURIComponent(window.location.href);
		return encodeURI(str);
	}
	
	,getPopupParams: function() {
		return 'resizable=yes,toolbar=no,menubar=no,location=no,scrollbars=no,status=no,height=400,width=600';
	}
	
	,getPlacementId: function(design, color) {
		if (!design) design = 'design';
		if (!color) color = 'color';
		return this.lookup[design][color];
	}
	
	,handleClickEvent: function() {
		window.open(this.getPopupUrl(), '_blank', this.getPopupParams(), false);
	}
	
	,handleErrorEvent: function() {
		jQuery('#' + this.IMAGE_ID).remove();
	}
	
};