(function($) {
$.fn.reverseOrder = function() {
	return this.each(function() {
		$(this).prependTo( $(this).parent() );
		//console.log(this);
	});
};
})(jQuery);

cllc = {
	model: {
		default_search: null
	},
	
	exists: true, // Indicates that the CLLC core has loaded and is required to use any other module.
	init: function() {
		// Allow console logging across all browsers
		try { console.log('console ready'); } catch(e) { var console = { log: function() {} }; }
		cllc.setup_nav();
		cllc.toggle_sidebar();
	},

	// function standard_error_handler
	// Runs the standard error handler which merely logs errors to the console. Typically called via catch{} blocks.
	// PARAMS
	//     error: [required] The thrown Error() object or a string describing the error
	standard_error_handler: function(error) {
		// If a string was provided, simply log the error string
		if (typeof(error) == "string" || typeof(error) == "STRING") {
			var error_msg = 'error: '+error;
		}
		// If an Error() was thrown, log its name and message.
		// If the browser provides it, also log the file name and line number of the error.
		else {
			var error_msg = "error ("+error.name;
			if (error.lineNumber) {
				error_msg += ", line "+error.lineNumber+", "+error.fileName;
			}
			error_msg += "): "+error.message;
		}
		console.log(error_msg);
	},
	
	setup_nav: function() {
		$('#cllc_corp_header ul.menu > li').each(function() {
			var menu = $(this).find('ul:first');
			$(this).data('menu_size', {
				'padding_top': menu.css('padding-top'),
				'height': menu.height(),
				'padding_bottom': menu.css('padding-bottom')
			});
		})
		.hover(function(e) {
			var menu_size = $(this).data('menu_size');
			
			$(this).find('ul').stop().css('height', 0).show().animate({
				'padding-top': menu_size.padding_top,
				'height': menu_size.height,
				'padding-bottom': menu_size.padding_bottom
			}, {queue: false, duration: 200});
		}, function(e) {
			$(this).find('ul').animate({
				'padding-top': 0,
				'height': 0,
				'padding-bottom': 0
			}, {queue: false, duration: 200, complete: function() {
				$(this).hide();
			}});
		});
		
		// Allow clicking anywhere in the menu item
		$('#cllc_corp_header ul ul li').live('click', function(e) {
			window.location.pathname = $(this).find('a').attr('href');
		});

		// Highlight this page's nav item
		$("#cllc_corp_header ul li a[href='"+window.location.pathname+"']")
			.closest('ul.menu > li')
			.find('h4')
			.addClass('active');
			
		// Setup search nav
		var search_nav = $('#cllc_corp_header #search_nav input');
		cllc.model.default_search = search_nav.val();
		search_nav.focus(function(e) {
			if ($(this).val() == cllc.model.default_search) {
				$(this).val('');
			}
		}).blur(function(e) {
			if ($.trim($(this).val()) == '') {
				$(this).val(cllc.model.default_search);
			}
		});
		
		$("#search_nav_submitter").click(function(e) {
			$('#search_nav').submit();
		});
	},
	
	toggle_sidebar: function() {
		if ($.trim($('.rightCol').html()) == '') {
			$('.rightCol').hide();
		}
	}
};

$(cllc.init);




//Universal Window Function Type "yes" or "no" for scrollBar
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;
	window.open(aU,wN,wO);
	aC ? window.close():"";
}

function prepBrand(str) {
    return str + "?bid=chryslerllc&pid=chryslerllc.com&adid=www.chryslergroupllc.com&rid=&hrf=http://www.chryslerllc.com";
}