var PricingBlock = new Class(
		{

			initialize : function(cointainerId) {
			    this.mainIcon=null;
			    this.promotionOn=false;			    
			    
				this.container = $(cointainerId);
				this.containerId = cointainerId;
				
				this.baseMSRP = new Array("MSRP starting at","01","MSRP");//Label, amount, id For Html
				this.DFC = new Array("Destination Freight Charge", "0","DFC");//Label, amount, id For Html
				this.totalMSRP = new Array("Total MSRP ", "0","totalMSRP");//Label, amount, id For Html
				this.totalCashOffers = new Array("Total Cash Offers", "0","cashOffers");//Label, amount, id For Html
				this.promotion = new Array("Promo", "0","promo");//Label, amount, id For Html							
				this.accessoriesTotalPrice = new Array("Plus Dealer Installed Accessories Total<sup>2</sup>", "0","accessories");
				this.colorAndOption = new Array("Colors &amp; Options ", "0","colorAndOptions");
				this.netPrice=0;
				this.totalBelowMsrp = 0;
				this.liCounter=0;
				this.generatedHTML="";

			},

			/////////////////////////////////////////////////////////////////
			setBaseMSRP : function(baseMSRP, label) {
				this.baseMSRP[1] = baseMSRP;
				if (label != null && label != "undefined")
					this.baseMSRP[0] = label;
			},
			/////////////////////////////////////////////////////////////////
			setPromotion : function(promotionPrice, label) {
				this.promotion[1] = Math.round(parseFloat(promotionPrice));
				if (label != null && label != "undefined")
					this.promotion[0] = label;				
				this.promotionOn=true;
				
			},
			/////////////////////////////////////////////////////////////////
			setCashOffers : function(amount, label) {
				this.totalCashOffers[1] = amount;
				if (label != null && label != "undefined")
					this.totalCashOffers[0] = label;
			},
			/////////////////////////////////////////////////////////////////
			setColorAndOption : function(amount, label) {
				this.colorAndOption[1] = amount;
				if (label != null && label != "undefined")
					this.colorAndOption[0] = label;				
			},
			/////////////////////////////////////////////////////////////////
			setDFC : function(DFC, label) {
				this.DFC[1] = DFC;
				if (label != null && label != "undefined")
					this.DFC[0] = label;
				 this.dfcOn= true;
			},
			/////////////////////////////////////////////////////////////////
			setAccesories : function(accesoriesTotal, label) {
				this.accessoriesTotalPrice[1] = accesoriesTotal;
				if (label != null && label != "undefined")
					this.accessoriesTotalPrice[0] = label;
				 this.accessoriesPriceOn= true;
			},
			/////////////////////////////////////////////////////////////////
			showBox : function(section) {
				
				
			    if(section=="WS")
					this.showWSBox();
				if(section=="BYO"){
					$(this.containerId).innerHTML="";
					this.showBYOBox();
				}
				if(section=="PO")
					this.showPOBox();
				
			},
			/////////////////////////////////////////////////////////////////
			showWSBox : function() {				
				this.createLiHTML(this.baseMSRP[0], this.baseMSRP[1],null,this.baseMSRP[2]);	
				this.totalMSRP[1]=parseFloat(this.baseMSRP[1])+parseFloat(this.DFC[1]);
				if(this.promotionOn){
					if(this.mainIcon!="noImage")
						this.container.innerHTML += '<li class="priceBoxLeft offerImage"><img src="'+BASE_CONTEXT+'/assets/en/images/offers/'+this.mainIcon+'"/></li><li class="priceBoxright">&nbsp;</li>';
					
					this.container.innerHTML += '<li class="clear"></li>';
					this.createLiHTML(this.promotion[0], this.promotion[1],null,"promo");		
				}
				this.createLiHTML(this.totalCashOffers[0], this.totalCashOffers[1],"-");
				document.getElementById('wsSummaryCashOffer').innerHTML = "-$"+formatCurrency(this.totalCashOffers[1])+".00";
				document.getElementById('wsSummaryTotal').innerHTML = "$"+formatCurrency(this.calculateNetPrice())+".00";
				this.createLiHTML("Your Price",this.calculateNetPrice(),null,"after");
				this.createLiHTML("Total Amount Below MSRP",this.totalBelowMsrp,null,"below");
			},
			/////////////////////////////////////////////////////////////////
			generateHTML : function() {				
				this.getLiHTML(this.baseMSRP[0], this.baseMSRP[1],null,this.baseMSRP[2]);	
				this.totalMSRP[1]=parseFloat(this.baseMSRP[1])+parseFloat(this.DFC[1]);
				if(this.promotionOn)
					this.getLiHTML(this.promotion[0], this.promotion[1],null,"promo");
				this.getLiHTML(this.totalCashOffers[0], this.totalCashOffers[1],"-");
				this.getLiHTML("Your Price<sup>1</sup>",this.calculateNetPrice(),null,"after");
				this.getLiHTML("Total Amount Below MSRP",this.totalBelowMsrp,null,"below");
			},
			/////////////////////////////////////////////////////////////////
			showBYOBox : function() {
				colorsOptions=this.getAsFloat(this.colorAndOption[1]);
				totalPromo=parseFloat(this.promotion[1])+parseFloat(this.DFC[1])+colorsOptions;	
				this.totalMSRP[1]=parseFloat(this.baseMSRP[1])+parseFloat(this.DFC[1])+colorsOptions;
				
				this.createLiHTML(this.baseMSRP[0], this.baseMSRP[1],null,this.baseMSRP[2]);	
				this.createLiHTML(this.DFC[0], this.DFC[1],null,this.DFC[2]);				
				this.createLiHTML(this.colorAndOption[0], this.colorAndOption[1],null,this.colorAndOption[2]);	
				
				
				this.createLiHTML("Total MSRP",this.totalMSRP[1],null,"TotalMSRP" );				
				if(this.promotionOn){	
					if(this.mainIcon!="noImage")
						this.container.innerHTML += '<li class="priceBoxLeft">&nbsp;</li><li class="priceBoxright offerImage"><img src="'+BASE_CONTEXT+'/assets/en/images/offers/'+this.mainIcon+'"/></li>';
					this.container.innerHTML += '<li class="clear"></li>';					
					this.createLiHTML(this.promotion[0], totalPromo,null,"promo");	
				}
				this.createLiHTML(this.totalCashOffers[0], this.totalCashOffers[1],"-",this.totalCashOffers[2]);
				yourPrice=this.calculateNetPrice();
				this.createLiHTML("Your Price<sup>1</sup>",yourPrice,null,"after");
				$('yourPriceTop').innerHTML="$"+formatCurrency(yourPrice);				
				$('belowTop').innerHTML="$"+formatCurrency(this.totalBelowMsrp)+ " below MSRP";
				
				
				this.createLiHTML("Total Amount Below MSRP",this.totalBelowMsrp,null,"below");
				this.createLiHTML(this.accessoriesTotalPrice[0],this.accessoriesTotalPrice[1],null,this.accessoriesTotalPrice[2]);				

			},
			/////////////////////////////////////////////////////////////////
			showPOBox : function() {		
				this.promotion[1]=parseFloat(this.promotion[1])+parseFloat(this.DFC[1]);
				this.createLiHTML(this.baseMSRP[0], this.baseMSRP[1],null,this.baseMSRP[2]);
				this.createLiHTML(this.DFC[0], this.DFC[1],null,this.DFC[2]);
				this.totalMSRP[1]=parseFloat(this.baseMSRP[1])+parseFloat(this.DFC[1]);
				this.createLiHTML("Total MSRP",this.totalMSRP[1],null,"TotalMSRP");
				
				if(this.promotionOn){		
					if(this.mainIcon!="noImage")
						this.container.innerHTML += '<li class="priceBoxLeft">&nbsp;</li><li class="priceBoxright offerImage"><img src="'+BASE_CONTEXT+'/assets/en/images/offers/'+this.mainIcon+'"/></li>';	
					else this.container.innerHTML += '<li class="priceBoxLeft">&nbsp;</li><li class="priceBoxright offerImage" style="visibility:hidden">image</li>';
					this.createLiHTML(this.promotion[0], this.promotion[1],null,"promo");				
				}
				
				if(this.totalCashOffers[1]!="0")
					this.createLiHTML(this.totalCashOffers[0], this.totalCashOffers[1],"-",this.totalCashOffers[2]);
				

				this.createLiHTML("Your Starting Price after all cash offers<sup>(2)</sup>",this.calculateNetPrice(),null,"after");
				this.createLiHTML("Total Amount Below MSRP",this.totalBelowMsrp,null,"below");

			},
			/////////////////////////////////////////////////////////////////
			setIcon : function(iconName) {
				this.mainIcon=iconName;	
			
			},		
			/////////////////////////////////////////////////////////////////
			setLAVIcon : function(iconName,cellId) {
				this.mainIcon=iconName;	
				if(this.mainIcon!="noImage")
					$(cellId).style.backgroundImage="url('"+BASE_CONTEXT+'/assets/en/images/offers/'+this.mainIcon+ "')";				
			},	
			/////////////////////////////////////////////////////////////////
			calculateNetPrice : function() {
				colorsOptions=this.getAsFloat(this.colorAndOption[1]);
				totalCost=Math.round(parseFloat(this.baseMSRP[1])+parseFloat(this.DFC[1])+
						colorsOptions);				
				totalDeductions=Math.round(parseFloat(this.totalCashOffers[1]));
				if(this.promotionOn){
					totalWithPromo=Math.round(Math.round(parseFloat(this.promotion[1])) + parseFloat(this.DFC[1])+
							colorsOptions - totalDeductions);
					this.totalBelowMsrp=Math.round( parseFloat(this.totalMSRP[1])-totalWithPromo);
					this.netPrice= totalWithPromo;
				}
				else{ this.totalBelowMsrp= parseFloat(this.totalMSRP[1])-totalCost- totalDeductions;
				this.netPrice= totalCost- totalDeductions;
				
				}
				return this.netPrice;
			},

			/////////////////////////////////////////////////////////////////
			getNetPrice: function(label, price) {
			return this.netPrice;
			},
			/////////////////////////////////////////////////////////////////
			clearBox : function(){
				this.container.innerHTML="";
			},
			/////////////////////////////////////////////////////////////////
			getHTML: function(){
				return "<ul class=\"offerPriceList clear\">"+this.generatedHTML+"</ul>";
			},
			/////////////////////////////////////////////////////////////////
			clearHTML: function(){
				this.generatedHTML="";
			},
			
			/////////////////////////////////////////////////////////////////
			getLiHTML : function(label, price,sign,id) {
				this.liCounter++;
				if (sign == null || sign == "undefined")
					sign = "";
				liElement = "<li  class=\"priceBoxLeft\" id=\"left"+id+"\">" + label + ":</li>" + "<li class=\"priceBoxright\" id=\"right"+id+"\">"
						+"$"+ sign + formatCurrency(price) + "</li><br style=\"clear:both\"/>"
				this.generatedHTML+=liElement;
			},
/////////////////////////////////////////////////////////////////
			getAsFloat: function(price) {			
			cleanPrice=	price.replace(/,/g, "");
			return parseFloat(cleanPrice);
			},			
			/////////////////////////////////////////////////////////////////
			createLiHTML : function(label, price,sign,id) {
				this.liCounter++;
				if (sign == null || sign == "undefined")
					sign = "";				
				liElement = "<li  class=\"priceBoxLeft\" id=\"left"+id+"\">" + label + ":</li>" + "<li class=\"priceBoxright\" id=\"right"+id+"\">"
						+"$"+ sign + formatCurrency(price) + "</li><br style=\"clear:both\"/>"
				this.generatedHTML+=liElement;
				this.container.innerHTML += liElement;
			}
			
			
		});

