Cufon.replace('#menu li.cabecera');
var default_section = "home";
var default_menu = "group_empresa";
var current_new = 0;
var total_news = 0;
var noticias;
var videoVisible=1;
var menu_activo = "";
function activar(param){
	//$("#ver_mas").html(param);
	$("#menu li[rel=cooperativas]").trigger("click");
	if(param=="valde1")
	    document.location="http://www.es-core.com/fichas%20productos/fichavppbvaldebebas.html";
	else if(param=="valde2")
	    document.location="http://www.es-core.com/fichas%20productos/fichavppbvaldebebas2b.html";
		
	else if(param=="valde3")
	    document.location="http://www.es-core.com/fichas%20productos/fichacooperativadeveterinarios.html";
	else if(param=="illescas")
	    document.location="http://www.es-core.com/fichas%20productos/fichaillescas.html";
	else if(param=="puerta")
	    document.location="http://www.es-core.com/fichas%20productos/fichaPUERTAvaldebebas.html";
	else
	    $("#group_cooperativas a[rel=encurso]").trigger("click");
}
function loadContent(alias, noimage){
	/*if(videoVisible)
		hideVideo(alias);*/
	if(alias==undefined)
		return;
    $("#image").hide();
	$("#image img").fadeOut(function(){
		$("#image").html("<img width='400px' style='display:none' src='fotos/"+alias+".jpg'/>");

        if (typeof noimage != "undefined" && noimage == true ) {
            $("#image").hide();
            $("#text_content").addClass('wide')
        }else{
            $("#image").show();
		    $("#image img").fadeIn();
            $("#text_content").removeClass('wide')
        }
	});


	$("#text_content").fadeOut(function(){
		//$.get("ajax.php?action=getContent&alias="+alias, function(data){
		if($("#st_"+alias)==undefined)
			return
		data = $("#st_"+alias).html();
		$("#text_content").html(data);
		Cufon.replace('#text_content h2');
		Cufon.replace('#text_content h3');
		$("#text_content").fadeIn();
		loadAccordion();
	});

}
function loadAccordion(){
	$(".accordion").hide();
	$(".accordion_header").css("cursor","pointer").click(function(){
		$(".accordion").slideUp();
		$(".accordion", this).slideDown();
		$(this).css("cursor", "auto");
	});
}
function hideVideo(alias){
	$.fancybox.close();
}

function loadNew(){
	$("#news_current").html(current_new+1);
	$("#news_titular").html(noticias[current_new].title);
	$("#fecha").html(noticias[current_new].date);
	var api = $('#ver_mas').eq(0).simpletip();
	// Perform a simple API call to update tooltip contents
	api.update(noticias[current_new].text);

}
function loadNews(){
	$.getJSON("ajax.php?action=getNews", function(data){
		$("#news_total").html(data.num_datos);
		noticias = data.datos;
		total_news = data.num_datos;
		loadNew();
	});
}
$(document).ready(function(){
	$("#ver_mas").simpletip({
		content: "",
		fixed: true,
		position: 'top' 
	});
	$("#video_activator").fancybox({
		'padding'           : 0,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'width'				: 800,
		'height'			: 270,
		'transitionOut'		: 'none',
		'overlayOpacity'	: 0.9,
		'onClosed'			: function(){
			swfobject.embedSWF("swf/skyline.swf", "footer", "1280", "250", "9.0.0", "expressInstall.swf", params);
		}
	}).hide();
	$("#acceso_boton").fancybox({
		'padding'           : 0,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'width'				: 800,
		'height'			: 270,
		'transitionOut'		: 'none',
		'overlayOpacity'	: 0.9,
		'onClosed'			: function(){
			$("#footer").show();
		},
		'onStart'			: function(){
			$("#footer").hide();
		}		
	});

	$("#wrapper").css('margin-top', 0);//mh);

	$("#video_activator").trigger('click');

	loadContent(default_section, true);
	$("#menu ul").hide().slideDown(1600);
	$("#logo").hide().fadeIn(800);
	$("#menu li").css("cursor","pointer").click(function(){
		if(!$(this).hasClass("active")){
			loadContent($("a", this).attr("rel"));
			$("#menu li.active").removeClass("active");/*.animate({"left":"0px"});*/
			$(this).addClass("active").css("position","relative");/*.animate({"left":"-10px"});*/
		}
	});
	loadNews();
	$("#news_prev_button").click(function(){
		if(current_new>0){
			current_new--;
			loadNew();
		}
	});
	$("#news_next_button").click(function(){
		if(current_new<total_news-1){
			current_new++;
			loadNew();
		}	
	});
	$("#menu li.cabecera").click(function(e){
        e.stopPropagation();
        //If has the class "hascontent" load some content
        if ($(this).hasClass('home')) {
            loadContent(default_section, true);
        }else{
            menu_activo = $(this).attr("rel");
            $("span.group").slideUp(function(){
                $(this).hide();
            });
            setTimeout(function(){
                $("#group_"+menu_activo).slideDown(500);
            }, 300);
        }
		
	});
	$("#"+default_menu).slideDown();
});


