//jQuery's noConflict mode
jQuery.noConflict();

//extension de Jquery pour trouver les positions d'un élément.
jQuery.fn.extend({
	findPos : function() {
       var obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
	} 
});

/*
	Class:    	dwIMageProtector
	Author:   	David Walsh
	Website:    http://davidwalsh.name
	Version:  	1.0.0
	Date:     	08/09/2008
	Built For:  jQuery 1.2.6
*/

jQuery.fn.protectImage = function(settings) {
	settings = jQuery.extend({
		image: 'http://www.nsc-groupe.com/fileadmin/templates/NSC_Nonwoven/img/blank.gif',
		zIndex: 10
	}, settings);
	return this.each(function() {
		var position = jQuery(this).position();
		var height = jQuery(this).height();
		var width = jQuery(this).width();
		jQuery('<img />').attr({
			width: width,
			height: height,
			src: settings.image
		}).css({
			border: '0px',
			top: position.top,
			left: position.left,
			position: 'absolute',
			zIndex: settings.zIndex
		}).appendTo('body')
	});
};



/*jQuery(window).bind('load', function() {
	jQuery('img').protectImage();
});
*/

jQuery(document).ready(function(){
	
	//redirectLang();
	
	
	jQuery('.group').children('.headerGroup').toggle(
    function(){
    //alert(jQuery(this).html());
      jQuery(this).parent().parent().children('.group').each(function (src){
				jQuery(this).children('.contentGroup').slideUp('slow');
			});
			jQuery(this).parent().children('.contentGroup').slideDown('slow');
		},
		function(){
      jQuery(this).parent().parent().children('.group').each(function (src){
				jQuery(this).children('.contentGroup').slideUp('slow');
			});
			jQuery(this).parent().children('.contentGroup').slideDown('slow');
		}
  )
	
	jQuery('.titleAgent').click(
		function(){
			jQuery('.titleActif').each(function (src){
				jQuery(this).removeClass('titleActif');
			});
			var className = jQuery(this).attr('class');
			className = className.replace('titleAgent ','');
			jQuery(this).addClass('titleActif');
			jQuery('.hiddenTxt').each(function (src){
				jQuery(this).hide();
			});
			jQuery('.'+className).slideDown('slow');
		}/*,
		function(){
			jQuery(this).removeClass('titleActif');
			var className = jQuery(this).attr('class');
			className = className.replace('titleAgent ','');
			
			var classNameH = jQuery(this).attr('class');
			jQuery('.'+className).each(function (){
				classNameH = jQuery(this).attr('class');
				if (classNameH.indexOf('titleAgent') == '-1'){
					jQuery(this).slideUp('slow');
				}			
			});
		}*/
	);
	
	jQuery('.selectBox select').change( function() {
		//jQuery('.'+jQuery(this).val()).click();
		jQuery('#'+jQuery(this).val()).parent().parent().children('.headerGroup').click();
		href = document.location.href.split('#');
		document.location=href[0]+"#"+jQuery(this).val();
	});
	
	jQuery('.menuCasquetteOn').hide();
	
	jQuery('.btnNSC_off').click( function (){
		var posElmMK 		= jQuery(this).findPos();
		jQuery('.menuCasquetteOn').hide();
		jQuery('.menuCasquetteOn').css({top: (posElmMK.y)});
		jQuery('.menuCasquetteOn').css({left: (posElmMK.x-203)});
		jQuery('.menuCasquetteOn').slideDown();
	});
	
	jQuery('.btnNSC_on').click( function (){
		jQuery('.menuCasquetteOn').slideUp();	
	});
	
	jQuery('#id').change( function(){
		document.location="/index.php?id="+jQuery(this).val()+"&L="+jQuery("#lang").val();
	});
	
});

function redirectLang(){
	var domaine = 	"http://www.nsc-nonwoven.com/";
	var langBrowser = obtenirCodeLangueNavig();
	
	var uri	=	(document.location.href).replace(domaine,'');

	var langUri = uri.toLowerCase().substring(0, 2);
	if ( langUri == '' || (langUri != 'fr' && langUri != 'en') ){
		if ( langBrowser == 'fr'){
			document.location.href=domaine+'fr/accueil.html';
		}else{
			document.location.href=domaine+'en/home.html';
		}
	}
}

function obtenirCodeLangueNavig() {
	var lct="en";
	if (navigator.language) {
		lct=navigator.language.toLowerCase().substring(0, 2);
	} else if (navigator.userLanguage) {
		lct=navigator.userLanguage.toLowerCase().substring(0, 2);
	} else if (navigator.userAgent.indexOf("[")!=-1) {
	    var debut=navigator.userAgent.indexOf("[");
	    var fin=navigator.userAgent.indexOf("]");
	    lct=navigator.userAgent.substring(debut+1, fin).toLowerCase();
	}
	return lct;
} 

