$(document).ready(function(){
						   
var loginWindowStatus = 0;

$("#mainNav ul>li").append("<div class='leftCorner'></div><div class='rightCorner'></div>");

$("ul.topiclist li").hover(function() {
  $(this).addClass("hover");
},function() {
  $(this).removeClass("hover");
});

// Clear #bd position absolute
$("#bd #column03").after("<div class='clearFloat'></div>");

// Fix left content box
  var top = $('#featureBox').offset().top;
  $(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();

    // whether that's below the form
    if (y >= top) {
      // if so, ad the fixed class
      $('#featureBox').addClass('fixed');
    } else {
      // otherwise remove it
      $('#featureBox').removeClass('fixed');
    }
  });
  
  // Fix right column
  var featureTop = $('#column03').offset().top;
  $("body").append("<div id='debug' style='position:fixed; bottom:0; left:0;'></div>");
  $(window).scroll(function (event) {

    var scrollTop = $(window).scrollTop();
	var columnHeight = $("#column03").height();
	var docHeight = $(document).height();
	var winHeight = $(window).height();
	var cropped =  columnHeight-winHeight;
	var gone = scrollTop + winHeight;
	var theHeight = columnHeight + 213;
	var toBottom = docHeight - (winHeight + scrollTop) ;
	var col3FromTop = (winHeight + scrollTop) - columnHeight;
	
	// Do the magic
	if (gone >= theHeight) {
	  $("#phpbb #column03").addClass("fixed");
	} else {
	  $("#phpbb #column03").removeClass("fixed");
	};
	/*if (col3FromTop < 3568) {
	  $("#column03").css({position:"relative",padding:"0 0 400px 0"});
	} else {
	  $("#column03").css({position:"fixed",padding:"0px"});
	};*/	
	
	$("#debug").html(col3FromTop);
	
  });
  
  // Set the variables for Golden Pages search
  var $watValue;
  var $waarValue;
  
  // If the value is bla then clear it otherwise fill it with the saved value that was recorded
  // when the input last lost its focus.
  $("#goldenpages input#wat").focus(function() {
    var $this = $(this);
    if($this.val() == "What are you looking for?") {
      $(this).val("");
    } else {
      $this.val($watValue);
    }
  });
  // First get the value and record it in $watValue
  // If there's no text fill the input with bla
  // If there is text fill it with $watValue i.e. the same text 
  $("#goldenpages input#wat").blur(function() {
    var $this = $(this);
    $watValue = $this.val();
    if($this.val() == "") {
      $this.val("What are you looking for?");
    } else {
      $this.val($watValue);
    } 
  });

  // Same principle as above.
  $("#goldenpages input#waar").focus(function() {
    var $this = $(this);
    if($this.val() == "Where?") {
      $(this).val("");
    } else {
      $this.val($waarValue);
    }
  });
  // Same principle as above.
  $("#goldenpages input#waar").blur(function() {
    var $this = $(this);
    $waarValue = $this.val();
    if($this.val() == "") {
      $this.val("Where?");
    } else {
      $this.val($waarValue);
    }
  });
  
  // Show hide login
  $("a#login").click(function(event) {
	if(loginWindowStatus==0) {
		$(this).addClass("hover");
    	$("#navlogin").fadeIn("fast");
		loginWindowStatus = 1;
	} else {
		$(this).removeClass("hover");
		$("#navlogin").fadeOut("fast");
		loginWindowStatus = 0;
	}
	event.preventDefault();
  });
  
  $("#closeLogin").click(function() {
	$("#login").removeClass("hover");
    $("#navlogin").fadeOut("fast");
	loginWindowStatus = 0;
	event.preventDefault();
  });
  
  // Hide menu by adding "hidden" class
  // $("#mainNav li ul").addClass("hidden");
  // Show menu
  $("#mainNav li.menu").hover(function() {
    $("#mainNav li.menu ul").removeClass("hidden");
  },function() {
	  $("#mainNav li.menu ul").addClass("hidden");
  });
  
  // Add class to first post
  $("#page-body .post:first").addClass("firstPost");
  
  $("#forum_button, #forumlink, #forum_button_end, #page-body p.right, hr").css("display","none");
  
  $("dl.pmlist").prepend("<div class='guide'>Type the username of the person you want to send a PM to then click the 'Add' button.</div>");
  
  /*
  $(".postprofile").each(function() {
    var $this = $(this);
    $this.find("dd:eq(2),dd:eq(3)").css("display","none");
  });
  */

// Close Document Ready
});
