try { console.log('init console... done'); } catch(e) { console = { log: function() {} }; }

/*Protocol Re-direct for SSL*/

function redirectPageBasedOnSSL() {
	//only swap protocols when on UAT and PROD. Avoid TEST
	if( location.href.indexOf( "://test" ) == -1) {
		if(typeof(remain_ssl) == "undefined") {
			if(location.protocol == "https:") {
				window.location = location.href.split("https:").join("http:");
			}       
		}
		else {
			if(location.protocol == "http:") {
				window.location = location.href.split("http:").join("https:");
			}
		}
	}
	else {
		if(location.protocol == "https:") {
			window.location = location.href.split("https:").join("http:");
		}
	}
}

if(!getParameter('disable_ssl_redirect')){
	redirectPageBasedOnSSL();
}

function setZip(zip){
	Cookie.set('zipcode',zip);
}

/*This method takes a string from dealer XML and 
returns the appropriate format based on string length.*/

function formatXMLValue(xmlData){
	var xmlDataLength = xmlData.length;

	//Phone
	if(xmlDataLength == 10){
		var areaCode = xmlData.substring(0,3);
		var phonePrefix = xmlData.substring(3,6);
		var phoneLineNumber = xmlData.substring(6);
		xmlData = "("+areaCode+") " + phonePrefix + "-" + phoneLineNumber;
	}

	//Long Zip
	if(xmlDataLength == 9){
		var zip1 = xmlData.substring(0,5);
		var zip2 = xmlData.substring(5);
		xmlData = zip1 + "-" + zip2;
	}

	return xmlData;
}

//REMOVE AFTER ESPIFF CAMPAIGN
function buildESPIFF() {
	var message = "Are you sure you want to sign up for this extra $500 Cash Allowance?";
	var content = $('main_content');
	var div = new Element('div', {
		'id': 'adjust_dealer',
		'class': 'adjust_dealer'
	});
	var para = new Element('p');
	var span = new Element('span');
	var anch = new Element('a').setProperty('href', '#');
	para.setHTML(message).injectInside(div);
	anch.clone().addEvent('click', function() {
		eventESPIFF(true);
	}).setHTML(glossary_label_yes_please).injectInside(span);
	anch.clone().addEvent('click', function() {
		eventESPIFF(false);
	}).setHTML(glossary_label_no_thanks).injectInside(span);
	span.injectInside(div);
	div.injectInside(content);
}

function espiff(app, family) {
	family = family.substring(4);
	if (family == "durango"
		|| family == "nitro"
		|| family == "ram_2500"
		|| family == "ram_3500"
		|| family == "commander"
		|| family == "liberty")
	{
		var espiffUrl = "https://wsprod.bbdodetroit.com/launch/2008BrandeSpiff.jsp?pageid=" + app + "&vehid=" + family;
	}
}

function eventESPIFF(go) {
	if (go) {
		flexWin('https://wsprod.bbdodetroit.com/launch/2008BrandeSpiff.jsp?pageid=promo&vehid='+cur_vehicle,'yes','715','600','espiff','no');
	}
	$('adjust_dealer').remove();
}
//REMOVE AFTER ESPIFF CAMPAIGN

/* onload handler setter */
var onloadRef = window.onload;
var cur_section;
var populate_zip;
var audio_on_text;
var audio_off_text;
var es_confirm_apps;

/*
window.ie - will be set to true if the current browser is internet explorer (any).
window.ie6 - will be set to true if the current browser is internet explorer 6.
window.ie7 - will be set to true if the current browser is internet explorer 7.
window.khtml - will be set to true if the current browser is Safari/Konqueror.
window.gecko - will be set to true if the current browser is Mozilla/Gecko.
*/

if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;
else if (document.childNodes && !document.all && !navigator.taintEnabled) window.khtml = true;
else if (document.getBoxObjectFor != null) window.gecko = true;

window.onload = function() {
	if(onloadRef != null) {
		onloadRef();
	}
	for(var i = 0; i < window_onload.length; i++){
		eval( window_onload[i]);
	}
};

function onload_register(func){
	window_onload.push(func);
}
/* end onload handler */

/* navigation menus */
var cur_menu;
var cur_sub_menu;
var isFormOpen;
var toggle, toggleOpen;
var curClassName = "";
var form_elements_to_turn_on = new Array();

/* Set up menu elements for mouse events */
function setup_menus(){
	var timer;
	$$('div.features_menu').each(function(f) {
		f = $(f);
		var menuWidth = cllc.constants.get('FEATURE_MENU_PADDING');
		var fmc = $(f.getLast());
		fmc.getFirst().getChildren().each(function(lc){
			if(lc.hasClass('link_container') || lc.hasClass('feature_nav_divider')){
				menuWidth = menuWidth + parseInt($(lc).getSize().scrollSize.x, 10);
			}
		});
		fmc.setStyle("width", menuWidth + "px");
		if ((f.getPosition().x - $('wrapper').getPosition().x) + f.getSize().scrollSize.x + (menuWidth / 2) > 960) {
			var menuOffSet = -(f.getPosition().x - $('wrapper').getPosition().x) + 960 - menuWidth;
		}
		else{
			//var menuOffSet = (0 - (menuWidth / 2) + (f.getSize().scrollSize.x / 2)) - menuWidth;
			var menuOffSet = 0 - (menuWidth / 2) + (f.getSize().scrollSize.x / 2);
		}
		fmc.setStyle("left", menuOffSet + "px");

		f.onmouseover = function() {
			if (this.timer) { clearTimeout(this.timer); }
			this.menuBuffer = setTimeout("checkMenus('"+this.id+"_container')", 200);
		};

		f.onmouseout = function() {
			if (!isFormOpen) {
				if(this.menuBuffer) { clearTimeout(this.menuBuffer); }
				this.timer = setTimeout("hide('"+this.id+"_container')", 200);
			}
		};
	});

	$('brand_menus').getChildren().each(function(m) {
		$(m).onmouseover = function() {
			if ($(m).id != "dealer_finder" && $(m).id != "build_menu" && $(m).id != "owners_menu") {
				if (this.timer) { clearTimeout(this.timer); }
				this.menuBuffer = setTimeout("checkMenus('"+this.id+"_container')", 200);
			}
		};

		$(m).onmouseout = function() {
			if (!isFormOpen) {
				if ($(m).id != "dealer_finder" && $(m).id != "build_menu" && $(m).id != "owners_menu") {
					if(this.menuBuffer) { clearTimeout(this.menuBuffer); }
					this.timer = setTimeout("hide('"+this.id+"_container')", 1);
				}
			}
		};
	});

	$$('.menu_select_field').each(function(f) {
		$(f).onfocus = function() { formMenuHolder(true); };
		$(f).onblur = function()  { formMenuHolder(false); };
	});

	$$('.sub_menu_btn').each(function(s){
		$(s).onclick = function() { toggleSubMenu(this.getNext()); };
	});

	$$('.button_list_menu_btn').each(function(s){
		$(s).onclick = function() { toggleSubMenu(this.getNext()); };
	});
}

function formMenuHolder(argValue){
	isFormOpen = argValue;
}

/* Check to see what the current menu status is */
function checkMenus(whichMenu){
	if(cur_menu != whichMenu){
		show(whichMenu);
		cur_menu = whichMenu;
	}
}

function setFX(el, attrib, dur){
	return new Fx.Style(el, attrib, {duration: dur});
}

/* Turn on New Menu */
function show(whichMenu){
	//blur all open select boxes and hide the open menu (but only if a form select is open)
	if(isFormOpen){
		$$('.menu_select_field').each(function(f) {
			f.blur();
		});
		if(cur_menu){
			hide(cur_menu);
		}
	}
	var menu = $(whichMenu);

	//determine if the menu exsits before tyring to manipulate it
	if(menu){
		//Find nav link and add hover state
		if(menu.hasClass('features_menu_container')){
			var menu_children_arr = menu.getParent().getChildren();
			var menu_link = menu_children_arr[0];

			if (curClassName != "vehicle_feature_nav_link_on") {
				curClassName = "vehicle_feature_nav_link";
			}

			menu_link.addClass('vehicle_feature_nav_link_on');
		}
		else {
			var menu_link = menu.getPrevious();
			menu_link.addClass('brand_menu_link_on');
		}

		//set before calculation to calcuate with borders
		menu.setStyle('border-style', 'solid');

		var menuHeight = menu.getSize().scrollSize.y;
		var menuWidth = menu.getSize().scrollSize.x;

		var menuX = menu.getPosition().x;
		var menuY = menu.getPosition().y;

		if(window.ie6){
			$$('select').each(function(s) {
				if (s.className != "menu_select_field") {
					var elX = s.getPosition().x;
					var elY = s.getPosition().y;

					//if ((element begins between the left and right edge of the menu) OR (element starts to the left of the menu, but extends into the area))
					if ((elX  > menuX && elX  < (menuX + menuWidth)) || ( ((elX + s.getSize().scrollSize.x) > menuX ) && (elX < menuX))) {
						// if (element is contained within the vertical space occupied by the menu)
						if (elY > menuY && elY < (menuY + menuHeight)) {
							s.setStyle('visibility', 'hidden');
							form_elements_to_turn_on.push(s);
						}
					}
				}
			});
		}
		menu.setStyle('height', menuHeight+"px");
		menu.setStyle('visibility', 'visible');

		isFormOpen = false;
	}
}

/* Turn off Current Menu */
function hide(whichMenu){
	/* if a sub menu is open on my menu, close it.
	Reset cur_sub_menu so the other menu sub menus can open/close as needed */
	if ($(cur_sub_menu)) {
		if($(cur_sub_menu).getParent().id == whichMenu){
			$(cur_sub_menu).getLast().setStyle('height','0px');
			$(cur_sub_menu).getLast().setStyle('display', 'none');

			var link = $(cur_sub_menu).getFirst();
			link.removeClass('sub_menu_btn_at');
			link.addClass('sub_menu_btn');
			cur_sub_menu = "";
		}
	}
	cur_menu = null;
	var menu = $(whichMenu);

	if ($('flyouts')) { swapFlyout(''); }
	//determine if menu exists before manipulation
	if(menu){
		if(menu.hasClass('features_menu_container')){
			var menu_children_arr = $(menu.getParent()).getChildren();
			var menu_link = menu_children_arr[0];
			menu_link.removeClass('vehicle_feature_nav_link_on');
			menu_link.addClass(curClassName);
		}else{
			var menu_link = menu.getPrevious();
			menu_link.removeClass('brand_menu_link_on');
			menu_link.addClass('brand_menu_link');
		}
		for(var t = 0; t < form_elements_to_turn_on.length; t++){
			form_elements_to_turn_on[t].setStyle('visibility', 'visible');
		}
		form_elements_to_turn_on = [];
		menu.setStyle('height','0px');
		menu.setStyle('visibility', 'hidden');

		//make sure we turn our border off!!
		menu.setStyle('border-style','none');
	}
}

/* Toggle sub menu`s in the current main menu */
function toggleSubMenu(whichMenu){
	var menu = $(whichMenu);

	if (menu) {
		// This line allows Safari to pick up the actual height of the about-to-open menu div
		menu.setStyle('display', 'block');

		var menuHeight = menu.getSize().scrollSize.y;
		var parent = $(menu.getParent().getParent().id);
		var parent_button_id = menu.getParent().id;
		var parentHeight = parent.getSize().scrollSize.y;
		var closeHeight = 0;
		var toggleParent = new Fx.Style(parent, 'height',{duration: 300});

		//If there is a menu open already, close it
		if(parent_button_id != cur_sub_menu && self.cur_sub_menu){
			var menu_to_close = $(cur_sub_menu).getLast();
			if(menu_to_close.className != "button_list_wrapper_closed" && menu.className != "button_list_wrapper_closed"){
				closeHeight = $(menu_to_close).getStyle('height').toInt();
				var toggle_last = new Fx.Style(menu_to_close, 'height',{duration: 300}).addEvent('onComplete', function(){
					menu_to_close.setStyle('display', 'none');
				});
				toggle_last.start(0);

				var cur_link = $(cur_sub_menu).getFirst();
				cur_link.removeClass('sub_menu_btn_at');
				cur_link.addClass('sub_menu_btn');

				cur_sub_menu = "";
			}
		}

		//Open the menu that was clicked
		if(parent_button_id != cur_sub_menu && menu.getStyle('height') == "0px"){
			if(closeHeight > menuHeight){formMenuHolder(true);}
			var toggle = new Fx.Style(menu, 'height',{duration: 300}).addEvent('onComplete', function(){
				formMenuHolder(false);
			});

			menu.setStyle('display', 'block');

			toggleParent.start(parentHeight + menuHeight - closeHeight);
			toggle.start(menuHeight);
			cur_sub_menu = parent_button_id;

			var link = menu.getParent().getFirst();

			link.removeClass('sub_menu_btn');
			link.addClass('sub_menu_btn_at');

		}
		else{
			//this is the close click for the menu
			var toggle = new Fx.Style(menu, 'height',{duration: 300}).addEvent('onComplete', function(){
				menu.setStyle('display', 'none');
			});
			toggle.start(0);
			toggleParent.start(parentHeight - menuHeight);

			//if closing the only open menu, reset cur_sub_menu
			cur_sub_menu = "";

			var link = menu.getParent().getFirst();

			link.removeClass('sub_menu_btn_at');
			link.addClass('sub_menu_btn');
		}
	}
}

function show_vehicle_menu(){
	show_menu = true;
	if(typeof cllc.constants.get('AUTOMATICALLY_SHOW_VEHICLE_MENU') != 'undefined') {
		show_menu = cllc.constants.get('AUTOMATICALLY_SHOW_VEHICLE_MENU');
	}
	if(show_menu == true) {
		$('vehicle_menu').onmouseover();
		$('vehicle_menu').timer =  setTimeout("hide($('vehicle_menu_container'))", 5000);		
	}
}


function show_shopping_menu(){
	$('shop_menu').onmouseover();
	$('shop_menu').onmouseout = function(){};// override to do nothing
}

/* end navigation menus */

/* vehicle as shown info */
var infoShown = false;
var inTransition = false;
var s;
var init_y_pos_info_container;
var content_div_offset;
var vehicle_pricing_block_height;

function vehicle_info_setup(){
	var vehicle_info = $('vehicle_shown_info');
	init_y_pos_info_container = $('vehleftarrow').getTop();
	content_div_offset = $('content').getTop();
	vehicle_pricing_block_height = $('vehicle_pricing_background').getSize().size.y;
	if(vehicle_info){
		var info_block_height = $('vehicle_shown_info_detail').getSize().scrollSize.y;
		vehicle_info.addEvent('mouseover', function(){
			clearTimeout(s);
			if(infoShown == false && inTransition == false) {
				inTransition = true;
				linkTrack("as_shown", "roll_over");
				new Fx.Style('vehicle_shown_info_detail','height',{duration:100, onComplete:infoOpened}).start(info_block_height);
				if (brand_id == "dodge"){
					new Fx.Style('vehicle_shown_info_container','top',{duration:100}).start(init_y_pos_info_container - info_block_height - content_div_offset);
					new Fx.Style('vehicle_pricing_background','top',{duration:100}).start(init_y_pos_info_container - info_block_height - content_div_offset - vehicle_pricing_block_height);
					new Fx.Style('vehicle_pricing','top',{duration:100}).start(init_y_pos_info_container - info_block_height - content_div_offset - vehicle_pricing_block_height);
				}
				$('vehleftarrow').addClass("downarrow");
				$('detail').addClass("detail_highlight");
				return false;
			}
		});

		vehicle_info.addEvent('mouseout', function(){
			s = setTimeout(hideInfo, 50);
		});
	}
}

function hideInfo(){
	if(infoShown == true && inTransition == false) {
		inTransition = true;
		new Fx.Style('vehicle_shown_info_detail','height',{duration:200, onComplete:infoClosed}).start(0);
		if (brand_id == "dodge"){
			new Fx.Style('vehicle_shown_info_container','top',{duration:200}).start(init_y_pos_info_container - content_div_offset);
			new Fx.Style('vehicle_pricing_background','top',{duration:200}).start(init_y_pos_info_container - content_div_offset - vehicle_pricing_block_height);
			new Fx.Style('vehicle_pricing','top',{duration:200}).start(init_y_pos_info_container - content_div_offset - vehicle_pricing_block_height);
		}
		if ($('miles_per_gallon')){$('miles_per_gallon').setStyle("visibility", "visible");}
		$('vehleftarrow').removeClass("downarrow");
		$('detail').removeClass("detail_highlight");
		return false;
	}
}
function fade_down_model_info(){ /* Trys to set contents invisible, but contents may not be available */
	if ($defined($('vehicle_shown_info_container'))) { $('vehicle_shown_info_container').setStyle("visibility", "hidden"); }
	if ($defined($('vehicle_pricing_background'))) { $('vehicle_pricing_background').setStyle("visibility", "hidden"); }
	if ($defined($('vehicle_pricing'))) { $('vehicle_pricing').setStyle("visibility", "hidden"); }
	if ($defined($$('#vehicle_pricing p'))) { $$('#vehicle_pricing p').setStyle("visibility", "hidden"); }
	if ($('miles_per_gallon')){$('miles_per_gallon').setStyle("visibility", "hidden");}
	if ($('pricing_box')){$('pricing_box').setStyle("visibility", "hidden");}
	//
	if($defined($$('p.starting_at_p'))){$$('p.starting_at_p').setStyle("visibility", "hidden");}
}

function fade_up_model_info(){
	if ($defined($('vehicle_shown_info_container'))) { $('vehicle_shown_info_container').setStyle("visibility", "visible"); }
	if ($defined($('vehicle_pricing_background'))) { $('vehicle_pricing_background').setStyle("visibility", "visible"); }
	if ($defined($('vehicle_pricing'))) { $('vehicle_pricing').setStyle("visibility", "visible"); }
	if ($defined($$('#vehicle_pricing p'))) { $$('#vehicle_pricing p').setStyle("visibility", "visible"); }
	if ($('miles_per_gallon')){$('miles_per_gallon').setStyle("visibility", "visible");}
	if ($('pricing_box')){$('pricing_box').setStyle("visibility", "visible");}
}

function check_pricing(){
	$$('.as_shown_p').each(function(as_p){
		var as_p = $(as_p);
		if(as_p.getLast().innerHTML == "X"){
			as_p.setHTML(as_p.innerHTML.replace(/\s\$/g,' '));
			as_p.getLast().innerHTML = glossary_label_see_dealer;
		}
		else if(as_p.getLast().innerHTML == "NA"){
			as_p.setHTML("");
		}
	});
	$$('.starting_at_p').each(function(start_p){
		var start_p = $(start_p);
		var start_val = start_p.getLast().innerHTML;
		if(start_val == "X" || start_val == "$X"  || start_val == " $X"){
			start_p.setHTML(glossary_label_pricing_avail_soon);
		}
		else{
			$(start_p.getNext()).setStyle('visibility', 'visible');
		}
		start_p.setStyle('visibility', 'visible');
	});
}

var as_shown_holder = 0;
function update_pricing(num){
	var asp = $('as_shown_price');
	if (asp){
		num = parseInt(num, 10);
		if(as_shown_holder == 0)as_shown_holder = parseFloat((asp.innerHTML.split(',')).join(""));
		num += as_shown_holder;
		if(!isNaN(num))	asp.setHTML(comma_format(num));
	}
}
function comma_format(num){
	var n = new String(num);
	var a = [];
	while(n.length > 3) {
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if (n.length > 0) { a.unshift(n); }
	return a.join(",");
}

function infoOpened() {
	infoShown = true;
	inTransition = false;
}

function infoClosed() {
	infoShown = false;
	inTransition = false;
}

// ==========================================================
// update_pricing_mpg() 
// ==========================================================
function update_pricing_mpg(startingAt, asShown, cityMpg, hwyMpg) {
	if(hwyMpg && $('hwy_value')) {
		$('hwy_value').setText(hwyMpg);
	}

}

/* end vehicle as shown info */


// the variable to hold the flash name
var flashName;
var seedID = Math.floor(Math.random()*11111);
/*Turn on rendering div*/
function showFlash(argSwf,argElement,argFlashVars,overrideLowBand,overrideFlashVersion){
	//console.log('argSwf = ' + argSwf + ' argElement =' + argElement + ' argFlashVars =' + argFlashVars + ' overrideLowBand =' + overrideLowBand  + ' overrideFlashVersion = ' + overrideFlashVersion);
	if($(argElement)) {
		// if we have main content lets temporarily clone it for the print stylesheet
		if(argElement == "main_content") {
			if ($(argElement).getFirst() && $('promo_background')){
				if ($(argElement).getFirst().getTag() == 'map') {
					var clone = $(argElement).getElement('img').clone().injectAfter('promo_background');
				}
				else {
					var clone = $(argElement).getFirst().clone().injectAfter('promo_background');
				}

				clone.addClass('print');
				clone.setProperty('id', 'clone');
				var myArray = $$('#clone li');
				for(var i=0; i<myArray.length; i++) {
					myArray[i].setProperty('id', '');
				}
				myArray = $$('#clone a');
				for(var i=0; i<myArray.length; i++) {
					myArray[i].setProperty('id', '');
				}
				myArray = $$('#clone div');
				for(var i=0; i<myArray.length; i++) {
					myArray[i].setProperty('id', '');
				}
				myArray = $$('#clone ul');
				for(var i=0; i<myArray.length; i++) {
					myArray[i].setProperty('id', '');
				}
				myArray = $$('#clone p');
				for(var i=0; i<myArray.length; i++) {
					myArray[i].setProperty('id', '');
				}
				myArray = $$('#clone span');
				for(var i=0; i<myArray.length; i++) {
					myArray[i].setProperty('id', '');
				}
			}
		}

		if(argElement == "model_image") {
			var clone = $(argElement).getFirst().clone().injectAfter('colors');
			clone.addClass('print');
		}

		// cache buster for IE7 redraw issues
		if(argElement == "promos") {
			argSwf+= "?r=" + new Date().getTime();
		}

		var individualID = Math.floor(Math.random()*11111);
		/*
		    Prepare to load in the Flash rendering engine.
		    Uses Unobtrusive Flash Objects by Bobby van der Sluis
		    http://www.bobbyvandersluis.com/ufo/
		*/

		var isSafari = "";
		navigator.userAgent.indexOf("Safari")>= 0 ? isSafari = true : isSafari = false;

		var isLTOpera92 = "";
		navigator.userAgent.indexOf("Opera") >= 0 && parseFloat(navigator.appVersion) < 9.2 ? isLTOpera92 = true : isLTOpera92 = false;

		//Should Flash even be shown? (does user want it / can their browser support Flash 8 functionality)

		if ((userData.bandwidth != "low" && isLTOpera92 == false) || overrideLowBand ) {

			var site_config = {
				'host':location.host,
				'src':location.href,
				'title':document.title,
				'isSafari':isSafari,
				'isLTOpera92':isLTOpera92,
				'asset_path':'en',
				'EOF':'EOF'
			};

			if(typeof(userData.zipcode) != "undefined") {
				site_config['zip'] = userData.zipcode;
			}
			if( (typeof(cur_year) !="undefined" && cur_year != '') && (typeof(cur_vehicle) !="undefined" && cur_vehicle != '') ) {
				site_config['cur_vehicle'] = vehicle_data[cur_year][cur_vehicle].apps.trilogy;
			}
			if(typeof(brand) != "undefined") {
				site_config['brand'] = brand;
			}
			if(typeof(embedded_disclaimers) != "undefined") {
				site_config['embedded_disclaimers'] = Json.toString(embedded_disclaimers);
			}

			var flash_vars = '';
			for(k in site_config) {
				if (k != "toJSONString") {
					flash_vars += "&" + k + "=" + encodeURIComponent(site_config[k]);
				}
			}
			// deep link & query strings
			if(location.href.indexOf("?") != -1) {
				// if we have a src in the query we need to strip it out to avoid overwrite
				if(location.href.indexOf("src=") != -1) {
					// split on the src
					var queryCleanedArray = location.href.split("src=");
					// if we have additional values past the src value
					if(queryCleanedArray[1].indexOf("&") != -1) {
						// remove the src altogether
						queryCleanedArray[1] = queryCleanedArray[1].substring(queryCleanedArray[1].indexOf("&")+1, queryCleanedArray[1].length);
					}
					else {
						// set the val to empty
						queryCleanedArray[1] = "";
					}
					// join on empty
					var cleanedVersion = queryCleanedArray.join("");
					flash_vars += "&" + cleanedVersion.substr(location.href.indexOf("?")+1);
				}
				else {
					flash_vars += "&" + location.href.substr(location.href.indexOf("?")+1);
				}
			}

			// add local connect sound vars
			flash_vars += "&localconnect_seed=" + seedID;
			flash_vars += "&localconnect_id=" + individualID;
			if (userData.audiopref == "on"){
				flash_vars += "&audio_pref=on";
			}
			else if (userData.audiopref == "off"){
				flash_vars += "&audio_pref=off";
			}
			else {
				flash_vars += "&audio_pref=off";
			}
			// add text size preference
			if (typeof(userData.featureTextSize) == "number"){
				flash_vars += "&text_size="+userData.featureTextSize;
			}

			if ($(argElement)) {
				var render_foo = document.getElementById(argElement);
				render_foo.style.display = 'block';
			}

			// set the name fo the flash based on the div
			flashName = argElement +  '_flash';

			// pass the containing div height and width
			flash_vars += "&stageWidth="+parseInt($(argElement).getStyle('width'), 10);
			
			var flashDivHeight = jQuery('#'+argElement).height();
			
			// we found that the div height has to be over 25 or otherwise the menus get shoved to the top
			// 25 seems to be the magic # that all browsers can agree is bigger than an empty div
			if(flashDivHeight > 25)
			{
				flash_vars += "&stageHeight="+parseInt($(argElement).getStyle('height'), 10);
			}else
			{
				flash_vars += "&stageHeight="+jQuery('#'+argElement).parent().height();
			}

			if(argFlashVars != null) {
				// check if we need to pass the entire combined user data object
				if(argFlashVars.indexOf("passUserData=true") != -1) {
					flash_vars += "&cookieUserData=" + getCombinedUserData();
				}
            
				flash_vars += argFlashVars;
			}
            
			var debug_html = getParameter('flash');
			var flash_version;
			if(debug_html == "false" && debug_html !=  ""){
				flash_version = 11;
			}
			else if (overrideFlashVersion != null){
				flash_version = overrideFlashVersion;
			}
			else if(argElement == "main_flash_embed")
			{
				flash_version = 10;
			}
			else {
				flash_version = 8;
			}
            
			//var flashvars = false;
			var params = {
				bgcolor:      "#FFFFFF",
				scale:        "noscale",
				wmode:        "transparent",
				play:         "true",
				quality:      "high",
				menu:         "false",
				flashvars: flash_vars,
				allowScriptAccess:"always" 
			};
			var attributes = {
				id:   flashName,
				name: flashName
			};
            
			//SWFObject replaces the entire DIV, so lets create an injection DIV inside our target
			var flash_injection_id = argElement + "__flash_injection";
			var flash_injection_element = new Element('div', { 'id': flash_injection_id } );
            
			$(argElement).empty();
			$(argElement).adopt(flash_injection_element);
			
			//console.log();
            
			flash_version_string = flash_version.toString() + ".0.0";
			if(swfobject.hasFlashPlayerVersion(flash_version_string))
			{
				swfobject.embedSWF(argSwf,
									flash_injection_id,
									"100%",
									"100%",
									flash_version_string,
									"",
									flash_vars,
									params,
									attributes);
				$(argElement).style.visibility = 'visible';
			}else
			{
				if (jQuery('#feature_media').length > 0) 
				{
					//console.log('feature page');
					jQuery('#main_flash_embed').height(jQuery('#feature_media').height());
				}else
				{
					//console.log('home page');
					jQuery('#main_flash_embed').height(jQuery('#main_content').height());
				}
				jQuery('#low_band_src').css('display', 'none');
				swfobject.embedSWF('/crossbrand/shared/flash/expressInstall.swf',
									flash_injection_id,
									"100%",
									"100%",
									"6.0.0",
									"",
									'',
									params,
									attributes);
				$(argElement).style.visibility = 'visible';
			}
			
		}
		else {
			jQuery('#main_content').css('visibility', 'visible');
			jQuery('#main_content').css('height', jQuery('#low_band_src').height());
			jQuery('#promos').css('visibility', 'visible');
			if (jQuery('#custom_center_image_div').length > 0) 
			{
				jQuery('#custom_center_image_div').css('visibility', 'visible');
			}
			// the promo div had this class initially, but older browsers would improperly place the div when it conatined Flash.
			if ($('promos')){
				$('promos').style.overflow = 'auto';
				setlowbanddaalink();
			}
		}
	}
}

// External Interface hack for IE out of memory error
function nullFlashLoopFunction() { __flash_savedUnloadHandler = null; }
window.onbeforeunload = nullFlashLoopFunction;

function hasFlashMin(){
	var debug_html = getParameter('flash');
	var flash_version = 8;
	if(debug_html == "false" && debug_html !=  ""){
		flash_version = 10;
	}
	flash_version_string = flash_version.toString() + ".0.0";
	return(swfobject.hasFlashPlayerVersion(flash_version_string));
}

function setAudio() {
	if ($('audio_text').innerHTML == audio_off_text){
		$('audio_text').setHTML(audio_on_text);
		window.document["audio_controller_flash"].SetVariable("audio_pref", "off");
		window.document["audio_controller_flash"].change(); // telling Flash to turn the sound off
		userData.audiopref = "off";
	}
	else{
		$('audio_text').setHTML(audio_off_text);
		window.document["audio_controller_flash"].SetVariable("audio_pref", "on");
		window.document["audio_controller_flash"].change();  // telling Flash to turn the sound on
		userData.audiopref = "on";
	}
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
}

//New Code for Tab nav
var disclaimersShown = false;
var logosShown = true;

function showDisclaimers(){
	if(!disclaimersShown){
		$('logo_links').setStyle('display','none');
		$('logo_link_topper').setStyle('display', 'none');
		$('brand_tab').removeClass('b_border');
		logosShown = false;

		if ($('disclaimers')){
			$('disclaimers').setStyle('display', 'block');
			disclaimersShown = true;
		}

		$('legal_tab').toggleClass('b_border');
	}

}

function showLogos(){
	if (!logosShown){
		if ($('disclaimers')){
			$('disclaimers').setStyle('display','none');
			$('legal_tab').removeClass('b_border');
			disclaimersShown = false;
		}

		$('logo_links').setStyle('display', 'block');
		$('logo_link_topper').setStyle('display', 'block');
		logosShown = true;

		$('brand_tab').toggleClass('b_border');
	}

}

/* Universal function to get parameter from url string */
function getParameter(aP){var qS = new String(location.search.substring(1,location.search.length));var p = qS.split("&");var val = "";if(aP){for(i=0;i<p.length;i++){if(p[i].split( "=" )[0] == aP){val = p[i].split( "=" )[1];}}return val;}}

function wrap(argApp, argMisc, argFamily, argModel) {
	argApp = argApp.toLowerCase();
	var sizedWin = false;
	var options = "";
	var model_year = argFamily.substr(0,4);
	if (isNaN(model_year)) {
		model_year = "";
	}
	else {
		//year must be prepended, so family var is what is left after the four digit year
		argFamily = argFamily.substr(4);
	}

	//fix for Chrysler 300
	if (model_year == "300") {
		model_year = "";
		argFamily = "300";
	}

	var launchUrl = getDomain() + "/bridge/index.html?";

	if (argMisc != '' )	launchUrl += argMisc + "&";

	if (argMisc.indexOf( "zipcode" ) == -1 && !isNaN(populate_zip)) {
		launchUrl += "zipcode=" + populate_zip + "&";
	}

	launchUrl += "app=" + argApp + "&family=" + argFamily + "&model=" + argModel + "&year=" + model_year;

	if (argApp == "chrome" || argApp == "edmunds" || argApp == "cf_pmt_est" || argApp == "cf_app_cred") {
		sizedWin = true;
		var app_width;
		var winHeight;
		if (argApp == "chrome" || argApp == "edmunds") {
			app_width = 840;
			winHeight = ( window.screen.availHeight - 130 );		
			options = "resizable,scrollbars,toolbar,";
		}
		else if (argApp == "cf_app_cred") {
			app_width = 770;
			winHeight = ( window.screen.availHeight - 130 );		
			options = "scrollbars=yes,toolbar=yes,resizable=yes,status=yes,location=yes,menubar=yes,";		
		}
		else if (argApp == "cf_pmt_est") {
			app_width = 615;
			winHeight = 475;				
			options = "scrollbars=no,toolbar=no,resizable=yes,status=no,location=no,menubar=no,";		
		}	
		var winWidth = app_width;
		options += "width=" + winWidth + ",height=" + winHeight;
		if (window.screen) {
			var xPos = ( screen.availWidth - winWidth ) / 2;
			var yPos = ( ( screen.availHeight - winHeight ) / 2 ) - 40;
			options += ",left=" + xPos + ",screenX=" + xPos;
			options += ",top=" + yPos + ",screenY=" + yPos;
		}
	}

	if (argApp == "ext_url") {
		sizedWin = true;
		launchUrl = "http://" + argMisc;
		options = "scrollbars=yes,toolbar=yes,resizable=yes,status=yes,location=yes,menubar=yes,";			
	}

	if (argApp == "ext_sni") {
		sizedWin = true;
		launchUrl = "http://" + argMisc + "/new-inventory/index.htm?reset=InventoryListing";
		options = "scrollbars=yes,toolbar=yes,resizable=yes,status=yes,location=yes,menubar=yes,";			
	}

	if (!es_confirm_apps) {
		if (sizedWin) {
			window.open( launchUrl, "Application", options );
		}
		else {
			window.location = launchUrl;
		}

	}
}

// get proper domain for global navigation images and links
function getDomain( argLink ) {
	var curUrl = document.location.href;
	var newUrl = "";
	var thisDomain = cllc.constants.get('BRAND_ID')+".com";

	if (curUrl.indexOf( "iw-mount" ) >= 0 || curUrl.indexOf( "organic" ) >= 0) {
		// preserve virtualization
		newUrl = "";
	}
	else if (curUrl.indexOf( "://test" ) >= 0) {
		newUrl = "http://test";
	}
	else if (curUrl.indexOf( "://uat" ) >= 0) {
		newUrl = "http://uat";
	}
	else {
		newUrl = "http://www";
	}

	if (newUrl != ""){
		newUrl = newUrl + "." + thisDomain;
	}
	if (argLink) {
		if( argLink.indexOf( "javascript:" ) >= 0 || argLink.indexOf( "/" ) != 0 ) {
			return argLink;
		}
		else {
			return newUrl + argLink;
		}
	}
	else {
		return newUrl;
	}
}

// get proper domain and http protocal for global navigation sourced images, styles, and target links
function getDomainImg( argLink ) {
	var curUrl = document.location.href;
	var newUrl = getDomain();
	var protocol = "";

	if(curUrl.indexOf("-5") >= 0){
		protocol = curUrl.indexOf("https:") >= 0 ? "https://":"http://";
		if(protocol == "https://"){
			var newUrlSplit = newUrl.split( "://" )[1];
			newUrlSplit = newUrlSplit.replace( /\./, "-5." );
			newUrl =  protocol + newUrlSplit;
		}
	}
	return newUrl;
}

// Please note these list of arguments (except the 'tabName') are for the signature of current
// function wrap (so, if you modify the wrap function, please modify the signation of
// callVehicleCompare function) accordingly
function callVehicleCompare(tabName, argApp, argTracking, argFamily, argModel) {
	if ((typeof(trilIsCompareSpec) == 'undefined') || (trilIsCompareSpec == null) || (typeof(changeTab) == 'undefined')) {
		wrap(argApp, argTracking, argFamily, argModel);
	}
	else {
		changeTab(tabName);
	}
}

// exit window
function confirmNewWindow(newUrl){ window.open(newUrl, TARGET='_blank'); }

function flexWin(aU,aS,aW,aH,aN,aO,aX,aY,aC){
	var wN = aN ? aN : "myWin" + nocacheRandom();
	var oV = aO == "all" ? 1 : 0;
	var oS = "history="+oV+",toolbar="+oV+",location="+oV+",directories="+oV+",status="+oV+",menubar="+oV+",resizable="+oV;
	var wO = aO != "all" ? aO : oS;
	var wW = aW ? aW : 800;wO += ",width=" + wW;
	var wH = aH ? aH : 600;wO += ",height=" + wH;
	var sB = ",scrollbars="+aS;wO+=sB;
	var wX = aX ? aX :(screen.availWidth-wW)/2;wO+=",left="+wX+",screenX="+wX;
	var wY = aY ? aY :((screen.availHeight-wH)/2)-40;wO+=",top="+wY+",screenY="+wY;
	//temporary code for 9/15 to handle CF integration from MoMS Pmt Est buttons
 //to be removed for M09 when those pages are generated.
	if (aU.indexOf("tname=cf_payment") > -1){
	wrap('cf_pmt_est','zipcode='+populate_zip,cur_year+cur_vehicle,'');
 } else {
	window.open(aU,wN,wO);
	aC ? window.close():"";
 }

}

function nocacheRandom(){var axel = Math.random() + "";var ord = axel * 1000000000000000000;return ord;}

function highlightVehicleNav(){
	if (cur_section == "features" && $(cur_section)){
		$(cur_section).addClass("vehicle_feature_nav_link_at");
		$(cur_section).getParent().addClass("right_hover");
		$(cur_section).getParent().getParent().addClass("left_hover");
	}
	else if (cur_section != null && cur_section != "features"){
		if ($(cur_section)) {
			$(cur_section).addClass("vehicle_nav_link_at");
			$(cur_section).getParent().addClass("right_hover");
			$(cur_section).getParent().getParent().addClass("left_hover");
		}
	}
}

function setBandwidth(bandwidth) {
	userData.bandwidth = bandwidth;

	//Bake the userData cookie
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});

	//Refresh the page (requires JS 1.2)
	window.location.reload( false );
}

function muteAudio(val) {
	userData.muteAudio = val;

	//Bake the userData cookie
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
}


var userData = new Object;
function getUserData(skipPrefSets){
	cookieUserData = Cookie.get('userdata');

	if(cookieUserData) {
		//Decompress JSON values of userData
		userData = eval('(' + cookieUserData + ')');
	}

	if(Cookie.get('zipcode')) {
		userData.zipcode = Cookie.get('zipcode');
	}

	//Bake the userData cookie
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});

	// hold back calls
	if(!skipPrefSets) {
		setUserPreferences();
		setUserSegment();
		handleAkamaiLowBand();
	}
}

function handleAkamaiLowBand() {
	//Bandwidth detection based on Akamai cookie
	ak_cookie = Cookie.get('CT_Akamai');
	if(ak_cookie && !userData.bandwidth) {
		ak_bandwidth = ak_cookie.split("throughput=");
		if(ak_bandwidth[1]) {
			if(ak_bandwidth[1].split(",")[0] == "low") {
				userData.bandwidth = "low";				

				var html_contents = "";
				html_contents += '<div id="akamai_lowband">';
				html_contents += '<img src="/en/images/ak_select_title.gif" class="ak_title" />';
				html_contents += "We've detected that you are using a slower connection to access the site.<br />To provide a great experience for all users we offer two versions of our site.<br />";
				html_contents += "<strong>The slower connection speed detected indicates that you may wish to select our low-bandwidth site.</strong>";
				html_contents += '<a href="javascript:setBandwidth(\'low\');"><img src="/en/images/ak_select_low.gif" /></a>';
				html_contents += "<span class='ak_link_desc'><strong>Recommended for users with dialup/modem or slower connections.</strong><br />Images optimized and videos removed to reduce download times.</span>";
				html_contents += '<a href="javascript:setBandwidth(\'high\');"><img src="/en/images/ak_select_high.gif" /></a>';
				html_contents += "<span class='ak_link_desc'><strong>Recommended for users with cable modem, DSL or other broadband connection speeds.</strong><br />Contains videos, animations and audio best experienced with a high-speed internet connection.</span>";
				html_contents += "<span class='ak_link_footer'>You can change your bandwidth setting at any time by selecting the <u>Low/High Bandwidth Version</u> setting in the page footer</span>";
				html_contents += '</div>';

				showHTML(html_contents);
			}
		}
	}
}

function setUserPreferences(){
	if (((location.toString()).indexOf("com/es/") != -1) || ((location.toString()).indexOf("htdocs/es/") != -1)){
		audio_on_text = "Audio Activado";
		audio_off_text = "Audio Desactivado";
		es_confirm_apps = true;
	}
	else{
		audio_on_text = "Audio On";
		audio_off_text = "Audio Off";
		es_confirm_apps = false;
	}

	/*All Zip Code boxes*/
	populate_zip = Cookie.get('zipcode');
	if (!populate_zip){
		populate_zip = userData.zipcode;
	}
	$$('input').each(function(zip_input){
		if(zip_input.name == "zipcode"){
			if(populate_zip && populate_zip != "false" && populate_zip != "undefined"){
				zip_input.value = populate_zip;
				defaultZipCodeValue = populate_zip;
			}else{
				zip_input.value = glossary_label_zip;
				defaultZipCodeValue = glossary_label_zip;
			}
		}
	});

	if(userData.bandwidth == "low"){
		if ($('footer_links')){
			var link = $('footer_links').getFirst().getNext();
			link.setHTML(glossary_label_high_band);
			link.title = glossary_label_high_band;
			link.name="&lid=High Bandwidth Version&lpos=global_footer";
			link.href="javascript:setBandwidth('high');";
		}
	}

	var audio_text_div = $('audio_text');

	if (audio_text_div) {
		if (userData.audiopref == "on") {
			audio_text_div.setHTML(audio_off_text);
		}
		else if (userData.audiopref == "off") {
			audio_text_div.setHTML(audio_on_text);
		}
		else {
			audio_text_div.setHTML(audio_off_text);
			// set the pref if the pref is undefined
			userData.audiopref = "on";
			Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
		}
	}
	if (hasFlashMin() && userData.bandwidth != "low" && $('audio_button')){
		$('audio_button').setStyles({visibility: 'visible'});
	}
	if (!hasFlashMin()){
		// the promo div had this class initially, but older browsers would improperly place the div when it conatined Flash.
		if ($('promos')){
			$('promos').style.overflow = 'auto';
			setlowbanddaalink();
		}
	}
}

function setlowbanddaalink(){
	if ($$('#promos ul')) {
		var promo_set_uls = $$('#promos ul');
		var first_ul = promo_set_uls[0];
		var third_promo_li = first_ul.getChildren();
		third_promo_li[2].setProperties({
			id: 'third_promo_holder'
		});

		third_promo_link = $$('#third_promo_holder a');
		third_promo_href = third_promo_link.getProperty('href').toString();

		if (third_promo_href.substr(third_promo_href.length-1,third_promo_href.length) == "#"){
			third_promo_link.setProperty('href',"javascript:wrap('daa','','');");
		}
	}
}

function setUserSegment(){
	if (dealerInfo.id != null) {
		setSeg("14");
	}
	else if (userData.zipcode) {
		setSeg("13");
	}
	else {
		setSeg("12");
	}
}

function setSeg(argSeg){
	_hbSet('seg', argSeg);
	_hbSend();
}

function handleSSIEmbeddedDisclaimers() {
	embedded_disclaimers = {};
	var next_disclaimer = 1;
	activated_disclaimers = {};
	var last_count = 0;

	//Count how many disclaimers are already numbered on the page
	$$('dt.disclaimer_text').each(function(existing_disclaimer){
		if(!isNaN(existing_disclaimer.innerHTML)) {
			next_disclaimer++;
			last_count = Number(existing_disclaimer.innerHTML);
		}
	});
	
	/////// making sure EmbeddedDisclaimers are counting from the last rendered number instead of just the number of discalimers with in the dl
	if(next_disclaimer <= last_count){
		next_disclaimer = last_count + 1;
	}

	//Find disclaimers that need to be renumbered
	$$('sup.embedded_disclaimer').each(function(embedded_disclaimer){
		disclaimer_id = embedded_disclaimer.innerHTML;
		disclaimer_id = disclaimer_id.substring(1,disclaimer_id.length - 1);
		if(typeof(embedded_disclaimers[disclaimer_id]) == "undefined") {
			embedded_disclaimers[disclaimer_id] = next_disclaimer;
			activated_disclaimers[disclaimer_id] = false;
			next_disclaimer++;
		}

		embedded_disclaimer.innerHTML = "["+embedded_disclaimers[disclaimer_id]+"]";

		$$('dt.embedded_disclaimer_text').each(function(footer_disclaimer){
			if(footer_disclaimer.innerHTML == disclaimer_id && activated_disclaimers[disclaimer_id]	== false) {
				footer_disclaimer.innerHTML = embedded_disclaimers[disclaimer_id];
				footer_disclaimer.removeClass("hide");
				$(footer_disclaimer.nextSibling).removeClass("hide");
				activated_disclaimers[disclaimer_id] = true;
			}
		});
	});

	$$('sup.embedded_disclaimer_hidden').each(function(embedded_disclaimer){
		disclaimer_id = embedded_disclaimer.innerHTML;
		activated_disclaimers[disclaimer_id] = false;
	});

	//Find ownership disclaimers that need to be shown
	$$('sup.embedded_disclaimer_hidden').each(function(embedded_disclaimer){
		disclaimer_id = embedded_disclaimer.innerHTML;

		$$('dt.embedded_disclaimer_text').each(function(footer_disclaimer){
			if(footer_disclaimer.innerHTML == disclaimer_id && activated_disclaimers[disclaimer_id]	== false) {
				footer_disclaimer.innerHTML = "&nbsp;";
				footer_disclaimer.removeClass("hide");
				$(footer_disclaimer.nextSibling).removeClass("hide");
				activated_disclaimers[disclaimer_id] = true;
			}
		});
	});
}

//
//	iePngFix()
//	Allows transparent PNG images to be display correctly in IE 5.5 and 6
//  http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
//  CSS backround PNGs not supported, use filter:progid:DXImageTransform.Microsoft.AlphaImageLoader in CSS for PNG backgrounds.
//
function iePngFix() {
	for(var i = 0; i < document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			
			// this if statement fixes an issue where in IE 6 the hopepage copy, which is a png for some reason
			// won't load into Flash due to the fact that the img tag is being hacked for png support on a hidden element
			if(jQuery(img).parent().attr('id') != 'homepage_copy_block' || userData.bandwidth == "low")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText + ";";
				var imgWidth = "width: " + ((img.width) ? img.width + "px;" : "100%;");
				var imgHeight = "height: " + ((img.height) ? img.height + "px;" : "100%;");

				if (img.align == "left")	imgStyle = "float:left;" + imgStyle;
				if (img.align == "right")	imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href)	imgStyle = "cursor:hand;" + imgStyle;

				var strNewHTML = "<span " + imgID + imgClass + imgTitle
					+ " style=\"" + imgWidth + imgHeight + imgStyle
					+ " filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					+ "(src='" + img.src + "', sizingMethod='image');\"></span>";
				img.outerHTML = strNewHTML;
				--i;
			}
		}
	}
}

/*This was put in to set a title attribute on the disclaimer link with an
SSI glossary term. There is no clean way to do this in the XSL.*/

function setDisclaimerLinkTitle(){
	if($('brand_tab')) $('brand_tab').toggleClass('b_border');
}

function flashFeatureSectionTextLink(flash_url,flash_lid,flash_lpos){
	document.location = flash_url;
	linkTrack(flash_lpos, flash_lid);
}

function getCurVehicleValue(){
	return cur_vehicle;
}

function rollMe(element) {}

function vehicleMenu_rollOver(element) {
	if(element.id != cur_section + '_left'){
		$(element.id).addClass('left_hover');
		$(element.id).getFirst().addClass('right_hover');
	}
}

function vehicleMenu_rollOut(element) {
	if(element.id != cur_section + '_left'){
		$(element.id).removeClass('left_hover');
		$(element.id).getFirst().removeClass('right_hover');
	}
}

function setButtonType(buttonTypeValue,txtVal){
	userData.buttonType = buttonTypeValue;
	Cookie.set('userdata', Json.toString(userData), {duration: 365, path: "/"});
	bottonTypeList = buttonTypeValue.toLowerCase().split(" ");
	buttonTypeJoined = bottonTypeList.join("");
	//alert(cur_vehicle+"test_"+buttonTypeJoined+"button");
	linkTrack("test", cur_vehicle+"test_"+buttonTypeJoined+"button");
	if(txtVal){
		//linkTrack("test", buttonTypeValue);
		//appendToMLC(txtVal);
	}
	//linkTrack('content_button_test', bottonTypeList.toLowerCase().join(""));
}

function getButtonType(){
	cookieUserData = Cookie.get("userdata");
	return cookieUserData;
}

function appendToMLC(txtVal){
	hbx.mlc+=txtVal;
	resetMLC(hbx.mlc);
	//alert("ran new mlc");
	//alert(hbx.mlc);
}
function resetMLC(newMLC){
	hbx.mlc = newMLC;
	_hbSet('vcon', newMLC);
	_hbSend();
}
function getCurVehicleValue(){
	return cur_vehicle;
}
function scheduleTestDriveVideoLink(){
	document.location = "/bridge/index.html?app=testdrive&family="+cur_vehicle;
}
function findDealerVideoLink(){
	document.location = "/bridge/dealerloc.html";
}

function brandPopup(target,vehicle,year){
	flexWin("/bridge/index.html?app="+target+"&family="+vehicle+"&year="+year,'yes','770','600',target,'all');
}

// Identical to getParameter() except sniffs the contents of the URL's # anchor instead of the ? query parameters
function getHashParameter(aP){var qS = new String(location.hash.substring(1,location.hash.length));var p = qS.split("&");var val = "";if(aP){for(i=0;i<p.length;i++){if(p[i].split( "=" )[0] == aP){val = p[i].split( "=" )[1];}}return val;}}

// Converts an integer like so: 10000 -> 10,000
function insertCommas(num) {
	num = num.toString();
	return (num.length > 3) ? insertCommas(num.substr(0, num.length - 3)) + ',' + num.substr(num.length - 3) : num ;
}

// ==========================================================
// getCombinedUserData() -- combines session and persistent
// ==========================================================
function getCombinedUserData() {
	var sessionUserData = Cookie.get("usersessiondata"); 
	// if we have a cookie return
	if(sessionUserData && cookieUserData) {
		return escape(sessionUserData.slice(0, -1) + ", " + cookieUserData.slice(1));
	}
	else {
		return escape(cookieUserData);
	}
}

// ###############################################################################################
// #################  controls the me / me too icons on the brand home page #####################
var featureMeTagCalloutVal = "";
function setFeatureCallout(_val) {
	featureMeTagCalloutVal = _val;
	thisMovie("main_content_flash").featureCallout();
}
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
}
function getFeatureCallout(){
	return featureMeTagCalloutVal;
}
var dateAtPageStart = getCurrentTime();
function getCurrentTime(){
	_currentTime = new Date();
	return Number(_currentTime);
}
function getStartTime(){
	return dateAtPageStart;
}

// ==========================================================
// setFlashCookie() 
// ==========================================================
function setFlashCookie(param) {

	// see if we already have a usersesion data cookie
	var cookie = Cookie.get('usersessiondata');
	var UserSessionData = new Object;

	if(cookie) {
		//Decompress JSON values of userData
		UserSessionData = eval('(' + cookie + ')');
	}

	UserSessionData[param] = true;
	Cookie.set('usersessiondata', Json.toString(UserSessionData), {duration: 0, path: "/"});

}

function resetMLC(newMLC){
	hbx.mlc = newMLC;
	_hbSet('vcon', newMLC);
	_hbSend();
}

function getDealerState(){
	return dealerInfo.state;
}

//This is Garbage Clean up for IE 7 
function garbage_remove(){
	if (navigator.userAgent.indexOf("MSIE 7") > -1 || navigator.userAgent.indexOf("MSIE 6") > -1 || navigator.userAgent.indexOf("MSIE 8") > -1) {
		// overriding the mootools garbage collection event listener in IE7 only for removing listeners on OBJECT tags that IE7 can't reference
		Garbage.trash = garbage_trash;
	}
}

function garbage_trash(){
	// overriding the mootools garbage collection event listener in IE7 only for removing listeners on OBJECT tags that IE7 can't refernece
	Garbage.collect(window);
	Garbage.collect(document);
	Garbage.elements.each(function(el){
		if(el.toString().indexOf("http://") == -1 && el.toString().indexOf("javascript:") == -1) {
			//el.removeEvents();
			el.extend = null;
		}
	});
}

// ==========================================================
// data send to flash() -
// ==========================================================
function getFlashDataFromDiv(divID, flashDivID)
{
	// set the sizes
	jQuery('#'+flashDivID).css('height',(jQuery('#'+divID).height()));
	if(cllc.constants.get('BRAND_ID') == "chrysler"){ jQuery('#low_band_src').css('display', 'none'); }
	
	// feed the data
	var page_XHTML = "<?xml version='1.0' encoding='UTF-8'?>";	
	page_XHTML += cllc.dom2xml.convert('#' + divID);
	window.document[flashDivID+"_flash"].setData(page_XHTML);
	
	jQuery('#low_band_src').css('display', 'none');
}

onload_register('handleSSIEmbeddedDisclaimers();');
onload_register('highlightVehicleNav();');
onload_register('check_pricing();');
onload_register('setDisclaimerLinkTitle();');
onload_register('garbage_remove();');
if (window.ie6) { onload_register('iePngFix();'); }

function disclaimerBridge(disclaimerId)
{
	return jQuery(disclaimerId)[0].innerHTML;
}

