////////////////////////////////////////////////////////////////
// HomeNet JS Core Site Library
// HomeNet Inventory Hosting
// (c) 2010, HomeNet Automotive LLC
////////////////////////////////////////////////////////////////

// ***************************************
// Define our Modules.InventoryHosting namespace
// ***************************************
if (typeof HNSITE == 'undefined') HNSITE = {};
if (typeof HNSITE.Modules == 'undefined') HNSITE.Modules = {};
HNSITE.Modules.InventoryHosting = {};


// ***************************************
// Main Page Initializer
// ***************************************
$j(function() {

	// Setup the side search
	$j.getScript(HNSITE.Settings.Environment.ScriptPool + 'hnsite-inventory-sidesearch.min.js', function() {
		HNSITE.Modules.InventoryHosting.SideSearch.Init({
			inventoryColumn: 'div.vehicle-results-wrap',
			panelHeader: 'h4'
		});
	});
	
	// Photo and Video Viewer Lightbox
	$j("a.launch-photo-viewer").fancybox({
		'width': 650,
		'height': 540,
		'autoScale': false,
		'transitionIn': 'none',
		'transitionOut': 'none',
		'type': 'iframe'
	});
	$j("a.launch-video-viewer").fancybox({
		'width': 420,
		'height': 390,
		'autoScale': false,
		'transitionIn': 'none',
		'transitionOut': 'none',
		'type': 'iframe',
		'scrolling'   : 'no'

	});
	
	// Allow browse page cells to be clickable as well for linking to details page
	$j("#page-contents div.vehicle-results-wrap > .vehicle-listing").delegate(".vehicle-inner-wrap", "click", function(event) {
		var detailsLink = $j(this).siblings(".vehicle-title-wrap").find("> h6 > a").attr('href');
		location.href = detailsLink;
	});
	
	HNSITE.UI.Custom.StandardForm.Initializer({
		formName: 'no-results-form',
		submitClass: 'no-results-submit',
		postFile: '/inventory/browse/no-results-form.asp',
		thanksMessage: '<p>We have successfully received your inquiry and will be in contact with you as soon as possible. ' + 
					   'If you have questions in the meantime, please call us. Thank you for choosing Alan Byer Volvo!</p>'
	});
});

// ***************************************
// Define our InventoryHosting.Browse namespace
// ***************************************
HNSITE.Modules.InventoryHosting.Browse = {};

// <summary>
// View the users checked vehicles side by side on the comparison page
// </summary>
HNSITE.Modules.InventoryHosting.Browse.CompareVehicles = function(element, parent) {
	var compareUrl = '/inventory/browse/compare.asp?compare=';
	var results = HNSITE.UI.Checkboxes.Count(element, parent);
	if (results.checked > 1 && results.checked < 5) {
		location.href = compareUrl + HNSITE.UI.Checkboxes.Values(element, parent, function(cbThis) {
			return cbThis.checked;
		}).join('&compare=');
	}
	else if (results.checked >= 5)
		$j.jGrowl("Please select less than five vehicles in order to compare them", { life: 5000, header: 'Compare Vehicles', theme: 'hn-browse-jgrowl' });
	else
		$j.jGrowl("Please select more than one vehicle in order to compare them", { life: 5000, header: 'Compare Vehicles', theme: 'hn-browse-jgrowl' });
};

// <summary>
// Functionality for the sort by drop box to change to its provided urls
// </summary>
HNSITE.Modules.InventoryHosting.Browse.SortBy = function(element) {
	location.href = $j(element).val();
};

