// JavaScript Document


		h.init('portfolio');
		var initial = true;
		var gall = new Gallery.Core('img', {
			url : 'galleries/galleries.xml',
			datatype : 'xml',
			transition : ['wipeLeftFade', 'fadeOutThenIn'],
			holdingSlide : false
		});
		$('text-screen').set('tween', {link:'cancel'});
		
		var c = new Gallery.Components.CaptionBar( gall, 'text-screen', {
		  useHTML:true,
		  showCaption: function(el){
			  el.set('tween', {duration:1500});
			  if(el.get('html') != '') el.tween('left', 0);
		  },
		  hideCaption: function(el){
			  if( this.gallery.currentIndex != ( 0 || 1 ) ){
				  el.tween('left', -500);
			  }
		  }
		});
		
		var p = new Gallery.Components.Preloader( gall, {
			onStart: function(gallName, number){
				$('preloader').setStyle('display', 'block');
				$('preloader').set('tween', {link:'cancel'});
			},
			onTick: function(obj){
				$('preloader-bar').tween('width', obj.loaded.percentage);
			},
			onFinish: function(){
				$('preloader').tween('opacity', 0);
			}
		});
		
		var s = new Gallery.Components.Slideshow( gall, 6000 );
		
		$('left-arrow').setOpacity(0);
		$('right-arrow').setOpacity(0);
		
		$('left-arrow').addEvent('mouseover', function(){
			this.setStyle('background-image', this.getStyle('background-image').replace('.png', '_on.png') );
		});
		$('left-arrow').addEvent('mouseout', function(){
			this.setStyle('background-image', this.getStyle('background-image').replace('_on', '') );
		});
		$('right-arrow').addEvent('mouseover', function(){
			this.setStyle('background-image', this.getStyle('background-image').replace('.png', '_on.png') );
		});
		$('right-arrow').addEvent('mouseout', function(){
			this.setStyle('background-image', this.getStyle('background-image').replace('_on', '') );
		});
		
		$('img').addEvent('mouseenter', function(){
			$('left-arrow').tween('opacity', 1);
			$('right-arrow').tween('opacity', 1);
			$('logo').tween('left', 0);
		});
		$('img').addEvent('mouseleave', function(){
			$('left-arrow').tween('opacity', 0);
			$('right-arrow').tween('opacity', 0);
			$('logo').tween('left', -175);
		});
		
		gall.addEvent('transitionComplete', function(){
			if( $('text-screen').get('html') == ''){ c.hideCaption(); }
			if( $('text-screen').get('html') != ''){ 
				if( initial ){
					c.showCaption.delay(1000, c);
					initial = false;
				}else{
					c.showCaption();
				}
			}
		});
		/*
		gall.addEvent('transitionBegin', function(){
			if( $('text-screen').get('html') == ''){ c.hideCaption(); }
			if( $('text-screen').get('html') != ''){ c.showCaption(); }
		});*/
				
		
		$('right-arrow').addEvent('click', function(){
			gall.options.transition = ['wipeLeftFade', 'fadeOutThenIn'];
			s.pause();
			gall.goTo('next');
		});	
		$('left-arrow').addEvent('click', function(){
			gall.options.transition = ['wipeRightFade', 'fadeOutThenIn'];
			s.pause();
			gall.goTo('previous');
		});	
		
