function slide_pane(obj) {

	var pane = $(obj.get('rel'));
	var p = pane.getPosition(pane.getParent());

	//$$('.left_col > ul.menu > li').removeClass('current');
	//obj.getParent().addClass('current');

	$('pane_container').tween('marginLeft', -1 * p.x.toInt());
	if (obj.get('rel') == 'home' && config.current_pane != 'home') {
		$('homepage_bg').tween('opacity', 1);
		$('liltxtlogo').tween('opacity', 0);
	}
	if (obj.get('rel') != 'home' && config.current_pane == 'home') {
		$('homepage_bg').tween('opacity', 0);
		$('liltxtlogo').tween('opacity', 1);
	}
	config.current_pane = obj.get('rel');
	
}

function show_gallery(obj) {
	var rel = JSON.decode(obj.get('rel'));
	if (typeof(rel) == 'object' && rel.hasOwnProperty('gal_id') && Galleries.hasOwnProperty(rel.gal_id)) {

		var _i = Galleries.gallery_info[rel.gal_id];
		_i.gal_id = rel.gal_id;

		$('gallery_choices').addClass('hidden');
		$('current_gallery').removeClass('hidden').grab(new Element('p', { html: '<h4>Loading "'+ _i.title+'" gallery please wait</h4>' }));
		
		//*
		var _root = new Element('div', {
			id: 'gallery-'+rel.gal_id,
			'class': 'slideshow',
			html: '<h4>Choose a picture:</h4>'
		});//.set('data-slideshow','delay:2000 duration:1000 transition:slideLeft');
		//*/
		
		var _a = new Element('a', {
			href: '#',
			text: 'click here to return to the gallery list',
			id: '_reset_gallery_link',
			styles: {
				backgroundColor: '#ff0000',
				color: '#ffffff',
				padding: 6,
				fontSize: 14,
				display: 'block',
				marginBottom: 12
			}
		});

		_root.grab(_a);

		Galleries[rel.gal_id].each(function(i) {
			var _title = i.name;
			_title += (i.caption ? ': ' + i.caption : '');
			var _el = new Element('a', {
				href: _i.img_dir + i.filename,
				target: 'viewer',
				title: _title,
				rel: 'g:'+_i.gal_id+',type:'+i.image_type+',width:'+i.width+',height:'+i.height
			}).addClass('squeezegallery');
			
			_el.grab(new Element('img', {
				src: _i.thumb_dir + i.filename,
				width: 100,
				height: 100,
				border: 0
			}));
			
			_root.grab(_el);
		});
		
/*
<a href="/pictures/stairs_6.jpg" target="viewer" class="squeezegallery" title="STAIRS: picture 1"
	rel="g:g6,type:jpg,width:600,height:450"><img src="/pictures/stairs_6_t.jpg" width="60" height="60" border="0" /></a>
*/

		$('current_gallery').empty().set('html',_root.get('html'));

		$('current_gallery').getElements("a.squeezegallery").each(function(a) {
			var options = a.rel.split(",");
			options.each(function(o) {
				opt = o.split(":");
				if (opt[0] == "g") {
					if (cur_sg_tag == "" || cur_sg_tag != opt[1]) {
						if (cur_sg_tag != "") { sg_tags[cur_sg_tag] = sg_count; }
						cur_sg_tag = opt[1];
						sg_count = 0;
					}
					a.id = sg_count + opt[1];
					a.store("gt",opt[1]);
				}
			});
			
			a.addEvent('click', function(e) {
				new Event(e).stop();
				sg(this);
			});
			sg_count++;
		});
		
		// this catches the last tag count
		sg_tags[cur_sg_tag] = sg_count;

		$('_reset_gallery_link').addEvent('click', function(e) {
			var ee = new Event(e);
			ee.preventDefault();
			$('current_gallery').addClass('hidden').empty();
			$('gallery_choices').removeClass('hidden');

		});
				
	} else {
		alert('Sorry, there was an error loading that gallery');
		console.log('failed to load G, rel + Galleries: ');
		console.dir(rel);
		console.dir(Galleries);
	}
}

function start_page() {

	$('main_menu').getElements('li').each(function(li) {
		li.getElements('a').addEvent('click', function(e) {
			var ee = new Event(e);
			ee.preventDefault();
			slide_pane(this);
		});
	});
	
	$$('a.panel_click').addEvent('click', function(e) {
		var ee = new Event(e);
		ee.preventDefault();
		slide_pane(this);
	});
	
	$$('div.gallery_choice').addEvent('click', function(e) {
		var ee = new Event(e);
		ee.preventDefault();
		show_gallery(this);
	});
/*	
	$$('div.thumbs a').each(function(a) {
		a.addEvent('click', function(e) {
			var ee = new Event(e);
			ee.preventDefault();
			var r = this.get('rel');
			//console.log('rel: ' + r + ', ' + $(r));
			if (config.current_video != r) {

				pause_all_videos();

				$('media-'+r).getParent().getElements('div.qtvr').addClass('hidden');
				$('media-'+r).removeClass('hidden');
				if ($('media-'+r).getElement('div').hasClass('video_placeholder')) {
					$('media-'+r).getElement('div').getElement('a').fireEvent('click');
				}
				if (config.videos['media-'+r] == undefined) {
					//console.log('PAGE setting up video with ID=videojs_media-'+r);
					if ($('videojs_media-'+r) && $('videojs_media-'+r).get('tag') == "video") {
						config.videos['media-'+r] = VideoJS.setup('videojs_media-'+r);
						config.videos['media-'+r].onPlay(function() { pause_all_videos(config.videos['media-'+r]); } );
					}
				}
				
				if (config.videos['media-'+r] && config.videos['media-'+r].play != undefined) {
					config.videos['media-'+r].play();
				}

			}
			config.current_video = r;
			
		});
	});
*/
//	$('start_link').fireEvent('click');
	
}

var config = {
	current_pane: 'home'
};

window.addEvent('domready', function() {
	start_page();
});

