/*! Copyright (c) 2011 Whale
 * 
 * Written by: Paulo Almeida
 * Version: 1.0.0
 * 
 * Requires: 1.2.2+
 */

var form_visita_on=false;
var form_info_on=false;
var form_finan_on=false;

var doc_ready=false;

$(document).ready(function() {


//###################   LOGIN    #########################################  

    $('#login_form').animate({
      top: '+=70',
      height: 0, 
    }, 1);
    $('#login_cancel').animate({
      opacity: 0.0,
      top: '+=70',
      height: 0, 
    }, 1);


    $('#login_click').click(function() { 

      $('#login_click').animate({
         top: '+=0',
         height: '-=30',
       }, 300); 
   
      $('#login_form').animate({
         top: '+=0',
         height: '+=220',
       }, 500);

      $('#login_cancel').animate({
         opacity: 1.0,
         top: '+=0',
         height: '+=20',
       }, 700);

    });

    $('#login_cancel').click(function() { 

    $('#login_form').animate({
      height: '-=220',
    }, 400);

      $('#login_click').animate({
         top: '+=0',
         height: '+=30',
       }, 600); 

      $('#login_cancel').animate({
         opacity: 0.0,
         top: '+=0',
         height: '-=20',
       }, 200);

    });


//###################  FORM BUTTONS   #####################################




    $('#form_visita').animate({
      opacity: 0.0,
      height: 0,
      top: -400,
    }, 1);
    $('#form_info').animate({
      opacity: 0.0,
      height: 0,
      top: -400,
    }, 1);
    $('#form_finan').animate({
      opacity: 0.0,
      height: 0,
      top: -400,
    }, 1);

    $('#bt_visita').click(function() {

      if(form_visita_on==false){

       form_visita_on=true;

       $('#form_visita').animate({
         opacity: 0.0,
         height: 0,
         top: 160,
       }, 10);

	if(document.getElementById('form_visita').offsetHeight<290){
           $('#form_cancel_visita').animate({
              opacity: 1.0,
           }, 50);
	   $('#form_visita').animate({
             opacity: 1.0, 
      	     height: '+=310',
  	   }, 600, function() {
    	   // Animation complete.
  	   });
	   $('#content').animate({
      	     top: '+=335',
  	   }, 600, function() {
    	   // Animation complete.
  	   });
        };

        return false; 
      };

    });

    $('#bt_info').click(function() { 

      if(form_info_on==false){

       form_info_on=true;

       $('#form_info').animate({
         opacity: 0.0,
         height: 0,
         top: 160,
       }, 10);

	if(document.getElementById('form_info').offsetHeight<290){
           $('#form_cancel_info').animate({
              opacity: 1.0,
           }, 50);
	   $('#form_info').animate({
             opacity: 1.0, 
      	     height: '+=215',
  	   }, 600, function() {
    	   // Animation complete.
  	   });
	   $('#content').animate({
      	     top: '+=230',
  	   }, 600, function() {
    	   // Animation complete.
  	   });
        };

        return false; 
      };

    });

    $('#bt_finan').click(function() { 

      if(form_finan_on==false){

       form_finan_on=true;

       $('#form_finan').animate({
         opacity: 0.0,
         height: 0,
         top: 160,
       }, 10);

	if(document.getElementById('form_finan').offsetHeight<290){
           $('#form_cancel_finan').animate({
              opacity: 1.0,
           }, 50);
	   $('#form_finan').animate({
             opacity: 1.0, 
      	     height: '+=310',
  	   }, 600, function() {
    	   // Animation complete.
  	   });
	   $('#content').animate({
      	     top: '+=335',
  	   }, 600, function() {
    	   // Animation complete.
  	   });
        };

        return false; 
      };

    });

    $('#form_cancel_visita').click(function() { 

       form_visita_on=false;
       form_info_on=false;
       form_finan_on=false;

       if(document.getElementById('form_visita').offsetHeight>200){
            $('#form_cancel_visita').animate({
             opacity: 0.0,
             }, 50, function() {
    	   // Animation complete.
  	   });
            $('#form_visita').animate({
             opacity: 1.0,
             height: '-=310'
            }, 500, function() {
    	   // Animation complete.
  	   });
	   $('#content').animate({
      	     top: '-=335',
  	   }, 550, function() {
    	   // Animation complete.
  	   });
            $('#form_visita').animate({
             top: '-=600'
            }, 5, function() {
    	   // Animation complete.
  	   });
        };
    });
    
    
    $('#form_cancel_info').click(function() { 

       form_visita_on=false;
       form_info_on=false;
       form_finan_on=false;

       if(document.getElementById('form_info').offsetHeight>200){
            $('#form_cancel_info').animate({
             opacity: 0.0,
             }, 50, function() {
    	   // Animation complete.
  	   });
            $('#form_info').animate({
             opacity: 1.0,
             height: '-=215'
            }, 500, function() {
    	   // Animation complete.
  	   });
	   $('#content').animate({
      	     top: '-=230',
  	   }, 550, function() {
    	   // Animation complete.
  	   });
            $('#form_info').animate({
             top: '-=600'
            }, 5, function() {
    	   // Animation complete.
  	   });
        };

    });

    $('#form_cancel_finan').click(function() { 

       form_visita_on=false;
       form_info_on=false;
       form_finan_on=false;

       if(document.getElementById('form_finan').offsetHeight>200){
            $('#form_cancel_finan').animate({
             opacity: 0.0,
             }, 50, function() {
    	   // Animation complete.
  	   });
            $('#form_finan').animate({
             opacity: 1.0,
             height: '-=310'
            }, 500, function() {
    	   // Animation complete.
  	   });
	   $('#content').animate({
      	     top: '-=335',
  	   }, 550, function() {
    	   // Animation complete.
  	   });
            $('#form_finan').animate({
             top: '-=600'
            }, 5, function() {
    	   // Animation complete.
  	   });
        };
    });




//#################  BOTTOM NAVBAR   #####################################


    $('#bt01_shadow').animate({
      opacity: 0.2, 
    }, 1);

    $('#bt01_tab').animate({
      opacity: 0.0,
      height: 5,
      top: 485, 
    }, 1);
    $('#bt01_shadow').animate({
      opacity: 0.2, 
    }, 1);

    $('#bt02_tab').animate({
      opacity: 0.0,
      height: 5,
      top: 485, 
    }, 1);
    $('#bt02_shadow').animate({
      opacity: 0.2, 
    }, 1);

    $('#bt03_tab').animate({
      opacity: 0.0,
      height: 5,
      top: 485, 
    }, 1);
    $('#bt03_shadow').animate({
      opacity: 0.2, 
    }, 1);

    $('#bt04_tab').animate({
      opacity: 0.0,
      height: 5,
      top: 485,  
    }, 1);
    $('#bt04_shadow').animate({
      opacity: 0.2, 
    }, 1);


    $("#bt01").hover(
      function () {
            /*$('#bt01_tab').animate({
             opacity: 0.0, 
      	     top: '=485',
      	     height: '=5',
            }, 10);*/
            $('#bt01_tab').animate({
             opacity: 0.95, 
      	     top: '-=155',
      	     height: '+=140',
            }, 800);
            $('#bt01_image').animate({
      	     top: '+=30',
            }, 1000);
            $('#bt01_shadow').animate({
             opacity: 1.0,
            }, 1000);
      }, 
      function () {
            /*$('#bt01_tab').animate({
             opacity: 1.0, 
      	     top: '=330',
      	     height: '=140',
            }, 1);*/
            $('#bt01_tab').animate({
             opacity: 0.0,
      	     top: '+=155',
      	     height: '-=140',
            }, 500);
            $('#bt01_image').animate({
      	     top: '-=30',
            }, 500);
            $('#bt01_shadow').animate({
             opacity: 0.2,
            }, 500);
      }
    );


    $("#bt02").hover(
      function () {
            /*$('#bt02_tab').animate({
             opacity: 0.0, 
      	     top: '=485',
      	     height: '=5',
            }, 10);*/
            $('#bt02_tab').animate({
             opacity: 0.95, 
      	     top: '-=155',
      	     height: '+=140',
            }, 800);
            $('#bt02_image').animate({
      	     top: '+=30',
            }, 1000);
            $('#bt02_shadow').animate({
             opacity: 1.0,
            }, 1000);
      }, 
      function () {
            /*$('#bt02_tab').animate({
             opacity: 1.0, 
      	     top: '=330',
      	     height: '=140',
            }, 1);*/
            $('#bt02_tab').animate({
             opacity: 0.0,
      	     top: '+=155',
      	     height: '-=140',
            }, 500);
            $('#bt02_image').animate({
      	     top: '-=30',
            }, 500);
            $('#bt02_shadow').animate({
             opacity: 0.2,
            }, 500);
      }
    );

    $("#bt03").hover(
      function () {
            /*$('#bt03_tab').animate({
             opacity: 0.0, 
      	     top: '=485',
      	     height: '=5',
            }, 10);*/
            $('#bt03_tab').animate({
             opacity: 0.95, 
      	     top: '-=155',
      	     height: '+=140',
            }, 800);
            $('#bt03_image').animate({
      	     top: '+=30',
            }, 1000);
            $('#bt03_shadow').animate({
             opacity: 1.0,
            }, 1000);
      }, 
      function () {
            /*$('#bt03_tab').animate({
             opacity: 1.0, 
      	     top: '=330',
      	     height: '=140',
            }, 1);*/
            $('#bt03_tab').animate({
             opacity: 0.0,
      	     top: '+=155',
      	     height: '-=140',
            }, 500);
            $('#bt03_image').animate({
      	     top: '-=30',
            }, 500);
            $('#bt03_shadow').animate({
             opacity: 0.2,
            }, 500);
      }
    );

    $("#bt04").hover(
      function () {
            /*$('#bt04_tab').animate({
             opacity: 0.0, 
      	     top: '=485',
      	     height: '=5',
            }, 10);*/
            $('#bt04_tab').animate({
             opacity: 0.95, 
      	     top: '-=155',
      	     height: '+=140',
            }, 800);
            $('#bt04_image').animate({
      	     top: '+=30',
            }, 1000);
            $('#bt04_shadow').animate({
             opacity: 1.0,
            }, 1000);
      }, 
      function () {
            /*$('#bt04_tab').animate({
             opacity: 1.0, 
      	     top: '=330',
      	     height: '=140',
            }, 1);*/
            $('#bt04_tab').animate({
             opacity: 0.0,
      	     top: '+=155',
      	     height: '-=140',
            }, 500);
            $('#bt04_image').animate({
      	     top: '-=30',
            }, 500);
            $('#bt04_shadow').animate({
             opacity: 0.2,
            }, 500);
      }
    );



//################   LANGUAGE MENU   ####################################################

    $(".dropdown img.flag").addClass("flagvisibility");

    $(".dropdown dt a").click(function() {
        $(".dropdown dd ul").toggle();
    });
                        
    $(".dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $(".dropdown dt a span").html(text);
        $(".dropdown dd ul").hide();
        $("#result").html("Selected value is: " + getSelectedValue("sample"));
     });
                        
     function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
     }

     $(document).bind('click', function(e) {
         var $clicked = $(e.target);
         if (! $clicked.parents().hasClass("dropdown"))
         $(".dropdown dd ul").hide();
      });




});
