/* ----------------------------------------------- */

$(document).ready(main);



function main()
{
	$('iframe').attr('src', getIframeUrl() );
	registerEvents();
	resizeIframe();
	initarraw();
}

function initarraw ()
{
//Inicialitzem els estats tots a punt per ser maximitzats.
  arrawStatecon = 0;
  arrawStateace = 0;
  arrawStatedata = 0;
  arrawStatecomputer = 0;
  arrawStatevozip = 0;
}

function getIframeUrl()
{
	var url = window.location.href;
	var iframe_url = 'http://www.adam.es/intro3.html';
	var param_start = url.indexOf("iframe=");
	if( param_start != -1 ) 
		iframe_url = url.substr(param_start+7,url.length-param_start-7);
	if( iframe_url.indexOf("http://") == -1) 
		iframe_url = "http://" + iframe_url;
	return iframe_url;
}


function registerEvents()
{
  $(window).resize( function() {resizeIframe();} );
  $("#adamvozip").bind("click", function(){ 
  onArrowvozip();
  menudiv('extra5');
  	});
  $("#adamdatacenter").bind("click", function(){ 	
  onArrowdata();
  menudiv('extra3');
	});
  $("#adamcomputer").bind("click", function(){ 
  onArrowcomputer();
  menudiv('extra4');
	});
  $("#contacto").bind("click", function(){
  onArrowcon();
  menudiv('extra2');
	});
  $("#acercade").bind("click", function(){
  onArrowace();
  menudiv('extra');
	});
  $("#datacenterbcn").bind("click", function(){
  onUpArrowall();
  $('iframe').attr('src', 'http://www.adamdatacenter.es');
  });
  $("#datacentermadrid").bind("click", function(){
  onUpArrowall();
  $('iframe').attr('src', 'http://www.adamecotech.es');
  });
  $("#ltelefoniaip").bind("click", function(){
  onUpArrowall();
  $('iframe').attr('src', 'http://www.adamvozip.es');
  });
  $("#lcomputer").bind("click", function(){
  onUpArrowall();
  $('iframe').attr('src', 'http://www.adamcomputer.es');
  });
  $("#minimize").bind("click", function(){
  onUpArrowall();
  });
  $("#webmail").bind("click", function(){ 
  onUpArrowall();
  netejachromemenu();
  $('iframe').attr('src', 'http://mail.adam.es/v2');
  });
  $("#soporte").bind("click", function(){ 
  onUpArrowall();
  netejachromemenu();
  $('iframe').attr('src', 'http://webs.adam.es/adam/soporte.htm');
	});
  $("#clientes").bind("click", function(){ 
  onUpArrowall();
  netejachromemenu();
  $('iframe').attr('src', 'http://clients.adam.es/');
	});
  /* Llista css amb estat actiu */
  $('ul li a').click(function() {
  $(this).parent().addClass('active').siblings().removeClass('active');
  });
 /* Fi Llista css amb estat actiu */

} //Fi register events

function netejachromemenu()
{
$('#chromemenu ul li a').parent().removeClass('active');
}

function onArrowcon()
{
	
	if( arrawStatecon == 0 ) {
	arrawStatecon = 1;
	onDownArrow();
	}
	else {
	arrawStatecon = 0;
	onUpArrow();
	}

	if( arrawStateace == 1 || arrawStatedata == 1 || arrawStatecomputer == 1 || arrawStatevozip == 1 ) {
	arrawStateace = 0;
	arrawStatedata = 0;
	arrawStatecomputer = 0;
	arrawStatevozip = 0;
	}

}


function onArrowace()
{
	
	if( arrawStateace == 0 ) {
	arrawStateace = 1;
	onDownArrow();
	}
		else {
	arrawStateace = 0;
	onUpArrow();
	}

	if( arrawStatecon == 1 || arrawStatedata == 1 || arrawStatecomputer == 1|| arrawStatevozip == 1 ) {
	arrawStatecon = 0;
	arrawStatedata = 0;
	arrawStatecomputer = 0;
	arrawStatevozip = 0;
	}
}


function onArrowdata()
{

	if( arrawStatedata == 0 ) {
	arrawStatedata = 1; ///Preparar icono per baixar iframe
	onDownArrow();
	}
	else {
	arrawStatedata = 0;
	onUpArrow();}

	if( arrawStateace == 1 || arrawStatecon == 1 || arrawStatecomputer == 1 || arrawStatevozip == 1) {
	arrawStatecon = 0;
	arrawStateace = 0;
	arrawStatecomputer = 0;
	arrawStatevozip = 0;
	}
}

function onArrowcomputer()
{

	if( arrawStatecomputer == 0 ) {
	arrawStatecomputer = 1; ///Preparar icono per baixar iframe
	onDownArrow();
	}
	else {
	arrawStatecomputer = 0;
	onUpArrow();}

	if( arrawStateace == 1 || arrawStatecon == 1 || arrawStatedata == 1 || arrawStatevozip == 1) {
	arrawStatecon = 0;
	arrawStateace = 0;
	arrawStatedata = 0;
	arrawStatevozip = 0;
	}
}

function onArrowvozip()
{

	if( arrawStatevozip == 0 ) {
	arrawStatevozip = 1; ///Preparar icono per baixar iframe
	onDownArrow();
	}
	else {
	arrawStatevozip = 0;
	onUpArrow();}

	if( arrawStateace == 1 || arrawStatecon == 1 || arrawStatedata == 1 || arrawStatecomputer == 1 ) {
	arrawStatecon = 0;
	arrawStateace = 0;
	arrawStatedata = 0;
	arrawStatecomputer = 0;
	}
}




function onDownArrow()
{

	$("#toolbar").animate(
		{
			height: 500
		}, 400, "swing", function()
			{
				
				/*$("#arrow").css("background-position", "-32px 0");*/
				$("#minimize").css("bottom", "455px");
				$("#minimize").css("visibility", "visible");

				resizeIframe();
			});

	$("#logo").animate({height: 495}, 400, "swing", function(){});
	$("#clientes").animate({height: 478}, 400, "swing", function(){});
	$("#soporte").animate({height: 478}, 400, "swing", function(){});
	$("#webmail").animate({height: 478}, 400, "swing", function(){});
	$("#txt1").animate({height: 467}, 400, "swing", function(){});
	$("#txt2").animate({height: 467}, 400, "swing", function(){});
	$("#txt3").animate({height: 467}, 400, "swing", function(){});


} //Fi onDownArrow



function onUpArrow()
{
	$("#toolbar").animate(
		{
			height: 49
		}, 400, "swing", function()
			{
				$("#arrow").css("background-position", "-16px 0");
				resizeIframe();
			});

	$("#logo").animate({height: 43}, 400, "swing", function(){});
	$("#clientes").animate({height: 27}, 400, "swing", function(){});
	$("#soporte").animate({height: 27}, 400, "swing", function(){});
	$("#webmail").animate({height: 27}, 400, "swing", function(){});
	$("#txt1").animate({height: 16}, 400, "swing", function(){});
	$("#txt2").animate({height: 16}, 400, "swing", function(){});
	$("#txt3").animate({height: 16}, 400, "swing", function(){});
}


function onUpArrowall()
{
	//Posem el estats a up
	initarraw();
	//Baixem la barra.
	$("#toolbar").animate(
		{
			height: 49
		}, 400, "swing", function()
			{
				$("#arrow").css("background-position", "-16px 0");
				resizeIframe();
			});

	$("#logo").animate(
		{
			height: 43
		}, 400, "swing", function()
			{});
	
	$("#clientes").animate({height: 27}, 400, "swing", function(){});
	$("#soporte").animate({height: 27}, 400, "swing", function(){});
	$("#webmail").animate({height: 27}, 400, "swing", function(){});
	$("#txt1").animate({height: 16}, 400, "swing", function(){});
	$("#txt2").animate({height: 16}, 400, "swing", function(){});
	$("#txt3").animate({height: 16}, 400, "swing", function(){});
}

function resizeIframe()
{
	$("#iframe").height( WindowHeight() - getObjHeight(document.getElementById("toolbar")) );
}

function WindowHeight()
{
	var de = document.documentElement;
	return self.innerHeight || 
		(de && de.clientHeight ) ||
		document.body.clientHeight;
}

function getObjHeight(obj)
{
	if( obj.offsetWidth )
	{
		return obj.offsetHeight;
	}		
	return obj.clientHeight;
}
/*////////////////////*/
/* menu show/hide div */
/*////////////////////*/
function menudiv(layer_ref){
if(layer_ref == 'extra'){
cdiv('extra','block');
cdiv('extra2','none');
cdiv('extra3','none');
cdiv('extra4','none');
cdiv('extra5','none');
}
if(layer_ref == 'extra2'){
cdiv('extra','none');
cdiv('extra2','block');
cdiv('extra3','none');
cdiv('extra4','none');
cdiv('extra5','none');
}
if(layer_ref == 'extra3'){
cdiv('extra','none');
cdiv('extra2','none');
cdiv('extra3','block');
cdiv('extra4','none');
cdiv('extra5','none');
}
if(layer_ref == 'extra4'){
cdiv('extra','none');
cdiv('extra2','none');
cdiv('extra3','none');
cdiv('extra4','block');
cdiv('extra5','none');
}
if(layer_ref == 'extra5'){
cdiv('extra','none');
cdiv('extra2','none');
cdiv('extra3','none');
cdiv('extra4','none');
cdiv('extra5','block');
}
}

function cdiv(layer_ref,state){
if(document.all){ //IS IE 4 or 5 (or 6 beta)
eval("document.all." +layer_ref+ ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}}

