function http_retrieve ( c_url, c_post_data )
{
	var c_method = ( typeof( c_post_data ) != "undefined" ) ? "POST" : "GET";
	var c = null;
	var c_send_data = "";
	if ( window.XMLHttpRequest ) { c = new XMLHttpRequest(); }
	else if ( window.ActiveXObject ) { c = new ActiveXObject( "Microsoft.XMLHTTP" ); }
	
	if ( typeof( c ) != "object" ) { return; }
	
	if ( c_method == "POST" )
	{
		for ( i in c_post_data )
		{
			if ( c_send_data ) { c_send_data += "&"; }
			c_send_data += esc( i ) +"="+ esc( c_post_data[ i ] );
		}
	}
	
	c.open( c_method, c_url, false );
	c.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	c.setRequestHeader( "X-Requested-By", "WsSys-Internal-Browser" );
	if ( c_method == "POST" ) { c.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); }
	
	c.send( c_send_data );
	
	if ( c.status != 200 ) { if ( debug ) alert( c.responseText ); return; }
	return c.responseText;
}

var projetos_lista =
[
	[ 'APM', 3, 'Perspectiva realizada para Anna Paula Moraes' ],
	[ 'CS', 7, 'Perspectiva realizada para CS interiores' ],
	[ 'CT', 4, 'Perspectiva realizada para Cristina Tonelotti' ],
	[ 'CTMB', 3, 'Perspectiva realizada para Cristina Tonelotti e Melissa Béber' ],
	[ 'ES', 5, 'Perspectiva realizada para Érica Sampaio' ],
	[ 'GL', 1, 'Perspectiva realizada para Gabriela Lucas' ],
	[ 'GM1', 1, 'Acervo Pessoal - Varanda étnica' ],
	[ 'GM2', 1, 'Acervo Pessoal - Recepção SPA' ],
	[ 'GM3', 1, 'Acervo Pessoal - Marketing natal' ],
	[ 'GM4', 1, 'Acervo Pessoal - Concurso Spoleto' ],
	[ 'GM5', 1, 'Acervo Pessoal - Jardim de inverno' ],
	[ 'LB', 1, 'Perspectiva realizada para Letícia Bocci Romualdo' ],
	[ 'MB', 2, 'Perspectiva realizada para Melissa Béber' ],
	[ 'PP', 1, 'Perspectiva realizada para Tita Portilho' ],
	[ 'RZ', 3, 'Perspectiva realizada para ARZ Design' ],
	[ 'SA', 2, 'Perspectiva realizada para Sandra Araújo' ],
	[ 'SD', 14, 'Perspectiva realizada para Studio DWG' ],
	[ 'SM', 3, 'Perspectiva realizada para Silvana Marola' ],
	[ 'VR', 1, 'Perspectiva realizada para Vanessa Rossi' ]
];
var projetos_lista_continua = new Array();
for ( i in projetos_lista )
	for ( j = 1; j <= projetos_lista[ i ][1]; j ++ )
		projetos_lista_continua[ projetos_lista_continua.length ] = [ projetos_lista[ i ][0] +""+ j, projetos_lista[ i ][2] ];

var projetos_lista_continua_comofunciona = [ [ '_PRV', 'Exemplo de prévia de uma perspectiva' ], [ 'CS2', 'Exemplo de uma perspectiva monocromática<br />Perspectiva realizada para CS interiores' ], [ 'RZ3', 'Exemplo de uma perspectiva colorida<br />Perspectiva realizada para ARZ Design' ] ];

var projetos_tipo = "padrao", projetos_pagina = 1, projetos_por_pagina = 5;
function projetos_navega ( pagina )
{
	var v, html = "";
	for ( i in projetos_lista_continua )
	{
		if ( i < ( pagina - 1 ) * projetos_por_pagina )
			continue;
		if ( i > pagina * projetos_por_pagina - 1 )
			break;
		
		v = projetos_lista_continua[ i ];
		
		// html += "<img src=\"projetos/miniaturas/N"+ projetos_lista_continua[ i ][0] +".jpg\" width=\"107\" height=\"107\" border=\"0\" style=\"float:left; margin-right:13px; cursor:pointer; \" onclick=\"projetos_abrir( "+ i +" );\" onmouseover=\"this.src = 'projetos/miniaturas/C"+ projetos_lista_continua[ i ][0] +".jpg'; \" onmouseout=\"this.src = 'projetos/miniaturas/N"+ projetos_lista_continua[ i ][0] +".jpg'; \" />";
		html += "<img src=\"projetos/miniaturas/C"+ projetos_lista_continua[ i ][0] +".jpg\" width=\"107\" height=\"107\" border=\"0\" style=\"float:left; margin-right:13px; cursor:pointer; \" onclick=\"projetos_tipo = 'padrao'; projetos_abrir( "+ i +" ); \" />";
	}
	projetos_pagina = pagina;
	
	document.getElementById( "projetos_anterior" ).style.visibility = "visible";
	document.getElementById( "projetos_proxima" ).style.visibility = "visible";
	if ( projetos_pagina == 1 )
	{
		document.getElementById( "projetos_anterior" ).style.visibility = "hidden";
	}
	else if ( projetos_pagina == Math.ceil( projetos_lista_continua.length / projetos_por_pagina ) )
	{
		document.getElementById( "projetos_proxima" ).style.visibility = "hidden";
	}
	
	
	document.getElementById( "projetos_miniaturas" ).innerHTML = html;
}

function projetos_anterior ( )
{
	if ( projetos_pagina == 1 )
		return;
	
	projetos_navega( projetos_pagina - 1 );
	
}

function projetos_proxima ( )
{
	if ( projetos_pagina == Math.ceil( projetos_lista_continua.length / projetos_por_pagina ) )
		return;
	
	projetos_navega( projetos_pagina + 1 );
}

var projetos_aberto = false,
	projetos_i = null;
function projetos_abrir ( i )
{
	var lista = projetos_lista_continua;
	if ( projetos_tipo == "comofunciona" )
		lista = projetos_lista_continua_comofunciona;
	document.getElementById( "projetos_visualizar" ).innerHTML = "<img src=\"projetos/"+ lista[ i ][0] +".jpg\" onload=\"projetos_centraliza( this ); \" style=\"display:none; \" /><br /><div style=\"padding:5px; font-size:9pt; text-align:right; color:#FFF; line-height:1; \"><div style=\"float:left; font-weight:bold; \">"+ ( projetos_tipo == "padrao" ? "<span style=\"cursor:pointer; "+ ( i > 0 ? "\" onclick=\"projetos_abrir( "+ ( i - 1 ) +" ); " : "color:#999; " ) +"\">&laquo; Anterior</span> &middot; <span style=\"cursor:pointer; \" onclick=\"projetos_fechar(); \">Fechar</span> &middot; <span style=\"cursor:pointer; "+ ( i < lista.length - 1 ? "\" onclick=\"projetos_abrir( "+ ( i + 1 ) +" ); " : "color:#999; " ) +"\">Próxima &raquo;</span>" : "<span style=\"cursor:pointer; \" onclick=\"projetos_fechar(); \">Fechar</span>" ) +"</div>"+ lista[ i ][1] +"</div>";
	document.getElementById( "projetos_visualizar_carregando" ).style.display = "";
	document.getElementById( "projetos_visualizar_fundo" ).style.display = "";
	projetos_aberto = true;
	projetos_i = i;
}

function projetos_centraliza ( obj )
{
	obj.style.display = "";
	document.getElementById( "projetos_visualizar" ).style.display = "";
	document.getElementById( "projetos_visualizar" ).style.marginTop = "-"+ parseInt( obj.height / 2 ) +"px";
	document.getElementById( "projetos_visualizar" ).style.marginLeft = "-"+ parseInt( obj.width / 2 ) +"px";
	document.getElementById( "projetos_visualizar_carregando" ).style.display = "none";
	document.getElementById( "musica_controles" ).style.display = "none";
	document.getElementById( "rodape" ).style.display = "none";
}

function projetos_fechar ( )
{
	document.getElementById( "projetos_visualizar" ).style.display = "none";
	document.getElementById( "projetos_visualizar_fundo" ).style.display = "none";
	document.getElementById( "musica_controles" ).style.display = "";
	document.getElementById( "rodape" ).style.display = "";
	projetos_aberto = false;
}

function projetos_teclado ( e )
{
	if ( !projetos_aberto )
		return;
	
	if ( e.keyCode == 27 )
		projetos_fechar();
	else if ( projetos_tipo == "padrao" && e.keyCode == 37 && projetos_i > 0 )
		projetos_abrir( projetos_i - 1 );
	else if ( projetos_tipo == "padrao" && e.keyCode == 39 && projetos_i < projetos_lista_continua.length - 1 )
		projetos_abrir( projetos_i + 1 );
}

window.onkeydown = function ( e ) { projetos_teclado( e ) };

var pagina_anterior = "entrada";
function navega ( pagina, titulo, sem_anim )
{
	var i = 0, passos = 60, intervalo = 10;
	
	if ( pageTracker )
		pageTracker._trackPageview( "/site/"+ pagina );
	
	if ( pagina_anterior == pagina )
		return;
	
	if ( sem_anim )
	{
		document.getElementById( "conteudo-"+ pagina_anterior ).style.display = "none";
		document.getElementById( "conteudo-"+ pagina ).style.display = "";
		document.getElementById( "barra" ).style.marginTop = "-267px"; 
		document.getElementById( "barra_logo" ).style.marginTop = "-267px"; 
	}
	else
	{
		document.getElementById( "conteudo-"+ pagina_anterior ).style.display = "";
		document.getElementById( "conteudo-"+ pagina_anterior ).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
		document.getElementById( "conteudo-"+ pagina ).style.display = "";
		document.getElementById( "conteudo-"+ pagina ).style.opacity = "0";
		document.getElementById( "conteudo-"+ pagina ).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
		
		if ( pagina_anterior == "entrada" )
		{
			var inicial = -51, final = -267;
			for ( i = 0; i <= passos; i ++ )
			{
				window.setTimeout( "document.getElementById( \"barra\" ).style.marginTop = \""+ parseInt( inicial + ( ( final - inicial ) * ( i / passos ) ) ) +"px\"; ", intervalo * i );
				window.setTimeout( "document.getElementById( \"barra_logo\" ).style.marginTop = \""+ parseInt( inicial + ( ( final - inicial ) * ( i / passos ) ) ) +"px\"; ", intervalo * i );
			}
		}
		i = 0;
		for ( j = 0; j <= passos; j ++ )
		{
			window.setTimeout( "document.getElementById( \"conteudo-"+ pagina_anterior +"\" ).style.opacity = \""+ parseInt( 1 * ( 1 - j / passos ) * 100 ) / 100 +"\"; ", intervalo * ( i + j ) );
			window.setTimeout( "try { document.getElementById( \"conteudo-"+ pagina_anterior +"\" ).filters.item( \"DXImageTransform.Microsoft.Alpha\" ).opacity = \""+ parseInt( 100 - ( 100 * j / passos ) ) +"\"; } catch ( e ) { }", intervalo * ( i + j ) );
			window.setTimeout( "document.getElementById( \"conteudo-"+ pagina +"\" ).style.opacity = \""+ parseInt( 1 * ( j / passos ) * 100 ) / 100 +"\"; ", intervalo * ( i + j ) );
			window.setTimeout( "try { document.getElementById( \"conteudo-"+ pagina +"\" ).filters.item( \"DXImageTransform.Microsoft.Alpha\" ).opacity = \""+ parseInt( 100 * ( j / passos ) ) +"\"; } catch ( e ) { }", intervalo * ( i + j ) );
		}
		
		window.setTimeout( "try { document.getElementById( \"conteudo-"+ pagina_anterior +"\" ).style.removeAttribute( 'filter' ); } catch ( e ) { }", intervalo * ( i + j ) );
		window.setTimeout( "document.getElementById( \"conteudo-"+ pagina_anterior +"\" ).style.display = \"none\"; ", intervalo * ( i + j ) );
		window.setTimeout( "try { document.getElementById( \"conteudo-"+ pagina +"\" ).style.removeAttribute( 'filter' ); } catch ( e ) { }", intervalo * ( i + j ) );
		window.setTimeout( "document.getElementById( \"conteudo-"+ pagina +"\" ).style.display = \"\"; ", intervalo * ( i + j ) );
	}
	
	pagina_anterior = pagina;
	document.title = "Design & Interiores"+ ( titulo ? " - "+ titulo : "" );
	location.replace( "./#"+ pagina );
}

var bola_link = null, bola_titulo = null;
function bola_troca ( pos_x, pos_y, lnk, titulo )
{
	if ( pos_y )
	{
		document.getElementById( "bola" ).style.display = "";
		document.getElementById( "bola" ).style.top = pos_y - 19 +"px";
		document.getElementById( "bola" ).style.left = pos_x - 19 +"px";
		document.getElementById( "bola" ).title = titulo;
		bola_link = lnk;
		bola_titulo = titulo;
	}
	else
	{
		document.getElementById( "bola" ).style.display = "none";
		bola_link = null;
		bola_titulo = null;
	}
}

function bola_clica ( )
{
	if ( bola_link )
		navega( bola_link, bola_titulo );
}

var perspectivas_count = 0;
function perspectivas_inicializa ( )
{
	var resposta = http_retrieve( "perspectivas_carrega.php" );
	if ( resposta.indexOf( "OK" ) != 0 )
		return;
	var perspectivas_count = resposta.substr( 2 );
	
	if ( perspectivas_count != 0 )
		document.getElementById( "div_perspectivas" ).innerHTML = "Já fizemos "+ perspectivas_count +" perspectivas.";
}

var scrap_lista = [];
var scrap_num = 0;
function scrap_inicializa ( )
{
	var resposta = http_retrieve( "scrap_carrega.php" );
	if ( resposta.indexOf( "OK" ) != 0 )
		return;
	var scrap_lista_raw = resposta.substr( 2 ).split( "|" ), j = -1, k = 0;
	
	for ( i = 0; i < scrap_lista_raw.length; i ++ )
	{
		if ( i == 0 || k == 2 )
		{
			j ++;
			scrap_lista[ j ] = new Array();
		}
		
		if ( k == 2 )
			k = 0;
		
		scrap_lista[ j ][ k ] = unescape( scrap_lista_raw[ i ] );
		
		k ++;
	}
	scrap_carrega( scrap_num );
}
function scrap_carrega ( num )
{
	if ( typeof( scrap_lista[ num ] ) == "undefined" )
		return;
	
	document.getElementById( "scrap_mensagem" ).innerHTML = scrap_lista[ num ][1] +"<br /><div style=\"padding-top:5px; font-size:8pt; color:#EEE; \">"+ scrap_lista[ num ][0] +"</div>";
	scrap_num = num;
}
function scrap_anterior ( )
{
	if ( scrap_num == 0 )
		return;
	scrap_carrega( scrap_num - 1 );
}
function scrap_proximo ( )
{
	if ( scrap_num - 1 == scrap_lista.length )
		return;
	scrap_carrega( scrap_num + 1 );
}

function inicializa ( )
{
	if ( location.hash && location.hash != "#" )
		navega( location.hash.replace( /^#/, "" ), "", true );
	else
		pageTracker._trackPageview( "/site/" );	
	projetos_navega( 1 );
	perspectivas_inicializa();
	scrap_inicializa();
	
	/*
	var s1 = new SWFObject( "musicas/player.swf", "ply", "328", "20", "9", "#FFFFFF" );
	s1.addParam( "allowscriptaccess", "always" );
	s1.addParam( "flashvars", "file=musicas/playlist.xspf&autostart=true&repeat=always&volume=80" );
	s1.write( "musica" );
	*/
}

var player;

function playerReady ( obj )
{
	player = document.getElementById( obj['id'] );
	player.addControllerListener( "ITEM", "musica_muda" );
}

function musica_muda ( obj )
{
	switch ( obj.index )
	{
		case 0:
			document.getElementById( "site" ).className = "lilas";
			break;
		case 1:
			document.getElementById( "site" ).className = "laranja";
			break;
		case 2:
			document.getElementById( "site" ).className = "azul";
			break;
	}
}
function musica_anterior ( )
{
	player.sendEvent( "PREV" );
}
function musica_proxima ( )
{
	player.sendEvent( "NEXT" );
}
function musica_playpause ( )
{
	player.sendEvent( "PLAY" );
}

