$(document).ready( function() {
    $('#info').hide();

    $('#roaming-country select').change( function() {
        var val = $(this).val().split('/');
        var p   = val[0];
        var pe  = val[1];
        var pp  = val[2];
        window.location = 'http://www.elisa.fi/matkaviestinta/roaming/index.cfm?o=199.40&p='+ p +'&pp='+ pp +'&pe='+ pe;
    });
});

function roaming(country) {
    if (!isNaN(country)) {
        $('#roaming-content').load('/matkaviestinta/roaming/country.php?id='+ country, function() {

            $('.tooltip').hover( function(e) {
                this.t = this.title;
                this.title = "";
                $('body').append('<p id="tooltip">'+ this.t +'</p>');
                $('#tooltip')
                    .css("top",(e.pageY - 30) +'px')
                    .css("left",(e.pageX + 30) +'px')
                    .fadeIn('fast');
            }, function() {
                this.title = this.t;
                $('#tooltip').remove();
            });
            $('.tooltip').mousemove( function(e) {
                $("#tooltip")
                    .css("top",(e.pageY - 30) + "px")
                    .css("left",(e.pageX + 30) + "px");
            });

            $('.operator h3').click(function() {
                elem = $(this);
                if (elem.parent().attr('class').indexOf('act') != -1) {
                    $('table.extra tbody').hide();
                    elem.parent().children('.content').slideUp('fast', function() { elem.parent().toggleClass('act'); });
                } else {
                    elem.parent().toggleClass('act');
                    elem.parent().children('.content').slideDown('fast');
                    elem.parent().addClass('act');
                }
            });

            $('table.extra-data').hide();

            $('table.extra thead').click( function() {
                var id = $(this).parent().attr('id');
                id = id.split('-');
                id = id[1] +'-'+ id[2];
                $('#extra-data-'+ id).slideToggle('fast');
            });

        });

        $('#info').show();
    }
}
