
$(document).ready(function() {
	
	$('.view-show-sitemap .views-row-first a').html('Home');
	
	
(function ($) {
// VERTICALLY ALIGN FUNCTION
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('margin-top', mh);
	});
};
})(jQuery);

	
	$('.field-field-text-one .field-item.odd').append($('#block-views-list_vacancies-block_1').html());
	$('#block-views-list_vacancies-block_1').html('');
	$('.galleryoverlay').hide();
	
    $("#scroll-content-id").load('/showgallery/9', function() {	});		  

	function rsz(){
		var scrollPane = $('#header');
	  	winWidth = scrollPane.width();
	  	divWidth = 1400;
	    var offs = parseInt((winWidth-divWidth)/2) + "px";
	    //alert(offs);
		$('#block-views-header_gallery-block_1').css('margin-left',offs);
		var oScrollbar = $('.scroll-pane');
        oScrollbar.tinyscrollbar();
        oScrollbar.update();
        oScrollbar.scrollup();
          $('.overview').css('left','0');
          $('.thumb').css('left','0');
          $('.galleryimage').vAlign(); 
           $('.closegallerybutton').css('left',(($('.galleryborder').width() /2) + ($('.galleryimage').width()/2) -20 ) + 'px');
      	   	$('.closegallerybutton').css('top',(($('.galleryborder').height() /2) - ($('.galleryimage').height()/2) -20) + 'px');
      	   		$('.leftarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
      	   	   	   	$('.rightarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
		    $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
	}
		window.onresize = rsz;
		window.onload = rsz;
	    $('.gardengallery').hide();
		$('#block-menu-primary-links li.leaf.last a').click(function(evt) {
			
		
			
			evt.preventDefault();
  		$('.gardengallery').slideToggle(function() { 	 $(window).resize();
  		$('.galleryoverlay').fadeOut();  		if (1==1) {
		          var countwidth = 0;
                  $('.scroll-pane .imagecache').each(function () {  countwidth += $(this).width() + 10 ; })
                  $('.scroll-content').css('width', countwidth);
                  $('.scroll-pane .overview').css('width', countwidth + 10);
                   
                		var oScrollbar = $('.scroll-pane');
oScrollbar.tinyscrollbar();

// Do some content changes....

oScrollbar.update();

oScrollbar.scrollup();
                     $('.overview').css('left','0');
          $('.thumb').css('left','0');
		}	});
	    $('#block-menu-primary-links li.leaf.last ').toggleClass('active-trail');
	    
		       
	});
	
	
	$('.gallerytitle').click(function(event) {
		
		
		
		  event.preventDefault();
		  $('.gallerytitleselected').removeClass('gallerytitleselected');
		  $(this).addClass('gallerytitleselected');
		 // alert('/' + $(this).attr('id').replace('-','/'));
		              $("#scroll-content-id").fadeOut(200).load('/' + $(this).attr('id').replace('-','/'), function() {
      $(this).fadeIn(300); 
                  var countwidth = 0;
              
                  $('.scroll-pane .imagecache').each(function () { countwidth += $(this).width() + 10 ; })
                  $('.scroll-content').css('width', countwidth);
                  $('.scroll-pane .overview').css('width', countwidth + 10 );
          $('.scroll-pane').tinyscrollbar();
          $('.overview').css('left','0');
          $('.thumb').css('left','0');
          
			});		  
					  
		  });
	$('.galleryloader').live('click', function(event) {
		  event.preventDefault();
		    var countimages = 0;
                  $('.scroll-pane .imagecache').each(function () { ;countimages += 1; })
                  
                  
          if ($('.track').width() != $('.thumb').width()) {
		  // Align the scroll bar to the image clicked
		  var bigincrement = ($('.overview').width() - $('.track').width() )/countimages;
		  var increment = ($('.track').width() - $('.thumb').width())/countimages;
		// var listItem = $('.scroll-content-item');

		 var leftpos =  ($('.scroll-content-item').index($(this).parent()) + 1) * increment;
	var bigleftpos =  ($('.scroll-content-item').index($(this).parent()) + 1) * bigincrement;
		  $('.thumb').animate({left:leftpos },1500);
	      $('.overview').animate({left:-bigleftpos },1500);
          }
  //  $('.node').addClass('grow');
   	  $('.field-field-text-one').animate({ 
        height: "100%"
      }, 1500 );
 
		  $('.galleryoverlay').html("<div class='galleryborder'><div class='leftarrow'>Prev</div><div class='closegallerybutton'></div><img class='galleryimage' src='" + $(this).attr('href') + "' style='margin:0px auto;' /><div class='rightarrow'>Next</div></div>" );
		
		 
		 	$('.leftarrow').hover(function () {
	
		$('.leftarrow').css('background','url("/images/fancylefthover.png") no-repeat scroll center center transparent');
		 $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		}, function () {
	$('.leftarrow').css('background','url("/images/fancyleft.png") no-repeat scroll center center transparent');
			 $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		});
		 
		 	 	$('.rightarrow').hover(function () {
	
		$('.rightarrow').css('background','url("/images/fancyrighthover.png") no-repeat scroll center center transparent');
		 $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		}, function () {
			$('.rightarrow').css('background','url("/images/fancyright.png") no-repeat scroll center center transparent');
			 $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		});
		
		
		 	$('.galleryimage').hover(function () {
	
		    $('.closegallerybutton').css('display','block');
		
		}, function () {
			 $('.closegallerybutton').css('display','none');
			
		});
		
		
		 	$('.closegallerybutton').hover(function () {
	
		    $('.closegallerybutton').css('display','block');
		
		}, function () {
			
			
		});
		
		
	
		 $('.closegallerybutton').live('click',function () {$('.galleryimage').click();});
		 
		 	$('.galleryimage').live('click',function () {
		  $('.galleryborder').fadeOut(function () {$('.galleryoverlay').slideUp(400); $('.node').removeClass('grow');});
		    $('.field-field-text-one').css('height','auto');
		}); 
		

		
		  $('.galleryborder').hide();
		  // Stop the jump
		  $('.galleryoverlay').slideDown(function () { $('.galleryimage').hide();  $('.leftarrow').hide(); $('.rightarrow').hide();  $('.closegallerybutton').hide(); $('.galleryborder').fadeIn(function () {  $('.galleryimage').show(); $('.galleryimage').vAlign(); 
		  
		     $('.closegallerybutton').css('left',(($('.galleryborder').width() /2) + ($('.galleryimage').width()/2) -20 ) + 'px');
      	   	$('.closegallerybutton').css('top',(($('.galleryborder').height() /2) - ($('.galleryimage').height()/2) -20) + 'px');
      	   	   	   	$('.leftarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
      	   	   	   	$('.rightarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
  $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		          $('.leftarrow').show(); $('.rightarrow').show(); 
		      });});
		  
		 
      	  $('html,body').animate({scrollTop: $("#block-menu-primary-links").offset().top},'slow');  

	
		  
	});
	     
   $('.leftarrow').live('click',function(evnt) {
      evnt.preventDefault();
      var getimageurl =  $('.galleryimage').attr('src');
      var nextimage = $(".galleryloader[href='" + getimageurl + "']").parent().prev().children().attr('href');
      if (nextimage === undefined) {nextimage = $(".galleryloader:last").attr('href');}
      $('.leftarrow').hide(); $('.rightarrow').hide();  $('.closegallerybutton').hide();
      $('.galleryimage').hide().attr('src',nextimage).delay(800).fadeIn(function () {
      	$('.galleryimage').vAlign();  
      		
        $('.closegallerybutton').css('left',(($('.galleryborder').width() /2) + ($('.galleryimage').width()/2) -20 ) + 'px');
      	   	$('.closegallerybutton').css('top',(($('.galleryborder').height() /2) - ($('.galleryimage').height()/2) -20) + 'px');
      		$('.leftarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
      	   	   	   	$('.rightarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
      	   	   	   	  $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		     $('.leftarrow').show(); $('.rightarrow').show(); 
      	});

    
     
      
	});
	
		
    $('.rightarrow').live('click',function(evnt) {
      evnt.preventDefault();
      var getimageurl =  $('.galleryimage').attr('src');  
      var nextimage = $(".galleryloader[href='" + getimageurl + "']").parent().next().children().attr('href'); 
      
      if (nextimage === undefined) {nextimage = $(".galleryloader:first").attr('href');}
      $('.leftarrow').hide(); $('.rightarrow').hide(); $('.closegallerybutton').hide();
      $('.galleryimage').hide().attr('src',nextimage).delay(800).fadeIn(function () {
      	$('.galleryimage').vAlign();  
      	
         $('.closegallerybutton').css('left',(($('.galleryborder').width() /2) + ($('.galleryimage').width()/2) -20 ) + 'px');
      	   	$('.closegallerybutton').css('top',(($('.galleryborder').height() /2) - ($('.galleryimage').height()/2) -20) + 'px');
      	   		$('.leftarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
      	   	   	   	$('.rightarrow').css('width',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) -30) + 'px');
      	   	   	   	  $('.leftarrow').css('background-position',(($('.galleryborder').width() /2) - ($('.galleryimage').width()/2) - 155 ) + 'px' + ' center' );
		     $('.rightarrow').css('background-position','25px center' );
		     	$('.leftarrow').show(); $('.rightarrow').show(); 
      	});
           
	});
	
		$('.gallnav a:first').addClass('gallerytitleselected');


$('.closebutton').click(function() {
	$('#block-menu-primary-links li.leaf.last a').click();
	});
	
	
$('#menu-overview-form').prepend('<a href="/wiki" style="font-size:14px; ">[ Back to Wiki ]</a>');

});


