window.RICH_FACES_EXTENDED_SKINNING_ON = false;

// Konami code ---------------------------------------------------------------------------------------------------------
/*
 if (window.addEventListener) {
 var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
 window.addEventListener("keydown", function(e) {
 kkeys.push(e.keyCode);
 if (kkeys.toString().indexOf(konami) >= 0) {
 kkeys.clear();
 // User entered Konami Code
 alert('Hi #{elUtils.replaceApostrophe(loggedUser.displayName)}!');
 }
 if (kkeys.length > 10) {
 kkeys.clear();
 }
 }, true);
 }   */

// Shadowbox -----------------------------------------------------------------------------------------------------------
//Shadowbox.loadLanguage(language, contextPath + '/js/shadowbox/lang');
//Shadowbox.loadPlayer(['img', 'flv', 'iframe', 'html', 'qt', 'swf', 'wmp'], contextPath + '/js/shadowbox/player');
//Shadowbox.loadSkin('classic', contextPath + '/js/shadowbox/skin');

// Rilegge gli elementi della pagina
function SetupShadowBox() {
    Shadowbox.clearCache();
    Shadowbox.setup();
    // 'img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv'
}

// Usato da flash
var openShadowbox = function(content, player, title) {
    Shadowbox.open({
        content:    content,
        player:     player,
        title:      title
    });
}

/*
 window.onload = function()
 {
 setTimeout('SetupShadowBox()', 2000);
 }; */

jQuery(document).ready(function() {
    //jQuery("#breadCrumb0").jBreadCrumb({easing:'swing'});
    Shadowbox.init();
});

var allowPageReload = true;
var ajaxPageRefreshEnabled = true;
function reloadPage() {
    if (allowPageReload) {
        if (ajaxPageRefreshEnabled) {
            ajaxPageRefresh();
        } else {
            // Cannot use this because it ask for data resubmit if coming from a POST
            //location.reload();
            window.location = window.location.href;
        }
    }
}

function showHelpMP(title, text) {
    jQuery('#helpMPTitle').html(title);
    jQuery('#helpMPContent').html(text);
    Richfaces.showModalPanel('helpMP');
}

function hideHelpMP() {
    Richfaces.hideModalPanel('helpMP');
}

// Scroll panel
var isAutoScrollEnabled = function(elemId) {
    var div = jQuery(elemId)[0];

    if (div != null) {
        // certain browsers have a bug such that scrollHeight is too small
        // when content does not fill the client area of the element
        var scrollHeight = Math.max(div.scrollHeight, div.clientHeight);
        return (div.scrollTop == (scrollHeight - div.clientHeight));
    }

    return true;
}

var autoScrollPanel = function(elemId) {
    var div = jQuery(elemId)[0];

    if (div != null) {
        // certain browsers have a bug such that scrollHeight is too small
        // when content does not fill the client area of the element
        var scrollHeight = Math.max(div.scrollHeight, div.clientHeight);
        div.scrollTop = scrollHeight - div.clientHeight;

//                                    console.log('scrollHeight:'+scrollHeight);
//                                    console.log('clientHeight:'+div.clientHeight);
//                                    console.log('scrollTop:'+div.scrollTop);
    }

};

// Deprecated
function scrollToBottom(elementId) {
    var element = $(elementId);
    element.scrollTop = element.scrollHeight;
}

// Analytics code
function snetTrackEvent(category, action, opt_label, opt_value) {
    _gaq.push(['_trackEvent', category, action, opt_label, opt_value]);
}

function snetAddCustomVar(index, name, value, opt_scope) {
    _gaq.push(['_setCustomVar', index, name, value, opt_scope]);
}

function recordOutboundLink(link, category, action) {
    _gat._getTrackerByName()._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100);
}

function recordExternalOutboundLink(category, action) {
    _gat._getTrackerByName()._trackEvent(category, action);
}

jQuery(document).ready(function() {
    jQuery(function() {
        jQuery('.image-rollover').hover(function() {
            var currentImg = jQuery(this).attr('src');
            jQuery(this).attr('src', jQuery(this).attr('hover'));
            jQuery(this).attr('hover', currentImg);
        }, function() {
            var currentImg = jQuery(this).attr('src');
            jQuery(this).attr('src', jQuery(this).attr('hover'));
            jQuery(this).attr('hover', currentImg);
        });
    });
});

jQuery(document).ready(function() {
    jQuery('.animated-image').find('.caption').fadeOut();

    jQuery(function() {
        jQuery('.animated-image').hover(function() {
            var obj = jQuery(this).find('.caption');
            obj.animate({bottom: '0px'},{queue:false,duration:300});
            obj.fadeIn();
        }, function() {
            var height = jQuery(this).find('.caption').css('height');
            var obj = jQuery(this).find('.caption');
            obj.animate({bottom:'-'+height},{queue:false,duration:300});
            obj.fadeOut();
        });
    });
});
