
			   
						   
						   
	////////////////////////////
////	CHANGE CLASS
///////////////////////////
$(document).ready(function() {
					   
  $('#main').masonry({
    // options
    itemSelector : '.box',
    columnWidth: 77.1,
    isAnimated: true,
    resizeable: true,
    animationOptions: {duration: 1000,
        queue: false,
        easing: 'linear'
      }
  });

        $('li a').live('click', function(e) {
            e.preventDefault();
            var $this = $(this);

            $this.animate();

            $this.closest('ul').children('li').removeClass('Opened');
            $this.parent().addClass('Opened');

            $("#contenuto > .Opened").eq(0).height();

            $('#main').masonry( 'reload' );
            
            return false;
        });


    $('.closeBOX').live('click', function() {
        that = this;
        $(this).siblings('#gbox .target').animate({
            opacity: 0.25,
            left: '+=50',
            height: 'toggle'
        }, 10000, function() {
            $(that).parent("li:first").attr("class", "box col1 black");


            $(that).parent('.closeBOX').prev("#gbox").fadeOut('slow', function(){

                });

            $('#main').masonry( 'reload' );
        });

        return false;
    });
/////////////////////////////
        $('#closerabbit').click (function() {
               $('#rabbit').slideToggle();
            return false;
        });
				
//////////////////////////		

    function get_page(event) {
      tmp = $(event.target).parent().attr('wp:id');
      if( tmp == null) {
          tmp =  $(event.target).parent().parent().attr('wp:id');
      }

        var datak = {
            action: 'get_page',
            post_id: tmp
        };

        jQuery.ajax({
            url: ajaxurl,
            data: datak,
            type: 'POST',
            tryCount : 0,
            tryLimit: 3,
            success: function(data) {
                $('#rabbit').html(data);

            if(datak.post_id == "3553") {
                    jQuery.validator.addMethod("notEqual", function(value, element, param) {
                        return this.optional(element) || value != param;
                    }, "Inserisci un valore diverso da quello preimpostata");

                    // validate signup form on keyup and submit
                    $("#cvForm").validate({

                        rules: {

                            email: {

                                required: true,

                                email: true

                            },

                            firstname: {

                                notEqual: 'Nome',

                                required: true

                            },

                            lastname: {

                                notEqual: 'Cognome',

                                required: true

                            },

                            cv: {

                                required: true,

                                accept: "pdf|docx|doc|odt|rtf"

                            },

                            tipo: {
                                required: true
                            }



                        },
                        errorElement: "em",

                        messages: {

                            firstname: "Inserisci il tuo nome",

                            lastname: "Inserisci il tuo cognome",

                            email: "Inserisci un indirizzo email valido",

                            cv: "Inserisci un file in formato valido (PDF, docx, doc, odt, rtf)",

                            tipo: "Seleziona di che tipo sei"

                        },
                        errorPlacement: function(error, element) {
                            if (element.attr("name") == "tipo")
                            {
                                error.appendTo("#tipoError");
                            } else {
                                error.insertAfter(element);
                            }

                        }

                    });

                    $("#cvForm").formToWizard({

                        submitButton: 'ok'

                    });







                    $.ajaxSetup({
                        async:false
                    });
                    data = {
                        action: 'get_busydays'
                    }

                    var bookedDays = Array();
                    $.post(ajaxurl, data, function(response){
                        $.each(response, function(n, k) {
                            bookedDays.push(unescape(k));
                        });
                    });
                    $.ajaxSetup({async:true});



                    var day = new Date();

                    var tomorrow = new Date();

                    day.setDate(day.getDate()+1);

                    $( "#datepicker" ).datepicker(

                    {

                        beforeShowDay: function(date) {
                            if( date.getDay() == 0 || date.getDay() == 6) {
                                return [false];
                            }

                            var dateAsString = $.datepicker.formatDate("dd/mm/yy", date);

                            var result = $.inArray( dateAsString, bookedDays ) ==-1 ? [true] : [false, 'occupato'];

                            return result;



                        },

                        create: function(dateText, inst) {

                            $("#date").val(dateText);

                        },

                        minDate: day,

                        maxDate: '+6m',

                        onSelect:  function(dateText, inst) {

                            $('#date').val(dateText)

                        }

                    });

                }
            },
            error : function(xhr, textStatus, errorThrown ) {
                this.tryCount++;
                if (this.tryCount <= this.retryLimit) {
                    $.ajax(this);
                    return;
                }
                return;
            }
        });
    }

    $('#rabbit').hide();
	
	    $('.appunt').click(function (e) { 
			 $('#rabbit').load($(this).attr('href'));
        return false;
            e.preventDefault();
  });
	
	
	
    $('.footer-hands,#newslettericon').bind('click', function(event) {
        if($('#rabbit').is(':visible')) {
            get_page(event);
        } else {
            $('#rabbit').slideToggle('slow', get_page(event));
        }
        return false;
    });
    $('.footer-hands,.appunt').bind('click', function(event) {
        if($('#rabbit').is(':visible')) {
            get_page(event);
        } else {
            $('#rabbit').slideToggle('slow', get_page(event));
        }
        return false;
    });


   jQuery.fx.step.corner  = function(fx) {
      // Change both top and left values.
      // Will work with em and % values too!
      fx.elem.style.top = fx.now + fx.unit;
      fx.elem.style.right = fx.now + fx.unit;
    };

    $("#scrollobli").mouseover(function(event){
      $("#scrollobli .block").stop().animate({corner: '-12px'},{duration: 300});

    });
    $("#scrollobli").mouseout(function(event){
      $("#scrollobli .block").stop().animate({corner: '-1px'},{duration: 300});
          

    });
    $("#scrollobli2").mouseover(function(event){
      $("#scrollobli2 > .block").stop().animate({corner: '-12px'},{duration: 300});

    });
    $("#scrollobli2").mouseout(function(event){
      $("#scrollobli2 .block").stop().animate({corner: '-1px'},{duration: 300});

    });
    $("#scrollobli3").mouseover(function(event){
      $("#scrollobli3 .block").stop().animate({corner: '-12px'},{duration: 300});

    });
    $("#scrollobli3").mouseout(function(event){
      $("#scrollobli3 .block").stop().animate({corner: '-1px'},{duration: 300});

    });
    $("#scrollobli4").mouseover(function(event){
      $("#scrollobli4 .block").stop().animate({corner: '-12px'},{duration: 300});

    });
    $("#scrollobli4").mouseout(function(event){
      $("#scrollobli4 .block").stop().animate({corner: '-1px'},{duration: 300});

    });
    $("#scrollobli5").mouseover(function(event){
      $("#scrollobli5 .block").stop().animate({corner: '-12px'},{duration: 300});

    });
    $("#scrollobli5").mouseout(function(){
      $("#scrollobli5 .block").stop().animate({corner: '-1px'},{duration: 300});

    });


    $('.slidetitles').stop().animate({opacity: '0'},{duration: 300});

    $('.slidefoot').mouseover(function(){
        $('.slidetitles').stop().animate({opacity: '1'},{duration: 300});

        return false;
    });
    $('.slidefoot').mouseout(function(){
        $('.slidetitles').stop().animate({opacity: '0'},{duration: 300});
        return false;
    });


    });

(function($) {
  $(function() {
     $('.reload_link').click(function() {
            var data = {
                    action: 'get_post',
                    post_id: $(this).attr('wp:id')
            };

            that = this;
            type = $(this).attr('wp:type');

            jQuery.post(ajaxurl, data, function(response) {
                

                if(response == 0 || response == '') {
                    //console.log('Error');
                }
                
                if(type == 'articolo') {
                    $(that).next('div .target').html(response);
                    return;
                }

                $(that).next('div .target').html(response);

                height = 0;
                width = 0;

                images = $(that).next('div .target').find('img');
                $.each(images, function() {
                    if( $(this).height() > height){height = $(this).height();}
                    if( $(this).width() > width) {width = $(this).width();}
                });

                createThumbnails = false;
                
                if( $(images).size() > 1 ) {
                    createThumbnails = true;
                } else {
                
                $(".Opened #gbox").css('padding-bottom', '30px');

                }

                $(that).next('div .target').attr('height', height);
                $(that).next('div .target').attr('width', width);
                $(".galleria-stage").css('height', height);
                $(".galleria-stage").css('width', width);
				
				

                current_gallery = jQuery('#gallery-'+$(that).attr('wp:id'));
                
                true_height = height + 100;

// bind the method to Galleria.ready
Galleria.ready(function(options) {

if(options.thumbnails ) {
//    console.log($(this._target).attr('id'));
    id = '#' + $(this._target).attr('id');
//    console.log(parseInt($(id + ' .galleria-container').css('padding-bottom')));
//    padding = parseInt($(id + ' .galleria-container').css('padding-bottom').replace("px", "")) + 55;
//    console.log(padding);
//    //alert(padding);
//    $(id + ' .galleria-container').css('padding-bottom', padding);
//    console.log($(id + ' .galleria-container').css('padding-bottom'));

    // this = the gallery instance
    // options = the gallery options
    if (!$.browser.msie  || parseInt($.browser.version) > 8) {

        if( $(id + ' .galleria-stage').collision('.galleria-thumbnails-container').length > 0) {
            $(id + ' .galleria-container').css('padding-bottom', '200px');
            //console.log($(id + ' .galleria-container').css('padding-bottom'));
        }
    } else {
        $(id + ' .galleria-container').css('padding-bottom', '200px');
    }
}
});

                jQuery('#gallery-'+$(that).attr('wp:id')).galleria({
                        width: width,
                        height: height,
                        thumbnails: createThumbnails,
                        showInfo: false,
                        showCounter: false,
                        showImagenav:false,
                        imageCrop:'width',
                        imagePosition:'center center',
                        transition:'fade',
                        maxScaleRatio:1,
                        thumbCrop:false,
                    extend: function(options) {
                        this.bind('image', function(e) {
                            target = $(e.imageTarget);
                            height_container = $('.galleria-container', current_gallery).css('height');
                            $('.galleria-container', current_gallery).css('height', function(index, value){
                               return $(target).css('height');
                            });

                            fff = $('.galleria-images', current_gallery).find('.galleria-image')[1];
                            $(fff).css('height', $(target).css('height'));
                            
                            $(target).parent().tooltip({
                                track: true,
                                delay: 0,
                                showURL: false,
                                bodyHandler: function() {
                                    return $("<img style='width:34px; height:34px;'/>").attr("src", "wp-content/themes/birdsite/img/tooltip.png");
                                }
                            });
                            $(current_gallery).find('.galleria-stage').css('background-image','url()');;
                        });

                        this.bind('loadfinish', function(e) {
                            $target = $(e.imageTarget);
                            $($target).css('top', '5px');
                        });
                        this.bind('loadstart', function(e) {
                            $target = $(e.imageTarget);
                            $($target).css('top', '5px');
                        });

                        this.bind('thumbnail', function(e) {
//                            height = 156;
//                            width = 120;
//                            if ( $(e.thumbTarget).attr('width') >  $(e.thumbTarget).attr('height') ) {
//                                width = '120%';
//                            } else {
//                                width = '120%';
//                            }

                            $('.galleria-stage', e.target).css('width', '');
                            $('.galleria-thumbnails', e.target).css('height', '');
                        //$(".galleria-images").find("img").attr('title', 'open project');
                        //$(".galleria-images").find("img").attr('alt', 'open project');
                        //$(".galleria-images").find("img").attr('id', 'imgGbig');
                        });
							  
                    }
                });
            }).error(function(xhr, textStatus, errorThrown ) {
                      this.tryCount++;
                      if (this.tryCount <= this.retryLimit) {
                          $.ajax(this);
                          return;
                      }
					  		  
                      return;
            });
			
     });
 });
})(jQuery);

///////////////////////////////////////////////
////////////////  slide up end
///////////////////////////////////////////////
/////////	fade images
///////////////////////////////////////////////
// On window load. This waits until images have loaded which is essential
	$(window).load(function(){
							
							
$(".wrap .col1:first a").append("<div id='overlaybg'></div>");

//// fine function tutti i menu tranne il primo

		// Fade in images so there isn't a color "pop" document load and then on window load
		$("li .alink #thumb").fadeIn(1000);

		// clone image
		$('li .alink #thumb').each(function(i, k){
			if(i == 0) {
				$(this).addClass("exclude");
				return; 
			}
			var el = $(this);
			el.css({"position":"absolute"}).wrap("<div class='img_wrapper' style='display: inline-block'>").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"998","opacity":"0"}).insertBefore(el).queue(function(){
				var el = $(this);
				el.parent().css({"width":"156px","height":this.height});
				el.dequeue();
			});
			this.src = grayscale(this.src);
		});

		// Fade image
		$('li .alink #thumb').mouseenter(function(){
			if( $(this).hasClass("exclude") ) {
				return;	
			}	
			$(this).parent().find('img:first').stop().animate({opacity:1}, 750);
			
//			 $(this).parent().prepend('<div id="overdiv"><img src="wp-content/themes/birdsite/img/thumbover.png" width="156" height="156" border="0"  ></div>');
		})
		$('li .alink #overdiv').mouseenter(function(){
			$(this).parent().find('img:first').stop().animate({opacity:1}, 750);

		})
		$('li .alink').mouseleave(function(){
			$('.img_grayscale').stop().animate({opacity:0}, 500);
			$('#overdiv').remove();

		});

	});

	// Grayscale w canvas method
	function grayscale(src){
		var canvas = document.createElement('canvas');
		var ctx = canvas.getContext('2d');
		var imgObj = new Image();
		imgObj.src = src;
		canvas.width = imgObj.width;
		canvas.height = imgObj.height;
		ctx.drawImage(imgObj, 0, 0);
		var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
		for(var y = 0; y < imgPixels.height; y++){
			for(var x = 0; x < imgPixels.width; x++){
				var i = (y * 4) * imgPixels.width + x * 4;
				var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
				imgPixels.data[i] = avg;
				imgPixels.data[i + 1] = avg;
				imgPixels.data[i + 2] = avg;
			}
		}
		ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
		return canvas.toDataURL();
    }
	
	/// plugin
	
function ShowPDF(elementid, mypdf){
var el = document.getElementById(elementid);
   var content = '<embed src="' + mypdf + '#zoom=100" width="420" height="450">';
    if (document.getElementById && !document.all) {
        //firefox
        var rng = document.createRange();
        rng.setStartBefore(el);
        var htmlFrag = rng.createContextualFragment(content);
        while (el.hasChildNodes())
        el.removeChild(el.lastChild);
        el.appendChild(htmlFrag);
    } else {
        //explorer
        el.innerHTML = content;
    }
} 

/// plugin su mac
	
	
function ShowPDF(elementid, mypdf){
var el = document.getElementById(elementid);
   var content = '<embed src="' + mypdf + '#zoom=100" width="420" height="450">';
    if (document.getElementById && !document.all) {
        //firefox
        var rng = document.createRange();
        rng.setStartBefore(el);
        var htmlFrag = rng.createContextualFragment(content);
        while (el.hasChildNodes())
        el.removeChild(el.lastChild);
        el.appendChild(htmlFrag);
    } else {
        //explorer
        el.innerHTML = content;
    }
} 

$("document").ready(function() {

if($(".jcarousel-clip .galleria_wp li").length == 1)
{
   $("#primotitolo").hide();
   $(".galleria_thumb ").hide();
}		


$("#contenuto .post p span, #contenuto .post .iframecon span").prepend('<div ><a href="../index.php"><img src="../wp-content/themes/birdsite/img/close_.gif" alt="X"></a></div>');
// $("#contenuto .post .iframecon ").append('<div style="float:left; margin:30px; " ><a href="../index.php"><img src="../wp-content/themes/birdsite/img/close_.gif" alt="X"></a></div>');





});

// Set up a 30 Hz frame rate
frameRate    =  30;
timeInterval = Math.round( 1000 / frameRate );
relMouseX    = 0;
//relMouseY    = 0;

$(document).ready( function () {
  // get the stage offset
  offset = $('#stage').offset();

  // start calling animateFollower at the 'timeInterval' we calculated above
  atimer = setInterval( "animateFollower()", timeInterval );
} );

// track and save the position of the mouse
$(document).mousemove( function(e) {
  mouseX = e.pageX-120;
//  mouseY = e.pageY;
  relMouseX = mouseX - offset.left;
//  relMouseY = mouseY - offset.top;

  // display the current mouse positions
  $('#mouse_x-trace').text( mouseX );
//  $('#mouse_y-trace').text( mouseY );
} );

// move the image where the mouse is
// this function is called by the setInterval command above to run
// at a rate of 30 frames per second
function animateFollower() {
  $('#follower').css('left', relMouseX);
//  $('#follower').css('top', relMouseY);
}

$(function() {
    $('#follower').hover(function() { 
        $('#divTwo').show(); 
    }, function() { 
        $('#divTwo').hide(); 
    });
	$('#divTwo, #imgFOL').click(function() { 
        $('#page').hide(); 
    });
	
	
	
});




