
$(document).ready(function(){
		
		
		  
  		var topmax = Math.max($("#topleft").height(), $("#topright").height());
  		topmax = Math.max($("#top-wide").height(), topmax);
  		var botmax = Math.max($("#bottomleft").height(), $("#bottomright").height());
  		botmax = Math.max($("#bottom-wide").height(), botmax);
        
      var top_height = topmax+'px';
  		var bottom_height = botmax+'px';
  		var rightcolumn_tmp = topmax+botmax+25;
  		var content_tmp = topmax+botmax+60;
  		
  		if (botmax == 0) {
	       rightcolumn_tmp = topmax+botmax;
	       content_tmp = topmax+botmax+35;
	     }
	     
	     var min_rightcolumn = Math.max(rightcolumn_tmp, 765)+'px';
	     var min_content = Math.max(content_tmp, 800)+'px';
	     
	     var rightcolumn_height = rightcolumn_tmp + 'px';
	     var content_height = content_tmp + 'px';
	     
	     //alert("rightcolumn: " + rightcolumn_height + "\n rightMin: " + min_rightcolumn + "\n Content: " + content_height ); 		
  		
  		//alert("TopRight: " + topright_height + "\n RightColumn: " + rightcolumn_height + "\n Content: " + content_height ); 		
  		
  		$("#topleft").css({"height":"auto !important", "height":top_height});
  		$("#topright").css({"height":"auto !important", "height":top_height});
  		$("#bottomleft").css({"height":"auto !important", "height":bottom_height});
  		$("#bottomright").css({"height":"auto !important", "height":bottom_height});
  		//$("#rightcolumn").css({"min-height":rightcolumn_height, "height":"auto !important", "height":rightcolumn_height});
  		//$("#content").css({"min-height":content_height, "height":"auto !important", "height":content_height});
  		$("#rightcolumn").css({"min-height":min_rightcolumn, "height":"auto !important", "height":rightcolumn_height});
  		$("#content").css({"min-height":min_content, "height":"auto !important", "height":content_height});

      var countdown = {
        init: function() {
            countdown.remaining = countdown.max - $(countdown.obj).val().length;
            if (countdown.remaining < 0)
            {
               countdown.remaining = 0;
               $('.remaining').addClass("error");
            }
            else
            {
               $('.remaining').removeClass("error");
            }    
            if ($(countdown.obj).val().length > countdown.max) {
                $(countdown.obj).val($(countdown.obj).val().substring(0,countdown.max));
            }          
            
            $('.remaining').html(countdown.remaining + " characters remaining.");

        },
        max: null,
        remaining: null,
        obj: null
    };
    
    $('.countdown').each(function() {
        var c = $(this).attr("class");
        countdown.max = parseInt(c.match(/limit_[0-9]{1,}_/)[0].match(/[0-9]{1,}/)[0]);
        countdown.obj = this;
        iCount = setInterval(countdown.init,1000);
        
        $(this).focus(function() {
            var c = $(this).attr("class");
            countdown.max = parseInt(c.match(/limit_[0-9]{1,}_/)[0].match(/[0-9]{1,}/)[0]);
            countdown.obj = this;
            iCount = setInterval(countdown.init,1000);
        }).blur(function() {
            countdown.init();
            clearInterval(iCount);
        });
    });
});
 
/*
** Image Gallery
*/ 
function showPic(whichpic)
{
    var source = whichpic.getAttribute("href");
    var placeholder = document.getElementById("placeholder");
    source = source.replace('tn_','img_');
    placeholder.setAttribute("src",source);   
}

function roll_over(img_id, img_src)
{

   var imageholder = document.getElementById(img_id);
   imageholder.setAttribute("src", img_src);
}