//copyright Brisbane Website Design 30.com.au
$(document).ready(function() {
  //Box hover effects ---------------------------------------------------------
  $(".box .content").hover(function () {
      $(this).prev("div").animate({opacity: 0}, {queue:false,duration:200});
    }, function () {
      $(this).prev("div").animate({opacity: 1}, {queue:false,duration:400});
    }
  );
  $('.box').click(function() {
    window.location.href = $(this).find('a').attr('href');
    return(false);
  });


  //Automatic Google Translation via API --------------------------------------
  $.translate(function(){
      function translateTo( destLang ){


          originalColor = '#262c33';
          var tlc = $.translate().toLanguageCode
          if( tlc( destLang ) == "pl" && tlc($.cookie("destLang")) == "pl") {
            $('#flags ul').find('a').removeClass('load');
            return;
          }
            $('#menu, .menus, #main_left, #main_center').translate( 'pl', destLang, {   //translate from english to the selected language
              not: '#jq-translate-ui, #calendar, #contact, .syntaxhighlighter',  //by default the generated element has this id
              fromOriginal:true,   //always translate from english (even after the page has been translated)
              start: function(){
                  $('#container').css('color', '#a0a8b2');
                  $('#ozwebsites').removeClass('robot');
                  $('#ozwebsites').html($('#ozwebsites-translate').html())
                  $('#ozwebsites').show()
              },
              complete: function(){
                  $('#container').css('color', originalColor);
                  //$('#ozwebsites').hide();
                  $('#ozwebsites').addClass('robot');
                  $('#flags').find('a.load').removeClass('load').addClass('finish');
                  if (destLang == 'en') {
                    $('#ozwebsites').hide()
                  } else {
                    $('#ozwebsites').html($('#ozwebsites-hint').html());
                  }

              },
              error: function(){
                  $('#container').css('color', originalColor);
                  $('#ozwebsites').hide()
              }
          });
      }
      $("#ozwebsites a").live("click", function(){
        translateTo('en');
        $('#flags ul').find('a').removeClass('finish');
        $('#flags ul').find('a').removeClass('load');
        return(false);
      });
      $('#flags').find('a').click(function(){
        $('#flags').find('a').removeClass('finish');
        $(this).addClass('load');
        var lang = $(this).attr('id');
        translateTo( lang );
        $.cookie('destLang', lang );
        return false;
      });
      //if dont exist an cookie set browserlang to cookielang
      if( $.cookie("destLang") == null) $.cookie('destLang', browserlang);
      var destLang = $.cookie('destLang'); //get previously translated language
      if( destLang ) translateTo( destLang );
  });



  //Forms ---------------------------------------------------------------------
  $("input[type=text], textarea").bind("focus",function(){
    $(this).addClass("formactive");
  });
  $("input[type=text], textarea").bind("blur",function(){
    $(this).removeClass("formactive");
  });


  //Navigation ----------------------------------------------------------------
  $("a.button").hover(function () {
      if (!$(this).hasClass('active')) $(this).animate({opacity: 1}, {queue:true, duration:200});
    }, function () {
      if (!$(this).hasClass('active')) $(this).animate({opacity: 1}, {queue:true, duration:400});
    }
  );
  $("a.button").css('opacity', 1);
  $("a.button.active").css('opacity', 1);
  $(".level_1 .trail a:first").css('opacity', 1).addClass('active');
  $("a.submenu.button").click(function() {
    return(false);
  });
});


