var requested;
var enableAjax = false;

function toggleBlind(id){
	if($(id).style.display == 'block'){
		Effect.BlindUp(id,{
			afterFinish:function(){
				$(id).style.display = 'none';
			}
		});
	}else{
		Effect.BlindDown(id,{
			afterFinish:function(){
				$(id).style.display = 'block';
			}
		});
	}
}

function toggleVisibility(elementId, forceToBlock){
    var element = $(elementId);
    if(element.getStyle('display') == 'none' || forceToBlock == true){
        element.setStyle({
            display : 'block'
        });
    }else{
        element.setStyle({
            display : 'none'
        });
    }
}

function ajaxRequest(source, container){
    if(requested != source){
    	$('loadingAjax').show();
        requested = source;
        new Ajax.Request(source,{
            method:'get',
            onSuccess: function(dataTransfer){
                var response = dataTransfer.responseText;
                Element.update(container, response);
                //new Effect.BlindDown(container,{});
                $('loadingAjax').hide();
            },
            onFailure: function(){
				alert('Something went wrong on an ajax request :(');
			}
        });
    }
}

function replaceLinksWithAjax(ajaxClass, content, extraJS){
    var elements = $$('.'+ajaxClass);
    elements.each(function(element){
        var hrefValue = element.getAttribute('href');
        if(hrefValue.indexOf("javascript") != 0){
            var newHrefValue = "ajaxRequest('"+hrefValue+"?ajax=1','"+content+"');"+extraJS+"return false;"
            element.setAttribute('onclick', newHrefValue);
        }
    });
}

function hideElements(classElement){
    var elements = $$('.'+classElement);
    elements.each(function(element){
        element.setStyle({
            display : 'none'
        });
    });
}



if(enableAjax == true){
    document.observe(
        "dom:loaded",
        function() {
            replaceLinksWithAjax('ajax', 'content', '');
            $('loadingAjax').hide();
        }
    );
}




