/*		Web 2.0 stuff		*/

var $jQ = jQuery.noConflict();

(function($jQ) {
	$jQ.hasCSS = function() {
		$jQ('body').append(
                $jQ(document.createElement('div')).attr('id','css_test')
                .css({ width:'1px', height:'1px', display:'none' })
        );
        var _v = ($jQ('#css_test').width() != 1) ? false : true;
        $jQ('#css_test').remove();
        return _v;
	};
})(jQuery);

(function($jQ) {
  $jQ.fn.toggleFocus = function() {
	return this.each( function() {
	  var input =  $jQ(this) ;
	  var label = input.parents("form").find("label");
	  label.each(
		function (){
		   if ($jQ(this).attr("for")==input.attr("id")){
			if ($jQ(this).find(".jblurval").text()!=""){
			  label_text = $jQ(this).find(".jblurval").text();
			  $jQ(this).find(".jblurval").css("display","none");
			}
			else {
			  $jQ(this).css("display","none");
			  var label_text = $jQ(this).text() || "" ;
			}
			/*  add value in input  */
			function insertMsg( msg ) {
				input.val(msg);
			}
			input.focus( function() {
				var valeur = input.val() ;
				if ( label_text == valeur ) {
					insertMsg("");
				}
				input.blur(function() {
					if (input.val() != "" ){
						valeur = input.val();
					} else {
						valeur = label_text ;
					}
				   insertMsg(valeur);
				});
			});
			insertMsg(label_text);
		  }
	  });
	});
  };
})(jQuery);



jQuery(document).ready(function($jQ) {
  /*______ Carte de voeux ___________*/	
	
  //if (!$jQ.cookie('voeux2010')) {
  //  $jQ("#Page").append('<a href="http://www.groupe-ufg.com/fileadmin/voeux-2010/LFP_Voeux_2010.html" id="hidden_link" class="hidden iframe">hidden_link</a>');
  //  $jQ("#hidden_link").fancybox({ 'frameWidth': 880, 'frameHeight': 470, 'overlayOpacity':0.7, 'overlayShow': true, 'overlayColor':'#000' });
  //  $jQ("#hidden_link").trigger('click');    
  //  var date = new Date();
  //  date.setTime(date.getTime() + (24 * 60 * 60 * 1000));
  //  $jQ.cookie('voeux2010', 'vu', { path: '/', expires: date });
  //}
	/*____________  open close ______________*/
/*	function toggleImg(src){
		var nwsrc;
		if( /open/.test(src) ) {
			nwsrc = src.replace("open","close");
		}else if(/close/.test(src)){
			nwsrc = src.replace("close","open");
		}else {
			return nwsrc;
		}
		return nwsrc;
	}
    if($jQ(".OpenClose").length > 0) {
        $jQ(".OpenClose").each(function(){
            var OC = $jQ(this);
            var innOC =  OC.find(".inner2");
            var img = OC.find(".btn_OpenClose img");
            img.click(function(event){
                event.stopPropagation();
                var src =  img.attr("src");
                var newsrc = toggleImg(src);
                innOC.slideToggle("slow",function(){
                    img.attr("src",newsrc);
                });
            });
        });
    }
	*/


	 $jQ(".OpenCloseGp").prepend('<p class="Toggle"><a href="javascript:;">Tout ouvrir / Tout fermer</a></p>');
	 $jQ(".OpenCloseGp .Toggle a").click(function(event){
	    event.stopPropagation();
	    $jQ(this).toggleClass("close");
      if (this.className == "close"){
        $jQ(this).parents(".OpenCloseGp").find(".inner2").slideUp("slow");
        $jQ(this).parents(".OpenCloseGp").find(".OpenClose").removeClass("on");
      }
      else {
        $jQ(this).parents(".OpenCloseGp").find(".inner2").slideDown("slow");
        $jQ(this).parents(".OpenCloseGp").find(".OpenClose").addClass("on");
      }
    });

	 if($jQ(".OpenClose").length > 0) {
        $jQ(".OpenClose").each(function(){
            var OC = $jQ(this);
			var btn_OC = $jQ(this).find(".btn_OpenClose");
            var innOC =  OC.find(".inner2");
            btn_OC.click(function(event){
                event.stopPropagation();
                innOC.slideToggle("slow",function(){
                    OC.toggleClass("on");
                });
            });
        });
    }


/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */

(function($jQ) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */

	$jQ.fn.equalizeCols = function(){
		var height = 0,
			reset = $jQ.browser.msie ? "1%" : "auto";
		return this
			.css({"height" : reset})
			.each(function() {
				height = Math.max(height, this.offsetHeight);
				ht = "auto";
				minH = Math.max(height, this.offsetHeight);
				if (jQuery.browser.msie &&parseInt(jQuery.browser.version)<=6) {
				 ht = Math.max(height, this.offsetHeight);
				}
			})
			.css({"height" : ht, "minHeight" : minH})
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$jQ(this).css({"height" : height - (h - height)});
				};
			});
	};

})(jQuery);

if ($jQ('.moduleBox').length>0){
  $jQ('.moduleBox').equalizeCols();
}

/*______ focus input recherche ___________*/
$jQ('.jblur').toggleFocus();


/*______ Redirection Gamme produit ___________*/
if ($jQ('select#gammes').length>0) {
  $jQ('select#gammes').change(function () {
	if ($jQ('select#gammes option:selected').val()!=-1) {
		url_action = $jQ('select#gammes option:selected').val();
		$jQ('form[@name="tousprofils"]').attr('action',url_action);
		$jQ('form[@name="tousprofils"]').submit();
	}
  });
}


});


/* auto completion*/
var dataKeys = {};

jQuery(document).ready(function() {

	function fnTraiteResponse(data) {
		if( $jQ("#mot_cle").length > 0 ) {
			$jQ("#mot_cle").autocomplete(data, {
				minChars:1,
				matchSubset:1,
				max: 12,
				autoFill: true,
				mustMatch: false,
				matchContains: false,
				scroll:false,
				width:117,
				selectOnly:1
			});
		}
	}

	var dorequest = function(url){        //fn pour envoyer une requete selon url
		$jQ.getJSON( url, function(tab){
			if( tab ) {
				dataKeys = tab;
				var data = [];
				for(var v in tab) {
					data.push( v );
				}
				fnTraiteResponse( data );
			}
		 });
	}

	dorequest("index.php?eID=tx_sa_produits");

	if( $jQ("#AnnexeEntrees li").length > 0 ) {
		$jQ("#AnnexeEntrees li:has('ul')").bind("mouseenter focus", function(){$jQ(this).addClass('over');});
		$jQ("#AnnexeEntrees li:has('ul')").bind("mouseleave blur", function(){$jQ(this).removeClass('over');});
	}
	
	/* OUR RANGE OF PRODUCTS no margin for the last child */
	if( $jQ(".productrange .line .cell").length > 0 ) {
		$jQ(".productrange .line .cell:last-child").addClass("nomargin");
	}
	/* EN HOMEPAGE */
	if( $jQ("#Col1 .line .cell").length > 0 ) {
		$jQ("#Col1 .line .cell:last-child").addClass("nomargin");
	}
});
