

$(function() {
	var moreID = 0;
	$('.showmore').each(function() {
		$(this).html("<a href=\"javascript:showMore("+moreID+")\">more...</a>");
		$(this).next().hide();
		$(this).next().attr('id', 'more_' + moreID);
		$(this).attr('id', 'morea_' + moreID);
		moreID++;
	});
	
	$('.wrapform').each(function() {
		var action = $(this).attr('action');
		//$(this).before("<form action='"+action+"' method='post'>");
		$('.lastrow', this).after("<tr><td></td><td id='sendTD'><input type='button' onclick='sendFriend()' value='Send' /></td></tr>");
		//$(this).after('</form>');
	});

	$('.ajaxLoad').each(function() {
		var url = $(this).attr('url');
		var html = $(this).html();
		
		$(this).html("<a href='javascript:loadContents(\"" + url + "\")'>" + html + "</a>");
	});
	
	$('.ajaxLoad1').each(function() {
		var url = $(this).attr('url');
		var html = $(this).html();
		$(this).html("<a href='" + baseUrl + url + "'>" + html + "</a>");
	});
	
	$('.morenewwindow').each(function() {
		var e = $(this);
		var href = e.attr('href');
		e.attr('href', 'javascript:newWind("'+href+'")');
	});
	var list = '';
	$('.infopiece').each(function(){
		list += '<li><a href="javascript:showInfo(\''+$(this).attr('id')+'\')">'+$('h2', this).html()+'</a></li>';
	});
	$('#servicelist').html(list);

	$('.ajaxInfo').each(function(){
		var url = $(this).attr('href');
		$(this).attr('href', 'javascript:loadContents("'+url+'", true)');
	});

});
window.lastInfoID = null;
function showInfo(id) {
	if (window.lastInfoID == id) return;
	$('.infopiece').hide();
	$('#'+id).show();
	window.lastInfoID = id;
}

function newWind(url) {
	window.open(url, 'treatmentWnd', 'resizable=yes,scrollbars=yes,height=550,width=950', false);
}

function loadContents(url, ignoreBase) {
	if (!ignoreBase)
		url = baseUrl + url;
	$.get(url,null,function(html) {
		$('#dynContents').html(html);
		$('.morenewwindow').each(function() {
			var e = $(this);
			var href = e.attr('href');
			e.attr('href', 'javascript:newWind("'+href+'")');
		});
	});
}


function showMore(id) {
	
	$('#more_' + id).slideDown(
		function() {
			$('#morea_' + id).fadeOut();
		}
	);
	
}

function sendFriend() {
	var em = $('#email').val();
	var bdy = $('#body').val();
	$.post(baseUrl + 'jgp/sendmail', { email: em, body: bdy }, 
		function(r) {
			$('#contactForm').html(r);
		}
	);
}














