//
function desactive(cible) {
	$(cible).attr("disabled","disabled").children(":first").attr("selected","selected")
	.siblings().removeAttr("selected").parent().parent("div").addClass("nonactif");
	if (cible == "#modele") desactive("#version");
}
//
jQuery.fn.vjustify=function() {
    var maxHeight=0;
    this.each(function(){
        if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
    });
    this.each(function(){
        $(this).height(maxHeight + "px");
        if (this.offsetHeight>maxHeight) {
            $(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
        }
    });
};
//
$(function() {
	//if ($.browser.mozilla) { console.log ($("body").attr("id")); }

//- Capitalize Legrand 
	$('h3').each(function() {
		var el = $(this); 
		el.html(el.html().replace(/legrand/gi, '<span class="Legrand">Legrand</span>'));
	 });
	// navigation n-1: sections
    $('ul.sections li').ahover({
    	toggleEffect: {opacity: 0},
    	moveSpeed: 450,
	    hoverEffect: function() {
	        $(this)
	            //.css({opacity: 0.75})
	            .animate({opacity: 0.45}, 750)
	            .animate({opacity: 0.75}, 750)
	            .dequeue();
	        $(this).queue(arguments.callee);
	    }
	 });
	 
//- inline popups settings
    $.nyroModalSettings ({
		bgColor: '#062e47',
		padding: 0,
		margin: 0,
		width: 400,
		autoSizable: true
    });
	 offsetY = 0;

	// $('#adPartenaire a').nyroModal({ width: 400, height:550+offsetY });
	// $('#legrandIntro a').nyroModal({ width: 400, height:425+offsetY });
	// $('#newsletter_block a').nyroModal({ width: 400, height:225+offsetY });
	// $('#instant_contact a').nyroModal();
	$('a#fBasic').nyroModal({ width: 400, height:450+offsetY });
	$('#legrandGroupe a').nyroModal({ width: 400, height:425+offsetY });
	$('#concession_block a').nyroModal({ width: 400, height:450+offsetY });
	$('#financement_contact a').nyroModal({ width: 400, height:450+offsetY });
	//
	/*$(".finfo a").defuscate();*/
	
	//gestion du zoom sur les vignettes - accueil
    $(".recentes").append("<a href='#' class='vignette_hover'><img src='data/medias/interface/placeholder.png' alt='vignette' width='150' height='113' /></a>");
    $("a.vignette_hover").bind("mouseleave", function(e){
    		$(this).hide();
    		$(".with_vhover").removeClass("with_vhover");
    });
    $('.annonce img').hover(function () {
		$(".with_vhover").removeClass("with_vhover");
		$(this).parent().parent().addClass("with_vhover");
		$("a.vignette_hover img").attr("src",$(this).attr("src"))
		.parent()
		.attr("href",$(this).parent().attr("href"))
		.css("left",$(this).position().left-70).css("top",$(this).position().top-45)
		.show();
		}, 
	function () {});
	
	
	// add new widget called zoomVignette
	$.tablesorter.addWidget({
		// give the widget a id
		id: "zoomVignette",
		// format is called when the on init and when a sorting has finished
		format: function(table) {
			
		    $("a.vignette_hover").bind("mouseleave", function(e){
		    	vignetteVisible = false;
		    	$(".hover").removeClass("hover");
		    	$(this).hide();
		    });
		    
		    $('table.tablesorter tbody img').bind("mouseenter", function (e) {
		    	$(".hover").removeClass("hover");
		    	vignetteVisible = true;
		    	var image = $(this).attr("src");
		    	$(this).parents("tr").addClass("hover");
				$("a.vignette_hover img").attr("src","/data/medias/produits/sm/"+image.substring(image.lastIndexOf("/")));
				$("a.vignette_hover")
				.attr("href",$(this).parent().attr("href"))
				.css("left",$(this).position().left-57).css("top",$(this).position().top-31)
				.show();
			});
		}
	});
	// definition tableSorter
	for (inc=1; inc<=3; inc++) { 
	    $("table#tableau-"+inc)
	    .tablesorter({ headers: { 0: { sorter: false} }, widthFixed: true, widgets: ['zebra','zoomVignette','cookie'] }) 
	    .tablesorterPager({container: $("#pager-"+inc), positionFixed: false, size: 15});
	}
	// gestion du zoom sur les vignettes - tableaux
	var vignetteVisible = false;
	
    $(".listing").append("<a href='#' class='vignette_hover'><img src='data/medias/interface/placeholder.png' alt='vignette' width='150' height='113' /></a>");
    
	$('.vignette_hover').bgiframe();
    $("a.vignette_hover").bind("mouseleave", function(e){
    	vignetteVisible = false;
    	$(".hover").removeClass("hover");
    	$(this).hide();
    });
    
    $('table.tablesorter tbody img').bind("mouseenter", function (e) {
    	$(".hover").removeClass("hover");
    	vignetteVisible = true;
    	$(this).parents("tr").addClass("hover");
		$("a.vignette_hover img").attr("src",$(this).attr("src"));
		$("a.vignette_hover")
		.attr("href",$(this).parent().attr("href"))
		.css("left",$(this).position().left-70).css("top",$(this).position().top-45)
		.show();
	});
    
    // cell Hover /click
    $("tbody tr").hover(function () { $(this).addClass("hover");
    }, function () { if (vignetteVisible != true) $(this).removeClass("hover");	
	}).click(function () {
    	var uri =$(this).find("a").attr("href");
    	window.location = uri; 
    });
    
    // over tab pour les fiches annonces
    //
    $(".thumbs").idTabs("!mouseover");
    
    // over tab pour les fiches annonces
    //
    $(".secBlock").hover(function () { $(this).addClass("sBHover");
    }, function () { $(this).removeClass("sBHover");	
	});
//- to remove text when user click inside the input
	$("#iti_form .ph:text").placehold();

//- first equalizing column test
	$(".service").vjustify();
	$(".innerCons").vjustify();
});
/* remise a 0 de cookie tablePage */
function resetTablePage ()
{
	$.cookieJar('tablepage').set('pageCourante', 0);
}

Tmodele = new Array();

function modele(id,marque,titre)
{
	this.id = id;
	this.marque = marque;
	this.titre = titre;
}

function add_option(val,id,libelle,champ_form,selected)
{
	ch_option = "option" + val;
	ch_option = new Option(libelle,id,false,selected);

	document.rechVehicule.elements[champ_form].options[document.rechVehicule.elements[champ_form].length] = ch_option;
	
}

function get_marque(id_modele)
{
	marque = document.rechVehicule.marque.options[document.rechVehicule.marque.selectedIndex].value
	document.rechVehicule.modele.length = 0;
	add_option(0,0,"modele...","modele");
	for (j=0; j< Tmodele.length;j++) {
		if (Tmodele[j].marque == marque) {
			selected = false;
			if (id_modele == Tmodele[j].id) selected = true;
			add_option((j+2),Tmodele[j].id,Tmodele[j].titre,"modele",selected);
			
		}
	}

	
}

function CheckSelect(champ,val)
{
	for(i=0;i<document.rechVehicule.elements[champ].options.length;i++) {
		if (document.rechVehicule.elements[champ].options[i].value==val) {
			document.rechVehicule.elements[champ].selectedIndex = i;
			break;
		}
    }
}