$(document).ready(function(){
    
  
        
    $("#login").click(function (e) {
      $("#login_window").show("slow");
        e.preventDefault();
      $("#container").fadeTo("slow", 0.1);  

    });
    
    $("#login_hide").click(function (e) {
      $("#login_window").hide("slow");
      e.preventDefault();
      $("#container").fadeTo("slow", 1);

    });
    
   // ===================== ANTI SPAM PROTECTION ===========
   $("#registration").submit(function(){
      $("#registration input[name='spam']").val("2");
   });
    
   //=========================== DIV ANIMATIONS 
    $("#newemail").click(function (e) {
      $("#newemaildiv").show("slow");
        e.preventDefault();
    });
    
    $("#newemailhide").click(function (e) {
      $("#newemaildiv").hide("slow");
        e.preventDefault();
    });
    
    $("#newpassword").click(function (e) {
      $("#newpassworddiv").show("slow");
        e.preventDefault();
    });
    
    $("#newpasswordhide").click(function (e) {
      $("#newpassworddiv").hide("slow");
        e.preventDefault();
    });
    
    $(".addnewcomment").click(function (e) {
      $("#newcomment").slideDown("slow");
        e.preventDefault();
    });
    
    $(".hidenewcomment").click(function (e) {
      $("#newcomment").slideUp("slow");
        e.preventDefault();
    });
    
    
    
    
        
    $("div.tn img").hover(
      function () {
        $(this).fadeTo("fast", 0.5);
      },
      function () {
        $(this).fadeTo("slow", 1);
      }
    );

  
                   
      $('#delete').click(function() {
          return confirm('R U sure?');
      });
      
     $("#dateselector select").change(function() {
        this.form.submit();
      });

      
      $("input").focus(function () {
         $(this).css('border','1px solid #369');
      });
      
      $("input").blur(function () {
         $(this).css('border','1px solid #CFD6E0');
      });

      

      
 
 //================= elements style
      $("h1").css("color", "#369");
      $("h3").css("color", "#369");
      $("a").css("color", "#369");
      $("input[name='email']").css("width", "250px");
      $("input[name='caption']").css("width", "500px");
      $("input[type='file']").css("width", "250px");
      $("input[type='submit']").hover(function(){$(this).fadeOut(100);$(this).fadeIn(100);});
      
      $(".ok").css("display", "none");  
      $(".ok").slideDown("slow");
      $(".error").css("display", "none");  
      $(".error").slideDown("slow");
      //$("#zoom").slideDown("slow");
      
      
      $("a").hover(
        function () {
          $(this).css("color", "#000");
        },
        function () {
           $(this).css("color", "#369");
        }
      );
 
//========================= validate username

    $("#username").keyup(function(e){
        var t = this;
        if (this.value != this.lastValue) {
          if (this.timer) clearTimeout(this.timer);
           $("#check_name").html('<img src="/i/loader.gif" alt="loading" /> checking...');
             this.timer = setTimeout(function () {
             $.get("/-check-name.php", { q: t.value},
                function(data){
                  $("#check_name").html(data);
                });
          }, 800);
          this.lastValue = this.value;
        }
    });
    
    
    
//========================== report unsuitable
    
    $(".unsuitable").click(function(e){
        e.preventDefault();
        var t = this;
        $.get("/-unsuitable.php", { q: t.id},
                function(data){
                  //$("#comment"+t.id).html(data);
                  $("#comment"+t.id).slideUp("slow", function(){
                      $("#comment"+t.id).text("Thank you for reporting this comment unsuitable. Your report will be revised by the editor.");
                      $("#comment"+t.id).slideDown("slow");
                  });
                });
    });


//========================== delete comment
    
    $(".delete").click(function(e){
        e.preventDefault();
        var t = this;
        $.get("/-delete-comment.php", { q: t.id},
                function(data){
                  //$("#comment"+t.id).html(data);
                  $("#comment"+t.id).slideUp("slow", function(){
                      $("#comment"+t.id).text("Comment has been deleted.");
                      $("#comment"+t.id).slideDown("slow");
                  });
                });
    });
    
    
    
//============== edit caption in-place      
         
        $('.edit').editable('/-edit.php',{
            indicator: '<img src="/i/loader.gif" alt="loading" /> Saving caption...',
            tooltip : 'Click to edit',
            placeholder: 'Click here to add caption',
            submit  : 'save',
            name    : 'q',
            id      : 'id'
        });
        
//============== add comment in-place      
         
        $('.addcomment').editable('/-new-comment.php',{
            indicator: '<img src="/i/loader.gif" alt="loading" /> Saving comment...',
            tooltip : 'Click to add comment',
            type      : 'textarea',
            placeholder: 'Click here to add comment',
            submit  : 'add comment',
            name    : 'q',
            id      : 'id',
            callback: function(){
                $('.addcomment').hide("fast");
                $('.response').html('<strong>Your comment has been submitted. Thanks!</strong>');
                $('#newcomment').fadeTo(1500,1).hide("slow", function(){
                    $('.response').html('');
                    $('.addcomment').show("fast");
                });
            }
        });


    // ================= ticker =============
    var options = {
    	newsList: "#news",
   		startDelay: 0,
   		tickerRate: 50, 		// time gap between display of each letter (ms)
      loopDelay: 2000,
      placeHolder1: ".",
      placeHolder2: "." 
  	}
  	$().newsTicker(options);
    
    
    
    
}); // ===================  end of on ready



