addEvent( window, "load", init );

function init()
{
	//addEvent(document.body,"click", noNoClick);
	addEvent( document, "contextmenu", noNoClick );
	//addEvent(document,"mousedown", noNoClick);
}

function noNoClick( e )
{
	var rightclick;
	if ( !e )
	{
		var e = window.event;
	}
	if ( e.which )
	{
		rightclick = (e.which == 3);
	}
	else
	{
		if ( e.button )
		{
			rightclick = (e.button == 2);
		}
	}
	alert( "Sorry! No Right Clickin'" );
	stopEvent( e );
}

function stopEvent( e )
{
	e.returnValue = false;
	if ( e.preventDefault )
	{
		e.preventDefault();
	}
}

function addEvent( obj, evt, fn )
{
	if ( obj.addEventListener )
	{
		obj.addEventListener( evt, fn, false );
	}
	else
	{
		if ( obj.attachEvent )
		{
			obj.attachEvent( 'on' + evt, fn );
		}
	}
}

var App = {
	textOnly: function( str )
	{
		if ( str.indexOf( '<' ) != -1 )
		{
			var s = str.split( '<' );
			for ( var i = 0; i < s.length; i++ )
			{
				if ( s[i].indexOf( '>' ) != -1 )
				{
					s[i] = s[i].substring( s[i].indexOf( '>' ) + 1, s[i].length );
				}
			}
			str = s.join( '' );
		}
		return str;
	},
	chop: function ( str, length )
	{
		length = (length < str.length - 1)
				? length
				: str.length - 2;
		while ( str.charAt( length - 1 ) != ' ' && str.indexOf( ' ', length ) != -1 )
		{
			length++;
		}
		str = str.substring( 0, length - 1 );
		return str + '...';
	}
};

YUI( {
	//Last Gallery Build of this module
	//	gallery: 'gallery-2010.03.11-21',
	gallery: 'gallery-2011.02.02-21-07'
} ).use( 'node', 'gallery-simple-menu', 'gallery-ellipsis', function( Y )
		{

			Y.on( 'available', function()
			{
				var archive_div_new = Y.one( '#menu_archives_div' );
				var archive_div_old = Y.one( '#BlogArchive1_ArchiveList' );
				var archive_link = Y.one( '#menu_archives' );

				// Copy HTML
				archive_div_new.set( 'innerHTML', archive_div_old.get( 'innerHTML' ) );

				// Setup Menu
				archive_link.plug( Y.Plugin.SimpleMenu );

				// Set Position
				archive_div_new.setStyle( 'left', archive_link.getX() );

				// Apply grouping
//				new HandleArchives();

				return;
				var archives = {};
				archive_div_new.all( 'ul li' ).each( function( node )
				{
					var year = node.one( 'a' ).get( 'text' ).substr( -4, 4 );
					if ( !archives[year] )
					{
						archives[year] = Y.all( {} );
					}
					archives[year].push( node );
				} );

			}, '#BlogArchive1_ArchiveList' );

			Y.on( 'available', function()
			{
				var categories_div_new = Y.one( '#menu_categories_div' );
				var categories_div_old = Y.one( 'div.cloud-label-widget-content' );
				var categories_link = Y.one( '#menu_categories' );

				if ( categories_div_new && categories_div_old && categories_link )
				{
					// Copy HTML
					categories_div_new.set( 'innerHTML', categories_div_old.get( 'innerHTML' ) );

					// Setup Menu
					categories_link.plug( Y.Plugin.SimpleMenu );

					// Set Position
					categories_div_new.setStyle( 'left', categories_link.getX() );
				}
			}, 'div.cloud-label-widget-content' );

			Y.on( 'available', function()
			{
				// Set all links in posts to open in new window.
				var links = Y.all( 'div.entry-content a' );
				if ( links )
				{
					links.setAttribute( 'target', '_blank' );
				}
			}, 'div.entry-content a' );

			Y.on( 'available', function()
			{
				// Remove Atom Feeds Link
				var feeds = Y.all( 'div.post-feeds, div.blog-feeds' );
				if ( feeds )
				{
					feeds.remove();
				}
			}, 'div.post-feeds, div.blog-feeds' );

			Y.on( 'domready', function()
			{
				// Post Columns
				var initialSkip = (window.location.pathname.length > 1 )
						? -1
						: 0, // zero index
						posts = Y.all( 'div.date-outer div.post' ),
						postContainer = Y.one( 'div.blog-posts' ),
						columnContainer = Y.Node.create( '<div class="column-container"></div>' ),
						clearDiv = Y.Node.create( '<div class="clear"></div>' );

				// Single Posts
				if ( posts.size() < 2 )
				{
					return;
				}
				posts.each( function( node )
				{
					if ( initialSkip == posts.indexOf( node ) )
					{
						return true;
					}
					var postHref = node.one( 'div.post-header .post-title a' ).get( 'href' ),
							img = node.one( 'img' ),
							header = node.one( 'div.post-header' ),
							footer = node.one( 'div.post-footer' ),
							readMore = Y.Node.create( '<div class="readmore"><a href="' + postHref + '">READ MORE...</a></div>' ),
							content = Y.Node.create( '<div class="post-content"></div>' ).set( 'innerHTML', App.textOnly( node.one( 'div.entry-content' ).get( 'innerHTML' ) ) ),
							container = Y.Node.create( '<div class="column-post"></div>' );

					container.appendChild( header );
					container.appendChild( img );
					container.appendChild( content );
					container.appendChild( footer );
					container.appendChild( readMore );

					columnContainer.appendChild( container );

					node.remove();
				} );

				columnContainer.appendChild( clearDiv );
				postContainer.appendChild( columnContainer );

				// Calc Heights
				posts = Y.all( 'div.column-post' );

				// Single Posts
				if ( posts.size() < 1 )
				{
					return;
				}
				posts.each( function( node )
				{
					var imgHeight = node.one( 'img' ).get( 'offsetHeight' ),
							headerHeight = node.one( 'div.post-header' ).get( 'offsetHeight' ),
							contentHeight = 580 - Number( imgHeight ) - Number( headerHeight ) - 25,
							content = node.one( 'div.post-content' ),
							lineHeight = 24,
							lines = Math.floor( contentHeight / lineHeight );
					if ( lines > 0 )
					{
						content.setStyle( 'height', contentHeight );
						content.ellipsis( { lines: lines } );
					}
					else
					{
						content.remove();
					}
				} );
			} );
		} );

/*
var HandleArchives = new Class( {
	initialize: function()
	{
		var gleanedData = this.gleanData( document.id( 'menu_archives_div' ) );
		this.buildHTML( gleanedData );
	},

	gleanData: function( container )
	{
		console.time( 'gleanData' );

		var monthElements = container.getElements( 'ul li a' ),
				rawData = monthElements.map( function( item, index, array )
				{
					var text = item.get( 'text' );
					return {
						link: item.get( 'href' ),
						title: text.substr( 0, text.length - 5 ),
						year: text.substr( -4, 4 ),
						count: item.getParent( 'li' ).get( 'text' ).trim().match( /\(([0-9]+)\)/ )[1]
					}
				} ),

				years = new Array(),
				yearsObj = new Object();

		rawData.each( function( item, index, array )
		{
			yearsObj[item.year] = yearsObj[item.year] || new Array();
			yearsObj[item.year].push( item );
		} );

		Object.each( yearsObj, function( value, key, object )
		{
			years.push( {
				title: key.toInt(),
				months: value
			} );
		} );

		console.timeEnd( 'gleanData' );

		return years.sort( this.sortArchives );
	},

	buildHTML: function( gleanedData )
	{
		console.time( 'buildHTML' );

		var liElements = gleanedData.map( function( item, index, array )
		{
			var li = new Element('li', {});
		} );

		console.timeEnd( 'buildHTML' );
		console.log( sortedData );
	},

	sortArchives: function( a, b )
	{
		return a.title + b.title;
	}
} );

addEvent( window, 'load', function()
{
	console.log( 'Dom Ready' );
} );
*/
