/* Clear 'SEARCH' from search box and focus when clicked */

function clearAndFocus( el ) {
  el.value = '';
  el.focus();
}   

/* Search mouseover/out functions */

function searchOver() {
  document.getElementById("searchimg").src = "/landing/images/search-bang-red1.jpg";
}

function searchOut() {
  document.getElementById("searchimg").src = "/landing/images/search-bang-black1.jpg";
}

/* Bottom blog box navigation */

$(document).ready(function() {
  $('#cse-search-box input#searchbox').attr('value','Search all CliqueClack'); 
  $('#cse-search-box').attr('action','search.php');
  $("#cse-search-box input[name$='as_sitesearch']").remove();
  
  $('#search_scroll a.tv').click(function() {
    $('#search_scroll img#search_tv').attr('src','/landing/images/search-tv-selected.jpg');
    $('#search_scroll img#search_food').attr('src','/landing/images/search-food.jpg');
    $('#search_scroll img#search_twitter').attr('src','/landing/images/search-twitter.jpg');

    $('#cse-search-box input#searchbox').attr('value','Search CliqueClack TV'); 
    $('#cse-search-box').attr('action','search.php');
    $("#cse-search-box input[name$='from']").remove();
    if( $("#cse-search-box input[name$='as_sitesearch']").length <= 0 ) {
      $('#cse-search-box').append('<input type="hidden" name="as_sitesearch" value="www.cliqueclack.com/tv">');
    }
  });
  $('#search_scroll a.food').click(function() {
    $('#search_scroll img#search_tv').attr('src','/landing/images/search-tv.jpg');
    $('#search_scroll img#search_food').attr('src','/landing/images/search-food-selected.jpg');
    $('#search_scroll img#search_twitter').attr('src','/landing/images/search-twitter.jpg');

    $('#cse-search-box input#searchbox').attr('value','Search CliqueClack Food'); 
    $('#cse-search-box').attr('action','search.php');
    $("#cse-search-box input[name$='from']").remove();
    if( $("#cse-search-box input[name$='as_sitesearch']").length <= 0 ) {
      $('#cse-search-box').append('<input type="hidden" name="as_sitesearch" value="www.cliqueclack.com/food">');
    }
  });
  $('#search_scroll a.twitter').click(function() {
    $('#search_scroll img#search_tv').attr('src','/landing/images/search-tv.jpg');
    $('#search_scroll img#search_food').attr('src','/landing/images/search-food.jpg');
    $('#search_scroll img#search_twitter').attr('src','/landing/images/search-twitter-selected.jpg');

    $('#cse-search-box input#searchbox').attr('value','Search us on Twitter'); 

    $('#cse-search-box').attr('action','http://search.twitter.com/search');
    //$("#cse-search-box input[name$='cx']").remove();
    //$("#cse-search-box input[name$='cof']").remove();
    //$("#cse-search-box input[name$='ie']").remove();
    //$("#cse-search-box input[name$='from']").append();
    if( $("#cse-search-box input[name$='from']").length <= 0 ) {
      $('#cse-search-box').append('<input type="hidden" name="from" value="CliqueClack">');
    }
  });

/*
  $('a.tweetout img').hover(
    function() {
      $(this).attr('src','/landing/images/tweet-quote-hover.jpg');
    },
    function() {
      $(this).attr('src','/landing/images/tweet-quote.jpg');
    });
*/

/*
  $('a.tweetout').click(
    function() {
      $('div#'+this.id+' div.tweet_content').animate({
        opacity: 0.4
      }, 1500 );
      $('div#'+this.id+' div.tweet_altcontent').fadeIn("slow");
    }
  );
*/

/*
  $(".clack-popup a").hover(function() { 
    $(this).next("em").stop(true, true).animate({opacity: "show", top: "-60"}, "slow"); 
  }, function() { 
    $(this).next("em").animate({opacity: "hide", top: "-70"}, "fast"); 
  }); 
*/

  var browser;

  $(".clackus_button_img").bind("click", function(e) {
    var id = this.id.replace("clackus_button_img_","");
    var tPosX = $("#clackus_button_" + id).offset().left -200;
    var tPosY = $("#clackus_button_" + id).offset().top -425;

    $(this).attr('src','/images/clack-us2.png');

/*
    if($.browser.msie) {
      tPosX = $("#clackus_button_" + id).offset().left -105;
      tPosY = $("#clackus_button_" + id).offset().top -520;
    } else if($.browser.safari) {
      tPosX = $("#clackus_button_" + id).offset().left -40;
      tPosY = $("#clackus_button_" + id).offset().top -425;
    }
*/
    $("#clackus_bubble_" + id).fadeIn("fast");
    //$("#clackus_bubble_" + id).css({top: tPosY, left: tPosX}).show();
    $("#clackus_bubble_" + id + " input").focus();
    $("#clackus_bubble_" + id + " input").select();

    e.stopPropagation(); // Stops the following click function from being executed
    $(".entrytitle_right").hover(function() {
      return;
    }, function() {
      $("#clackus_button_img_" + id).attr('src','/images/clack-us1.png');
      $("#clackus_bubble_" + id).fadeOut("fast");
    });

    //$(document).one("click", function(f) {
      //$("#clackus_button_img_" + id).attr('src','/images/clack-us1.png');
      //$("#clackus_bubble_" + id).fadeOut("fast");
    //});
  });

  // Following will stop bubble hiding when it is clicked
  //$("#bubble").bind("click", function(e) {
    //e.stopPropagation();
  //});

/*
  $('a[sharewith]').click(function(ev){
     var rel = $(this).attr('sharewith');
     var url = encodeURIComponent(self.location.href);
     var title = encodeURIComponent($('title:first').html());
     rel = rel.replace('{url}',url);
     rel = rel.replace('{title}',title);
     self.location.href = rel;
     return false;
  });
*/

/*
  $("#sidebar-left .categories .children").hide();

  $("#sidebar-left .categories .cat-item").hover(function() {
    $(this).children('.children').slideDown(300);
  }, function() {
    $(this).children('.children').slideUp(300);
  });
*/

});
