﻿
		jQuery(document).ready(function() {

	jQuery("a#ss").fancybox({'overlayOpacity':0.8});
	
	
});
		
		
jQuery(window).load(function() {

    function initializeMap(){
        jQuery('#map').fadeOut(500, function(){
            jQuery('#map').empty().css({
                width: '375px',
                height: '250px',
                backgroundImage: 'url(http://www.colip.com/wp-content/themes/colip/asset/img/ui/maps/mappe.jpg)',
                position: 'relative'
            });
            jQuery('#map').fadeIn();
            loadBullets('coast', false);
        });
    }

    function addZoomable(id, width, height, top, left){
        jQuery('<img class="zoomable" src="http://www.colip.com/wp-content/themes/colip/asset/img/ui/maps/blank.gif" id="' + id + '" />').css({
            border: 'none',
            position: 'absolute',
            width: width + 'px',
            height: height + 'px',
            top: top + 'px',
            left: left + 'px',
            cursor: 'pointer'
        }).appendTo('#map').click(function() {
            jQuery(this).siblings().fadeOut();
            jQuery(this).hide()
                   .attr('src', 'http://www.colip.com/wp-content/themes/colip/asset/img/ui/maps/' + id + '.gif')
                   .fadeIn('slow')
                   .animate({
                        width: '375px',
                        height: '250px',
                        top: '0px',
                        left: '0px'
                    }, 1000, '', function(){
                        jQuery('#map').css({backgroundImage: 'url(http://www.colip.com/wp-content/themes/colip/asset/img/ui/maps/' + id + '.gif)'}).empty();
                        loadBullets(id, true);
                    });
        });
    }
    
    function loadBullets(id, back){
        jQuery('#map').load( 'http://www.colip.com/wp-content/themes/colip/'+ id + '.html', {}, function(){

            if(back){
                jQuery('<p><a id="mapback" href="javascript:void(0)">indietro</a></p>')
                    .appendTo(this)
                    .click(function(){initializeMap()});
            }
            else{
                addZoomable('america-nord', 29, 19, 67, 20);
                addZoomable('america-centro', 29, 19, 96, 19);
                addZoomable('america-sud', 29, 19, 125, 48);
                addZoomable('europa', 29, 19, 62, 160);
                addZoomable('australia', 29, 19, 171, 343);
            }

            jQuery(this).children('a.bullet').each(function(){
                var coords = jQuery(this).attr('rel').split('-');
                jQuery(this).css({left: coords[0] + 'px', top: coords[1] + 'px'})
                       .hide()
                       .fadeIn();
                 var theID = jQuery(this).attr('id');
                 var theLink = 'a#' + theID; 
                jQuery( theLink).fancybox({'cyclic' : false,
                					 'overlayOpacity': 0.8});     

            });
        });
    }
    
    initializeMap();    

});

