/**
* iMedia Station (BRC) v2.0.0
*
* Original component ( (BRC) v2.0.0 ) by Dj Upalnite
*
* Porting to IPB3 ( (BRC) v2.0.0 ) by Dj Upalnite
* blackburnravers@hotmail.co.uk
*
* (c) Copyright Invision MP3 2004-2010
*/

var _imedia = window.IPBoard;

_imedia.prototype.imedia = {
	
	/**
	* Constructor: init events
	*
	* @param	void
	* @return	void
	*/
	
	init: function()
	{
		document.observe( 'dom:loaded', function()
		{
			/* Mod form submission */
			if ( $( 'modform' ) )
			{
				$( 'modform' ).observe( 'submit', ipb.forums.submitModForm );
			}
			
			/* Media listing filters */
			if ( $( 'filter_form' ) )
			{
				$( 'filter_form' ).hide();
				$( 'show_filters' ).show();
			}
			
			/* Statistic iMedia */
			$$( '.media_smedia' ).each( function( elem )
			{
				ipb.imedia.initStatPopups( elem );				
			} );
			
			/* Resizing images? */
			if ( $( 'theComments' ) )
			{
				ipb.global.findImgs( 'theComments' );
			}
			
			/* AJAX mark category as read */
			$$( '.imediaMarkCat' ).each( function( elem )
			{
				ipb.imedia.initCatMarker( elem );
			} );
		} );
	},
	
	initStatPopups: function( elem )
	{
		var statType	= elem.id.replace( 'smedia_', '' );
		var url				= ipb.vars[ 'base_url' ] + "&app=imedia&module=ajax&secure_key=" + ipb.vars[ 'secure_hash' ] + "&do=" + statType;
		
		$( elem ).observe( 'click', function( e )
		{
			Event.stop( e );			
			popup = new ipb.Popup( 'statsPane', { type: 'pane', modal: false, w: '600px', h: '600px', ajaxURL: url, hideAtStart: false, close: 'a[rel="close"]' } );
		} );
	},
	
	initCatMarker: function( elem )
	{
		var catId		= elem.id.replace( 'imedia_cat_img_', '' );
		var url			=	ipb.vars[ 'base_url' ] + "&app=imedia&module=ajax&section=markread&secure_key=" + ipb.vars[ 'secure_hash' ] + "&do=markread&marktype=cat&cid=" + catId;
		var classes	= $w( elem.className );
		
		$( elem ).observe( 'click', function( e )
		{
			new Ajax.Request( url, { method: 'post', onSuccess: function( t )
			{
				$( elem ).replace( ipb.global.boardMarkers[ classes[ classes.length - 1 ] ] );
			} } );
			
			Event.stop( e );
		} );
	}
}

ipb.imedia.init();
