var galleryvisible = '';
$('#lebody').css('background-position', '0px 0px');


$(document).ready(function() {
  
  //  Global functions   ================================== 
  

   (function($) {
	  var cache = [];
	  // Arguments are image paths relative to the current page.
	  $.preLoadImages = function() {
	    var args_len = arguments.length;
	    for (var i = args_len; i--;) {
	      var cacheImage = document.createElement('img');
	      cacheImage.src = arguments[i];
	      cache.push(cacheImage);
	    }
	  }
	})(jQuery)  
  
  function toggleMenu(){
		if ($('#menu').css('top') == '-375px') {
  	      $('#menu').animate({ 
            top: '50px'
            }, 200, 'linear', function() {});
  		} else { 
          $('#menu').animate({ 
            top: '-375px'
            }, 200, 'linear', function() {});
  		}
  }
  
    function showGallery(gallery) {
	    galleryvisible = '#container' + gallery;
	    url = 'pages/slide' + gallery + '.php';
	    $('#backen').fadeOut(200, function() {});
//	    $('#copyright').fadeOut(200, function() {});
	    $('#wallcontent').fadeOut(200, function() {
 	      $('#wallcontent').css('display', 'none');
	      $('#lebody').animate({
              backgroundPosition: '-50px 0px'
            }, 400, 'linear', function() {
	            $('.imagecontainer').css('display', 'none');
    	        $(galleryvisible).css('visibility', 'visible');
        	    $(galleryvisible).css('display', 'block');
		 	 	$('#megawrapper2000').load(url, function() {
					$(galleryvisible).css('visibility', 'hidden');
					$(galleryvisible).css('display', 'block');		
					 simpleSlide({
						 'swipe': 'true',
						 'set_speed': 300,				 
						 'callback': function() {
						}
					 }); 		 	 	
					$(galleryvisible).css('display', 'none');					 
					$(galleryvisible).css('visibility', 'visible');
			 	 	$(galleryvisible).fadeIn(200, function() {});
			 	 	$('.knappar').fadeIn(200, function() {});
		 	 	});
        	    
            }); 
         });    
    }    


  //  Event listeners for menu commands   ================================== 
  
  
    $('#menuend').click(function() {
      toggleMenu();
        // Animation complete.
    });
    
    $('#navworks').click(function() {
    	if (galleryvisible != '') {
    	// RENSA AKTUELL SIDA    	
	        toggleMenu();      
	        $(galleryvisible).css('visibility', 'hidden');
			$('#wallcontent').slideDown(200, function() {});
		      $('#lebody').animate({
	              backgroundPosition: '0px 0px'
	            }, 400, 'linear', function() {});
		    $('#backen').fadeIn(200, function() {});
		    $('#copyright').fadeIn(200, function() {});
        // If run for first time (IE when page loads)
    	} else {
			$('#wallcontent').slideDown(200, function() {});
	        toggleMenu();
	    }
    });



  //  Event listeners for galleries   ================================== 

    
    $('#gallery1').click(function() {
        showGallery('1');
    });
    $('#gallery2').click(function() {
        showGallery('2');
    });
    $('#gallery3').click(function() {
        showGallery('3');
    });
    $('#gallery4').click(function() {
        showGallery('4');
    });
    $('#gallery5').click(function() {
        showGallery('5');
    });
    $('#gallery6').click(function() {
        showGallery('6');
    });


    $('#navtexts').click(function() {
        toggleMenu();    
        showGallery('texts');
    });
    $('#navportfolio').click(function() {
        toggleMenu();    
        showGallery('portfolio');
    });
    $('#navcontact').click(function() {
        toggleMenu();    
        showGallery('contact');
    });
        
      
	$('.imagecontainer').live('mouseover mouseout', 
		function(event) {
			if(event.type == 'mouseover'){
				$('.left-button, .right-button').stop(true, true).fadeIn();
			}
			else {
				$('.left-button, .right-button').stop(true, true).fadeOut();
			}
		}
	);    
    
   //  Slideshow setup   ================================== 

      
    simpleSlide({
	    'set_speed': 300,
	    'status_width': 20,
	    'status_color_outside': '#aaa',
	    'status_color_inside': '#fff',
	    'fullscreen': 'false',
	    'swipe': 'true',
	    'callback': function() {
    	}
		});
 	

    
  //  Slask, rensa?   ================================== 
    


jQuery.preLoadImages("photos/nav1-on.jpg", "photos/nav2-on.jpg", "photos/nav3-on.jpg", "img/portfoliobg.jpg", "img/portshadow.png", "img/left-arrow.png", "img/right-arrow.png");


  }); 
  
  

