$(document).ready(function(e){

	//init_rota();
	$(".menuitem[title]").bind('click',function(e){ 
	//$(".menuitem").bind('click',function(e){
		//alert($(this).attr('title')+".ajx.php");
		//$(".menuitem").css({ "opacity":"1" , "filter":"alpha(opacity = 100)"});
		//$(this).css({ "opacity":"0.4" , "filter":"alpha(opacity = 40)" });
		var img;
		$(".menuitem").css({ "color":""});
		$(".menuitem").css({ "font-weight":"normal"});
		//onclick="$('.negrita').css('font-weight','normal');$(this).css('font-weight','bold');"
		$(this).css({ "color":"#BBC893" });
		$(this).css({ "font-weight":"bold" });
		$("#texto").html('<span style="position:absolute; left:20px; margin-top:40px;"><img src="img/spin.gif"></span>');
		
		if($(this).attr('title')=='neighborhood')
		{
			$("#imgcentral").fadeOut("fast", function(){
				$("#imgcentral").attr('src','');
				$("#imgcentral").attr('width','0');
				$("#imgcentral").attr('height','0');
				$("#imgcentral").fadeIn('fast');
				$('#flash').html('');
				$("#flash").html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="975" height="420"><param name="movie" value="slide_nei.swf" /><param name="quality" value="high" /><embed src="slide_nei.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="975" height="420"></embed></object>');
			});
		}
		else if($(this).attr('title')=='developer')
		{
			$("#imgcentral").fadeOut("fast", function(){
				$("#imgcentral").attr('src','');
				$("#imgcentral").attr('width','0');
				$("#imgcentral").attr('height','0');
				$("#imgcentral").fadeIn('fast');
				$('#flash').html('');
				$("#flash").html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="975" height="420"><param name="movie" value="slide_deve.swf" /><param name="quality" value="high" /><embed src="slide_deve.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="975" height="420"></embed></object>');
			});
		}
		else if($(this).attr('title')=='home')
		{
			$("#imgcentral").fadeOut("fast", function(){
				$("#imgcentral").attr('width','0');
				$("#imgcentral").attr('height','0');
				$("#imgcentral").attr('src','');
				$("#imgcentral").fadeIn('fast');
				$('#flash').html('');
				$("#flash").html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="975" height="420"><param name="movie" value="slide_home.swf" /><param name="quality" value="high" /><embed src="slide_home.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="975" height="420"></embed></object>');
			});
		}
		else
		{
			img=$(this).attr('rel');
			$("#preload").stop();
			$("#preload").attr('src','');
			//$("#imgcentral").fadeOut("fast", function (){
			$("#preload").attr('src',img);
			$("#preload").load(function(){
				$("#imgcentral").attr('width','975');
				$("#imgcentral").attr('height','420');
				$("#imgcentral").fadeOut("fast", function(){
					//$(".sizecentral").html('<img id="imgcentral" src="'+$("#preload").attr('src')+'" />');
					$('#flash').html('');
					$("#imgcentral").attr('src', $("#preload").attr('src') );
					$("#imgcentral").fadeIn("slow");//, function(){$("#imgcentral").stop();});
					//$("#imgcentral").fadeTo(100, 1);//, function(){$("#imgcentral").stop();});
					
				});
				
				//$("#imgcentral").stop();
			});			
		}
		//});
		$("#texto").load($(this).attr('title')+".ajx.php");
	});

	$("#logo").bind('click',function(e){
		$(".menuitem").css({ "color":""});
		$(".menuitem").css({ "font-weight":"normal"});
		$("#texto").html('<span style="position:absolute; left:160px; margin-top:40px;"><img src="img/spin.gif"></span>');
		$("#texto").load("home.ajx.php");
		$('#flash').html('');
		$("#imgcentral").fadeOut("fast", function(){
				$("#imgcentral").attr('src','');
				$("#imgcentral").attr('width','0');
				$("#imgcentral").attr('height','0');
				$("#imgcentral").fadeIn('fast');
				$("#flash").html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="975" height="420"><param name="movie" value="slide_home.swf" /><param name="quality" value="high" /><embed src="slide_home.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="975" height="420"></embed></object>');
		});
		//init_rota();							
	});

});
	
function gal(img)	
{
	$("#imgcentral").stop();
	$("#preload").attr('src',img);
	$("#preload").load(function(){
		$("#imgcentral").fadeOut("fast", function(){
			$("#imgcentral").attr('src',$("#preload").attr('src'));
			//$("#imgcentral").fadeIn("slow", function(){$("#imgcentral").stop();});
			$("#imgcentral").fadeTo(100, 1);
		});
	});	
}

var c=0;
img = new Array();
img[0]='img/centrales/concept.jpg';
img[1]='img/centrales/contact.jpg';
img[2]='img/centrales/developer.jpg';
img[3]='img/centrales/features.jpg';
img[4]='img/centrales/gallery.jpg';
img[5]='img/centrales/home.jpg';
img[6]='img/centrales/location.jpg';
img[7]='img/centrales/neighborhood.jpg';
img[8]='img/centrales/space.jpg';

function rota(i)
{
	//alert(img[c]);
	$("#preload").attr('src',img[c]);
	$("#preload").load(function(){
		$("#imgcentral").fadeOut("fast", function(){
			$("#imgcentral").attr('src',$("#preload").attr('src'));
			$("#imgcentral").fadeIn("slow", function(){$("#imgcentral").stop();});
		});
	});	
	c++;
	//alert('rota: ' + c);
	init_rota();
}
function init_rota()
{
	//alert('init: ' + c);
	if(c>=img.length){c=0;}
	setInterval('rota('+ c +')',10000);
}

function contact()
{
	var r=true;
	//alert($("#txt_name").val() + " - " + $("#txt_msg").val() + " - " + $("#txt_mail").val() );
	$("#txt_name").css("backgroundColor","");
	$("#txt_msg").css("backgroundColor",""); 
	$("#txt_mail").css("backgroundColor","");
	
	if($("#txt_name").val()=='' || $("#txt_name").val()=='Name') {r=false; $("#txt_name").css("backgroundColor","red");}
	if($("#txt_msg").val()=='' || $("#txt_msg").val()=='Write your message' ) {r=false; $("#txt_msg").css("backgroundColor","red");}
	if($("#txt_mail").val()=='' || $("#txt_mail").val()=='Email') {r=false; $("#txt_mail").css("backgroundColor","red");}
	if(r==true)
	{
		$('#texto').load('contact.ajx.php', { 'name': $('#txt_name').val(), 'msg': $('#txt_msg').val(), 'mail': $('#txt_mail').val() } )
	}
	else
	{
		alert('You must complete all fields');
	}
}