/*//////////////////////////// DOMREADY ////////////////////////////
_______________________________________________________________________________________________________ */


window.addEvent('domready', function() {

	/* check browser support and capabilityes (object detection) */
	if (chkDomSupport()) {

		// "more" revealing effect
		$(document).getElements('#boxMain span.more a').each(function(tgl) {
		
			// get toggler "extra" container
			tglext = tgl.getParent().getNext();
			if($chk(tglext) && tglext.hasClass('more_content')) {

				// store a reference to the container element and its height
				tgl.tglext = $(tglext);
				tgl.tglext.hgt = tgl.tglext.getCoordinates().height;

				// then hide it from users's view
				tgl.tglext.setStyles({'overflow':'hidden','padding-top':'0px','padding-bottom':'0px','visibility':'hidden','opacity':'0','height':'0px'});

			}
			
			// ... and then handle toggler event
			tgl.addEvent('click',function(e) {
				e.stop();
				this.setStyle('display','none');
				// use element's native "morph" effect implementation
				if($chk(this.tglext)) {
					this.tglext.morph({'height':this.tglext.hgt+'px','opacity':'1'});
				}
			});

		});

		// photo-gallery
		if ($('pageAbout')) {

			// get slimbox popup-links
			var galleryLinks = $$('#boxAboutPhotogallery a').filter(function(el) { return el.rel && el.rel.test(/^lightbox/i); });
			
			// set slimbox options
			var sbxOptions = { loop: true, overlayOpacity: 0.85, initialWidth: 400, initialHeight: 300, counterText: "Immagine {x} di {y}" };

			// init the slimbox control
			$$(galleryLinks).slimbox(sbxOptions, null, function(el) {
				return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
			});
		
		}
				
	}

});


/*//////////////////////////// FUNCTIONS ////////////////////////////
_______________________________________________________________________________________________________ */

function chkDomSupport() {

	// test minimal browser DOM support
	if( !document.getElementById || !document.appendChild || !document.createElement || typeof document.getElementsByTagName("head")[0].innerHTML == "undefined") {
		return false;
	} else {
		return true;
	}
}


/*//////////////////////////// CLASSES ////////////////////////////
_______________________________________________________________________________________________________ */





/*//////////////////////////// EXTENSIONS ////////////////////////////
_______________________________________________________________________________________________________ */

Element.extend({
 
	getParentsByTag: function(selector){
		return $$(selector).filter(function(el){
			return (el.hasChild(this));
		}, this).reverse();
	},

	getFirstParentByTag: function(selector){
		return $(this.getParentsByTag(selector)[0] || false);
	},

	conditionalClass: function(className,condition){
		condition ? this.addClass(className) : this.removeClass(className);
	},

	// #####  DONT'T REMOVE  #####
	safari2hatesmissingcommas: function(){ }

});

