(function($){
	$(document).ready(function(){
		
		$('.see-all a').live('click', function(e){
			var $desc = $('.site-desc-text', $(this).closest('.site-desc'));
			if ($desc.hasClass('one-liner')){
				$desc.removeClass('one-liner fixed-width');
				$(this).text('Less');
				$(this).parent().appendTo($desc);
			}
			else {
				$desc.addClass('one-liner fixed-width');
				$(this).text('See all');
				$(this).parent().appendTo($(this).closest('.site-desc'));
			}			
			return false;
		});			

		$('.site-list tbody.site-row-body tr').click(function(){
			$('.site-list tbody.site-row-body tr.selected').removeClass('selected');
			$(this).addClass('selected');
			
			//populate fields based on selected row
			$('> td', this).each(function(index){
				var siteDesc = $(this).text();
				var tdClass = $(this).attr('class');
				if (tdClass == 'site-desc'){
					var $desc = $('.site-desc-text', this).clone();
					$desc.find('.see-all').remove();
					siteDesc = $.trim($desc.text());
				}
				$('#' + tdClass.replace(/-/g, '')).val(siteDesc);
			});
		});
		
		$('#btnSave').click(function(){
			//@todo:temporary only
			location.href = 'page';
			return false;
		});
		
		$('#btnCancel').click(function(){
			location.href = 'page';
		});
	});
})(jQuery);