var firstlaunch=true;
var firstTime=true;
var faded=false;
var gallerymenuOut=false;
var galleryPaused=true;
var maingalleryPaused=false;
var fullscreenscroll="not-yet"; // conterrą setinterval globale

var totalwidth=$(window).width();


// TEST alert(currentpagevar);


$(document).ready(function() {

    if(!$.browser.msie) {
    
        $(".header_navigation_button_hover_2").css({opacity:0});
        $(".header_navigation_button_hover_3").css({opacity:0});
        $(".header_navigation_button_hover_4").css({opacity:0});
        $(".header_navigation_button_hover_5").css({opacity:0});
        $(".header_navigation_button_hover_6").css({opacity:0}); 
        $(".header_navigation_button_hover_7").css({opacity:0});
        $(".header_navigation_button_hover_8").css({opacity:0});
        
        $("#next").css({opacity:0}); $("#prev").css({opacity:0});
    
    }  else if($.browser.msie) {
        
        
        $(".header_navigation_button_hover_2").css({"display":"none"});
        $(".header_navigation_button_hover_3").css({"display":"none"});
        $(".header_navigation_button_hover_4").css({"display":"none"});
        $(".header_navigation_button_hover_5").css({"display":"none"});
        $(".header_navigation_button_hover_6").css({"display":"none"});
        $(".header_navigation_button_hover_7").css({"display":"none"});
        $(".header_navigation_button_hover_8").css({"display":"none"});
        
        $("#next").css({"display":"none"}); $("#prev").css({"display":"none"});
        
    }
    
    
      
    
    
 function f_out() {
    
    
        if($.browser.msie) {
    	   
           $(this).find("div").css({"display": "none"});
        
        } else if(!$.browser.msie){
            
       	    $(this).find("div").animate({opacity: 0.0},300);
        }
 }
 
  function f_in() {
    
    
        if($.browser.msie) {
    	   
           $(this).find("div").css({"display": "block"});
        
        } else if(!$.browser.msie){
            
           $(this).find("div").animate({opacity: 1.0},300); 
        }
 }
 
 
 function f_in_gal(){
    
        if($.browser.msie) {
    	   
           $(this).find("#next").css({"display": "block"});
           $(this).find("#prev").css({"display": "block"});
           $("#desc_conteiner").animate({top: "+=80"},301); 
        
        } else if(!$.browser.msie){
            
        
           $(this).find("#next").animate({opacity: 1.0},300); 
           $(this).find("#prev").animate({opacity: 1.0},300); 
           $(this).find("#desc_conteiner").animate({top: "+=80"},301); 
        }
    
 }
 
 
 function f_out_gal(){
    
        if($.browser.msie) {
    	   
           $(this).find("#next").css({"display": "none"});
           $(this).find("#prev").css({"display": "none"});
           $("#desc_conteiner").animate({top: "-=80"},301); 
        
        } else if(!$.browser.msie){
            
        
           $(this).find("#next").animate({opacity: 0.0},300); 
           $(this).find("#prev").animate({opacity: 0.0},300);
           $(this).find("#desc_conteiner").animate({top: "-=80"},301); 
        }
    
 } 
 
function onBefore() { 
    
    $('#preventer').css({"display": "block"});
    
    $('#gallery-image-description').animate({left: "+=265"},400); 
            $('#gallery-image-title').animate({left: "+=420"},400, function(){
                
                
                if(firstTime==false){
                    $('#gallery-image-description').html(" "); 
                    $('#gallery-image-title').html(" ");
                    
                } else {
                    
                    firstTime=false;
                    
                }
            }); 
            
     
  
}

function onAfter() { 

        
           

        $('#gallery-image-description').append('<div class="gallery-image-description-text">'+this.title+'</div>'); 
        $('#gallery-image-title').append('<div class="gallery-image-title-text">'+this.alt+'</div>');

        
            $('#gallery-image-description').animate({left: "-=265"},501); 
            $('#gallery-image-title').animate({left: "-=420"},501); 
            
            $('#preventer').css({"display": "none"});
            
                               
} 
 
$("#menu_2").hoverIntent( f_in, f_out);
$("#menu_3").hoverIntent( f_in, f_out);
$("#menu_4").hoverIntent( f_in, f_out);
$("#menu_5").hoverIntent( f_in, f_out);
$("#menu_6").hoverIntent( f_in, f_out);
$("#menu_7").hoverIntent( f_in, f_out);
$("#menu_8").hoverIntent( f_in, f_out);        

$("#menu_"+currentpagevar).find("div").css({"display":"block"});
$("#menu_"+currentpagevar).find("div").css({opacity:1.0});


$("#content-gallery").hoverIntent( f_in_gal, f_out_gal);       
       
    $('#header-gallery-conteiner').cycle({ 
             before : blockgalleries,
             fx:'fade', 
              speed:  801,
              //pager: "#homeslide_pager",
             timeout: 5000,
              requeueOnImageNotLoaded: true
              
         });  

        
function initMinigallery(whichone, pagerdiv){
      
        $(whichone).cycle({ 
            fx:     'scrollLeft', 
            speed:   700, 
            timeout: 4500, 
            pager:  pagerdiv,
            requeueOnImageNotLoaded: true,
            before: onBefore,
            after:  onAfter,
            next:   '#next', 
            prev:   '#prev' 
        }).cycle('pause');
    
}

        ////////////////////begin
      initMinigallery("#gallery-photos", "#gallery-navigation");


        //////////////////////// PNG FIX




});







function play(){
               
            
            
            $('#header-gallery-conteiner').cycle('pause');
                
            
            if(galleryPaused==true){    

                
                $('#gallery-button-play').html('stop slideshow');
                
                $('#gallery-button-play').removeClass().addClass('gallery-button-pause');
                
                $('#gallery-photos').cycle('resume');
                galleryPaused=false;
                
            } else { 
                
               
                $('#gallery-button-play').html('avvia slideshow');
               
                $('#gallery-button-play').removeClass().addClass('gallery-button-play');
                
                $('#gallery-photos').cycle('pause');
                galleryPaused=true;
               
            
            }
}

function change_mini_gallery(minigalleryID,sectionID){
    
                        
            
            if(!galleryPaused){ 
                play();
            }
    
    $('#gallery-photos').cycle('destroy');
    //$('#gallery-image-description').html(" ");
    $('#gallery-other-menu').slideUp('fast');

    gallerymenuOut=false;
    
    
    function fillgallerylayer(html){
        

        $('#content-gallery').slideUp(1000, function(){

            
           // $('#gallery-navigation').html(' ');
            $('#gallery-photos').html(' ');
            $('#gallery-photos').html(html);
        
        });
        $('#content-gallery').slideDown(1000);
        
    }
    

    $.ajax({
		type: "GET",
        cache: false, 
		url: "/addmeingallery_mini_changer.php?sectionID="+sectionID+"&mode=change_photos&id="+minigalleryID,
		dataType: "html",
		success:fillgallerylayer
	
	});
  
    
}


function galleryShowmenu(whichone) {
    
    if(gallerymenuOut==false){
        
        gallerymenuOut=true;
        $(whichone).slideDown(300);

    
    } else {
        
        gallerymenuOut=false;
        $(whichone).slideUp(300);                
    }
    
}


function blockgalleries (){
    
    $('#gallery-photos').cycle('pause');  
    
}
/*
 function f_out() {
    
    	$(this).find("img").animate({opacity: 0.0},300);
    
 }
 
  function f_in() {
    
    	$(this).find("img").animate({opacity: 1.0},300);
    
 }
*/


//$(function(){

                    

    //$('#gallery-photos').cycle('pause');
       
    
// $(".menu_button").hoverIntent( f_out, f_in )
                                                                
//});

function stopshow(){
    
     $('#gallery-photos').cycle('pause');
    
}

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FULLSCREEN GALLERY FUNCTION */
var maxGALLERYcurrentID="4";  // galleria attuale

var maxIMGcurrentID="notyet";
var maxIMGcurrentURL="notyet";
var maxIMGcurrentTITLE="notyet";
var maxIMGcurrentDESC="notyet";
var fullscreenGalleryOUT=false;


function viewFullscreenGallery_overlay(){  // FIRST MAXGALLERY LAUNCH - GIOVANNIDEMA@GMAIL.COM
    
    if(fullscreenGalleryOUT==false){
    
    fullscreenGalleryOUT=true;
    
    var whichgallery=maxGALLERYcurrentID;
    
    $('html, body').animate({scrollTop:0}, 'slow', function(){
        
       $('#header-gallery-conteiner').cycle('pause');
       
       
           if($.browser.msie){
  
                 $('html').css({'overflow':'hidden'});
 
             }else{
 
                 $('body').css({'overflow':'hidden'});
                 $('html').css({'overflow':'hidden'});
    
             }
        
       $('.supershadow').animate({width: totalwidth+"px"}, 700, function(){
        
            activatefullscreen();
            $('#holder').show();
            $('#fullscreen-controls').show();
            // // $('#MAXpreloader').show();
        
       });     
            
            function fullscreengallery(html){
                
                                   
               // $('#wallpaper').attr("src", maximgURL);
                $('#holder').append("<div>"+html+"</div>");
            
                shadowout(fullscreenGalleryOUT);
            }
            
            $.ajax({
				type: "GET",
                cache: false, 
				url: "addmeingallery_maxi_changer.php?id="+whichgallery+"&currentIMG="+maxIMGcurrentID,
				dataType: "html",
				success:fullscreengallery
			
			});
            
           
        
    });
    
    } // if gallery firstlaunch end
    
}


function shadowout(somevars){

			
			 $('.supershadow').animate({left: totalwidth}, 500, function (){
				

                    	if(somevars=="chiudi"){        
                        
                        if($.browser.msie){
                      
                        $('html').css({'overflow':'auto'});
                     
                       }else{
                     
                        $('body').css({'overflow':'visible'});
                        $('html').css({'overflow':'visible'});
                     
                       }
                         } 




				$('.supershadow').css({"width": "0.01px", "left":"0px"});

    	
			});
            
            				    
                    

            
      
            
            
			//$('#supersize').slideDown("1000");
}



function firstmaximage(var_id,var_url,descriptionz){
    
    
    maxIMGcurrentID=var_id;
    maxIMGcurrentURL=var_url;
    maxIMGcurrentDESC=descriptionz;
    
    /* TEST  alert(maxIMGcurrentID);*/
    /* TEST  alert(maxIMGcurrentURL);*/
    /* TEST alert(maxIMGcurrentDESC);*/           
                    
    $('#desc_text').html(maxIMGcurrentDESC);

    $('#wallpaper').attr('src', maxIMGcurrentURL).load(function(){
        $('#MAXpreloader').fadeOut("slow");
    });
        

}

    


function maxIMGprevnext(prevornext){
    
    
   /* TEST alert(prevornext) */
            
       
  
            function changemaxIMG(html){
                
                $('#holder').append("<div>"+html+"</div>"); 

            }
            
          
        $('#MAXpreloader').fadeIn(700, function(){ 
            
            $.ajax({
				type: "GET",
				url: "addmeingallery_maxi_changer.php?currentid="+maxGALLERYcurrentID+"&currentIMGchange="+maxIMGcurrentID+"&mode="+prevornext,
				dataType: "html",
				success:changemaxIMG
			
			}); 
            
       });      
    
  
}



function maxCLOSE(){
    
    
$('.supershadow').animate({width: totalwidth+"px"}, 700, function(){   
        
    $('#holder').hide();
    $('#fullscreen-controls').hide();
    $('#MAXpreloader').hide();
    fullscreenGalleryOUT=false;


    
});



    shadowout("chiudi");


}



/*<div class="clearer"></div>  


<div id="divtest" onclick="$('#body').style{'overflow':'hidden'}" style="clear: both ! important; display: block;">test</div>*/
