var requested;
var enableAjax = true;

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 ajaxRequest(source, container){
    if(requested != source){
        $('loader').style.display = 'block';
        requested = source;
        new Effect.BlindUp(container, {
            afterFinish : function(){
                new Ajax.Request(source,{
                    method:'get',
                    onSuccess: function(dataTransfer){
                        var response = dataTransfer.responseText;
                        Element.update(container, response);
                        $('loader').style.display = 'none';
                        new Effect.BlindDown(container,{
                            afterFinish : function(){
                                //window.onload();
                            }
                        });
                        
                    },
                    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');
        var newHrefValue = "javascript:ajaxRequest('"+hrefValue+"?ajax=1','"+content+"');"+extraJS+"return false;"
        element.setAttribute('onclick', newHrefValue);
    });
}

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



if(enableAjax == true){
	Event.observe(window, 'load',function() {
        replaceLinksWithAjax('artistsAjax', 'artistContent', '');
		hideElements('toHide');
        //replaceLinksWithAjax('ajaxApprofondisci', 'content', "new Effect.ScrollTo('content');");
    });
}




