function inicializar(visible, playlist, page) {
	inicializarPlayers(visible, playlist);
	attachLeerMas($("#textos_superiores"));
	clickNoticias();
	hoverNoticias();
	embedMapa(page);
}
function attachLeerMas($contenedor) {
	var $button = $("a.leer_mas:not(.noclick)", $contenedor);
	$button.unbind("click");
	$button.click(function(){ leerMas($contenedor, $(this)); return false; });
}
function attachLeerMenos($contenedor) {
	var $button = $("a.leer_mas:not(.noclick)", $contenedor);
	$button.unbind("click");
	$button.click(function(){ leerMenos($contenedor, $(this)); return false; });
}
function leerMas($contenedor, $boton) {
	$contenedor.stop(true, false);
	var height = 156 + $(".contenido", $contenedor).height() + parseInt($(".contenido", $contenedor).css("padding-top").replace("px","")) + parseInt($(".contenido", $contenedor).css("padding-bottom").replace("px",""));
	$boton.addClass("menos");
	$contenedor.animate({height:height}, 1000, "easeInOutQuad", function(){
		attachLeerMenos($contenedor, $boton);
	});
	$(".contenido", $contenedor).stop(true, false);
	$(".contenido", $contenedor).animate({opacity:1}, 1500);
}
function leerMenos($contenedor, $boton) {
	$(".contenido", $contenedor).stop(true, false);
	$(".contenido", $contenedor).animate({opacity:0}, 500);
	$contenedor.stop(true, false);
	$boton.removeClass("menos");
	$contenedor.animate({height:156}, 1000, "easeInOutQuad", function(){
		attachLeerMas($contenedor, $boton);
	});
}
function clickNoticias() {
	$("#noticias .noticia").each(function(i) { clickNoticia($(this)); });
}
function clickNoticia($noticia) {
	var href = $(".caption .caption_content h3 a", $noticia).attr("href");
	$noticia.click(function(){
		document.location = href;
	});
}
function hoverNoticias() {
	$("#noticias .noticia").each(function(i) { hoverNoticia($(this)); });
}
function hoverNoticia($noticia) {
	var $content = $(".caption .caption_content", $noticia);
	$noticia.hover(function(){
		$content.stop(true, false);
		$content.animate({opacity:0}, 300);
		$content.animate({"padding-top":260}, 300, null, function(){
			$content.css({
				"background-image": "url(/images/noticia_leer_mas.png)"
			});
			$content.animate({opacity:1}, 800);
		});
	},function(){
		$content.stop(true, false);
		var callback = function() {
			$content.css({
				"background-image": "none"
			});
			$content.animate({"padding-top":15}, 300);
			$content.animate({opacity:1}, 300);
		}
		if($content.css("padding-top") == "260px") {
			$content.animate({opacity:0}, 800, null, callback);
		}
		else {
			callback();
		}
	});
}
function changeComboDepartamentos(select, page) {
    if(page == 'concesionarios'){
        changeRegionConcesionarios(select.value);
    }else if(page == 'talleres'){
        changeRegionTalleres(select.value);
    }
	//document.location = "?pest="+select.value;
}
function embedMapa(paginaConcesionarios) {
    var nombreFuncion = (paginaConcesionarios == 'concesionarios' ? 'changeRegionConcesionarios' : 'changeRegionTalleres');
	if($("#mapa_concesionarios").length == 1) {
        var attributes = {};

		swfobject.embedSWF('/flash/mapa.swf', 'mapa_concesionarios', 760, 350, '6', null, { urlPath: paginaConcesionarios, funcName: nombreFuncion }, {wmode: "transparent"}, attributes);
    }
}

function changeRegionConcesionarios(id){

    $(window).scrollTo( $('#ancla_concesionarios').offset().top + 265, 1200, { easing:'swing', queue:true, axis:'y' } );
    $.ajax({
        url: 'contentConcesionario',
        method: 'post',
        data: 'pest='+id,
        dataType: 'json',
        success: function (json){
            if(json.response == 'OK')
            {
                $('#contenido_concesionarios').html(json.content);
            }
        }
    });
}

function changeRegionTalleres(id){
    $(window).scrollTo( $('#ancla_talleres').offset().top + 265, 1200, { easing:'swing', queue:true, axis:'y' } );
    $.ajax({
        url: 'contentTaller',
        method: 'post',
        data: 'pest='+id,
        dataType: 'json',
        success: function (json)
        {
            if(json.response == 'OK'){
                $('#contenido_talleres').html(json.content);
            }
        }
    });
}
