$(document).ready(function(){ 
  if ($("#google_map").length>0) {
    initialize();
  }

  $('.pressList').accordion({ header: 'h3' , autoHeight: false });
  $("#banner li").hover(function() { //On hover...

    var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

    //Set a background image(thumbOver) on the &lt;a&gt; tag 
    $(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
    //Animate the image to 0 opacity (fade it out)
    $(this).find("span").stop().animate({opacity: 0}, 300);
    } , function() { //on hover out...
      //Animate the image back to 100% opacity (fade it back in)
      $(this).find("span").stop().animate({opacity: 1}, 300);
    });
    
    $("#banner li.vertical").hover(function() { //On hover...

      var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

      //Set a background image(thumbOver) on the &lt;a&gt; tag 
      $(this).find("a.thumbVertical").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
      //Animate the image to 0 opacity (fade it out)
      $(this).find("span").stop().animate({opacity: 0}, 300);
      } , function() { //on hover out...
        //Animate the image back to 100% opacity (fade it back in)
        $(this).find("span").stop().animate({opacity: 1}, 300);
      });
    // function uno() { 
      //    $("#topics.article").toggle() ;
      //    $("#main.section").css('borderTop', '3px solid #2d0b01');  
      //    $("a.forTopics").addClass('selectedForTopics'); 
      //    $("a.forStore").removeClass('selected'); 
      //    $("a.forElearning").removeClass('selected');  
      //  }
      // 
      //  function due() { 
        //    $("#elearning.article").toggle() ;
        //    $("#main.section").css('borderTop', '3px solid #444');  
        //    $("a.forTopics").removeClass('selectedForTopics'); 
        //    $("a.forStore").removeClass('selected'); 
        //    $("a.forElearning").removeClass('selected');
        //    $("#topics.article").toggle() ;
        //    
        //  }
        // 
        //  function tre() { 
          //    $("#store.article").animate({height: "290px"}, {queue: false, duration: 700, easing: 'swing'});
          //    $("#elearning.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});
          //    $("#topics.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});
          //    $("#main.section").css('borderTop', '3px solid #282828');  
          //    $("a.forStore").addClass('selected');
          //    $("a.forTopics").removeClass('selectedForTopics'); 
          //    $("a.forElearning").removeClass('selected');
          //  }
          //  function quattro() { 
            //    $("#store.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});
            //    $("#elearning.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});
            //    $("#topics.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});        
            //    $("#main.section").css('borderTop', '3px solid #444');  
            //    $("a.forStore").removeClass('selected');
            //    $("a.forTopics").removeClass('selectedForTopics'); 
            //    $("a.forElearning").removeClass('selected');
            //  }
            //  function cinque() { 
              //    $("#elearning.article").animate({height: "290px"}, {queue: false, duration: 700, easing: 'swing'});
              //    $("#topics.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});
              //    $("#store.article").animate({height: "0"}, {queue: false, duration: 700, easing: 'swing'});
              //    $("#main.section").css('borderTop', '3px solid #282828'); 
              //    $("a.forElearning").addClass('selected');  
              //    $("a.forStore").removeClass('selected');
              //    $("a.forTopics").removeClass('selectedForTopics');       
              //  }
              //  function sei() { 
                // $("#elearning.article").animate({height: "320px"}, {queue: false, duration: 700, easing: 'swing'});
                //     $("#topics.article").animate({height: "320px"}, {queue: false, duration: 700, easing: 'swing'});
                //    $("#store.article").animate({height: "320px"}, {queue: false, duration: 700, easing: 'swing'});
                //    $("#main.section").css('borderTop', '3px solid #444'); 
                // }

                $("#store.article").hide();
                $("#topics.article").hide();
                $("#elearning.article").hide();
                $("#moreInfoSlide").css('position', 'static');
                $("a.forElearning").live("click", function() { 
                  if($('a.forTopics').hasClass('selectedForTopics') || $('a.forStore').hasClass('selected')) {
                  } else if($("a.forElearning").hasClass('selected')) {
                    $("a.forElearning").removeClass('selected');
                    $("#elearning.article").slideUp("slow");
                    $("#main.section").css('borderTop', '3px solid #444');
                    $("a.forTopics").fadeTo("slow", 1);
                    $("a.forStore").fadeTo("slow", 1);
                  }  
                  else {
                    $("#elearning.article").slideDown("slow");
                    $("#main.section").css('borderTop', '3px solid #282828'); 
                    $("a.forElearning").addClass('selected');  
                    $("a.forStore").removeClass('selected');
                    $("a.forTopics").removeClass('selectedForTopics'); 
                    $("a.forTopics").fadeTo("slow", 0.4);
                    $("a.forStore").fadeTo("slow", 0.4);
                  }    
               
                  });
                  $("a.forTopics").live("click", function() { 
                     if($('a.forElearning').hasClass('selected') || $('a.forStore').hasClass('selected')) {
                      } else if($('a.forTopics').hasClass('selectedForTopics')) {
                        $("a.forTopics").removeClass('selectedForTopics');
                        $("#topics.article").slideUp('slow');
                        $("#main.section").css('borderTop', '3px solid #444'); 
                        $("a.forElearning").fadeTo("slow", 1);
                        $("a.forStore").fadeTo("slow", 1);
                    }    
                    else {
                  $("#topics.article").slideDown("slow");
                  $("#main.section").css('borderTop', '3px solid #2d0b01'); 
                  $("a.forElearning").removeClass('selected');  
                  $("a.forStore").removeClass('selected');
                  $("a.forTopics").addClass('selectedForTopics');   
                  $("a.forElearning").fadeTo("slow", 0.4);
                  $("a.forStore").fadeTo("slow", 0.4);
                  }
                  
                    });

                    $("a.forStore").live("click", function() {
                      if($('a.forTopics').hasClass('selectedForTopics') || $('a.forElearning').hasClass('selected')) {
                      } 
                      else if($('a.forStore').hasClass('selected')) {
                         $("#store.article").slideUp("slow");
                          $("a.forStore").removeClass('selected');
                          $("#main.section").css('borderTop', '3px solid #444');   
                          $("a.forTopics").fadeTo("slow", 1);
                          $("a.forElearning").fadeTo("slow", 1);   
                      }
                      else {
                        $("#store.article").slideDown("slow");
                        $("#main.section").css('borderTop', '3px solid #282828'); 
                        $("a.forElearning").removeClass('selected');  
                        $("a.forStore").addClass('selected');
                        $("a.forTopics").removeClass('selectedForTopics');     
                        $("a.forTopics").fadeTo("slow", 0.4);
                        $("a.forElearning").fadeTo("slow", 0.4);  
                      }
                    
                    
                      });

                      $(".close a").click(function() { 
                        $("#store.article").slideUp("slow");
                        $("#elearning.article").slideUp("slow");
                        $("#topics.article").slideUp("slow");			
                        $("#main.section").css('borderTop', '3px solid #444');
                        $("a.forTopics").removeClass('selectedForTopics'); 
                        $("a.forStore").removeClass('selected');
                        $("a.forElearning").removeClass('selected'); 
                        $("a.forTopics").fadeTo("slow", 1);
                        $("a.forStore").fadeTo("slow", 1); 
                        $("a.forElearning").fadeTo("slow", 1);                      
                      });

                      function onAfter() { 
                        /*$('.linkTo').html("") .append('<a href="index.php?m=progetti">' + this.alt + '</a>'); */
                        $('.linkTo').html("") .append(this.alt); 
                      }
                      $('#slideShow') 
                      .before('<div id="nav">') 
                      .cycle({ 
                        fx:     'scrollRight', 
                        speed:  'slow', 
                        after:   onAfter,
                        timeout: 6000, 
                        pager:  '#nav' 
                      });
                      $('.forTabs .tabStarter').tabs();
                      $('a[rel*=facebox]').facebox({
                        //next_image    : 'img/icon/next.gif',
                        //play_image    : 'http://famspam.com/images/icons/small/fast_forward.png',
                        //pause_image   : 'http://famspam.com/images/icons/small/fast_forward.png',
                        //prev_image    : 'img/icon/prev.gif'

                      });

                      $("#primary.nav li").hover(
                        function () {
                          $(this).addClass("hover");
                        }, 
                        function () {
                          $(this).removeClass("hover");
                        }
                      );

                      // customizzazione del validate
                      $('#contributor').validate({
                        errorPlacement: function(error, element) {
                          error.appendTo( element.parents('p').addClass('error') );
                        },
                        highlight: function( element, errorClass ) {
                          $( element ).addClass( errorClass ).parents('p').removeClass('success').addClass('error');
                        },
                        unhighlight: function( element, errorClass ) {
                          $( element ).removeClass( errorClass ).parents('p').removeClass('error').addClass('success');
                        }
                      });
											$('.galleria').addClass('gallery_demo'); // adds new class name to maintain degradability

											
											$('ul.gallery_demo').galleria({
												history   : true, // activates the history object for bookmarking, back-button etc.
												clickNext : true, // helper for making the image clickable
												insert    : '.galleriaContainer', // the containing selector for our main image
												onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

													// fade in the image & caption
													if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
														image.css('display','none').fadeIn(1000);
													}
													caption.css('display','none').fadeIn(1000);

													// fetch the thumbnail container
													var _li = thumb.parents('li');

													// fade out inactive thumbnail
													_li.siblings().children('img.selected').fadeTo(500,0.5);

													// fade in active thumbnail
													thumb.fadeTo('fast',1).addClass('selected');

													// add a title for the clickable image
													image.attr('title','Next image >>');
												},
												onThumb : function(thumb) { // thumbnail effects goes here

													// fetch the thumbnail container
													var _li = thumb.parents('li');

													// if thumbnail is active, fade all the way.
													var _fadeTo = _li.is('.active') ? '1' : '0.5';

													// fade in the thumbnail when finnished loading
													thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

													// hover effects
													thumb.hover(
														function() { thumb.fadeTo('fast',1); },
														function() { _li.not('.active').children('img').fadeTo('fast',0.5); } // don't fade out if the parent is active
													)
												}
											});
											


                    }); 


                    $(".addToCart a").click(function(){ $(function dosubmit() {
                      $(".qta-versioni").submit();

                    });

                  });


                  window.onload=intercetta;
                  function intercetta() {
                    for (var i=0; i<document.links.length; i++)
                    if(document.links[i].rel=="blank"){
                      document.links[i].target="_blank";
                    }
                  }