/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$.fn.sm_contentReload = function (url)
{
	$(this).find("div#sm_content").slideUp("normal", function(){
		$(this).load(url, function(){
			$(this).slideDown();
			$(this).find("h2 a").click(function(){
				$("div#sm_registry").sm_contentReload(registry+'?page=companies&id='+$(this).attr('href'));
				return false;
			});
		});
	});
};

$.fn.sm_application = function ()
{
	var app = $(this);
	app.find("select:not(select:first)").hide();

	app.find("input[type='button']").click(function(){
		var type = $(this).attr('class');
		var element = $("select[name='"+type+"']");

		if (element.css('display') == 'none')
		{
			app.find("select").slideUp("normal", function(){
				$(this).find("option:selected").removeAttr('selected');
				app.find("select[name='"+type+"']").slideDown();
			});
		}
	});

	app.find("select").change(function(){
		app.sm_contentReload(registry+"?page="+$(this).attr('name')+"&id="+$(this).find("option:selected").val());
	});
};

$(document).ready(function(){

	$("div#sm_registry").load(registry, function(){

		$(this).slideDown().sm_application();

	});

});