$(document).ready(function(){
  $.timer(10000, function(timer) {
		$.get('/home/get_feedback_stream.js?feedback_id=' + max_stream_feedback_id, {}, null, 'script' );
    timer.reset(30000); 
  });
   
  $.timer(7000, function(timer) {
    var currImage = $("#simage").attr('src');
    if (currImage.indexOf('home1') != -1) {
      $("#simage").attr('src', '/images/home2.png').fadeIn("slow");
    } else if (currImage.indexOf('home2') != -1) {
      $("#simage").attr('src', '/images/home3.png').fadeIn("slow");
    } else {
      $("#simage").attr('src', '/images/home1.png').fadeIn("slow");
    }
    timer.reset(7000); 
   });
   
   $("#add-search").append($("#gsearch").remove());
   $("#gsearch").show();
   //necessary because i remove the element above and then append it, so the event handlers are gone
   search_init();


});

function search_init() {
  $.default_search_text = 'Start typing here...';
  $(".g-search #q").val($.default_search_text);
  $(".g-search #q").removeClass('active');

  $("#global-search-submit").click(
    function() {
      if ($(".g-search #q").val() == $.default_search_text || $("#q").val().trim() == "") {
        $("#q").effect("highlight", {}, 3000);
        return false;
      }
    }
  );
   
  $(".g-search #q").focus( function() {
      if ($(".g-search #q").val() == $.default_search_text || $(".g-search #q").val().length == 0) {
        $(this).val('');
      }
  });
  
  $(".g-search #q").blur( function() {
      if ($(this).val().length == 0) {
        $(this).val($.default_search_text);
      }
      $(this).removeClass('active');
  });
}

