var Ctrl = new function()
{
  this.messagerFlash = function(cible) // un clic du flash, résultat sur le html
  {
	var url = Util.action2href("dms/produitType/messagerFlash")+"?cible="+cible;
	$("div.txtCible").load(url);
  }
  
  this.init = function(options)
  {
		if ($.validator)
      $.validator.messages = 
			{
			    required:   '&nbsp;<img src="'+page_options.relative_url_root+"dmsPlugin/images/16/asterisk_orange.png"+'" />'
			                +'&nbsp;<span style="color:#D57213; font-style:italic;">Required</span>',
			    email:      "Thanks to enter a valide e-mail.",
			    url:        "Thanks to enter a valid url.",
			    number:     "Thanks to enter a valid number."
			};
		// Démarrage des flashs / accueil
		
		var flash_class = "flash_accueil";
		var flash_dir = "images/flash_accueil.swf";
		var flash_width = 635;
    var flash_height = 210;
    var flash_name = "nomFlashAccueil";       // sans importance
    var flash_version = "9";
		
    if ($("div."+flash_class).length && !options.no_flash)
    {
			var new_id = "id_for_"+flash_class;
			$("div."+flash_class).attr("id", new_id);
      var so = new SWFObject(options.relative_url_root+flash_dir, flash_name, flash_width, flash_height, flash_version, "");
      so.addParam("wmode", "opaque");
      so.write(new_id);
    }
	
			// produit
		
		var flash_class = "flash_squelette";
		var flash_dir = "images/flash_squelette.swf";
		var flash_width = 150;
    var flash_height = 400;
    var flash_name = "nomFlashSquelette";       // sans importance
    var flash_version = "9";
		
    if ($("div."+flash_class).length && !options.no_flash)
    {
			var new_id = "id_for_"+flash_class;
			$("div."+flash_class).attr("id", new_id);
      var so = new SWFObject(options.relative_url_root+flash_dir, flash_name, flash_width, flash_height, flash_version, "");
      so.addParam("wmode", "opaque");
      so.write(new_id);
    }
		
		// Pré-validation des formulaires
		
    $("form.validate_me").each(function(){
			$(this).validate({});
	  });
	 
	 if ($("div.affiche_message_reussit").length) {
        $.facebox.settings.classBody = 'newsletter';
        $.facebox.settings.loadingImage = Util.img_src("../../css/facebox/loading.gif");
        $.facebox.settings.closeImage = Util.img_src("../../css/facebox/close.gif");
        $.facebox("<span style='color:#fff;' class='message_reussit'>Your request has been processed and is being validated</span>");
      }
	 if ($("div.affiche_message_erreur").length) {
        $.facebox.settings.classBody = 'newsletter';
        $.facebox.settings.loadingImage = Util.img_src("../../css/facebox/loading.gif");
        $.facebox.settings.closeImage = Util.img_src("../../images/fermer_facebox_newsletter.jpg");
        $.facebox("<span style='color:red;' class='message_reussit'>Your request has been cancelled because an error occurred.</span>");
      }
	 // Menu accordéon

//	    $("ul.accordion_me").accordion({
//				navigation: true,
//				header: "a.a_acc_head",
//				active: '.selected',
//				autoHeight: false,
//				alwaysOpen: false,
//				clearStyle: true
	
//			}).find("a.a_acc_head").rebind("click", function()
//			{
//				if ($('.action_normal').length) 
//		  	location.href = $(this).attr("href");
//		  else {
//		  	$('div.produitType').load($(this).attr('href') + '/afficheCateg?produit_type_id=' +$(this).attr('rel'));
//				$('div.image_categ_produit').load($(this).attr('href') + '/imageCateg?produit_type_id=' +$(this).attr('rel'));
//		  }
				
//			});
		$('a.image_produit').livequery(function(){
			$(this).each(function(){
				$(this).rebind('click', function(){
					  $.facebox.settings.loadingImage = Util.img_src("../../css/facebox/loading.gif");
	          $.facebox.settings.closeImage = Util.img_src("../../css/facebox/close.gif");
	          $.facebox.loading();
	          $.get($(this).attr('href'), function(data){
	          $.facebox(data);
	          if($.browser.msie && $.browser.version < 7)
	           $("#facebox").bgiframe();
	        });
	          return false;
	        });
			});
		});
		
		$('a.info').rebind('click', function(){
      $('.formulaire_newsletter').toggle(500).show();
			return false;
    });
		// Rotation des images de focus
		
		$('#main_focus_cycle').cycle();
		
	}
};

$(function()
{
  Ctrl.init(page_options);
});

