/*
General functions for NowSeriously's first Wordpress Theme
Giovanni Piller Cottrer - 2008
*/

/* things to do on document load */
$(document).ready( function () {
  // if javascript is enabled, hides some elements
  //$('#spread').slideUp();
  //$('#about').slideUp();
  $("a#spread-button").removeClass("open");
  $("a#about-button").removeClass("open");
  $(".hide").removeClass("hide");
  $("#s-huge").addClass("hide");
  $().localScroll( {duration:200} ); // smooth scrolling enabled (very fast)
  
  // loads tooltips (the function is moreover)
  simple_tooltip("a","tooltip");

  /* stores search input's default text */
  var searchText = "or search for something..";
  $("#s").val(searchText)

  /* original background */
  var originalBG = "#FFFFFF";
  var flashBG = "#fff4cf";

  /* share button on single post (toggle social sites icons) */
  $("a#spread-button").click(function() {
	$('#spread').animate({backgroundColor:flashBG},50);
    $('#spread').animate({backgroundColor:originalBG},250);
	$('#spread').animate({backgroundColor:flashBG},250);
    $('#spread').animate({backgroundColor:originalBG},250);
	$('#spread').animate({backgroundColor:flashBG},250);
    $('#spread').animate({backgroundColor:originalBG},250);
  });

  
  /* about button on single post (toggle about informations) */
  var originalColor = $("#about .info").css("color");
  var flashColor = "#000";
  $("a#about-button").click(function() {
    $('#about .info').animate({color:flashColor},50);
    $('#about .info').animate({color:originalColor},250);
    $('#about .info').animate({color:flashColor},250);
    $('#about .info').animate({color:originalColor},250);
    $('#about .info').animate({color:flashColor},250);
    $('#about .info').animate({color:originalColor},250);
  });

  /* comment area focus when clicking on the #comment-button element */
  $("a#comment-button").click(function() {
    $(".comment-form textarea").focus();  
  });

  /* HUGE search input appears + focus when clicking on a .go-search element */
  $(".go-search-huge").click(function() {
    $(".huge").addClass("hide");
    $("#s-huge").removeClass("hide");
    $("#s-huge-input").focus();
  });
  
  /* HUGE search input auto-clean */
  $("#s-huge-input").click(function() {
    if($("#s-huge-input").val() == searchText) {
		$("#s-huge-input").val("");
	}
  }).blur(function(){ // if the cursor leave the input reset its value
    if($("#s-huge-input").val()==""){
      $("#s-huge-input").val(searchText);
    }
  });


  /* search input auto-clean on click */
  $("#s").click(function() {
    if($("#s").val() == searchText) {
		$("#s").val("");
	}
  }).blur(function(){ // if the cursor leave the input reset its value
    if($("#s").val()==""){
      $("#s").val(searchText);
    }
  });

}); // <----------- $(document).ready ENDS HERE!!!
//------------------------------------------------|


/* external function to manage tooltips (links with ".tip" class only!) */
function simple_tooltip(target_items, name){
  $(target_items).each(function(i){
    $("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");
    var my_tooltip = $("#"+name+i);

    if($(this).attr("title") != "" && $(this).hasClass("tip")){ // checks if there is a title and has .tip class
      $(this).removeAttr("title").mouseover(function(){
        my_tooltip.css({opacity:0.8, display:"none"}).show();
      }).mousemove(function(kmouse){
        my_tooltip.css({left:kmouse.pageX-95, top:kmouse.pageY+15});
      }).mouseout(function(){
        my_tooltip.fadeOut(100);
      });
    }
  });

}

/* stupid facebook share-this function */
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}