﻿
/*
 ***********************************
 * SIFR UTILITY METHODS
 ***********************************
 */

	
	var sIFR_Utilities = {

		/*
		 * GENERIC SIFR REPLACED ELEMENT TEXT UPDATE 
		 *
		 * @argument : uniqueJQSelector :: unique jquery formatted selector;
		 * @argument : text :: Update text (html formatted e.g: "update <span class='span'>text</span>" )
		 * @argument : isUpperCase :: Boolean indicating when text should be reformatted to uppercase of left untouched
		 *
		 * IMPORTANT :: this technique assumes that there is ONLY 1 object tag within the replaced element and that it is the FIRST CHILD
		 *
		 * EXAMPLE :: << sIFR_Utilities.replaceSifrText($("div.column2 > div.panel-compare > div.header > h2"), "i've been updated <span class='span'>mofo</span>", true); >>
		 */
			replaceSifrText : function (uniqueJQSelector, text, isUpperCase)
			{
				var target = sIFR.getReplacementByFlashElement(uniqueJQSelector.children()[0]);
				target.replaceText((isUpperCase) ? text.toUpperCase() : text);
				
				
			},
			
			
		/*
		 * UPDATE FAVOURITE SIDE PANEL HEADER
		 *
		 * @argument : n :: current total number of favourites
		 *
		 * EXAMPLE CALL << sIFR_Utilities.updatePanelHeader_favourites(50); >>
		 */
			updatePanelHeader_favourites : function (n)
			{
				var n_display;
				var n_total = n;
				
				n_display = (n >= 3) ? 3 : n;
				
				var str_1 = "Favourite vehicles <span class='span'>(";
				var str_2 = "";
				var str_3 = ")</span>"
				
				if (n > 0)
				{
					str_2 =  String(n_display + " / " + n_total);
				}
				else {str_2 = "0"}
				
				sIFR_Utilities.replaceSifrText($("div.column2 > div.panel-favourites > div.header > h2"), (str_1 + str_2 + str_3), true);
			},
			
			
		/*
		 * UPDATE COMPARE SIDE PANEL HEADER
		 *
		 * @argument : n :: current total number of vehicles added to comapare
		 *
		 * EXAMPLE CALL << sIFR_Utilities.updatePanelHeader_compare(3); >>
		 */
			updatePanelHeader_compare : function (n)
			{
				
				var str_1 = "Vehicle compare quick view <span class='span'>(";
				var str_2 = "";
				var str_3 = ")</span>";
				
				if (n != undefined) str_2 = n;
				if (n >= 3) str_2 = "3";			
				
				sIFR_Utilities.replaceSifrText($("div.column2 > div.panel-compare > div.header > h2"), (str_1 + str_2 + str_3), true);
			}
			
	}

		