$(function(){
    $('.fadein img:gt(0)').hide();
    setInterval(function(){
        $('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');
    }, 5000);
});

function initMenus() {
    $('ul.menu ul').hide();
    $.each($('ul.menu'), function(){
        $('#' + this.id + '.expandfirst ul:first').show();
    });
    $('ul.menu li a').click(
        function() {
            var checkElement = $(this).next();
            var parent = this.parentNode.parentNode.id;

            if($('#' + parent).hasClass('noaccordion')) {
                $(this).next().slideToggle('normal');
                return false;
            }
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                if($('#' + parent).hasClass('collapsible')) {
                    $('#' + parent + ' ul:visible').slideUp('normal');
                }
                return false;
            }
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $('#' + parent + ' ul:visible').slideUp('normal');
                checkElement.slideDown('normal');
                return false;
            }

            return false;
        });
}

$(document).ready(function() {
    initMenus();
});

$(function() {
    $('#gallery a').lightBox();
});

$(document).ready(function() {
    //Default Action
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content
        var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active content
        return false;
    });
});

$(document).ready(function() {
    // call the tablesorter plugin
    $("table").tablesorter({
        sortList: [[0,0]]
    });
});

stLight.options({
    publisher:'ba1bc200-d2c4-497a-8d29-83ec45835c08'
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20199964-1']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
})();

function initialize_map_home() {
    if (GBrowserIsCompatible()) {
        var map_home = new GMap2(document.getElementById("map_home"));
        var point_home = new GLatLng(43.039778, 12.623261);
        map_home.setCenter(point_home, 16);
        map_home.setMapType(G_HYBRID_MAP);
        map_home.setUIToDefault();

        var marker_home = new GMarker(point_home);
        GEvent.addListener(marker_home, "click", function() {
            marker_home.openInfoWindowHtml('Busti rimorchi agrigoli');
        });
        map_home.addOverlay(marker_home);
    }
}

function initialize_map_world() {
    if (GBrowserIsCompatible()) {
        var map_home = new GMap2(document.getElementById("map_world"));
        var point_home = new GLatLng(43.039778, 12.623261);
        map_home.setCenter(new GLatLng(0, 0), 1);
        map_home.setMapType(G_HYBRID_MAP);
        map_home.setUIToDefault();

        var marker_1 = new GMarker(new GLatLng(47.320099, 7.984221));
        GEvent.addListener(marker_1, "click", function() {
            marker_1.openInfoWindowHtml('Höliweg 24, 5745 Safenwil - AG, Svizzera');
        });
        map_home.addOverlay(marker_1);

        var marker_2 = new GMarker(new GLatLng(43.324027, 145.596267));
        GEvent.addListener(marker_2, "click", function() {
            marker_2.openInfoWindowHtml('Higashi Nemuro Nemu Kasai-Gun,<br/> Hokkaido 082-0005, Giappone');
        });
        map_home.addOverlay(marker_2);
    }
}


