if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

function getQueryVariable(pURL) {
  var lvVars = new Array();

  if (pURL) 
  {
    var lvParams = pURL.split('&');
    for (var i=0;i<lvParams.length;i++) 
    {
      nameValue = lvParams[i].split('=');
      lvVars[nameValue[0]]=(nameValue.length == 2)? nameValue[1]:null;
    }
  }

  return lvVars;
}


$(document).ready(function() {
    
    //Vérifier si IE
    var isIE = false;
    if (($.support.opacity != true) && ($.support.objectAll != true)) {
        isIE = true;
    };
    //Vérifier numero version
    (function($) {
        var userAgent = navigator.userAgent.toLowerCase();
    
        $.browser = {
            version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
            safari: /webkit/.test( userAgent ),
            opera: /opera/.test( userAgent ),
            msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
            mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
        };
    })(jQuery);
    var browserVersion = Math.round($.browser.version);
    //Vérifier IE6
    var isIE6 = false;
    if ((isIE == true) && (browserVersion == 6)) {
        isIE6 = true;
    };
    //Vérifier IE7
    var isIE7 = false;
    if ((isIE == true) && (browserVersion == 7)) {
        isIE7 = true;
    };
    //console.log(isIE,isIE6,browserVersion);
		
    /*
    //recherche avancée
    $('#recherche-avancee-plus').append('<div class="fermer"><a href="#" title="Fermer">X</a></div>');
    $('#recherche-avancee-plus .fermer a').click(
        function(){
            $('#recherche-avancee-plus').slideUp('slow');            
            return false;
        }
    )
    $('#recherche-simple div input').focus(
        function(){
            $('#recherche-avancee-plus').slideDown('slow');            
        }
    );
    
    //effet hover menu #nav
    $('#nav li:not(.active)').hover(
        function(){
            $(this).addClass('hover');
            $('ul',this).slideDown();
        },
        function(){
            $(this).removeClass('hover');
            $('ul',this).slideUp('slow');
        }
    );
		*/
    
    //Boîte compte
    $('#header #compte li').hover(
        function(){
            $('ul', this).show();
        },
        function(){
            $('ul', this).hide();
        }
    );
    
    //inscription affichage formulaire groupe/agence
    $('#inscription #inscription-form .agence').hide();
    $('#inscription-groupe-conteneur input[value=0]').attr('checked','checked').click(
        function(){
            $('#inscription #inscription-form .agence').hide();
            $('#inscription #inscription-form .groupe').show();
        }
    );
    $('#inscription-groupe-conteneur input[value=1]').click(
        function(){
            $('#inscription #inscription-form .groupe').hide();
            $('#inscription #inscription-form .agence').show();
        }
    );
    
    //effet hover boîtes noires pour ie
    $('.article a').hover(
        function(){
            var parentElem = $(this).parent().parent();
            $(parentElem).addClass('hover');
        },
        function(){
            var parentElem = $(this).parent().parent();
            $(parentElem).removeClass('hover');
        }
    );
    $('#liste div.row div.article a').hover(
        function(){
            var parentElem = $(this).parent().parent();
            $(parentElem).addClass('hover');
        },
        function(){
            var parentElem = $(this).parent().parent();
            $(parentElem).removeClass('hover');
        }
    );
    $('.popup-album div.row div.article a').hover(
        function(){
            var parentElem = $(this).parent().parent();
            $(parentElem).addClass('hover');
            $('.illustration-overlay',parentElem).show();
        },
        function(){
            var parentElem = $(this).parent().parent();
            $(parentElem).removeClass('hover');
            $('.illustration-overlay',parentElem).hide();
        }
    );
    
    
    //"Accordéon" #nav-gauche
    var heightMenuGauche = $('#nav-gauche').height();
    var widthMenuGauche = $('#nav-gauche').width();
    if (isIE6) {
        $('#nav-gauche').attr('style',
                              'position: absolute; z-index: 3000; left:0;')      
        $('#nav-gauche').after('<div id="nav-gauche-ghost"> </div>');
        $('#nav-gauche-ghost').attr('style',
                                    'height: ' + heightMenuGauche + 'px; width:' + widthMenuGauche + 'px; margin-left: 3px; background: none; z-index: 2; position: static; float: left;')
    };
    if (isIE7) {
        $('#nav-gauche').attr('style',
                              'position: absolute; z-index: 3000; left:0;')      
        $('#nav-gauche').after('<div id="nav-gauche-ghost"> </div>');
        $('#nav-gauche-ghost').attr('style',
                                    'height: ' + (heightMenuGauche + 20) + 'px; width:' + (widthMenuGauche + 7) + 'px; margin-left: 3px; background: none; z-index: 2; position: static; float: left;')
    };
    $('#nav-gauche > ul > li:not(.current) > ul').hide();
    $('#nav-gauche > ul > li > span').attr('style','cursor: pointer;').click(
        function () {
            var elemParent =  $(this).parent();
            var contenu =  $(this).contents();
            elemParent.toggleClass('visible');
            $('> ul',elemParent).toggle();
            //fix ie6 pour prévenir les blms de hide/show + position relative
            if ((isIE6) || (isIE7)) { $('#nav-gauche > ul > li > ul').toggle().toggle(); };            
        });
    $('#nav-gauche > ul > li > ul > li > ul').hide().parent().prepend('<div class="plus">+</div>');
    $('#nav-gauche > ul > li > ul > li.current > ul').show();
    $('#nav-gauche > ul > li > ul > li.current .plus').contents().replaceWith('-');
    $('#nav-gauche > ul > li > ul > li .plus').click(
        function () {
            var elemParent =  $(this).parent();
            var contenu =  $(this).contents();
            var contenuText =  $(this).text();
            switch (contenuText) {
                case '-':
                    var contenuReplaced = '+';
                break;
                case '+':
                    var contenuReplaced = '-';
                break;
            };
            contenu.replaceWith(contenuReplaced);
            $('> ul',elemParent).toggle();
            //fix ie6 pour prévenir les blms de hide/show + position relative
            if ((isIE6) || (isIE7)) { $('#nav-gauche > ul > li > ul > li > ul').toggle().toggle(); };
        });
    
    
    
    
});
