function buildConsoleObject(){	
	if (!window.console ){
	    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	    window.console = {};
	    for (var i = 0; i < names.length; ++i){
			window.console[names[i]] = function() {};
		}
		names = null;
	}
}

buildConsoleObject();

rooftopfarms = {};

rooftopfarms.BackgroundImage = new Class({
	
	initialize: function(){
	
		this.ogImg = $( "img" );
		var imgSrc = this.ogImg.get( "src" );		
		var hSrc = imgSrc.substr( 0, imgSrc.length-"_low.jpg".length ) + ".jpg";
		
		this.friendsList = $( "footerFlyout" );
		if( this.friendsList ){
		    var content = this.friendsList.getElement( ".content" );
		    console.log( ">>>> ", content.getCoordinates().width );
            content.setStyle( "left", "-"+( content.getStyle( "width" ) ) );
			this.friendsList.getElement( "h3" ).addEvent( "mouseenter", this.showFriendsList.bindWithEvent( this ) );
			this.friendsList.addEvent( "mouseleave", this.friendsListLeft.bindWithEvent( this ) );			
		}
		this.searchForm = $( "searchForm" );
		this.searchToggle = $( "searchBox" );
		this.searchToggle.addEvent( "mouseenter", this.showSearchBox.bindWithEvent( this ) );
		this.searchToggle.addEvent( "mouseleave", this.searchBoxLeft.bindWithEvent( this ) );

		if( Browser.Platform.ipod ){
			this.ogImg.destroy();
			$( document.body ).setStyle( "background", "/images/mobileBg.jpg" );
			$( "footer" ).setStyle( "position", "static" );
		}else{
			this.highResImage = new Asset.image( hSrc, { 
				id: 'highResImage',
				title: this.ogImg.get("alt"),
				onload: this.replaceLowQualityImageWithHighQualityImage.bind( this )
			});
			this.ogImg.setStyles({
				"position": "fixed",
				"z-index": 1
			});
			this.image = {
				element: this.ogImg,
				width: this.ogImg.getCoordinates().width,
				height: this.ogImg.getCoordinates().height
			}
			window.addEvent( "resize", this.resizeImage.bind( this ) );
			this.resizeImage();			
		}

	},

	stopEvent: function( e ){
		if( e && e.stop ){
			e.stop();
		}else if( e ){
			e.returnValue = false;
		}
	},

	showFriendsList: function( e ){
		this.stopEvent( e );
		if( this.friendsHideTimer ) $clear( this.friendsHideTimer );
		this.friendsList.getElement( ".content" ).reveal();
	},
	
	friendsListLeft: function( e ){
		this.stopEvent( e );
		if( this.friendsHideTimer ) $clear( this.friendsHideTimer );
		this.friendsHideTimer = this.hideFriendsList.delay( 400, this );
	},
	
	hideFriendsList: function(){
		if( this.friendsHideTimer ) $clear( this.friendsHideTimer );
		this.friendsList.getElement( ".content" ).dissolve();		
	},
	
	showSearchBox: function( e ){
		this.stopEvent( e );
		if( this.searchHideTimer ) $clear( this.searchHideTimer );
		this.searchForm.reveal();
	},
	
	searchBoxLeft: function( e ){
		this.stopEvent( e );
		if( this.searchHideTimer ) $clear( this.searchHideTimer );
		this.searchHideTimer = this.hideSearchBox.delay( 400, this );
	},
	
	hideSearchBox: function(){
		if( this.searchHideTimer ) $clear( this.searchHideTimer );
		this.searchForm.dissolve();		
	},
	
	replaceLowQualityImageWithHighQualityImage: function(){

		this.highResImage.setStyles({
			"z-index" : 2,
			"opacity" : 0,
			"position" : "fixed",
			"width": this.image.width,
			"width": this.image.height
		});
		
		$( document.body ).adopt( this.highResImage );

		this.image.element = this.highResImage;

		this.highResImage.set( "morph", { duration: 1500, onComplete: this.onImageFadeInComplete.bind( this ) } );
		this.highResImage.setStyles({
			"position": "fixed",
			"z-index": 1
		});
		
		this.resizeImage();
		this.highResImage.morph( { 'opacity' : 1 } );

	},
	
	onImageFadeInComplete: function(){
		this.ogImg.destroy();		
	},
	
	resizeImage: function() {

		// calculate aspect ratio
	
		var win = window.getSize();

		var w = win.x;
		var h = win.y;
		var winRatio = w / h;

		var img = this.image;
	
		// image ratio
		var picRatio = img.width / img.height;

		if ( winRatio > picRatio ) {
			// scale image to window based on width
			var newHeight = ( w / img.width ) * img.height;
			var newWidth = w;
		} else {
			// scale image to window based on height
			var newHeight = h;
			var newWidth = ( h / img.height ) * img.width;
		}

		// center it
		newTop = -( newHeight - h ) * .5;
		newLeft =  -( newWidth - w ) * .5;
	
		img.element.setStyles({
			top: newTop,
			left: newLeft,
			width: newWidth,
			height: newHeight
		});
	
		img = null;
	}

});

window.addEvent( "domready", function(){
	rooftopfarms.bgImg = new rooftopfarms.BackgroundImage(); 
});
