

$(document).ready(function()
{
  /**
   * Topmenu animate
   */
  $("#jqAnimTopMenu li a").each
  (
    function()
    {
      $(this).hover(function()
      {
        if (!this.oldColor) this.oldColor = $(this).css("color");
        if (this.run) return;
        this.run = true;

        if ($(this.parentNode).hasClass("first"))
        {
          $(".topMenuLeft div").animate({opacity: 0.85}, 300, "linear");
        }

        $(this).animate({opacity: 0.85, "color": "#f24523"}, 300, "linear", function(){ this.run = false; });
      },
      function()
      {
        var c = this.oldColor;

        if (!$(this).hasClass("sel"))
        {
          if ($(this.parentNode).hasClass("first"))
          {
            $(".topMenuLeft div").animate({opacity: 1}, 300, "linear");
          }

          $(this).animate({opacity: 1, "color": c}, 300);
        }
      });
      return true;
    }
  );

  /**
   * Partners animate
   */
  $("#jqAnimPartner li").each
  (
    function()
    {
      var div = this.getElementsByTagName('div')[0];
      var a = this.getElementsByTagName('a')[0];
      $(this).hover(function()
      {
        $(div).stop();
        $(a).stop();
        $(div).css({display: 'block', opacity: 0.3, width: 0});
        $(div).animate({width: '90%'}, 500, 'swing');
        $(a).animate({marginLeft: 25}, 500, 'linear');
      },
      function()
      {
        $(div).stop();
        $(a).stop();
        $(div).animate({width: '0'}, 500, 'swing');
        $(a).animate({marginLeft: 20}, 500, 'linear');
      }
      );
      return true;
    }
  );
  
  /**
   * Forms animate
   */

  $(".tbl tr").each
  (
    function()
    {
      var td_left =  this.getElementsByTagName("th")[0];
      var td_right = this.getElementsByTagName("td")[this.getElementsByTagName("td").length-1];
      var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');

      if (!$(td_right).hasClass("foot"))
      {
        var div = document.createElement("div");
        div.innerHTML = td_right.innerHTML;
        
        if (rslt &&  Number(rslt[1]) < 7 && $(td_right).height() > 27)
        {
          div.style.height = $(td_right).height() + 4 + "px";
          //div.style.lineHeight = $(td_right).height() -4 + "px";
        }
        else
        {
          div.style.height = $(td_right).height() + 3 + "px";
          //div.style.lineHeight = $(td_right).height() + 3 + "px";
        }
        
        var div2 = document.createElement("div");
        div2.innerHTML = td_left.innerHTML;

        if (rslt &&  Number(rslt[1]) < 7 && $(td_left).height() > 27)
        {
          div2.style.height = $(td_left).height() + 4 + "px";
          div2.style.lineHeight = $(td_left).height() + 4 + "px";
        }
        else
        {
          div2.style.height = $(td_left).height() + 3 + "px";
          div2.style.lineHeight = $(td_left).height() + 3 + "px";
        }
        
        if (td_right)
        {
          $(td_right).empty();
          $(td_right).append(div);

          $(td_right.firstChild).css({position: "relative"});
          
          var topimg = document.createElement("img");
          topimg.src = "/grf/round_right_top.png";
          topimg.style.position = "absolute";
          topimg.style.top = "0px";
          
          if ($(td_right).height() > 27)
            topimg.style.right = "-8px";
          else topimg.style.right = "-5px";
          
          var bottomimg = document.createElement("img");
          bottomimg.src = "/grf/round_right_bottom.png";
          bottomimg.style.position = "absolute";
          bottomimg.style.bottom = "0px";
          
          if ($(td_right).height() > 27)
              bottomimg.style.right = "-8px";
          else bottomimg.style.right = "-5px";

          $(td_right.firstChild).append(topimg);
          $(td_right.firstChild).append(bottomimg);
        }

        if (td_left)
        {
          $(td_left).empty();
          $(td_left).append(div2);

          $(td_left.firstChild).css({position: "relative"});

          var topimg = document.createElement("img");
          topimg.src = "/grf/round_left_top.png";
          topimg.style.position = "absolute";
          topimg.style.top = 0;

          if ($(td_left).height() > 27)
            topimg.style.left = "-3px";
          else topimg.style.left = "-3px";

          var bottomimg = document.createElement("img");
          bottomimg.src = "/grf/round_left_bottom.png";
          bottomimg.style.position = "absolute";
          bottomimg.style.bottom = "0px";

          if ($(td_left).height() > 27)
            bottomimg.style.left = "-3px";
          else bottomimg.style.left = "-3px";
          
          $(td_left.firstChild).append(topimg);
          $(td_left.firstChild).append(bottomimg);
        }
      }
      return true;
    }
  );

  $(".tbl tr").each
  (
    function()
    {
      $(this).hover(function()
      {
        if (hoverItem && !$(hoverItem.getElementsByTagName("td")[0]).hasClass("foot"))
          $(hoverItem).animate(
          {
            backgroundColor: "#000000",
            color: "#000000"
          }, 100);
        hoverItem = this;
        $(this).stop();

        if (!$(this.getElementsByTagName("td")[0]).hasClass("foot"))
          $(this).animate(
          {
            backgroundColor: "#1F1F1F",
            color: "#9F9F9F"
          }, 400);
      },
      function()
      {
        $(this).stop();
        if (!$(this.getElementsByTagName("td")[0]).hasClass("foot"))
          $(this).animate(
          {
            backgroundColor: "#000000",
            color: "#000000"
          }, 100);
      }
      );
      return true;
    }
  );

  $(".tbl tr td input, .tbl tr td select, .tbl tr td textarea").each
  (
    function()
    {
      $(this).focus(function()
      {
        $(this).stop();
        tr = this;round_left_bottom.png
        while (tr.tagName.toLowerCase() != "tr") tr = tr.parentNode;

        if (!hoverItem || tr != hoverItem)
        {
          if (hoverItem && !$(hoverItem.getElementsByTagName("td")[0]).hasClass("foot"))
            $(hoverItem).animate(
            {
              backgroundColor: "#101010",
              color: "#606060"
            }, 100);

          if (!$(tr).hasClass("foot"))
            $(tr).animate(
            {
              backgroundColor: "#1F1F1F",
              color: "#9F9F9F"
            }, 400);
        }
        
        hoverItem = tr;
        
      });

      $(this).blur(function()
      {
        tr = this;
        while (tr.tagName.toLowerCase() != "tr") tr = tr.parentNode;
        $(this).stop();

        if (!$(tr).hasClass("foot"))
          $(tr).animate(
          {
            backgroundColor: "#101010",
            color: "#606060"
          }, 100);
      });
      return true;
    }
  );
  
  /**
   * Galery opacity effect
   */

  $(".contentThumbs a, .contentThumbsAuto a").each(function()
  {
    $(this).css({opacity: 0.5});
    $(this).hover(function()
    {
      $(this).stop();
      $(this).animate({opacity: 1}, 200);
    },
    function()
    {
      $(this).stop();
      $(this).animate({opacity: 0.5}, 200);
    });
  });

  $('input').each(function ()
  {
    if ($(this).tooltipInit)
    {
      $(this).tooltipInit(this.title,
      {
        imageDir: 'images/tooltip/',
        dir: 'up',  // up | down | auto
        position: 'right top', // [left | right] [top | bottom] | mouse
        offset: {top: 12, left: 3}, // top margin, left margin
        show: 'focus', // focus | hover | focus hover
        startcss: {opacity: 0},
        showanimate: [{opacity: 1}, 300, "linear"], // same as jquery animate
        hideanimate: [{opacity: 0}, 300, "linear"], // same as jquery animate
        resizeanimate: [{}, 300, "linear"] // same as jquery animate
      });
      this.title = '';
    }
  });

  fixAllPNG();
  fixbgpng.fnLoadPngs();
});

var hoverItem = false;




