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, claret: 509, leaf: 510, night: 511, steel: 512, suede: 513, teal: 514 },
		Lexus_Endorsed6: { black: 601, blue: 602, dark_blue: 603, green: 604, grey: 605, grey_blue: 606, light_blue: 607, red: 608, claret: 609, leaf: 610, night: 611, steel: 612, suede: 613, teal: 614 },
		Lexus_Endorsed7: { black: 701, blue: 702, dark_blue: 703, green: 704, grey: 705, grey_blue: 706, light_blue: 707, metallic_black: 708, red: 709, claret: 710, leaf: 711, night: 712, steel: 713, suede: 714, teal: 715 },
		Lexus_Endorsed8: { black: 801, blue: 802, dark_blue: 803, green: 804, grey: 805, grey_blue: 806, light_blue: 807, red: 808, claret: 809, leaf: 810, night: 811, steel: 812, suede: 813, teal: 814 },
		Lexus_Endorsed9: { sapphire: 901, onyx: 902, jade: 903, granite: 904, chocolate: 905, claret: 906, leaf: 907, night: 908, steel: 909, suede: 910, teal: 911 },
		Lexus_Endorsed10: { sapphire: 1001, onyx: 1002, jade: 1003, granite: 1004, chocolate: 1005, claret: 1006, leaf: 1007, night: 1008, steel: 1009, suede: 1010, teal: 1011 },
		Lexus_Endorsed11: { sapphire: 1109, onyx: 1109, jade: 1109, granite: 1109, chocolate: 1109, claret: 1109, leaf: 1107, night: 1108, steel: 1109, suede: 1110, teal: 1111 }
	}
	
  ,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();
	}
	
};