﻿var GLOBAL_LISTE_OCCASIONS_DU_MOMENT = "";


$(document).ready( function( ) {

	if ( !$.browser.msie )
	{
		$('.BandeauBackground').each( function( e ) {
			$(this).width( $(this).width() - 20 )
		});
	}
} );


function callFloodlight( u1, u2 ) 
{
	var axel = Math.random() + "";
	var a = axel * 10000000000000;
//	document.write('<iframe src="http://fls.doubleclick.net/activityi;src=484988;type=par2011;cat=paris556;u1='+u1+';u2='+u2+';ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
	$("body").append( $('<iframe src="http://fls.doubleclick.net/activityi;src=484988;type=par2011;cat=paris556;u1='+u1+';u2='+u2+';ord=1;num=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'));
}



function TitleTogglePlusMoins( node )
{
	if ( $(node).attr('disable-openclose') == "1" ) 
	{
		$('#'+node.id.replace('_title','_content')+':hidden').show();
		return;
	}

	// to Plus
	if ( node.className.indexOf( "Moins" ) > 0 )
	{
		node.className = "TitlePlus";
		$('#'+node.id.replace('_title','_content')).hide();
	}
	// to Moins
	else
	{
		node.className = "TitleMoins";
		$('#'+node.id.replace('_title','_content')).show();
	}
}



function ShowCompteurVO( node, url )
{
	//alert( url );
	
	url = unescape( url );
	url = url.replace( "[groupe_id]", SiteInfo.GroupeId );
	
	// Disable compteurs in Admin part
	//if ( SiteInfo.IsAdmin ) return;
	
	$.ajax({
		 type: "GET",
		 url: url,
		 dataType: "xml",
		 success: function(xml) {
			//alert( $(xml).find('count').text() );
			$(node).after("<span>"+$(xml).find('count').text()+"&#160;</span>");
			$(node).remove();
		}
	});	
}


function ShowExtractVO( node, url )
{
	
	//alert( url );	
	// Disable compteurs in Admin part
	//if ( SiteInfo.IsAdmin ) return;
	
	$.ajax({
		 type: "GET",
		 url: url,
		 dataType: "html",
		 success: function(html) {
			
			//alert( html );
			$(node).after(html);
			$(node).remove();
		}
	});	
}





function ShowSlideShow( node, p_SlideShowId )
{
	var url = "/web-services/Medias/getXmlMedias.aspx?id=" + p_SlideShowId;
	$.ajax({
		 type: "GET",
		 url: url,
		 dataType: "xml",
		 success: function(xml) {
			var SlideShow = "<div id=\"slideshowVO\" style=\"width:300px;height:250px;overflow:hidden;\" ondragstart=\"return false;\" onselectstart=\"return false\" onmousedown=\"return false\">";

			var countPhotos=0;
			$(xml).find( 'media_child' ).each( function(){
				var sClass="";
				var sId = "";
				var Path = $( $(this).find( "path" )[ 0 ] ).text();
				if( countPhotos==0 )
				{
					sClass 	= " class=\"active\" ";
					sId 	= " id=\"PhotoVO\" ";
				}
				
				SlideShow += "<IMG "+sId+" "+sClass+" width=\"262\" ondragstart=\"return false;\" onselectstart=\"return false\" onmousedown=\"return false\" src=\"" +Path+ "\" />";				
				countPhotos++;
			} );
			SlideShow += "</div>";
			
			$(node).after(SlideShow)
			$(node).remove();
			
			
			// ON ADAPTE TOUTES LES PHOTOS A LA HAUTEUR MINIMALE... 
			if ( $('#slideshowVO') && typeof slideSwitchNext != "undefined" )
			{
				
				var iSlideShowMaxHeight = 1000000;
				$('#slideshowVO IMG').each( function( i, val  ) {
					if ( $(val).height( ) < iSlideShowMaxHeight )
						iSlideShowMaxHeight = $(val).height( )
				});
				if ( iSlideShowMaxHeight > 10 )
					$('#slideshowVO').css( "height", iSlideShowMaxHeight+"px" ).css( "overflow", "hidden" );
			
				if ( countPhotos > 1 )
					setTimeout( "slideSwitchNext()", 3000 );
				if ( typeof placeLoupe != "undefined" ) placeLoupe( iSlideShowMaxHeight );
			}		
		
			//Affichage de la loupe
			if ( typeof placeLoupe != 'undefined' ) placeLoupe( );
			
			
			
			
			if ( $.browser.msie ) 
			{
				var oBt1 = document.getElementById( "SlideShowBt1" )
				var oBt2 = document.getElementById( "SlideShowBt2" )
				var oBt3 = document.getElementById( "SlideShowBt3" )
				var oBt4 = document.getElementById( "SlideShowBt4" )
				var oLoupeImg = document.getElementById( "imgLoupe" )
				
				if ( oBt1 ) {
					
					oLoupeImg.outerHTML = "<span onclick=\"openLoupe()\" style=\"" + "width:26px; height:24px;display:inline-block;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + oLoupeImg.src + "\', sizingMethod='scale');\"></span>"
					oBt1.outerHTML = "<span onclick=\"openLoupe()\" style=\"" + "width:73px; height:73px;display:inline-block;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + oBt1.src + "\', sizingMethod='scale');\"></span>"
					oBt2.outerHTML = "<span onclick=\"openLoupe()\" style=\"" + "width:66px; height:73px;display:inline-block;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + oBt2.src + "\', sizingMethod='scale');\"></span>"
					oBt3.outerHTML = "<span onclick=\"openLoupe()\" style=\"" + "width:64px; height:73px;display:inline-block;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + oBt3.src + "\', sizingMethod='scale');\"></span>"
					oBt4.outerHTML = "<span onclick=\"openLoupe()\" style=\"" + "width:85px; height:73px;display:inline-block;cursor:pointer;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + oBt4.src + "\', sizingMethod='scale');\"></span>"
				}
			}
			

		}
	});		
}


var aOccasionsDuMoment = [];
var currentOccasionsDuMoment = 0;
function OccasionsDuMoment( id_vehicules )
{

	// Reset Breve Right "Les Occasions du Moment"
	$('#MiseEnAvantVO_Content').html("");
	$('#MiseEnAvantVO').hide();
	currentOccasionsDuMoment = 0;
								
	// Example: WDB2304701F145027,WDD2210951A286965,WDD2210951A287764
	var url = "/web-services/VO/renderExtractVO.aspx?showall=1&ids="+id_vehicules+"&xml=1";
	
	//alert( url );
	$.ajax({
		 type: "GET",
		 url: url,
		 dataType: "xml",
		 success: function(xml) {
			
			// Load infos
			$(xml).find('vehicule').each( function() {
				var sUrlImg = $(this).find("photo:first").text();
				if ( sUrlImg != "" )
				{
					aOccasionsDuMoment[aOccasionsDuMoment.length] = {
						photo: sUrlImg,
						prix: $(this).find("prix:first").text(),
						name: $(this).find("modele_complete:first").text(),
						id: $(this).attr( "id" )
					};	
				}
			} );

			// Hide ?
			if ( aOccasionsDuMoment.length == 0 )
			{
				$('#MiseEnAvantVO').hide();
			}
			// Hide arrows ?
			else if ( aOccasionsDuMoment.length == 1 )
			{
				$('#MiseEnAvantVO').find(".Button1").hide();
				$('#MiseEnAvantVO').find(".Button2").hide();
				$('#MiseEnAvantVO').show();
				
				OccasionsDuMoment_Show( 0 );
			}
			// Init first VO
			else
			{
				//alert( "ok : " + $('#MiseEnAvantVO').html() );
				$('#MiseEnAvantVO').show();
				OccasionsDuMoment_Show( 0 );
			}
			
		}
	});	
}
 
function OccasionsDuMoment_Show( index )
{
	var sHtml = "";
	sHtml += "<div class='Content' align=\"center\" style=\"border:0px solid red;padding-top:40px;cursor:pointer;\">";
	sHtml += "<img width='150' src=\"" + aOccasionsDuMoment[index].photo + "\" alt=\"\" border=\"0\"/><br/>";
	sHtml += "<table cellpadding='0' cellspacing='0' style='margin-top:4px;' width='150'><tbody><tr><td colspan='2' style='padding-bottom:6px;'><span class='Content'>"+aOccasionsDuMoment[index].name+"</span></td></tr>"
	sHtml += "<tr><td><span class='Content'>Prix</span></td><td align='right'><span class='Content' style='font-weight:bold;font-size:12px;'>"+aOccasionsDuMoment[index].prix+"&#160;&#8364;</span></td></tr>"
	sHtml += "</tbody></table>";
	sHtml += "</div>";

	$('#MiseEnAvantVO_Content').html(sHtml);
	$('#MiseEnAvantVO_Content').children("div").click( function() { GotoVODuMoment( index ); } );
}

function OccasionsDuMoment_toLeft( )
{
	currentOccasionsDuMoment--;
	if ( currentOccasionsDuMoment < 0 ) currentOccasionsDuMoment = aOccasionsDuMoment.length - 1;
	OccasionsDuMoment_Show( currentOccasionsDuMoment )
}

function OccasionsDuMoment_toRight( )
{
	currentOccasionsDuMoment++;
	if ( currentOccasionsDuMoment >= aOccasionsDuMoment.length ) currentOccasionsDuMoment = 0;
	OccasionsDuMoment_Show( currentOccasionsDuMoment )
}



