var elem = '';
var elem1Alto = 0;
var elem2Alto = 0;
var elem3Alto = 0;

var minAncho = 1000;
var minAlto = 595;

var trActual = 0;
var trTotal = 0;

var winName = "titulo";
var win = null;

function AbreN(theURL, ancho, alto)
{
    var h = (screen.width-ancho)/2;
    var v = (screen.height-alto)/2;
    var windowprops = "top=0,left=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes, resizable=no,width="+ancho+",height="+alto+",left="+h+", top="+v;
    if (win) {
        win.close();
    }
    win = window.open(theURL, winName, windowprops);
}

function Actualiza()
{
    w = document.getElementById ('flash');
    ancho = alto = 0;
    if (typeof (window.innerWidth) == 'number') {
        ancho = window.innerWidth;
        alto = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        ancho = document.documentElement.clientWidth;
        alto = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        ancho = document.body.clientWidth;
        alto = document.body.clientHeight;
    }
    w.style.width = ancho < minAncho ? minAncho + "px" : "100%";
    w.style.height = alto < minAlto ? minAlto + "px" : "100%";
}

function ClientesIni()
{
	elem1Alto = $( '#con1' ).height();
	elem2Alto = $( '#con2' ).height();
	elem3Alto = $( '#con3' ).height();
	
	$( '#con1' ).css( 'height', '0' );
	$( '#con2' ).css( 'height', '0' );
	$( '#con3' ).css( 'height', '0' );
}

function ClientesPica( cual )
{
	if( elem != '' )
	{
		$( "#con" + elem ).stop().animate( { height: "0px" }, 300 );
	}
	
	if( cual == elem )
	{
		elem = '';
	}
	else
	{
		elem = cual;
		
		$( "#con" + elem ).stop().animate( { height: window[ 'elem' + elem + 'Alto' ] + "px" }, 300 );
	}
	
	
	ClientesPos();
}

function ClientesPos()
{
	if( elem == '' )
	{
		$( "#el1" ).stop().animate( { marginTop: ( ( 440 - 99 ) / 2 ) + "px" }, 300 );
	}
	else
	{
		var margenEl1 = ( 440 - 99 - window[ 'elem' + elem + 'Alto' ] ) / 2;
		$( "#el1" ).stop().animate( { marginTop: margenEl1 + "px" }, 300 );
	}
}

function ClientesTit( cual, estado )
{
	if( estado == 'over' )
	{
		$( "#tit" + cual ).stop().animate( { color: "#B61A4A" }, 300 );
	}
	else if( estado == 'out' )
	{
		$( "#tit" + cual ).stop().animate( { color: "#333333" }, 300 );
	}
}

function CmpIE()
{
	if( navigator.appName == "Microsoft Internet Explorer" )
	{
		version = parseFloat( navigator.appVersion.split( "MSIE" )[ 1 ] );
		
		if( version < 8 )
		{
			document.getElementById( 'avisoIE' ).innerHTML = "<img src=\"img/error.png\" > Est&aacute;s utilizando una versi&oacute;n obsoleta de Internet Explorer, de manera que algunos elementos de esta p&aacute;gina no se ver&aacute;n correctamente. Actual&iacute;zalo gratis desde <a href=\"http://www.microsoft.com/spain/windows/internet-explorer/\" target=\"_blank\" style=\"color: #333\" >aqu&iacute;</a>.";
			document.getElementById( 'avisoIE' ).className = "avisoJS";
		}
	}
}

function ConceptosFrase( cual, estado )
{
	if( estado == 'over' )
	{
		$( "#f" + cual ).stop().animate( { color: "#B61A4A" }, 300 );
		document.getElementById( 'f' + cual ).style.cursor = 'pointer';
	}
	else if( estado == 'out' )
	{
		$( "#f" + cual ).stop().animate( { color: "#9A9A9A" }, 300 );
	}
}

function DesactivaAtrasBt()
{
	window.history.forward();
}

function HistorialSec( cual )
{
	$( "#hd" + cual ).stop().toggle( '300' );
}

function HistorialSubSec( cual )
{
	$( "#hds" + cual ).stop().toggle( '300' );
}

function Inicia( ancho, alto, img, ver )
{
    if( ver==0 )
	{
        w = document.getElementById ('flashAlt');
        w.innerHTML = "<a href=\"noticias.php\" ><h1><img src=\"img/logo.png\" alt=\"Efectivamente Comunicación\" title=\"entrar\" border=\"0\" /></h1></a>";
    }
   
    minAncho = ancho;
    minAlto = alto;
    window.onresize=function(){Actualiza ();}
    Actualiza();
}

function PoliticaSocialIni()
{
	elem1Alto = document.getElementById( 'con1' ).offsetHeight;
	elem2Alto = document.getElementById( 'con2' ).offsetHeight;
	elem3Alto = document.getElementById( 'con3' ).offsetHeight;
	
	document.getElementById( 'con1' ).style.height = 0;
	document.getElementById( 'con2' ).style.height = 0;
	document.getElementById( 'con3' ).style.height = 0;
}

function PoliticaSocialPica( cual )
{
	if( elem != '' )
	{
		$( "#con" + elem ).stop().animate( { height: "0px" }, 300 );
	}
	
	if( cual == elem )
	{
		elem = '';
	}
	else
	{
		elem = cual;
		
		$( "#con" + elem ).stop().animate( { height: window[ 'elem' + elem + 'Alto' ] + "px" }, 300 );
	}
	
	
	PoliticaSocialPos();
}

function PoliticaSocialPos()
{
	if( elem == '' )
	{
		$( "#el1" ).stop().animate( { marginTop: ( ( 440 - 99 - 85 - 103 ) / 2 ) + "px" }, 300 );
	}
	else
	{
		var margenEl1 = ( 440 - 99 - 85 - 103 - window[ 'elem' + elem + 'Alto' ] ) / 2;
		$( "#el1" ).stop().animate( { marginTop: margenEl1 + "px" }, 300 );
	}
}

function PonSubMnu( cual, numElems )
{
	if( $( '#bt' + cual ).css( "height" ) == "22px" )
	{
		$( '#bt' + cual ).stop().animate( { height: ( ( 20 * numElems ) + 22 ) + "px" }, 200 );
		$( '#subMnu' + cual ).show();
	}
	else
	{
		$( '#bt' + cual ).stop().animate( { height: "22px" }, 200 );
		$( '#subMnu' + cual ).hide();
	}
}

function PonTrabajo( idTrabajo, idPostit, titulo, enlace )
{
	if( enlace != '' )
	{
		$( '#trabajoImg' ).html( '<a href="' + enlace + '" target="_blank" ><img src="gestor/imagen.php?mod=Trabajos&id=' + idTrabajo + '" border="0" /></a>' );
	}
	else
	{
		$( '#trabajoImg' ).html( '<img src="gestor/imagen.php?mod=Trabajos&id=' + idTrabajo + '" border="0" />' );
	}
	
	if( idPostit != '' )
	{
		$( '#trabajoPostit' ).html( '<img src="gestor/imagen.php?mod=Trabajos&id=' + idPostit + '" border="0" alt="' + titulo + '" />' );
	}
	else
	{
		$( '#trabajoPostit' ).html( '' );
	}
}

function ServiciosFrase( cual, estado )
{
	if( estado == 'over' )
	{
		var altoF = document.getElementById( 'f' + cual ).offsetHeight;
		
		//document.getElementById( 'f' + cual ).style.marginTop = ( - altoF - 5 ) + 'px';
		$( "#f" + cual ).stop().animate( { marginTop: ( - altoF - 5 ) + 'px' }, 200 );
	}
	else if( estado == 'out' )
	{
		//document.getElementById( 'f' + cual ).style.marginTop = '0px';
		$( "#f" + cual ).stop().animate( { marginTop: '0px' }, 200 );
	}
}

function TrabajosNav( dir )
{
	var tmp = trActual;
	
	trActual += dir == "atras" ? 6 : -6;
	
	if( trActual > 0 ) trActual = 0;
	
	if( trActual < -( trTotal - 6 ) ) trActual = -( trTotal - 6 );
	
	if( tmp != trActual ) $( '#trabajos' ).stop().animate( { marginLeft: ( 118 * trActual ) + 'px' }, 300 );
}
