/*—~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ M E N U.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

menuClass = new Class({

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I N I T.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	initialize: function() {
		this.menuAlbumInit();
	},


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I N I T.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MENU TREE INIT.
	menuAlbumInit: function() {
		if ($chk($('menuAlbumTree'))) {
			this.menuAlbumScrollInit();
			pictureFrameMorph = new Fx.Morph('pictureFrame', {duration: "normal", transition: Fx.Transitions.Sine.easeOut}); //Fx.Transitions.Cubic.easeOut
			$('menuAlbumTree').getElements('a[class$=Toggler]').each(function(tagObj, i) {
				//~~~~~~~~~~~~ Effect — Roll-overs.
				mainHandler.mainRolloverFxBackground(tagObj, '#5a5a5a');
				new Asset.image(tagObj.get('hreflang'));
				//~~~~~~~~~~~~~~~~~ Events — Click.
				tagObj.addEvent('click', function(e) {
					new Event(e).stop();
				});
				// Dollies + Description.
				if ((menuAlbumDollyObj = tagObj.getParent('li').getFirst('ul[class$=Content]')) && (menuAlbumTextObj = tagObj.getParent('li').getFirst('p[class$=Text]'))) {
					menuAlbumDollyObj.erase('class');
					menuAlbumTextObj.getFirst('a').destroy();
				}
				// Dollies.
				else if (menuAlbumDollyObj = tagObj.getParent('li').getFirst('ul[class$=Content]')) {
					mainHandler.mainRolloverFxBackgroundRemove(tagObj);
					tagObj.setStyles({cursor: "default"});
					menuAlbumDollyObj.erase('class');
					tagObj.erase('class');
				}
				// Direct Link.
				else if (!tagObj.getParent('li').getFirst('*[class$=Text]')) {
					tagObj.erase('class');
					tagObj.addEvent('click', function(e) {
						this.menuTreeDisplayGallery(tagObj);
					}.bind(this));
				}
				//~~~~~~~~~~~~ Events — Roll-overs.
				tagObj.addEvents({
					mouseenter: function() {
						$('pictureFrame').setStyles({background: "#545454 url('"+tagObj.get('hreflang')+"') no-repeat center center"});
					},
					mouseleave: function() {
						$('pictureFrame').setStyles({background: "#545454"});
					}
				});
			}.bind(this));
			$('pictureFrame').setStyles({background: "#545454 url('"+$('menuAlbumTree').getElement('a[hreflang]').get('hreflang')+"') no-repeat center center"});
			// Paragraph link.
			$('menuAlbumTree').getElements('a[class$=Link]').each(function(tagObj, i) {
				tagObj.addEvent('click', function(e) {
					new Event(e).stop();
					this.menuTreeDisplayGallery(tagObj);
				}.bind(this));
			}.bind(this));
			// Init Accordion.
			this.menuAccordionInit();
		}
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SCROLL ALBUM TREE.
	menuAlbumScrollInit: function() {
		var menuAlbumScroll = new Scroller('menuAlbumFrame', {
			area: 125,
			velocity: 0.1
		});
		menuAlbumScroll.start();
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ACCORDION COMPUTE.
	menuAccordionInit: function() {
		menuAccordion = new Accordion($('menuAlbumTree').getElements('a[class$=Toggler]'), $('menuAlbumTree').getElements('ul[class$=Content], p[class$=Text]'), {
			display: false,
			show: false,
			opacity: false,
			alwaysHide: true,
			initialDisplayFx: false,
			transition: Fx.Transitions.Quad.easeOut,
			duration: "normal",
			onActive: function(toggler, content) {
				this.menuAccordionCurrent = toggler;
				toggler.fx.start(toggler.colorOver);
			}.bind(this),
			onBackground: function(toggler, content) {
				toggler.fx.start(toggler.colorOut);
			}
		});
		$('menuAlbumTree').getElements('a[class$=Toggler]').each(function(tagObj, i) {
			if (stringTrim(window.location.pathname, "/").replace(/^([a-z0-9\-_\/])+\//g, "").test(tagObj.get('id'), 'i'))
				menuAccordion.display(i);
		});
	},

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY GALLERY (Menu Tree Click).
	menuTreeDisplayGallery: function(tagObj) {
		// External link
		if (tagObj.get('href').test("http://", 'i')) {
			mafenetre = window.open(tagObj.get('href'), "_blank");
			mafenetre.focus();
		}
		// Internal gallery.
		else {
			pictureFrameMorph.start({
				left: [330, 20],
				width: [538, 848]
			});
			$('pictureFrame').setStyles({background: "#545454 url('/styles/images/loadingBar.gif') no-repeat center center"});
			//~~~~~~~~~~~~ Get Data.
			$('pictureGallery').hide().get('load', $merge(xhrOptions, {
				data: {
					xhrAct: "getGalleryHtml",
					galleryTupleId: tagObj.get('rel')
				},
				onSuccess: function() {
					//History.start();
					$('pictureFrame').setStyles({background: "#545454"});
					pictureGalleryObj = new gallery($('pictureGallery'));
				}			
			})).send();
		}
	}

});



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ O N   D O M   R E A D Y.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
window.addEvent('domready', function() {
	menuHandler = new menuClass();
});

