/**
 * Javascript part for Favourites module
 */
MPFAV_instances = new Array();
 
/**
 * Javascript object connected with instance of Favourites module
 */
function MPFAV_MemberProfile( sInstanceId ) {

	this.sInstanceId = sInstanceId;
	this.iAdd = 0;
	this.currentOffset = 0; // for member profile

	this.favouritesModify = function( sType, iObjectId ) {
		switch ( sType ) {
			case 'category':
				oCrux.callAjax( 'MemberProfile_Favourites_categoryFavourites', { parameters: [ this.sInstanceId, iObjectId, this.iAdd ] } );
				return true;
			break;
			case 'product':
				oCrux.callAjax( 'MemberProfile_Favourites_productFavourites', { parameters: [ this.sInstanceId, iObjectId, this.iAdd ] } );
				return true;
			break;
			case 'review':
				oCrux.callAjax( 'MemberProfile_Favourites_reviewFavourites', { parameters: [ this.sInstanceId, iObjectId, this.iAdd ] } );
				return true;
			break;			
		}
	}
	this.setAlwaysAdd = function( iValue ) {
		this.iAdd = iValue;
	}
	this.findClassAndReplaceAnchors = function( sClass, sAnchorText ) {
		$( '.' + sClass ).html( sAnchorText );
		return true;
	}
/*
 * Memeber profile functionality
 */	
	
	this.deleteItem = function( iObjectId, sType ) {
		iOffset = this.currentOffset;
		$(document).ready( function() {
		jQuery().yesNoDialog( {
					sMessage:	oCruxStrings.getString( 'MPFAV', 'delete_confirmation_text' ),
					sTitle: 	oCruxStrings.getString( 'MPFAV', 'delete_confirmation_title' )		
				},
				function( ) {
					oCrux.callAjax( 'MemberProfile_Favourites_deleteItem', { parameters: [ sInstanceId, iObjectId, sType, iOffset ] } );
				},
				''
			);
		});
	}
	
	this.deleteItemFromBox = function( sType, iObject, iTotalCount, sBodyId, sContent ) {
		
		$( '#row_' + sType + '_' + iObject ).fadeOut( "slow", function() { 
			$( '#' + sType + '_total_items' ).text( iTotalCount );
			$( '#' + sBodyId ).html( sContent );
		} );
		return true;
	}
	
	this.getContent = function( sInstanceId, sType, iLimit, iOffset ) {
		this.currentOffset = iOffset;
		oCrux.callAjax( 'MemberProfile_Favourites_getContent', { parameters: [ sInstanceId, sType, iLimit, iOffset ] } );
	}
			
/*
 * END of Memeber profile functionality
 */		
}
$(document).trigger( "MPFAV" );