var selected;

(function(){

window.addEvent('domready', function(){
window.addEvent('domready',function() { new SmoothScroll({ duration: 1500,transition: Fx.Transitions.Expo.easeOut }); 

});

	$$(".menu-list a").addEvent("click", function(e) {

		//	e.preventDefault();

			if(selected) selected.set("id", "");
			this.set("id", "menu-list-selected");
			selected = this;

	
		});

		// COLECTION
		$$(".collection-product").addEvent("mouseover", function(){

			this.getElements("p, img.collection-gallery-frame").fade(1);
		}).addEvent("mouseout", function(){

			this.getElements("p, img.collection-gallery-frame").fade(0);
		});

		$$(".collection-product > p, .collection-product img.collection-gallery-frame").fade("hide");
		
			// about
		$$(".about-product").addEvent("mouseover", function(){

			this.getElements("p, img.about-gallery-frame").fade(1);
		}).addEvent("mouseout", function(){

			this.getElements("p, img.about-gallery-frame").fade(0);
		});

		$$(".about-product > p, .about-product img.about-gallery-frame").fade("hide");
		
					// quality
		$$(".quality-product").addEvent("mouseover", function(){

			this.getElements("p, img.quality-gallery-frame").fade(1);
		}).addEvent("mouseout", function(){

			this.getElements("p, img.quality-gallery-frame").fade(0);
		});

		$$(".quality-product > p, .quality-product img.quality-gallery-frame").fade("hide");

		// ADV
		$$(".adv-cover").addEvent("mouseover", function(){

			this.getElements("p, img.adv-gallery-frame").fade(1);
		}).addEvent("mouseout", function(){

			this.getElements("p, img.adv-gallery-frame").fade(0);
		});

		$$(".adv-cover > p, .adv-cover img.adv-gallery-frame").fade("hide");

		configureNewsNavigation();
		configureAboutNavigation();

		// parallax
		$$("#models-0, #models-01, #models-02, #models-03, #models-1, #models-11, #models-12, #models-2, #models-21, #models-22, #models-3, #models-31, #models-32, #shirts").each(function(item){
			item.store('top', parseInt(item.getStyle('top')));
			item.store('y', item.getPosition().y);
			item.store('friction', parseFloat(item.get("data-friction")));
		});

		this.addEvent('scroll', verticalParallax);

	//	$("quality-logo").setStyle("opacity", .8);
	//	if(!Browser.ie)
	//		configureCustomScrollSpyCallBack();

		$$("#language-bar-line, #language-bar-line, #language-bar, #menu, #sections, #models").setStyle("display", "none");
		$$("html, body").setStyle("height", "100%");
		$$("body, html").setStyle("overflow-y", "scroll");

	}).addEvent('load', function(){

		$("loading").set("tween", { duration: 1000, transition: Fx.Transitions.Quint.easeInOut, unit: "%", onComplete: function(){
			$$("html, body").setStyle("height", "");
			$$("body, html").setStyle("overflow-y", "");
		}}).tween.delay(100, $("loading"), ["top", -100]);

		$$("#language-bar-line, #language-bar-line, #language-bar, #menu, #sections, #models").setStyle("display", "");

		if(Browser.ie)
			return;

		scrollSpyElements = $$('').fade('hide');
	});

	function verticalParallax(e){

		var windowScrollY = window.getScroll().y;

		$$("#models-0, #models-01, #models-02, #models-03, #models-1, #models-11, #models-12, #models-2, #models-21, #models-22, #models-3, #models-31, #models-32, #shirts").each(function(item){

			if((windowScrollY) >= item.getPosition().y)
				item.setStyle("top", item.retrieve('top') + (windowScrollY - item.retrieve('y'))  * item.retrieve('friction'));
		});
	};

	function configureNewsNavigation() {

		var newsNavigationItems = $$(".quality-pagination a");

		newsNavigationItems.each(function(item, index){

			item.addEvent('click', function(e){

				e.preventDefault();

				if(newsNavigationSelected == this)
					return;

				newsNavigationSelected.set("id", "");
				newsNavigationSelected = this;
				newsNavigationSelected.set("id",  "quality-pagination-selected");

				new Fx.Scroll( 'quality-focus-list',{ duration: 500, transition: Fx.Transitions.Expo.easeInOut }).start(index * 928, 0);
			});
		});

		newsNavigationSelected = newsNavigationItems[0];
	};

		function configureAboutNavigation() {

		var aboutNavigationItems = $$(".about-pagination a");

		aboutNavigationItems.each(function(item, index){

			item.addEvent('click', function(e){

				e.preventDefault();

				if(newsNavigationSelected == this)
					return;

				aboutNavigationSelected.set("id", "");
				aboutNavigationSelected = this;
				aboutNavigationSelected.set("id", "about-pagination-selected");

				new Fx.Scroll('about-focus-list', { duration: 500, transition: Fx.Transitions.Expo.easeInOut }).start(index * 928, 0);
			});
		});

		aboutNavigationSelected = aboutNavigationItems[0];
	};

	function configureShareLinks(e){

		e.preventDefault();

		var title = this.getParent().getParent().getElements('h3').get('text');
		var eventid = this.getParent().getParent().getFirst().get('data-eventid');
		var windowprops = 'width=600,height=400,top=0,left=0,toolbar=no,location=no,directories=no,status=no,scrollbars=no,menubar=no';
		var popup;

		if(this.hasClass('share-on-facebook'))
			popup = window.open('http://www.facebook.com/sharer.php?u=http://dromeclub.it/?eid=' + eventid + '&t='+title, 'remote', windowprops);
		else
			popup = window.open('http://twitter.com/home?status=@dromeclub // ' + title + ' // http://dromeclub.it', 'remote', windowprops);

		popup.moveTo(0, 0);
		popup.resizeTo(600, 400);
		popup.focus();
	};

	function configureFooterLogos() {

		$$("#footer-loghi a")
			.setStyle('opacity', .7)
			.set('tween', { duration: 403, transition: Fx.Transitions.Expo.easeOut })
			.addEvent('mouseenter', function(){ this.fade(1); })
			.addEvent('mouseleave', function(){ this.fade(.7); });
	};

	function scrollSpy(){

		var windowScroll;
		var windowScrollY = win.getScroll().y;
		var windowSizeY = win.getSize().y;

		if(!scrollSpyElements.length)
			window.removeEvent('scroll', scrollSpy);

		var elements = new Array();

		Array.clone(scrollSpyElements).each(function(item, index) {

			windowScroll = windowScrollY + windowSizeY - (item.scrollSpyOffset ? item.scrollSpyOffset : 300);

			if(windowScroll >= item.getPosition().y) {

				elements.push(item);
				scrollSpyElements = scrollSpyElements.erase(item);
			}
		});

		elements.each(function(item, index){

			if(typeof item.scrollSpyShow == "function")
				item.scrollSpyShow.delay(index * 200, item);
			else
				(function(){ item.morph({ 'opacity': 1 }); }).delay(index * 300);
		});
	};

	function configureCustomScrollSpyCallBack() {

		$$("hr").scrollSpyOffset = 100;
		$$("hr").each(function(item){
		
			item.scrollSpyShow = function() {

				this.setStyle('width', 0);
				this.setStyle('opacity', 1);
				new Fx.Tween(this, { duration: 1000, transition: Fx.Transitions.Back.easeInOut }).start('width', 950);
			};
		});
	}

})();

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11382876-5']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


		window.addEvent('domready',function() {
			/* smooth */
			new SmoothScroll({duration:100});
			
			/* link management */
			$('gototop').set('opacity','0').setStyle('display','block');
			$('gototop2').set('opacity','0').setStyle('display','block');
			$('gototop3').set('opacity','0').setStyle('display','block');
			$('peekshirt').set('opacity','0').setStyle('display','block');
			$('peekshirtsar').set('opacity','0').setStyle('display','block');
			$('peekamano').set('opacity','0').setStyle('display','block');
			$('peektrousers').set('opacity','0').setStyle('display','block');
			$('peektrousersat').set('opacity','0').setStyle('display','block');
			
			/* scrollspy instance */
			var ss = new ScrollSpy({
				min: 3340,
				max: 3900,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('gototop').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('gototop').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 4436,
				max: 4836,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('gototop2').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('gototop2').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 5419,
				max: 5819,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('gototop3').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('gototop3').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 6551,
				max: 7000,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('peekshirt').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('peekshirt').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 7371,
				max: 7720,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('peekshirtsar').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('peekshirtsar').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 7946,
				max: 8300,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('peekamano').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('peekamano').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 8521,
				max: 8896,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('peektrousers').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('peektrousers').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
			var ss = new ScrollSpy({
				min: 9096,
				max: 9459,
				onEnter: function(position,enters) {
					//if(console) { console.log('Entered [' + enters + '] at: ' + position.x + ' / ' + position.y); }
					$('peektrousersat').fade('in');
				},
				onLeave: function(position,leaves) {
					//if(console) { console.log('Left [' + leaves + '] at: ' + position.x + ' / ' + position.y); }
					$('peektrousersat').fade('out');
				},
				onTick: function(position,state,enters,leaves) {
					//if(console) { console.log('Tick  [' + enters + ', ' + leaves + '] at: ' + position.x + ' / ' + position.y); }
				},
				container: window
			});
			
					$$(".more-button a[href='#less']").addEvent("click", function(e) {

			e.preventDefault();

			var el = this.getParent().getPrevious();
			var index = el.retrieve('index');

			if(index) {
				index--;
				el.store('index', index);
				new Fx.Scroll(el, { duration: 1000, transition: Fx.Transitions.Expo.easeInOut }).start(960 * index, 0);
			}
		});

		$$(".more-button a[href='#more']").addEvent("click", function(e) {

			e.preventDefault();

			var el = this.getParent().getPrevious();
			var index = el.retrieve('index');

			if(index < parseInt(el.get("data-count") -1)) {
				index++;
				el.store('index', index);
				new Fx.Scroll(el, { duration: 1000, transition: Fx.Transitions.Expo.easeInOut }).start(960 * index, 0);
			}
		});
		});
		
		
