      function images_on()
                {
                    $("#image1").css("visibility","visible");
                   // $("#image2").css("visibility","visible");
                   // $("#image3").css("visibility","visible");
                    $("#image1").fadeIn(12);
                    $("#image2").fadeOut(1);
                    $("#image3").fadeOut(1);
                }
                function visibility_contact( variable )
                {
                    if(variable == 0)
                    {
                        $("#contacto .hidden").css('visibility','hidden');
                        $("#contacto #a3").css('visibility','visible');
                    }else{
                        $("#contacto .hidden").css('visibility','visible');
                        $("#contacto #a3").css('visibility','hidden');
                    }
                }
                //For know where we are.
                //0 -> HOME
                //1 -> More INFO
                //2 -> CONTACT
                var state = 0;
                //FUNCTION RESIZE
                function intro_out_resize()
                {
                     $("#info").animate({width:  "0px"}, { queue:false, duration:400 });
                     $("#contacto").animate({width: "122px"}, { queue:false, duration:400 });
                     wid = $("#box").width() - $("#title").width() -170;
                     $("#intro").animate({width: wid+"px"}, { queue:false, duration:400});
                }
                function info_out_resize()
                {
                     $("#intro").animate({width:  "0px"}, { queue:false, duration:400 });
                     $("#contacto").animate({width: "122px"}, { queue:false, duration:400 });
                     wid = $("#box").width() - $("#title").width() -170;
                     $("#info").animate({width: wid+"px"}, { queue:false, duration:400});
                }
                 function contact_out_resize()
                {
                    $("#info").animate({width: "0px"}, { queue:false, duration:400 });
                    $("#intro").animate({width: "0px"}, { queue:false, duration:400 });
                    wid = $("#box").width() - $("#title").width() -45;
                    $("#contacto").animate({width:  wid+"px"}, { queue:false, duration:400});
                }


                //FUNCTION CHANGE THE STATE
                function intro_out()
                {
                     intro_out_resize();
                     visibility_contact( 0 );
                     loadBackDrop('images/fondo2.jpg');
                     $("body").css("background-image","none");
                     $("#backdrop").fadeIn(500);
                     $("#image1").fadeIn(100);
                     state = 0;
                }
                function info_out()
                {
                     info_out_resize();
                     visibility_contact( 0 );
                     loadBackDrop('images/fondo1.jpg');
                     $("body").css("background-image","none");
                     $("#backdrop").fadeIn(1000);
                     $("#image2").css("visibility","visible");
                     $("#image2").fadeIn(500);
                     state = 1;
                }

                function contact_out()
                {
                    contact_out_resize();
                    visibility_contact( 1 );
                    loadBackDrop('images/fondo.jpg');
                    $("body").css("background-image","none");
                    $("#backdrop").fadeIn(1000);
                    $("#image3").css("visibility","visible");
                    $("#image3").fadeIn(500);
                    state = 2;
                   
                }

                $(document).ready(function ()
                        {

                                //FLASH fullscreen
                                $("body").append('<div id="backdrop"></div>');
                                $("#backdrop").hide();
                                loadBackDrop('images/fondo2.jpg');
                                $("body").css("background-image","none");
                                //intro_out();

                                $("#home, #title").click(
                                  function(){
                                    $("body").css("background-image","none");
                                    $("#backdrop").fadeOut(1000);
                                    $("#image2").fadeOut(100);
                                    $("#image3").fadeOut(100);
                                    $(document).oneTime(1000, "sds", intro_out  );

                                    //Activa logo
                                    $("#title").css("background-color","transparent");

                                  }
                                );

                                $("#a2").click(
                                  function(){
                                     $("body").css("background-image","none");
                                    $("#backdrop").fadeOut(1000);
                                    $("#image1").fadeOut(100);
                                    $("#image3").fadeOut(100);
                                    $(document).oneTime(1000, "sds", info_out  );

                                    //Activa logo
                                    $("#title").css("background-color","transparent");
                                     }
                                );

                                $("#a3, #contacto").click(
                                  function(){

                                    $("body").css("background-image","none");
                                    $("#backdrop").fadeOut(1000);
                                    $("#image1").fadeOut(100);
                                    $("#image2").fadeOut(100);
                                    $(document).oneTime(1000, "sds", contact_out  );

                                    //Return to old position color
                                    $("#contacto").css("cursor","default");
                                    $("#contacto").css("background-color","transparent"); 
                                  }
                                );
                                //ROLLOVER INTRO
                                $("#title").hover(
                                  function(){
                                        if(state != 0)
                                        {
                                        $("#title").css("cursor","pointer");
                                        $("#title").css("background-color","#689aba");
                                        }

                                },
                                  function () {
                                    $("#title").css("cursor","default");
                                     $("#title").css("background-color","transparent");
                                  }
                                );
                                //ROLLOVER CONTACTO
                                $("#contacto").hover(
                                  function(){
                                    
                                    if(state != 2)
                                        {
                                        $("#contacto").css("cursor","pointer");
                                        $("#contacto").css("background-color","#689aba");

                                        $("#a3 a").css("color","#FFFFFF");
                                        $("#a3 .link2").css("background-image","url(images/link1_hover.png)");
                                        }
                                },
                                  function () {
                                    $("#contacto").css("cursor","default");
                                    $("#a3 a").css("color","#5990b9");
                                    $("#a3 .link2").css("background-image","url(images/link1.png)");
                                    $("#contacto").css("background-color","transparent"); 
                                  }
                                );

                                //LOS RS
                                $("#logo2")
                                .mouseover(function() {
                                    var src = $(this).attr("src").match(/[^\.]+/) + "_hover.png";
                                    $(this).attr("src", src);
                                })
                                .mouseout(function() {
                                    var src = $(this).attr("src").replace("_hover", "");
                                    $(this).attr("src", src);
                                });




                                //RESIZE EVENT
                                  var resizeTimer = null;
                                  $(window).bind('resize', function() {
                                  if (resizeTimer) clearTimeout(resizeTimer);
                                  resizeTimer = setTimeout(doSomething, 100);
                                   });

                                //Create a layer
                                $("body").append('<div id="image1"><img src="images/image1.png" alt=" "></div>');
                                $("body").append('<div id="image2"><img src="images/image2.png" alt=" "></div>');
                                $("body").append('<div id="image3"><img src="images/image3.png" alt=" "></div>');
                                $("body").append('<div class="image-holder"></div>');

                                //ROOLLOVER
                                $("#masinfo").hover(
                                    function(){
                                     $(this).attr("src","images/redonda_hover.png");
                                    },
                                    function () {
                                        $(this).attr("src","images/redonda.png");
                                    }
                                );

                                //DETECT WIDTH
                                //if ((screen.width>=1024) && (screen.height>=768)) {}
                                if(screen.width<=1024){
                                     $("ul li p").css("font-size","10px");
                                     $(".large").css("width","157px");
                                }


                        });
                 function doSomething() {
                            if(state == 0) intro_out_resize();
                            if(state == 1) info_out_resize();
                            if(state == 2) contact_out_resize();
                          };
                /******************************************************************
                **PRELOADING LOADING
                ******************************************************************/
                 $(function () {
			//$('img').hide();//hide all the images on the page
                        $('#box').hide();
		});

		var i = 0;//initialize
		var int=0;//Internet Explorer Fix
		$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
                        $(document).oneTime(500, "preload", doThis  );
                });

		function doThis() {
			/*
                        var imgs = $('img').length;//count the number of images on the page
			if (i >= imgs) {// Loop the images
				clearInterval(int);//When it reaches the last image the loop ends
			}
			$('img:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
			i++;//add 1 to the count
                        */

                        $('#box').fadeIn(500);
                        $(document).oneTime(200, "sds", images_on  );
                        intro_out();
                        $('.image-holder').fadeOut(2);
		}

