  function whoVotedParse()
  {
    $(".whoVoted").unbind("click").click( function()
    {
      $(this).parent().find(".votedList").fadeIn();
      $(this).parent().find(".votedList a").click( function()
      {
        $(this).parent().fadeOut();
      });
    });
    $(".cancelVote").unbind("click").click( function()
    {
      postId = $(this).parent().parent().prev().attr("id").replace("Post", "");      
      $(this).parent().fadeOut();
      $.post("/scripts/php/cancelVote.php", { postId : postId }, function(){} );
      top.location.href=top.location.href;
    });
  }
  
$(document).ready( function()
{
  if ( window.console )
  {
    var fire = String(window.console.firebug);
    if ( fire.substr(0,1) > 0 ) {
      
      
      console.group();
      console.info('Welcome on TourismTome.com.');
      console.info('Please be aware, that we have to log this information, that you\'re using firebug, v. '+console.firebug+'.');
      console.groupEnd();
    }
  }

  $(".actTranslate").click( function()
  {
    $(this).hide();
    $(this).parent().find(".toTranslate").parent().fadeIn();
  });
  
  $(".valuablePost").click( function()
  {
      postId = $(this).parent().prev().attr("id").replace("Post", "");
      link = $(this);
      if ( postId.length == 8 )
      {
        $.ajaxSetup({async:false});
        $.post("/scripts/php/valuablePost.php", { postId : postId }, function(data)
        {
          link.replaceWith(data);
          whoVotedParse();
        });      
      }
  });
  
  whoVotedParse();
  
  $(".actEdit").click( function()
  {
    cDiv = $(this).parent().parent().find("div[id^=Comment]");
    cDiv.html("<textarea style=\'width: 410px; font-size: 11px; font-family: Tahoma; padding: 3px;\'>"+cDiv.html()+"</textarea><br /><input style=\'font-size: 10px; margin-left: 86px;\' type=\'button\' class=\'save\' value=\'OK\' />");

    cDiv.find("input.save").unbind("click").click( function()
    {
      $.post("/scripts/php/saveComment.php", { id : cDiv.attr("id"), loc : window.location.href, comment : cDiv.find("textarea").val() }, function(data)
      {
        if ( data == "OK" )
          cDiv.html( cDiv.find("textarea").val() ); 
      });
    });

  });
  
  $("a.sl").click( function()
  {
    $('p.sl').toggle();
  });
  
  if ( $(".toTranslate").length > 0 )
  {
    $("p.main115").prepend('<a href="http://translate.google.com/" target="_blank">Google Translate</a> tool is used for all dynamic translations. &nbsp; | &nbsp; ');
  }
  
  $(".toTranslate").click( function()
  {
    var tId = $(this).attr("rel");
    
    $.translate( $( "#"+tId ).html(), $(this).parent().find(".toLang").val(), {
      complete: function()
      {
      
       translated = this.translation.replace(/\<a(.*?)href="(.*?)"(.*?)\>(.*?)\<\/a\>/ig, '<a$1href="$2"$3>$2</a>');
        if ( translated )
        {
          if ( $("#"+tId+"Translated").length == 0 )
          {
            klon = $( "#"+tId ).clone();
            klon.attr("id", tId+"Translated").insertAfter( $( "#"+tId ) );
            $( "#"+tId ).hide();
          }
          
          $("#"+tId+"Translated").html( translated );
        }

      }} );

  });
  
  $("form").each( function()
  {
    var lastTabindex = 100;
    $(this).find("select:not([tabindex]), textarea:not([tabindex]), input:not([tabindex])").each( function()
    {                                                                                    
      lastTabindex++;
      $(this).attr("tabindex", lastTabindex);
    });
  });
 
});



function styleInputs()
{
  $("a.prevVideo").unbind("click").click( function()
  {
    link = $(this);
    $.get("/scripts/php/loadVideos.php", { vid:$(this).attr("vid"), id: $(this).attr("rel"), rel: $("#vType").val(), start: $(this).attr("start") }, function(data)
    {
      if ( data )
        $("#videosContent").html(data);
      
      styleInputs();   
    }, "html");
  });
  
  $("a.nextVideo").unbind("click").click( function()
  {
    link = $(this);
    $.get("/scripts/php/loadVideos.php", { vid:$(this).attr("vid"), id: $(this).attr("rel"), rel:  $("#vType").val(), start: $(this).attr("start")  }, function(data)
    {
      if ( data )
        $("#videosContent").html(data);
        
      styleInputs();
    }, "html");
  });

  $("input[type=checkbox]").each( function()
  {
    if ( $(this).hasClass("styled") )
      return true;

    var cName = $(this).attr("name");
    var cSelected = $(this).attr("checked");
    var cClass = ( cSelected ) ? "checkboxH" : "checkbox";
    var vParent = $(this);
    var cId = Math.random();
    
    cDiv = $('<img id="'+cId+'" border="0" name="'+cName+'" src="img/'+cClass+'.gif" style="cursor: pointer;" alt="" />').click( function()
    {
      if ( $(this).attr("src").indexOf("checkboxH.gif") != -1 )
      {
        $(this).attr("src", "img/checkbox.gif");
        vParent.removeAttr("checked");
      }
      else
      {
        $(this).attr("src", "img/checkboxH.gif");
        vParent.attr("checked", "checked");
      }
    });
    
    $(this).after( cDiv ).hide();
    $(this).addClass("styled");
    
    if ( $("img[id="+cId+"]").next().attr("style") )
    {
      $("img[id="+cId+"]").next().attr("rel", "masked");
      $("img[id="+cId+"]").next().click( function()
      {
        $("img[id="+cId+"]").click();
      }).css('cursor', 'pointer');
    }
  });


  $("input[type=radio]").each( function()
  {
    if ( $(this).hasClass("styled") )
      return true;
  
    var cName = $(this).attr("name");
    var cSelected = $(this).attr("checked");
    var cClass = ( cSelected ) ? "checkboxH" : "checkbox";
    var cActive = ( cSelected ) ? "active" : "";
    var vParent = $(this);
    var cId = Math.random();
    
    cDiv = $('<img id="'+cId+'" border="0" src="img/'+cClass+'.gif" name="'+cName+'" class="chckb '+cActive+'" style="cursor: pointer;" alt="" />').click( function()
    {
      if ( $(this).attr("src").indexOf("checkboxH.gif") != -1 )
      {
        $(this).removeClass("active");
        $(this).attr("src", "img/checkbox.gif");
        vParent.removeAttr("checked");
      }
      else
      {
        $("img[name="+cName+"].active").click();
        $(this).addClass("active");
        $(this).attr("src", "img/checkboxH.gif");
        vParent.attr("checked", "checked");
      }
    });

    $(this).after( cDiv ).hide();
    $(this).addClass("styled");

    if ( $("img[id="+cId+"]").next().attr("style") )
    {
      $("img[id="+cId+"]").next().attr("rel", "masked");
      $("img[id="+cId+"]").next().click( function()
      {
        $("img[id="+cId+"]").click();
      }).css('cursor', 'pointer');
    }

  });

}

$(document).ready( function()
{
  $('a.lb').each( function()
  {
    $(this).lightBox();
  });
  
  $('a.addComment').click( function()
  {

      $.get("/scripts/php/isLogged.php", function(data)
      {
        data = parseInt( data );
        if ( data > 0 )
         $('div.addComment').fadeIn();
        else
          alertMsg("nonLogged");
      }); 

    
  });
  
  styleInputs();

  $("a[id^=stick]").click( function()
  {
    link = $(this);
    id = $(this).attr('id').replace('stick', '');
    $.get('/scripts/php/topic.php', { action : 'stick', id : id }, function(ret)
    {
      link.html( ret );
    });
  });

  $("a[id^=close]").click( function()
  {
    link = $(this);
    id = $(this).attr('id').replace('close', '');
    $.get('/scripts/php/topic.php', { action : 'close', id : id }, function(ret)
    {
      link.html( ret );
      $("span.close").toggle();
    });
  });

  $("#wrongText").click( function()
  {
    $("#wtDiv .info").html("");
    $("textarea[name=old], textarea[name=new]").val("");
    $("#wtDiv table").show();
     
    $("#wtDiv input[type=button]").click( function()
    {
      $.ajaxSetup({ global: false, async: false });
      $.post("/scripts/php/saveSuggest.php", { "old" : $("textarea[name=old]").val(), "new" : $("textarea[name=new]").val() }, function(data)
      {
        $("#wtDiv table").hide();
        $("#wtDiv .info").html(data); 
      });
      setTimeout("$.unblockUI();", 3000);      
    });

    $.blockUI({ message: $("#wtDiv"), 
      css: { 
        border: "3px solid #EDBA21",
        width: "402px", 
        backgroundColor: "#85A51E"
      } 
    });

  });


});
