Shadowbox.init();
var $jq = jQuery.noConflict();

$jq(document).ready(function(){
	
	/**
	 * Roll over image
	 */
	$jq('.rollOver').rollOver();
	
	/**
	 * Roll over image appellations
	 */
	$jq('.rollOverAppellations').rollOver({useSpecificPath : true});
	 
	 $jq('a.image_appellation').live('mouseover',function(){
		$jq(this).attr('rev',$jq(this).find('img:first').attr('src'));
		$jq(this).find('img:first').attr('src',$jq(this).attr('rel'));
	 })
	 
	 $jq('a.image_appellation').live('mouseout', function(){
		$jq(this).find('img:first').attr('src',$jq(this).attr('rev'));
	 });
	
	/**
	 * Roll over image index cave
	 */
	 $jq('a.image_category').live('mouseover',function(){
		$jq(this).attr('rev',$jq(this).find('img:first').attr('src'));
		$jq(this).find('img:first').attr('src',$jq(this).attr('rel'));
	 })
	 
	 $jq('a.image_category').live('mouseout', function(){
		$jq(this).find('img:first').attr('src',$jq(this).attr('rev'));
	 });
	
	/**
	 * Vidage des champs sur click
	 */
	$jq('.deleteDefaultValueOnFocus').deleteDefaultValueOnFocus();
	
	/**
	 * Erreurs des champs de Formulaires
	 */
	initFormError();
	  
	/**
	 * FILTRE TYPE ANNONCE (club)
	 */
	if($jq( '#form_vente_entre_amis_search' ).length>0){
		$jq('#form_vente_entre_amis_search_type_annonce').live('change', function(){
			$jq( '#form_vente_entre_amis_search' ).submit();
		}); 
	}
	  
	/**
	 * FORM ANNONCE (club)
	 */
	if($jq( '#form_club_petites_annonces_depot' ).length>0){
		$jq('#form_club_petites_annonces_depot').formDepotAnnonce();
	}
	
	/**
	 * FORMULAIRE DE RECHERCHE VIN
	 */
	if ($jq('#form_full_search').length>0){
		$jq('#form_full_search').formFullSearch();
	}
	
	/**
	 * FORMULAIRE DE RECHERCHE NEGOCE
	 */
	if ($jq('#form_negoce_search').length>0){
		$jq('#form_negoce_search').formNegoceSearch();
	}
	
	/**
	 * GESTION DU ZOOM PRODUIT
	 */
	if ($jq('#fiche_produit_photo').length>0){
		$jq(document).on('mouseenter', 'div.centre_left', function(){
			$jq( '#zoom_produit' ).css('display', 'none');
		});
		$jq(document).on('mouseenter', '#zoom_produit', function(){
			$jq( '#zoom_produit' ).css('display', 'none');
		}); 
		$jq(document).on('mouseleave', 'div.centre_left', function(){
			$jq( '#zoom_produit' ).css('display', 'block');
		}); 
	} else {
		$jq( '#zoom_produit' ).css('display', 'none');
	}
	
	  
	/**
	 * MODULE DE TRI
	 */
	if($jq( '#module_tri_catalogue' ).length>0){
		var script_args_tri = '';
		if ( $jq('#script_args_tri' ).length>0){
			script_args_tri = $jq('#script_args_tri').val();
		}
		$jq( '#module_tri_catalogue' ).moduleTriCatalogue({searchParams : script_args_tri});
	}
	
	/**
	 * GESTION DES QUANTITES dans la fiche produits standard
	 */
	 if ($jq('#choix_conditionnement').length>0){
		 if ($jq('#choix_conditionnement').val() == ''){
			 $jq('#quantite_select').css('display','block');
			 $jq('#quantite_input').css('display','none');
		 } else {
			 $jq('#quantite_select').css('display','none');
			 $jq('#quantite_input').css('display','block');
		 }
		 
		 $jq('#choix_conditionnement').live('change', function(){
			if ($jq('#choix_conditionnement').val() == ''){
				$jq('#quantite_select [value="1"]').attr('selected',true);
				$jq('#quantite_select').css('display','block');
				$jq('#quantite_input').css('display','none');
			} else {
				$jq('#quantite_input').val("1");
			 	$jq('#quantite_select').css('display','none');
			 	$jq('#quantite_input').css('display','block');
			}
		});
	 } else {
		 if ($jq('#quantite_select').length>0){
			 $jq('#quantite_select').css('display','none');
		 }
	 }
	 
	 /**
	  * GESTION DU POPUP D'ACHAT DE LA CARTE CLUB
	  */
	 if ($jq('#popup_ajout_carteclub_destinataire').length>0){
		  $jq('#popup_ajout_carteclub_destinataire').formChoixDestinataire();
	 }
	 
	 
	 /**
	  * GESTION DU GOOGLEMAP DES BONNES ADRESSES
	  */
	var googlemapPageOptions = {
		disableDefaultUI:true,
		scrollwheel: false,
		zoomControl: false,
		draggable: false,
		disableDoubleClickZoom: true,
		keyboardShortcuts: false
	};
	if ($jq('#googleMapBonnesAdressesContainer').length>0){
		$jq('#googleMapBonnesAdressesContainer').googleMapBonnesAdresses({mapOption : googlemapPageOptions, mode : 'mini'});
	}
	if ($jq('#googleMapBonnesAdressesLayer').length>0){
		$jq('#googleMapBonnesAdressesLayer').googleMapBonnesAdresses();
	}
	
	
	
	/**
	 * ACCORDEONS BOUTIQUE
	 */
	if($jq( '.accordionContainer' ).length>0){
		$jq( '.accordionContainer' ).wfAccordion();
	}
	  
	  /**/
});
