var $j = jQuery.noConflict();

//doc ready
$j(document).ready(function() {
    //jquery goodness
	
	//OVERLAY
	$j('#shadowoverlay').css("opacity", 0);
	$j('#shadowoverlay').hide();
	
	$j('#shadowoverlay').click(function(e) {
		e.preventDefault();
		$j('#map .close').hide();
		
		//fade overlay & hide
         $j("#map .overlay").stop().animate({
            opacity: 0}, 500, function() {
            $j("#map .overlay").hide();
         });
         
         $j('#map .background-wrap').stop().delay(200).animate({
            opacity: 1}, 800, 'easeOutSine', function() {
         });
         
         $j('#map .markers a.marker').stop().delay(300).animate({
            opacity: 1 }, 800, function() {
                $j(this).removeClass('nomouse');
          });
          
          $j('#map .markers a.marker .fg-wrap').stop().animate({
            opacity: 1 }, 800, function() {
          });
          
          //fade and lock left links
         $j('.locations').stop().animate({
            opacity: 1}, 800, function() {
         });

         $j('.lock').hide();
		 
		 $j("#shadowoverlay").stop().animate({
            opacity: 0}, 500, function() {
            $j(this).hide();
         });
		
		$j(this).stop().animate({opacity: 0}, 300, function() {
			//hide
			$j(this).hide();
		});
	});
	
	//MAP
    $j('#map .background-wrap').css("opacity", 0);
    $j('#map .overlay').css("opacity", 0);
    $j('#map .markers div.marker-wrap').css("opacity", 0);
    $j('.b-logo').css("opacity", 0.4);
    $j('.b-left .afdeling').hide();
    $j('.b-left .afdeling').css("opacity", 0);
    
    $j('.b-left #euraqua').show();
    $j('.b-left #euraqua').css("opacity", 1);
    $j('.b-left .first').css("opacity", 1);
    $j('.b-left .first').addClass('active');
    
    //number1 text
    $j('#map .number-wrap').css("opacity", 0);
    $j('#map .number-wrap').stop().animate({
            opacity: 1}, 750, function() {
        });
    
    $j('#map .number-wrap').delay(500).animate({right: 0}, 400, 'easeOutSine');   
    $j('#map .number-wrap').animate({top: 0}, 400, 'easeOutSine');
               
    //map
    $j('#map .background-wrap').stop().delay(1500).animate({
            opacity: 1}, 1400, function() {
                //done -> fade markers
                $j('#map .markers div.marker-wrap').each(function(index){
                    $j(this).stop().delay(index * 100).animate({
                        opacity: 1}, 500, function() {
                    });
                });
                
                $j('.lock').hide();
        });
    
    //markers
    /*$j("#map .markers a.marker").hover(
      function () {
         if(!$j(this).hasClass('nomouse')){
             $j(this).find('.fg-wrap').stop().animate({
                opacity: 0 }, 200, function() {
              });
         }
      }, 
      function () {
          if(!$j(this).hasClass('nomouse')){
             $j(this).find('.fg-wrap').stop().animate({
                opacity: 1 }, 800, function() {
              });
          }
      }
    );*/
        
    $j("a.b-logo").hover(
      function () {
            var n = $j(this).attr('name');
            //fade other buttons
            $j('a.b-logo').each(function(index){
                if($j(this).attr('name') != n){
                    $j(this).stop().animate({
                        opacity: 0.4}, 500, function() {
                    });
                }else{
                   $j(this).stop().animate({
                    opacity: 1 }, 200, function() {
                  });
                }
            });
            
            //check if active, else show corresponding div
            if(!$j(this).hasClass('active')){
                //remove active item
                $j('.b-abs .active').removeClass('active');
                
                //add new active item
                $j(this).addClass('active');
                
                //fade all info divs
                $j('.b-rel .afdeling').stop().animate({
                     opacity: 0}, 500, function() {
                     $j(this).hide();
                });
                
                //show new info div
                var nId = '#' + $j(this).attr('name');
                $j(nId).show();
                $j(nId).stop().delay(400).animate({
                     opacity: 1}, 500, function() {
                });
            }
      }, 
      function () {
          if(!$j(this).hasClass('active')){
//
          }
      }
    );
        
    $j('#map .markers a.marker').click(function(e) {
        e.preventDefault();
        if(!$j(this).hasClass('nomouse')){
            var id = $j(this).parent().attr('id');

            //fade map
             $j('#map .background-wrap').stop().animate({
                opacity: 0.4}, 500, function() {
             });
             
             //fade and lock left links
             $j('.locations').stop().animate({
                opacity: 0.4}, 500, function() {
             });
             
             $j('.lock').show();
             
             $j('#map .markers a.marker').each(function(){
                 $j(this).addClass('nomouse');

                 if($j(this).attr('name')!= id){
                    $j(this).stop().stop().animate({
                        opacity: 0.4}, 500, function() {
                     });
                 }else{
                     $j(this).find('.fg-wrap').stop().animate({
                        opacity: 1 }, 800, function() {
                      });
                 }
             });
			 
			 //show shadowbox
			$j('#shadowoverlay').show();
			$j('#shadowoverlay').stop().animate({opacity: 0.5}, 300, function() {        
			});
			
			 //show correct overlay
			 var o = '#o-' + id;
			 $j('#map').find(o).show();
			 $j('#map .close').show();
			 $j('#map').find(o).animate({
				opacity: 1}, 800, function() {
			 });
        }
    }); 
    
     $j('#map .close').click(function(e) {
         e.preventDefault();
         $j(this).hide();
        //fade overlay & hide
         $j("#map .overlay").stop().animate({
            opacity: 0}, 500, function() {
            $j("#map .overlay").hide();
         });
         
         $j('#map .background-wrap').stop().delay(200).animate({
            opacity: 1}, 800, 'easeOutSine', function() {
         });
         
         $j('#map .markers a.marker').stop().delay(300).animate({
            opacity: 1 }, 800, function() {
                $j(this).removeClass('nomouse');
          });
          
          $j('#map .markers a.marker .fg-wrap').stop().animate({
            opacity: 1 }, 800, function() {
          });
          
          //fade and lock left links
         $j('.locations').stop().animate({
            opacity: 1}, 800, function() {
         });

         $j('.lock').hide();
		 
		 $j("#shadowoverlay").stop().animate({
            opacity: 0}, 500, function() {
            $j(this).hide();
         });
    }); 
    
    $j('.locations ul li a').click(function(e) {
         e.preventDefault();
         
         var id = $j(this).attr('id');

        //fade map
         $j('#map .background-wrap').stop().animate({
            opacity: 0.4}, 500, function() {
         });

         //fade and lock left links
         $j('.locations').stop().animate({
            opacity: 0.4}, 500, function() {
         });

         $j('.lock').show();

         $j('#map .markers a.marker').each(function(){
             $j(this).addClass('nomouse');

             var name = '-' + $j(this).attr('name');
             if(name!= id){
                $j(this).stop().stop().animate({
                    opacity: 0.4}, 500, function() {
                 });
             }else{
                 $j(this).find('.fg-wrap').stop().animate({
                    opacity: 1 }, 800, function() {
                  });
             }
         });
		 
		  //show shadowbox
			$j('#shadowoverlay').show();
			$j('#shadowoverlay').stop().animate({opacity: 0.5}, 300, function() {        
			});

         //show correct overlay
         var o = '#o' + id;
         $j('#map').find(o).show();
         $j('#map .close').show();
         $j('#map').find(o).animate({
            opacity: 1}, 800, function() {
         });
    }); 
});


