
$(document).ready(function() {

 
 //PNGFix   x crappy ie6
 if (jQuery.browser.msie)
 {    
    if(parseInt(jQuery.browser.version) == 6) 
    {  
         $(document).pngFix(); 
         $('#boxEcard').css({ "background-image":"url(img/backgroundCARTOLINA.gif)", "background-position":"top center", "background-repeat":"no-repeat", 	"background-color": "transparent" });
      
    } 
  else {
          $('#boxEcard').css({ "background-image":"url(img/backgroundCARTOLINA.png)", "background-position":"top center", "background-repeat":"no-repeat", 	"background-color": "transparent" });
      }          
 }

 else {
          $('#boxEcard').css({ "background-image":"url(img/backgroundCARTOLINA.png)", "background-position":"top center", "background-repeat":"no-repeat", 	"background-color": "transparent" });
      } 
 
 
 

  

//paginazione pagina bambini
 	$("#pageB1").click(function(){ 		
          	  $('#page2').fadeOut('slow');
          	  $('#page3').fadeOut('slow');
              $('#page1').fadeIn('slow');
  });
  
 	$("#pageB2").click(function(){ 		
              $('#page1').fadeOut('slow');
          	  $('#page3').fadeOut('slow');
          	  $('#page2').fadeIn('slow');
  });
  
 	$("#pageB3").click(function(){ 		
              $('#page1').fadeOut('slow');
          	  $('#page2').fadeOut('slow');
          	  $('#page3').fadeIn('slow');
  });




























//cycle immagini in sogni 
    $('.colonnadx').cycle({
		fx: 'fade', 
    speed:  3500, 
    next:   '.colonnadx', 
    timeout: 1 
	});











 
 
 
    
    //Eventi scroll
    $('.EventiFade').innerfade({ speed: 'slow', timeout: 5000, type: 'sequence', containerheight: 'auto' });
 





  //CHANGE BACKGROUND
  //get querystring var
  function getParameterByName( name )
  {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
  }
  
   if     ( getParameterByName('mod') == 114 && getParameterByName('tp')== 2 ) {var background_img = 'arielBG.jpg'; } 
   else if( getParameterByName('mod') == 114 && getParameterByName('tp')== 10 ) {var background_img = 'backgroundSTORIA.jpg'; } 
   else   { var background_img = 'mainBg.jpg';}  $("#container").css('backgroundImage','url(img/' + background_img +')');
  
  








  //backToHome button
//   $("#backHome").hover(
//         function () {
//                   $(this).animate({left:"40px"}, 1000, "easeOutBounce"
//                     );
//         }, 
//         function () {
//                 $(this).animate({ left:"0px" }, 1000,"easeOutBounce" );
//         }
//       );
    
    
  //pngfix
    $(document).pngFix(); 


//fix IE7 z-index issues
// $(function() {
// 	var zIndexNumber = 1000;
// 	$('#works').each(function() {
// 		$(this).css('zIndex', zIndexNumber);
// 		zIndexNumber -= 10;
// 	});
// });

  //mod css x pag non slide
    var serverUri = "<?=$_SERVER['REQUEST_URI']; ?>" 
    if ( serverUri != 'index.php'  &&  serverUri != '/index.php' && serverUri != ''  && serverUri != '/' )  
      {  
      $('body').css({ "background-image":"url(img/bk.jpg)", "background-position":"top center", "background-repeat":"no-repeat", 	"background-color": "#000" });
      }
    else
      {   
        //fix for IE6   x pag slide 
        if (jQuery.browser.msie)
         {    
            if(parseInt(jQuery.browser.version) == 6) 
            {  
//               $('#footer').css({ position: "absolute", "bottom": "0px" });
                $('#FooterCenterBox').css({ "bottom": "-1px" });
                $('#contentGeneric').css({ "overflow": "visible" });
            }    
         }        
      }

        //fix for IE6   in tutte le pag 
        if (jQuery.browser.msie)
         {    
            if(parseInt(jQuery.browser.version) == 6) 
            {  
                $('#contentGeneric').css({ "overflow": "visible" });
            }    
         }  


	
  //get the width of the element
  	 widthSingleElement   = $(".singleTab").width();
     paddingSingleElement = parseInt($(".singleTab").css("padding-right"));
  	 numberOfElement      = $("#slide").children().size();
  	 SlideTotalWidth      = numberOfElement*(widthSingleElement+paddingSingleElement); 
  	 $("#contentSlide").css({ width:SlideTotalWidth });  //iniect it!
  	  $("#slide").css({ width:SlideTotalWidth });  //iniect it!
  	 
  	//  $('#footer').css( 'left', SlideTotalWidth );
  	


 
 //AJAX GALLERY
//  	$(".pageGallery").hover(function(){ 
// 
//  	$(this).toggleClass("pageGalleryHover");
// },
//   function () {
//     $(this).removeClass("pageGalleryHover");
//   }
// );	
 
//  	$(".pageGallery").click(function(){ 		
// 	//$(this).toggleClass("active");
// 	
// 		//new ref da passare nella func e gen loader..
// 		var idPage = $(this).attr("idPage");
// 		var elem_sel = $("#usersGallery");
// 		//elem_sel.append('<div id="waitingblock"><img src="img/ajax-loader-gal.gif" /></div>'); 
// 		//ajax call
// 		$.ajax({
//       type: "POST",
//       url: "moduli/modulo_regusers_1/elementsGal.php",
//       data: "idPage="+ idPage ,
//       success: function(html){
// 
//            $('#usersGallery').fadeOut(200, function () {
//               elem_sel.replaceWith(html); 	
//               //ripeto il TOOLTIP per i nuovi elementi
//               $('.user a[title]').qtip({ style: { name: 'dark', tip: true },  position: { corner: {target: 'topMiddle', tooltip: 'bottomLeft' }}   });
// 
//            
//            });
//            
//        }
//   });	
// 
// });	
	
 
 //TOOLTIP
$('.users a[alt]').qtip({ style: { name: 'dark', tip: true },  position: { corner: {target: 'topMiddle', tooltip: 'bottomLeft' }}   });

//TOOLTIP HOME
$('.userHome img[title]').qtip({ style: { name: 'dark', tip: true },  position: { corner: {target: 'topMiddle', tooltip: 'bottomLeft' }}   });

//SLIDER x gallery pagination
	
	var pages = $('#paginator').attr("pages");
	var sliderWidth = 100 + (pages*2);
	  $('#pagSlider').animate({width: sliderWidth});
	
	         $('#pagSlider').slider({
	                 handle: '#slider-handle',
	                 min: 1,
	                 max: pages,
	                 start: function(e,ui){
	                         $('#slider-bubble').fadeIn('fast');
	                         $('#usersGallery').animate({opacity: .5}, 200);

	                 },
	                 stop: function(e,ui){

                   



                 $("#amount").html(ui.value);
                 var valuePage = ui.value;
	                 



		var elem_sel = $("#usersGallery");
		//elem_sel.append('<div id="waitingblock"><img src="img/ajax-loader-gal.gif" /></div>'); 
		//ajax call
		

$('#pagSlider').fadeIn(5000, function(){ 

		$.ajax({
      type: "POST",
      url: "moduli/modulo_regusers_1/elementsGal.php",
      data: "idPage="+ valuePage ,
      success: function(html){

              elem_sel.replaceWith(html); 	
              //ripeto il TOOLTIP per i nuovi elementi
              $('.user a[title]').qtip({ style: { name: 'dark', tip: true },  position: { corner: {target: 'topMiddle', tooltip: 'bottomLeft' }}   });
           
       }
  });	

});





	                 },
	                 slide: function(e,ui){
	
  
  
	                 }
	                 
	         });




 
      //***Slideshow

$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
};

$(document).ready(function () {
  $('.infiniteCarousel').infiniteCarousel();
});



  	

 });
