$(document).ready(function(){
  
//    $(function() {
//	$('#subSituacions a').lightBox({fixedNavigation:true});
//});
$(function() {
   $('#subSituacions a').lightBox({
	overlayBgColor: '#FFF',
	overlayOpacity: 0.6,
	imageLoading: 'images/lightbox-ico-loading.gif',
	imageBtnClose: 'images/close.gif',
	imageBtnPrev: 'images/prev.gif',
	imageBtnNext: 'images/next.gif',
	containerResizeSpeed: 350,
	txtImage: 'Imatge',
	txtOf: 'de'
   });
});

$(function() {
   $('.smoothbox a').lightBox({
	overlayBgColor: '#FFF',
	overlayOpacity: 0.6,
	imageLoading: 'images/lightbox-ico-loading.gif',
	imageBtnClose: 'images/close.gif',
	imageBtnPrev: 'images/prev.gif',
	imageBtnNext: 'images/next.gif',
	containerResizeSpeed: 350,
	txtImage: 'Imatge',
	txtOf: 'de'
   });
});
    var positionPont = new Array();
    var pontWidth=0;
    var posPont = 1;
    $('#pont .pont').each(function(i){

        /* Traverse through all the slides and store their accumulative widths in totWidth */

        positionPont[i] = pontWidth;
        pontWidth += $(this).width();

        /* The positions array contains each slide's commulutative offset from the left part of the container */

        if(!$(this).width())
        {
           //alert("Please, fill in width & height for all your images!");
            return false;
        }
        
        return true;
    });
   $('#ma').click(function(e){
      
        e.preventDefault();

       $('#pont').animate({
               marginLeft:-positionPont[posPont]+'px'
            },"slow");
            $('#tornar').show();
            $('#situacions').show();

    });
  $('#tornar').click(function(e){

        e.preventDefault();
       $('#pont').animate({
                marginLeft:'0px'
            },"slow");
$('#tornar').hide();
$('#situacions').hide();
    });
  $('#organitzacio').click(function(e){

        e.preventDefault();
       $('#subSituacions').animate({
                marginTop:'0px'
            },"slow");

    });
    $('#laboral').click(function(e){

        e.preventDefault();
       $('#subSituacions').animate({
                marginTop:'-350px'
            },"slow");

    });
      $('#serveis').click(function(e){

        e.preventDefault();
       $('#subSituacions').animate({
                marginTop:'-700px'
            },"slow");

    });

      $('#formacio').click(function(e){

        e.preventDefault();
       $('#subSituacions').animate({
                marginTop:'-1050px'
            },"slow");

    });
      $('#tempsLliure').click(function(e){
//console.log("situacio")
        e.preventDefault();
       $('#subSituacions').animate({
                marginTop:'-1400px'
            },"slow");

    });
    var totWidth=0;
    var positions = new Array();
	
    $('#slides .slide').each(function(i){
		
        /* Traverse through all the slides and store their accumulative widths in totWidth */
		
        positions[i]= totWidth;
        totWidth += $(this).width();
		
        /* The positions array contains each slide's commulutative offset from the left part of the container */
		
        if(!$(this).width())
        {
            alert("Please, fill in width & height for all your images!");
            return false;
        }
		
    });
	
    $('#slides').width(totWidth);

    /* Change the cotnainer div's width to the exact width of all the slides combined */

    $('#menu ul li a').click(function(e,keepScroll){
        /* On a thumbnail click */
if($(this).attr('id') =='equip'){
    $('#map').css('display', 'block')
}else{
    $('#map').css('display', 'none')
}
        $('li.menuItem').removeClass('act').addClass('inact');
        $(this).parent().addClass('act');
			
        var pos = $(this).parent().prevAll('.menuItem').length;
			
        $('#slides').stop().animate({
            marginLeft:-positions[pos]+'px'
        },450);
        /* Start the sliding animation */
			
        e.preventDefault();
        $('#situacions').hide();
         $('#pont').animate({
                marginLeft:'0px'
            },"fast");
    /* Prevent the default action of the link */
			
			
    // Stopping the auto-advance if an icon has been clicked:
    //	if(!keepScroll) clearInterval(itvl);
    });
	
    $('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
    /* On page load, mark the first thumbnail as active */
	
	
	
    /*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/
	 
    //	var current=1;
    //	function autoAdvance()
    //	{
    //		if(current==-1) return false;
    //
    //		$('#menu ul li a').eq(current%$('#menu ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
    //		current++;
    //	}
    //
    //	// The number of seconds that the slider will auto-advance in:
    //
    //	var changeEvery = 10;
    //
    //	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

    /* End of customizations */


    $('#menu ul li.menuItem a').click(function(e){

        /* On a thumbnail click */

        $('li.menuItem').removeClass('act').addClass('inact');
        $(this).parent().addClass('act');

        var pos = $(this).parent().prevAll('.menuItem').length;

        $('#slides').stop().animate({
            marginLeft:-positions[pos]+'px'
        },"slow");


        /* Start the sliding animation */

        e.preventDefault();
    /* Prevent the default action of the link */
    });
    $('.pBig a').click(function(event){


        var id = event.target.id
        event.preventDefault();

        var divDisplay = '#text'+id;
        // alert(divDisplay);
        //   $(divDisplay).fadeIn('slow');
        //$('#text').fadeOut('slow');

        $('#text').fadeOut(1000, function () {
            $('#text').remove();
            $(divDisplay).fadeIn('slow');

        });
        return false;
    });
$('#programa').click(function(e){
     $('li.menuItem').removeClass('act').addClass('inact');
        $(this).parent().addClass('act');

        var pos = $(this).parent().prevAll('.menuItem').length;

        $('#slides').stop().animate({
            marginLeft:'-2475px'
        },"slow");
        e.preventDefault();
})
    $('#menuCom ul li.menuItem:first').addClass('act').siblings().addClass('inact');
    /* On page load, mark the first thumbnail as active */
    /* Changing thedefault easing effect - will affect the slideUp/slideDown methods: */
    $.easing.def = "easeOutBounce";

    /* Binding a click event handler to the links: */
    $('li.buttons a').click(function(e){
 posPont = 0;
        $('#programa').stop().animate({
            marginTop:'-370px'
        },"slow");
//        console.log(e.attr('id'));
//        console.log(e.target.id)
       // alert(this.id);
        posPont = 1;
//        $(".backPont").text()
        /* Finding the drop down list that corresponds to the current section: */
        var dropDown = $(this).parent().next();

        /* Closing all other drop down sections, except the current one */
        $('.dropdown').not(dropDown).slideUp('slow');
        dropDown.slideToggle('slow');

        /* Preventing the default event (which would be to navigate the browser to the link's address) */
        e.preventDefault();
    });

    $("#contactar").submit(function(e){
        e.preventDefault();
        var str = $("form").serialize();
        $.ajax({
            type: "POST",
            url: "enviarMissatge.php",
            data: str,
            success: function(msg){

                $("#note").ajaxComplete(function(event, request, settings){

                    if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
                    {
                        result = '<div class="notification_ok">'+missatgeOK+'</div>';
                        $("#divForm").hide();
                    }
                    else
                    {
                        result = msg;
                    }
                    $(this).html(result);
                });
            }

        });

    })
var x = 50;
var y;
    var ocupado = 0;
    var pausa = null;

    //Cuando se pasa por encima del icono
    $('#icono').mouseover(function (){
        console.log(x);
        if(pausa) clearTimeout(pausa);
        if (ocupado == 0){
            ocupado = 1;
            $('.tooltip').css({
                //Aparece (ya que estaba en display none)
                top: 0,
                display: 'block',
                opacity: 0
            }).animate({
                //Sube 20px y pasa a ser opaco
                top: x,
                opacity: 1
            }, 'normal',
            function (){
                ocupado = 0;
            });
        }
    });
    //Cuando sale de la zona del icono
    $('#icono').mouseout(function (){

        pausa = setTimeout(function () {
            pausa = null;
            if (ocupado == 0){
                ocupado = 1;
                $('.tooltip').css({
                    opacity: 1
                }).animate({
                    top: '-=' + '50px',
                    opacity: 0
                }, 'slow',
                function(){
                    $('.tooltip').css({
                        display: 'none',
                        top: 0
                    });
                    ocupado = 0;
                });
            }else {
                $('.tooltip').css({
                    display: 'none'
                });
                ocupado = 0;
            }
        }, 500)
    });

 $('#icono').mousemove(function(e){
         x = e.pageX - this.offsetLeft;
         y = e.pageY - this.offsetTop;

    });

   var positionPont = new Array();
    var pontWidth=0;
    var posPont = 1;
    $('#pont .pont').each(function(i){

        /* Traverse through all the slides and store their accumulative widths in totWidth */

        positionPont[i] = pontWidth;
        pontWidth += $(this).width();

        /* The positions array contains each slide's commulutative offset from the left part of the container */

        if(!$(this).width())
        {
            // alert("Please, fill in width & height for all your images!");
            return false;
        }
//         positionPont[i] = pontHeight;
//        pontHeight += $(this).height();

        /* The positions array contains each slide's commulutative offset from the left part of the container */

        if(!$(this).height())
        {
            // alert("Please, fill in width & height for all your images!");
            return false;
        }
        return true;
    });
//    $('#queEs').click(function(i){
//        posPont = 0;
//        $('#programa').stop().animate({
//            marginTop:-positionPont[posPont]+'px'
//        },"slow");
//      //  alert("queEs");
//        posPont = 1;
//        $(".backPont").text()
//
//    });
    $('.aniPont').click(function(e){
        if(posPont<=4){
            $('#pont').stop().animate({
                marginLeft:-positionPont[posPont]+'px'
            },"slow");

        }else{
            $('#pont').stop().animate({
                marginLeft:'0px'
            },"slow");
            posPont=0;
            $(".backPont").text()

        }
        e.preventDefault();
        posPont +=1;
        if(posPont<=1){
            $(".backPont").text("")

            }
        if(posPont>1){
            $(".backPont").text(backText)

            }

    });
    $.fx.speeds._default = 1000;
	$(function() {
		$( "#dialog" ).dialog({
			autoOpen: false,
			show: "blind",
			hide: "explode"
		});
$( "#dialog" ).dialog( "option", "width", 650 );
		$( "#opener" ).click(function() {
			$( "#dialog" ).dialog( "open" );
			return false;
		});
                //setter

	});


    $("#contactar").submit(function(e){
        $("#divForm").show();
        e.preventDefault();
        var str = $("#contactar").serialize();
        $.ajax({
            type: "POST",
            url: "enviarMissatge.php",
            data: str,
            success: function(msg){
             //  console.log(msg)
                $("#note").ajaxComplete(function(event, request, settings){

                    if(msg == 1) // Message Sent? Show the 'Thank You' message and hide the form
                    {
//                      $("#divForm").hide();
//                     console.log(msg)
                    result = '';
                    $('#resposta').show();
                    $('.notification_ok').show();
                    $('#contents').hide();
                    }
                    else if(msg !=1)
                    {
                       $("#divForm").show();
                        result = msg;

                    }
                    $(this).html(result);


                });
                return false;
            }

        });

    })
        $("#usersButlleti").submit(function(e){
         e.preventDefault();
        var str = $("#usersButlleti").serialize();
        $.ajax({
            type: "POST",
            url: "xecUser.php",
            data: str,
            success: function(msg){
              // console.log(msg)
                $("#note").ajaxComplete(function(event, request, settings){

                    if(msg == 1) 
                    {
                    result = "<a href='butlleti.pdf'>Descarregar butlleti</a>";
                    
                    $('#formDownload').hide();
                    }
                    else if(msg !=1)
                    {
                       $("#divForm").show();
                        result = msg;

                    }
                    $('#download').show();
                    $("#download").html(result);


                });
                return false;
            }

        });

    })

});//ready
