/**
 * @website www.subaru.com
 * @description This file creates the main menu shown in the entire site.
 * @date 07/29/2011
 * @author Carlos Vega
 * @dependencies jquery-1.6.1.js
 * @version 1.0
 * Copyright (c) 2011 Subaru.com
 */

$(document).ready(function() {
	create_globalMenu();
});

/**
 * @description Creates the hover event for each menu.
 */
function create_globalMenu() {
	$('#fdr_detail').hover(
		function() {
			$(this).show();
		}, function() {
			$(this).hide();
		}
	);

	$('.n_find').hover(
		function() {
			$('#fdr_detail').show();
		}, function() {
			$('#fdr_detail').hide();
		}
	);

	$('.n_drop, .n_drop_vehicles').hover(
		function() {
			$(this).addClass('active');
		}, function() {
			$(this).removeClass('active');
		}
	);

	$('.v_drop').hover(
		function() {
			var isLastChild = $(this).hasClass('last');
			if(!isLastChild){
				var v_rel = $(this).children('a.v_model').attr('rel').split("~");
				var v_model = v_rel[0];
				var v_img_loaded = $('#img_'+v_model).hasClass('v_img_loaded');
				if (!v_img_loaded) {
					var modeYear = v_rel[1].substring(2, 4);
					var image_path = pathPrefix;
					image_path += "images/my"+modeYear+"/" + v_model + "/compare_default.png";
					var v_img = '<img src="'+image_path+'" alt="'+v_model+' image" />';
					$('#img_'+v_model).addClass('v_img_loaded').empty().append(v_img);
				}
			}
			$(this).addClass('active');
			$(this).parent('ul').addClass('flyout');
		}, function() {
			$(this).removeClass('active');
			$(this).parent('ul').removeClass('flyout');
		}
	);
}
