
var ultimoSeleccionado=-1;
var fondoSeleccionado=1;
var already_clicked = false;

$(document).ready( function() {
	$(".selector_transparency").css("opacity", "0.5");

	$(".selector_material_texto").hover(function() {
			if (ultimoSeleccionado!=$(this).attr("id"))
				$(this).animate( { "marginLeft": 15 }, 100 );
		}, function() {
			if (ultimoSeleccionado!=$(this).attr("id"))
				$(this).animate( { "marginLeft": 5 }, 100 );
		}
	);
	
	$(".selector_buy_button").hover(function() {
		$(this).addClass("selector_material_texto_seleccionado");
		$(this).animate({width:105}, 300);
	}, function() {
		$(this).removeClass("selector_material_texto_seleccionado");
		$(this).animate({width:90}, 300);
	});
	
	$(".selector_buy_button").click(function() {
		if (!already_clicked)
		{
			already_clicked=true;
			document.location = 'panier?add='+ultimoSeleccionado;
		} 
	});

	$(".selector_material_texto").click( function() {
		CambiaSeleccion($(this).attr("id"));	
	} );
	
	$(".selector_previo").click( function() {
		document.location = "selectionner-partie-photo?id="+$(this).attr("previo_id")+"&text="+$(this).attr("previo_txt");
	});
	
	$(".selector_escenario_imagen[id!=1]").css("opacity", 0.5);	
	
	$(".selector_escenario_imagen").hover(function() {
			if (fondoSeleccionado!=$(this).attr("id")) {
				$(this).animate({"opacity": 1.0});
			}
		}, function() {
			if (fondoSeleccionado!=$(this).attr("id")) {
				$(this).animate({"opacity": 0.5});
			}
	});
	
	$(".selector_escenario_imagen").click( function() {
		CambiaFondo($(this).attr("id"));
	});

});


function CambiaFondo(id)
{	
	$(".selector_escenario_imagen[id="+fondoSeleccionado+"]").animate({ "opacity": 0.5});
	fondoSeleccionado = id;
	$(".selector_escenario_imagen[id="+fondoSeleccionado+"]").animate({ "opacity": 1.0});
	$(".selector_zone_background").fadeOut('slow', 
			function() { 
				$(this).css("background-image", "url(http://fotodekora.regalosoriginales.org.es/photo-sur-toile/media/images/selector/fondo_"+id+".jpg)")
				.fadeIn('slow'); 
				}
	);
}

function SeleccionaTexto(nid)
{	
	$(".selector_material_linea_flecha#f"+nid).fadeIn( 'fast' );
	$(".selector_material_linea#l"+nid).animate( { width: 230 }, 100);
	$(".selector_material_texto#"+nid).animate( { "marginLeft": 25, "width": 200 }, 100 );
	$(".selector_material_texto#"+nid).addClass( "selector_material_texto_seleccionado" );	
	$("#selector_previo_"+nid).fadeIn('fast', function() {
		$(".dropShadow").remove();
	    $(this).dropShadow({left:-4});
	    $(".selector_buy_button").css("top", $("#selector_previo_"+nid).position().top+$("#selector_previo_"+nid).height() + 10);
		$(".selector_buy_button").css("left", $("#selector_previo_"+nid).position().left+ $("#selector_previo_"+nid).width()/2);
		$(".selector_buy_button").fadeIn('slow');
	});
}

function CambiaSeleccion(nid)
{
	var us = ultimoSeleccionado;
	if (ultimoSeleccionado!=-1)
	{
		$(".selector_buy_button").fadeOut('fast');
		$(".selector_material_linea_flecha#f"+ultimoSeleccionado).fadeOut( 'fast', function() {
			$(".selector_material_texto#"+us).animate( { marginLeft: 5, width: 190 }, 100 );
			$(".selector_material_texto#"+us).removeClass( "selector_material_texto_seleccionado");
			$(".selector_material_linea#l"+us).animate( { "width": 210 }, 100);
		});		
		$("#selector_previo_"+ultimoSeleccionado).removeShadow();
		$("#selector_previo_"+ultimoSeleccionado).fadeOut('fast', function() { 
			SeleccionaTexto(nid);
		});
	} else {
		SeleccionaTexto(nid);
	}	
	ultimoSeleccionado=nid;
}

