var DEBUG=0;//(typeof(window.console) != "undefined")?DEBUG=1:DEBUG=0;//alert(DEBUG);

var imgs = $$('#content img');

function webkit_version() {
	var version = 0;
	var regexp = /Safari\/([\d.]+)/;
	var result = regexp.exec(navigator.userAgent);
	if(result) {
		version = parseFloat(result[1]);
	}
	return version;
}
var webkit_version = webkit_version();

// alert(webkit_version);

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

	if( !$('press') ){
		imgs.setStyle('visibility', 'hidden' );
		imgs.setStyle('opacity', '0' );
	}
	
	$$('#nav .l1').addEvents({
		mouseover: function(){
			this.set('morph', { duration: 333 });

			// Change background color on mouseover
			this.morph({ color: '#999' });
		},
		mouseout: function(){
			this.morph({ color: '#000' });
		}
	});
	if( $('subnav') )  {

		if( $('extended') ) $('subnav').setStyle ('height', '0');
		if( $('extended-pages') ) $('subnav').setStyle ('height', '22px');

		$$('#subnav .l2').addEvents({
			mouseover: function(){
				this.set('morph', { duration: 333 });

				// Change background color on mouseover
				this.morph({ color: '#999' });
			},
			mouseout: function(){
				this.morph({ color: '#fff' });
			}
		});
	}

});

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

	if ( $('extended') && $('subnav') ) {

		var menuEffect = new Fx.Tween( $('subnav'), {
			'duration': 1334,
			'transition': Fx.Transitions.Sine.easeInOut
		});
		menuEffect.start('height', 0, 22);
	}

	if( $('press') && ( webkit_version==0||webkit_version>528 ) ) {
			// alert( Browser.Engine.version );
			$$('#content img').each(function(img){
			
				var span  = new Element('span');
				var newimg = new Element('img');
				span.inject( img, 'after' );
				newimg.inject( span );
				newimg.setProperty( 'src', img.getProperty('src') );
				newimg.setStyles( { 'opacity':'0', 'z-index':'1', 'display':'block' } );
				img.setStyles( { 'opacity':'1', 'z-index':'0' } );

				Pixastic.process(img, "desaturate", {average : true});

			});

			var imgElements		= $('content').getElements('span');		//console.log( "imgelements:"+imgElements.length );

			// thumbnail opacity setup, disabled for iphone.
			if ( Browser.Platform.ipod != true ) {
				imgElements.each( function(i) {
					i.addEvents({
						'mouseenter' : function() { this.getFirst().fade(1);  },
						'mouseleave' : function() { this.getFirst().fade(0);  }
					});
				});
			}
	} else {
			imgs.each(function(el){
				var fadeIn = new Fx.Tween(el, {
					'duration': 1334
				});
				fadeIn.start('opacity', 0, 1);
			});
	}

});