/**
 * @version 1.0
 *
 * @copyright Copyright 2010 WnG Solutions Sàrl, all rights reserved
 * @author Daniel Calderini <daniel [DOT] calderini [AT] wng [DOT] ch>
 * @package WnG Solutions
 */

// Initialisation de l'objet général "WnG"
var WnG = WnG || {};

/**
 * Fonction appelée automatiquement au chargement de la page
 *
 * @return void
 */
WnG.init = function() {
	WnG.tools.searchbox();
	WnG.tools.menuMain();
	WnG.tools.menuGroup();
	WnG.tools.jumpbox();
};


/**
 * Outils du site
 * @var Object
 */
WnG.tools = {
	/**
	 * Initialisation de la box de recherche dans la barre d'outils
	 *
	 * @return void
	 */
	searchbox: function() {
		var defaultValue = jQuery('#tx_indexedsearch_sword').attr('value');
		
		jQuery('#tx_indexedsearch_sword').focus(function() {
			var currentValue = jQuery(this).attr('value');
			if (currentValue == defaultValue)
				jQuery(this).attr('value', '');
		});
		
		jQuery('#tx_indexedsearch_sword').blur(function() {
			var currentValue = jQuery(this).attr('value');
			if (currentValue == '')
				jQuery(this).attr('value', defaultValue);
		});
	},
	
	/**
	 *
	 */
	menuGroup: function() {
		jQuery('#menuVaudoiseGroup li:not(#menuVaudoiseGroup li li, #menuVaudoiseGroup li li li)').hover(function() {
			jQuery(this).addClass('menuHover');
		}, function() {
			jQuery(this).removeClass('menuHover');
		});
	},
	
	/**
	 * Effet survol du menu principal
	 *
	 * @return void
	 */
	menuMain: function() {
		jQuery('#menuMain li:not(#menuMain li li, #menuMain li li li)').has('ul').hover(function() {
			jQuery(this).addClass('menuHover');
		}, function() {
			jQuery(this).removeClass('menuHover');
		});
		/*
		jQuery('#menuMain li:not(#menuMain li li, #menuMain li li li)').has('ul').hover(function(event) {
			jQuery(this).addClass('menuHover');
			jQuery('html').hover(function() {
				jQuery('#menuMain li:not(#menuMain li li, #menuMain li li li)').removeClass('menuHover');
			});
		});*/
	},
	
	/**
	 * Jump box (listes déroulantes)
	 *
	 * @return void
	 */
	jumpbox: function() {
		jQuery('.jumpbox').each(function(){
			// Initialisation
			jQuery(this).height(jQuery(this).find('li:first').height());
			jQuery(this).find('li:first').addClass('first');
			var notFirstLink = jQuery(this).find('li:not(:first)');
			
			// Effet survol
			notFirstLink.hide().hover(function() {
				jQuery(this).toggleClass('hover');
			});
			
			// Ouverture et fermeture de la liste
			jQuery(this).find('li').first().click(function() {
				jQuery('.jumpbox li:not(:first-child)').not(notFirstLink).hide();
				notFirstLink.toggle();
				return false;
			});
			
			// Click à coté de la liste
			jQuery('html').click(function() {
				notFirstLink.hide();
			});
			
			jQuery(this).click(function(e) {
				e.stopPropagation();
			});
		}).children('ul').css('position', 'absolute');
	}
};

