/*
function makeButtons(){
	$("div.ctl-button").corner();
};
*/

function openNW(){
    $('a.new-window')
	.livequery(function(){
		$(this).click(function(e){
        		window.open($(this).attr("href"));
        		return false;
    		});
    	});
};

function stripeTables() {
	$('table.striped').livequery(function(){
		$('tbody tr:not([th]):odd').addClass('odd');
		$('tbody tr:not([th]):even').addClass('even');
	});
};

function ajaxLink() {
        $("a.ajax-link")
                .livequery(function(){
                        $(this).click(function(e){
                                var randomnumber=Math.floor(Math.random()*1001);
				var targetId = "#" + this.rel;
                                $(targetId).empty();
                                $(targetId).append("Loading ...");
                                $(targetId).load($(this).attr("href") + "&ie_sucks=" + randomnumber);
				var targetOffset = $(targetId).offset().top;
				$('html, body').animate({scrollTop: targetOffset}, 400);
				location.hash = targetId;
                                return false;
                        });
                });
};

function haltAjaxDiv(formData, jqForm, options) {
	var formElement = jqForm[0];
	var targetId = $(formElement).parent();
	//$(formElement).animate({opacity:'toggle'}, 100);
	$(formElement).fadeOut('fast');
	$(targetId).append("<div id='loading'>Loading ...</div>");
};

function unhaltAjaxDiv(responseText, statusText, jqForm) {
	var formElement = jqForm[0];
	var targetId = $(formElement).parent();
	//$(formElement).animate({opacity:'toggle'}, 10);
	$(formElement).fadeIn('slow');
	$("#loading").remove();
	/*$(targetId).empty();
	$(targetId).append(responseText);*/
};

function ttlAjaxForm() {
        $("form.ajax_form")
                .livequery('submit', function(){
			var targetId = $(this).parent();
			var options = {
				target:		targetId ,
				beforeSubmit:	haltAjaxDiv,
				success:	unhaltAjaxDiv
			};
			$(this).ajaxSubmit(options);
			return false;
			/*$(this).ajaxForm(options);*/
			/*$(this).submit(function(e){
				$(this).ajaxSubmit(options);
				return false;
                        });*/
                });
};


$(document).ready(function(){
/*	makeButtons();*/
	openNW();
	stripeTables();
	ajaxLink();
	ttlAjaxForm();
});


