/////////////////////////////////// PLACEHOLDERS

function hasClass(el,cls) {
  return el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(el,cls) {
    if (!this.hasClass(el,cls)) el.className += " "+cls;
}
function removeClass(el,cls) {
    if (hasClass(el,cls)) {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        el.className = el.className.replace(reg,' ');
    }
}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function initFormPlaceholders() {

  if (!document.getElementsByTagName) return true;

  ourForms = document.getElementsByTagName('form');

  // go through each form
  var numForms = ourForms.length;
  for (var i=0;i<numForms;i++) {

    // go through each form element
    var numFormElements = ourForms[i].elements.length;
    for (var j=0;j<numFormElements;j++) {

      var el = ourForms[i].elements[j];

      // ignore submit buttons
      if (el.type == "submit") continue;

      // if we got a text type input or textarea
      if ((el.type == "text") || (el.type == "textarea")) {
        
      // only populate if empty
      if (el.value == '') {
          addClass(el, "placeholder");
          el.value = el.title;
      }

        // add auto clear if class contains auto-clear
    
          el.onfocus = function () {
            if (this.value == this.title) {
                removeClass(this, "placeholder");
                this.value = '';
            }
          }
          if (el.captureEvents) el.captureEvents(Event.FOCUS);

          el.onblur = function () {
            if (this.value == '') {
                this.value = this.title;
            }
            if (this.value == this.title) {
                addClass(this, "placeholder");
            }
          }
          if (el.captureEvents) el.captureEvents(Event.BLUR);
        
      }

    }

  }
}

addLoadEvent(initFormPlaceholders);

///////////////////// JQUERY

(function($) {

	$(document).ready(function() {

///////////////////////////// SLIDEOUTS

	  $('.sub ul').hide();
	  
	  $('.sub').click(function(){
	      if ($(this).find('ul').is(':hidden'))
	      {
	      $(this).find('ul').show();          
	    }
	    else
	      {
	      $(this).find('ul').hide();    
	    }
	  });

/////////////////////////// PROPORTIONAL IMAGE RESIZE

		$('.left-side .post img').each(function() {
		  var maxWidth = 487; // Max width for the image
		  var maxHeight = 700;    // Max height for the image
		  var ratio = 0;  // Used for aspect ratio
		  var width = $(this).width();    // Current image width
		  var height = $(this).height();  // Current image height

		  // Check if the current width is larger than the max
		  if(width > maxWidth){
		      ratio = maxWidth / width;   // get ratio for scaling image
		      $(this).css("width", maxWidth); // Set new width
		      $(this).css("height", height * ratio);  // Scale height based on ratio
		      height = height * ratio;    // Reset height to match scaled image
		  }

		  // Check if current height is larger than max
		  if(height > maxHeight){
		      ratio = maxHeight / height; // get ratio for scaling image
		      $(this).css("height", maxHeight);   // Set new height
		      $(this).css("width", width * ratio);    // Scale width based on ratio
		      width = width * ratio;    // Reset width to match scaled image
		  }
		});
	  
	});

})(jQuery);
