$(document).ready(function() {
	$('#suscribete').css({visibility: 'visible', display: 'none'});
	//$.scrollTo('#centro', 1);
	self.location.hash = 'centro';
	document.title = 'UNICEF';
	$('input#susEmail').focus(function() {
		var value=$(this).val();
		if( value == 'E-mail' )
			$(this).val('');
	}).blur(function() {
		var value=$(this).val();
		if(value == '') $(this).val('E-mail');
	});
});

var papasCurrentID = 'ninos';

function paraPapas(id)
{
	$('#'+papasCurrentID+' a').removeClass('sel');
	$('#'+id+' a').addClass('sel');
	papasCurrentID = id;
	$('#div_consejos, #div_unicef_en_mexico, #div_colabora').css( { overflow:"hidden" } );
	$('#contenido_footer').scrollTo('#div_'+id, 1000, { onAfter:function(){ 		
		if(id == "consejos"){
			$('#div_consejos').css( { height : "332px", "overflow-y" :"scroll", "overflow-x":"hidden"} );
		} else if(id == "unicef_en_mexico"){
			$('#div_unicef_en_mexico').css( { height:"332px", "overflow-y":"scroll", "overflow-x":"hidden" } );
		}
		else if(id == "colabora"){
			$('#div_colabora').css( { height:"332px", "overflow-y":"scroll", "overflow-x":"hidden" } );
		}
	} });
}

function newletter()
{
	$.ajax({
		  type: "POST",
		  url: "newsletter.php",
		  data: "email="+$('#susEmail').val(),
		  success: function(msg){
			  if( msg.substr(0, 6).toLowerCase() != "error:" ) {
				  $('#sus_contenido').hide();
			  }
			  $('#sus_msg').html(msg);
		  }
	  });
}

var noticiasPuntoActual = 0;

function noticiasScroll(hacia)
{
	var siguientePunto;
	if( hacia == "up" ) {
		var altoNoticias = $('#noticias_contenedor_scroll div').length * 76;
		siguientePunto = (noticiasPuntoActual + 76);
		if( siguientePunto < altoNoticias ) {
			noticiasPuntoActual = siguientePunto;
			$('#noticias_contenedor_scroll').scrollTo('+='+siguientePunto+'px', 500);
		}
	} else {
		if( noticiasPuntoActual > 0 ) {
			siguientePunto = (noticiasPuntoActual - 76);
			noticiasPuntoActual = siguientePunto;
			$('#noticias_contenedor_scroll').scrollTo('-=76px', 500);
		}
	}
}

function ir(seccion, func)
{
	if( func == undefined )
		$.scrollTo('#'+seccion, 1000);
	else
		$.scrollTo('#'+seccion, 1000, {onAfter: function() { eval(func) } });
	if( seccion == "arriba" )	{
		setTimeout("quitaMenu();", 800);
		//swfobject.embedSWF("flash/menu.swf", "menuFlashFooter", "890", "138", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {menuSel: 3 }, { wmode: "transparent" }, {});
	} else {
		$('#menu_top').html('<div id="menuFlashTop"></div>');
	}
}

function quitaMenu()
{
	$('#menu_top').html('<div id="menuFlashTop"><a href="javascript: void(0)" onclick="ir(\'centro\')">Home</a></div>');
}

var opcionesEncuestaTotal = 3;

function opcion(valor)
{
	if( valor > 0 )
	{
		$('#opcion').val(valor);
		seleccionaOpcion(valor);
	}
}

function seleccionaOpcion(valor)
{
	for( var i = 1; i <= opcionesEncuestaTotal; i++ )
	{
		if( valor == i )
			$('#check_'+i).addClass('encuesta_radio_sel');
		else
			$('#check_'+i).removeClass('encuesta_radio_sel');
	}
}

function votar()
{
	if( parseInt($('#opcion').val()) > 0 && parseInt($('#encuestaID').val()) > 0 )
	{
		$.ajax({
			type: "POST",
			url: "vota.php",
			data: "encuestaID="+$('#encuestaID').val()+"&votoID="+parseInt($('#opcion').val()),
			success: function(msg){
				$('#encuesta_bottom').html(msg);
			}
		});
	} else { alert('Selecciona una respuesta'); }
}

function menuLink(opcion)
{
	switch(opcion) {
		case 'unicef' :
			ir('centro', 'tb_show("","bienvenida.php?TB_iframe=true&height=218&width=384&modal=true","");');
			break;
		case 'participa':
			ir('centro', 'tb_show("","participa.php?TB_iframe=true&height=615&width=630&modal=true","");');
			break;
		case 'historia':
			ir('centro', 'tb_show("","historia.php?TB_iframe=true&height=571&width=523&modal=true","");');
			break;
		case 'jugar':
			swfobject.embedSWF("flash/cargador.swf", "flashTopContenedor", "887", "494", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {menuSel: 2, seccion : "Juegos.swf" }, { wmode: "transparent" }, {});
			ir('arriba');
			break;
		case 'derechos':
			swfobject.embedSWF("flash/cargador.swf", "flashTopContenedor", "887", "494", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {menuSel: 2, seccion : "Derechos.swf" }, { wmode: "transparent" }, {});
			ir('arriba');
			break;
		case 'convencion':
			swfobject.embedSWF("flash/cargador.swf", "flashTopContenedor", "887", "494", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {menuSel: 2, seccion : "Convencion.swf" }, { wmode: "transparent" }, {});
			ir('arriba');
			break;
		case 'papas':
			ir('abajo');
			break;
		case 'noticias':
			window.top.location = '<?php echo URL; ?>noticias/';
			break;
		case 'videos':
			window.top.location = '<?php echo URL; ?>videos/';
			break;
		default:
			break;
	}
}

function abreJuego(links)
{
	tb_show("",links,"");
}


window.onload = function(){
	
	/*swfobject.embedSWF("flash/cargador.swf", "flashTopContenedor", "887", "494", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {menuSel: 2 }, { wmode: "transparent" }, {});*/
						//swfobject.embedSWF("flash/menu.swf", "menuFlashTop", "890", "138", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {menuSel: 2 }, { wmode: "transparent" }, {});
	swfobject.embedSWF("flash/contacto.swf", "contacto", "279", "118", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {}, { wmode: "transparent" }, {});
	
	swfobject.embedSWF("flash/menu-arbol.swf", "menu_arbol_flash", "380", "478", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {}, { wmode: "transparent" }, {});
	
	swfobject.embedSWF("flash/gusano.swf", "guasanito", "130", "450", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {}, { wmode: "transparent" }, {});
	
	swfobject.embedSWF("flash/unicef hojitas.swf", "hojas", "990", "700", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {}, { wmode: "transparent" }, {});
	
	swfobject.embedSWF("flash/audio.swf", "sonido", "950", "25", "8", "http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75", {}, { wmode: "transparent" }, {});
	
}
