Cufon.replace('.harabara-bold', {
    fontFamily: 'Harabara Bold',
	hover: true,
	hoverables: { strong: true, em: true }
});

var lang,
	isIE6 = !$.support.opacity && !window.XMLHttpRequest;

$(document).ready(function () {
	
	if($('#lang').length){
		var _val = $('#lang').val();
		if(!_val){
			lang = "en";			
		} else {
			lang = _val;
		}
	} else {
		lang = "en";
	}
	
	$(document).ajaxError(function(e, xhr, settings, exception) {
		if(lang=="it"){						   
			alert('Si é verificato un errore durante il caricamento della risorsa: ' + settings.url + ' \n'+'Si prega di ricaricare questa pagina o di riprovare in seguito.');
		} else {						   
			alert('An error has occurred loading the resource: ' + settings.url + ' \n'+'Please reload this page or try later.');		
		}
	});
	
	$("a[rel='_blank']").live("click", function () {
        $(this).attr("target", "_blank");
    });

    $("a[rel='_top']").live('click', function () {
        $('html, body').animate({
            scrollTop: 0
        }, 'normal');
        return false
    });

    $("a[rel='_back']").live("click", function () {
        window.history.back();
        return false
    });

    $("a[rel*='_popup']").live("click", function () {
        var url = $(this).attr("href");
        var thisRel = $(this).attr("rel");
        var popupSize = thisRel.substr(thisRel.lastIndexOf("-") + 1);
        var popupWidth = popupSize.substr(0, popupSize.lastIndexOf("_"));
        var popupHeight = popupSize.substr(popupSize.lastIndexOf("_") + 1);
        window.open(url, 'popup', 'width=' + popupWidth + ', height=' + popupHeight + '');
        return false
    });

    $('.select-on-click').bind('focus blur mouseup', function (event) {
        if (event.type == "focus") {
            if (this.value == this.defaultValue) {
                this.value = '';
            }
            if (this.value != this.defaultValue) {
                this.select();
            }
        }
        if (event.type == "blur") {
            if (this.value == '') {
                this.value = this.defaultValue;
            }
        }
        if (event.type == 'mouseup') {
            event.preventDefault(); /* webkit */
        }
    });
	
	$('ul.media').each(function(){
		var $blocks = $(this).children('li'),							
			blocksLength = $blocks.length;		
		for (k=0; k< blocksLength; k=k+3){
      		$blocks.eq(k).add($blocks.eq(k+1)).add($blocks.eq(k+2)).wrapAll('<div style="clear:both;"></div>') ;
    	}		
	});
});

function loadNews(obj){
    var link = $("#php_self").val()+$(obj).find("option:selected").val();
    location.href = "/"+link;
}
