/* JQUERY */

// http://www.html-advisor.com/javascript/hide-email-with-javascript-jquery/
$(function() {
    $('span.mailme').each(function() {
        var at = / at /;
        var dot = / dot /g;
        var addr = $(this).html().replace(at,"@").replace(dot,".");
        $($(this)).after('<a href="mailto:' + addr + '" title="Send an email">' + addr + '</a>')
        .hover(function(){window.status="Send a letter!";}, function(){window.status="";});
        $($(this)).remove();
    });
    
});

$(document).ready(function() {
    /* http://www.thefutureoftheweb.com/blog/detect-ie6-in-javascript */
    var is_ie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
    var is_ie = /*@cc_on!@*/false;
    if (is_ie6) {
        var ext = 'gif';
    } else {
        var ext = 'png'; 
    }
    var root = _root;
    var media_url = _media_url;
    
    /* cambio lingua */
    $(".nav_language").click(
        function() {
            var language = $(this).attr('id').replace('nav_language_', '');
            $("#change_language_form_" + language).submit();
        }
    );
    
    $(".album_box a").hover(
        function() {
            $(this).children(":first-child .text").addClass("highlight");
        },
        function() {
            $(this).children(":first-child .text").removeClass("highlight");
        }
    );

    if ($("select#id_tipo_socio").length > 0) {
        changeUserTypeFields();
        $("select#id_tipo_socio").change(function() {
           changeUserTypeFields();
        });
    }
    
    $(".event_loader").click(
        function() {
            var type = $(this).attr('name').split('-')[0];
            var id = $(this).attr('name').split('-')[1];
            $(this).parents('.events_wrapper').load(root + '/get-event/' + type + '/' + id); // ajax
        }
    );
    
    $(".events_list_loader").click(
        function() {
            var type = $(this).attr('name');
            $(this).parents('.events_wrapper').load(root + '/get-events-list/' + type); // ajax
        }
    );
    
    /* django-cms riscrittura dellanaloga funzione in cms/js/plugin_editor.js */
    /* la finestra e' troppo piccola! L'altezza veniva settata a 315px! */
    setiframeheight = function(height, id){
        height = height + 300; // custom
        $('#iframe_'+id).height(height+"px");
    }
    
});

