//Bouton lien PROMOTION des pages de neufs
$(document).ready(function(){

 var $images = $('.panes > div .tbInfo img,.panes > div:hidden .tbInfo img');

    $images.each(function(){

        var $img = $(this);

        if($img.parent().is('a')){

            var $src = $img.attr('src');
            $img.css('border-style','none');

            var $src_hover = $src.replace('promotions','promotions-over');

            $img.hover(
              function(){
                  $(this).attr('src',$src_hover);
              },
              function(){
                  $(this).attr('src',$src);
            });

            $parent_css_options = {
              'display': 'block'
              ,'margin': 'auto'
              ,'width': '197px'
            };

            //lien
            $img.parent().css($parent_css_options);

            //td
            $img.parent().parent().css('vertical-align','middle');
        }
    });

})
//==========================================


//Bouton lien INVENTAIRE des pages d'usager
$(document).ready(function(){

    var $image = $('#allInventoryLink img');

    if($image.size()==1){
        var src = $image.attr('src');
        $image.hover(
            function(){
                $(this).attr('src',$(this).attr('src').replace('complete-pre-owned-inventory','complete-pre-owned-inventory-over'));
            }
            ,function(){
                $(this).attr('src',src);
            }
        );
    }

})
//==========================================



//*******************************************************************************
$(document).ready(function(){
	var bVideoPlayerExists = ($("#newCarsPlayerContainer").length != 0);
	//alert("bVideoPlayerExists = " + bVideoPlayerExists);

    $carListingVedette_h = 0;
    $carListingVedette = $('.carListingVedette');
    if($carListingVedette.size()==0){
        $carListingVedette = $('.carEmptyListingVedette');
    }


    if($carListingVedette.size()==1){
        var carListingVedettePadding = parseInt($carListingVedette.css("padding-top").replace("px","")) + parseInt($carListingVedette.css("padding-bottom").replace("px",""));
        var carListingVedetteMargin = parseInt($carListingVedette.css("margin-top").replace("px","")) + parseInt($carListingVedette.css("margin-bottom").replace("px",""));
        $carListingVedette_h =  $carListingVedette.height() + carListingVedettePadding + carListingVedetteMargin;
    }

    //alert($carListingVedette_h);

	if (bVideoPlayerExists)
	{
		var $visiblePane = $(".panes div:not([class])").filter(function(){return $(this).css('display') == 'block'});
		$(".tbInfo").css("position","absolute");
		$(".tbInfo").css("margin","0 0 0 0px");
		$(".tbInfo").css("padding","0 0 0 0px");
		$("div[class='playerSpacer']").css("width","750px");
		$("div[class='playerSpacer']").css("height","300px");
		$("div[class='playerSpacer']").css("background","white");
		$("div[class='playerSpacer']").css("display","block");
		$("div[class='playerSpacer']").css("position","absolute");
		$("div[class='playerSpacer']").css("margin","0px 0 0 0px");
		var tbInfoVerticalPadding = parseInt($visiblePane.find('.tbInfo').css("padding-top").replace("px","")) + parseInt($visiblePane.find('.tbInfo').css("padding-bottom").replace("px",""));
        $("div[class='playerSpacer']").css("top",$visiblePane.find('.tbInfo').position().top + $visiblePane.find('.tbInfo').height() + tbInfoVerticalPadding + 20);
		$(".tbDet").css("position","absolute");
		$(".tbDet").css("margin","0px 0 0 0px");
		$(".tbDet").css("padding","0px 0 0 0px");
		$(".tbDet").css("top",$visiblePane.find('.playerSpacer').position().top + $visiblePane.find('.playerSpacer').height() + 20);
		$(".CopyrightNotice").css("position","absolute");
		$(".CopyrightNotice").css("margin","0px 0 0 0px");
		$(".CopyrightNotice").css("padding","0px 0 0 0px");
		$(".CopyrightNotice").css("top",$visiblePane.find('.tbDet').position().top + $visiblePane.find('.tbDet').height()+20);
		var $customTextDiv_h=0;var $customTextDiv = $(".txtOtherNew");
		if($customTextDiv.size()!=0){$customTextDiv_h = $customTextDiv.height() + parseInt($customTextDiv.css("padding-top").replace("px","")) + parseInt($customTextDiv.css("padding-bottom").replace("px","")) + parseInt($customTextDiv.css("margin-top").replace("px","")) + parseInt($customTextDiv.css("margin-bottom").replace("px","")) + parseInt($customTextDiv.css("borderTopWidth").replace("px","")) + + parseInt($customTextDiv.css("borderBottomWidth").replace("px","")); }
		var panes_h = $visiblePane.find('.tbInfo').height() + $visiblePane.find('.tbDet').height() + $visiblePane.find('.CopyrightNotice').height() + $visiblePane.find('.playerSpacer').height() + 150;
		$(".panes div:not([class])").each(function(){$(this).css("height",panes_h)});
		var body_h = panes_h + $("div[class='detPromos']").height() + 60 + $customTextDiv_h + $carListingVedette_h;
		$("#body").css("height",body_h);
		$("#newCarsPlayerContainer").css("top",$visiblePane.find('.playerSpacer').position().top);
		$("#newCarsPlayerContainer").css("left",$visiblePane.find('.playerSpacer').position().left);	
	}
	else
	{
		var $visiblePane = $(".panes div:not([class])").filter(function(){return $(this).css('display') == 'block'});
		$(".tbInfo").css("position","absolute");
		$(".tbInfo").css("margin","0 0 0 0px");
		$(".tbDet").css("position","absolute");
		$(".tbDet").css("margin","0px 0 0 0px");
		$(".tbDet").css("padding","0px 0 0 0px");
		var tbInfoVerticalPadding = parseInt($visiblePane.find('.tbInfo').css("padding-top").replace("px","")) + parseInt($visiblePane.find('.tbInfo').css("padding-bottom").replace("px",""));$(".tbDet").css("top",$visiblePane.find('.tbInfo').position().top + $visiblePane.find('.tbInfo').height() + tbInfoVerticalPadding + 20);
		$(".CopyrightNotice").css("position","absolute");
		$(".CopyrightNotice").css("margin","0px 0 0 0px");
		$(".CopyrightNotice").css("padding","0px 0 0 0px");
		$(".CopyrightNotice").css("top",$visiblePane.find('.tbDet').position().top + $visiblePane.find('.tbDet').height() + 20);
		var $customTextDiv_h=0;var $customTextDiv = $(".txtOtherNew");
		if($customTextDiv.size()!=0){$customTextDiv_h = $customTextDiv.height() + parseInt($customTextDiv.css("padding-top").replace("px","")) + parseInt($customTextDiv.css("padding-bottom").replace("px","")) + parseInt($customTextDiv.css("margin-top").replace("px","")) + parseInt($customTextDiv.css("margin-bottom").replace("px","")) + parseInt($customTextDiv.css("borderTopWidth").replace("px","")) + + parseInt($customTextDiv.css("borderBottomWidth").replace("px","")); }
		var panes_h = $visiblePane.find('.tbInfo').height() + $visiblePane.find('.tbDet').height() + $("p[class='CopyrightNotice']:first").height() + 150;
		$(".panes div:not([class])").each(function(){$(this).css("height",panes_h)});
		var body_h = panes_h + $("div[class='detPromos']").height() + 40 + $customTextDiv_h + $carListingVedette_h;
		$("#body").css("height",body_h);
	}
})


