/*/////////////////////////////////////////////////////// CREDITS ///////////////////
_______________________________________________________________________________________________________

 |	
 |	FPNSNC.COM Website Scripting
 |	by Cristiano Rastelli - Area Web <more info: www.didoo.net>
 |	Last Update: June 2007
 |

 _______________________________________________________________________________________________________

	Table of Contents
	-----------------
	Configuration
	Global Variables


	Class Declarations
	------------------	

	Common
	. menu					[ initialize / tog ]

	Countdown
	. countdown				[ initialize / timeticker ]


	Functions Declarations
	-----------------------

	Detection
	. browserSupportDomHandling

	Common
	. zeroPad	

	Function Calls
	--------------
	. window onload initialize
	
_______________________________________________________________________________________________________ */




/*/////////////////////////////////////////////////////// CLASS DEFINITIONS ////////////////////
_______________________________________________________________________________________________________ */

/*............................... COMMON ........*/


var Menu = new Class({

	initialize: function() {

		this.menu = $('boxMenu');
		this.items = this.menu.getChildren();
		this.trigger = $E('#boxMenu #itemB a');
		this.blinder = $E('#boxMenu #itemB #boxSubmenuB');

		if ($('boxSidebar') && this.menu && this.trigger) {	// check HTML vs. expected DOM correspondence

			// assign the behavior to the menu item link
			this.trigger.addEvent('click', this.blind.bindAsEventListener(this));
			this.trigger.onclick = function(){return false;}
	
			// initialise the opacity effect & hide credits
			this.blinder.slidefx = new Fx.Slide(this.blinder.id);

			// show only if sub pages
			if (!($chk($('pageProdotti1')) || $chk($('pageProdotti2')) || $chk($('pageProdotti3')))) this.blinder.slidefx.hide();

			// tag current page
			for (i=0; i<this.items.length; i++) {
				this.items[i].getElements('a').each( 
					function(ln){ 
						if(getPage(ln.href) == getPage(location.href)) { 
							this.tag(this.items[i].id);
						} 
					}, this );
			}
		}

	},
	
	blind: function() {
		this.blinder.slidefx.toggle();	
	},

	tag: function(liid) {
		
		// tag as active
		$(liid).addClass('active');

		// add corner image
		var imgEl = new Asset.image('/media/img/interface/menu/item_active_tag.jpg', {id: 'actTagger'});
		imgEl.inject(liid);

	}

})



/*/////////////////////////////////////////////////////// FUNCTIONS DEFINITIONS ////////////////////
_______________________________________________________________________________________________________ */


/*............................... DETECTION ........*/

function browserSupportDomHandling() {

	// test if browser can't support advanced features...
	if( !document.getElementById || !document.appendChild || !document.createElement || typeof document.getElementsByTagName("head")[0].innerHTML == "undefined") {
		return false;
	} else {
		return true;
	}
}

function getPage(cu) {

	// strip query string from current url
	if(cu.indexOf("?") >= 0) { cu = cu.substring(0,cUrl.indexOf("?")); }

	// return current page
	return cu.split('/').getLast();

}


/*/////////////////////////////////////////////////////// ONLOAD DECLARATION ////////////////////
_______________________________________________________________________________________________________ */

window.onDomReady(function() { 	

	/* test browser capabilityes (object detection) */
	if (browserSupportDomHandling()) {
	
		// __ COMMON _______________
		
		/* navigation menu  */
		var myMenu = new Menu();

		/* carousel widget */
		if($chk($('boxCarousel'))) { 
			new CNETcarousel($('boxCarousel'), {
				rotateAction: 'click',
				slideInterval: 6000,
				autoplay: true
			}); 
		}

	}

});	
