


		var BoxGrid = FlirtXchange.ViewController.BoxGrid = new Object();
		
		BoxGrid.Settings = {
			LoaderLayerId : 'layer_loading',
			SectionTitleHolderId : 'current_section_title',
			GridSinglePageWidth : 717,
			GridWrapperId : 'dynamic_member_list',
			GridWrapperClassName : 'dynamic_member_list_width',
			NoResultLayerId : 'layer_no_result',
			Tabs : {
				WomanId : 'tab_female',
				ManId : 'tab_male',
				BothId : 'tab_gender_all',
				WomanClassPrefix : 'female_',
				ManClassPrefix : 'male_',
				BothClassPrefix : 'all_'
			}
		}
		
		BoxGrid.Storage = {
		}
		
		BoxGrid.Load = function(responseJSON) {
			BoxGrid.UpdateReferences(responseJSON.Info);
			BoxGrid.UpdateTitle(responseJSON.SectionTitle);
			BoxGrid.SetGridWidth(responseJSON.Pagination.PagesInSet, responseJSON.Pagination.CurrentPage);
			BoxGrid.SetData(responseJSON.Items, responseJSON.HTML);
			MainGrid.InitializeDragAndDrop(MainGrid.References.HTMLReference);
			BoxGrid.Pagination.Settings.Details = responseJSON.Pagination;
			BoxGrid.Pagination.Update();
		}
		
		BoxGrid.UpdateReferences = function(Info) {
			MainGrid.References.HTMLReference = Info.HTMLReference;
			var i = 0;
			if(!Object.isArray(MainGrid.References.HotListed)) {
				for(var MemId in MainGrid.References.HotListed) {
					if(!Object.isArray(Info.CrossReference[MemId])) Info.CrossReference[MemId] = new Array();
					
					if(Info.CrossReference[MemId].indexOf(MainGrid.References.HotListed[MemId]) == -1)
						Info.CrossReference[MemId].push(MainGrid.References.HotListed[MemId]);
					Info.JSONInfo[MemId] = MainGrid.References.JSONInfo[MemId];
				}
			}
			
			MainGrid.References.CrossReference = Info.CrossReference;
			MainGrid.References.JSONInfo = Info.JSONInfo;
		}
		
		BoxGrid.UpdateTitle = function(SectionTitle) {
			if($(BoxGrid.Settings.SectionTitleHolderId)) {
				$(BoxGrid.Settings.SectionTitleHolderId).innerHTML = SectionTitle;
			}
		}
		
		BoxGrid.SetGridWidth = function(Pages, Current) {
			Pages = (Pages) ? Pages : 1;
			var Width = BoxGrid.Settings.GridSinglePageWidth * Pages;
			$(BoxGrid.Settings.GridWrapperId).style.cssText = '';;
			/**if(!FlirtXchange.Common.IsIE && FlirtXchange.ViewController.GetLastRule().selectorText == BoxGrid.Settings.GridWrapperClassName) {
				with(FlirtXchange.ViewController.GetLastRule().style) {
					width = Width+'px';
					left = (-1 * (BoxGrid.Settings.GridSinglePageWidth * (Current - 1))) + 'px';
				}
			} else { */
				FlirtXchange.ViewController.AddRule('.'+BoxGrid.Settings.GridWrapperClassName, 'width: '+Width+'px; left:'+(-1 * (BoxGrid.Settings.GridSinglePageWidth * (Current - 1))) + 'px');
			//}
			
		}
		
		BoxGrid.SetData = function(NoOfItems, HTML) {
			if(!NoOfItems) {
				
				var newInner = $(BoxGrid.Settings.NoResultLayerId).innerHTML;
			} else {
				var newInner = HTML;
			}
			$(BoxGrid.Settings.GridWrapperId).innerHTML = newInner;
		}
		
		BoxGrid.ToggleLoader = function(state) {
			var Show = state || false;
			if(Show) {
				new Effect.Appear(BoxGrid.Settings.LoaderLayerId, {duration:0.5, from:0, to:1});
			} else {
				new Effect.Fade(BoxGrid.Settings.LoaderLayerId, {duration:0.5, from:1, to:0});
			}
		}
		
		BoxGrid.SortGenderTabs = function(key) {
			with (BoxGrid.Settings.Tabs) {
				if (key == 'm') {
					$(WomanId).className = WomanClassPrefix+'off';
					$(BothId).className = BothClassPrefix+'off';
					$(ManId).className = ManClassPrefix+'on';
				} else if (key == 'f') {
					$(ManId).className = ManClassPrefix+'off';
					$(BothId).className = BothClassPrefix+'off';
					$(WomanId).className = WomanClassPrefix+'on';
				} else {
					$(ManId).className = ManClassPrefix+'off';
					$(WomanId).className = WomanClassPrefix+'off';
					$(BothId).className = BothClassPrefix+'on';
				}
			}
		}
		
		//////////////////////////////////////////////////////////////////////////////
		/////////////////////////////////                  ///////////////////////////
		/////////////////////////////////    PAGINATION    ///////////////////////////
		//////////////////////////////////////////////////////////////////////////////
		
		BoxGrid.Pagination = new Object();
		
		BoxGrid.Pagination.Settings = {
			NextId : 'ListNext',
			PreviousId : 'ListPrevious',
			Details : {}
		}
		
		BoxGrid.Pagination.Update = function() {
			
			$(BoxGrid.Pagination.Settings.NextId).onclick = FlirtXchange.Common.CancelEvent;
			$(BoxGrid.Pagination.Settings.PreviousId).onclick = FlirtXchange.Common.CancelEvent;
			
			var Details = BoxGrid.Pagination.Settings.Details;
			
			with($(BoxGrid.Pagination.Settings.NextId)) {
				if(Details.CurrentPage != Details.PagesInSet) { //If there is more pages in the set. 
					style.display = 'inline';
					onclick = BoxGrid.Pagination.MoveForward;
				}
				else if((Details.CurrentPage == Details.PagesInSet) && (Details.CurrentSet < Details.Sets)) 
				{  //If there is no more pages in the set and next set is available
					style.display = 'inline';
					onclick = BoxGrid.Pagination.GetNextSet;
				} else {
					style.display = 'none';
				}
			}
			with($(BoxGrid.Pagination.Settings.PreviousId)) {
				if(Details.CurrentPage > 1)
				{
					style.display = 'inline';
					onclick = BoxGrid.Pagination.MoveBack;
				}
				else if((Details.CurrentPage == 1) && (Details.CurrentSet > 0))
				{
					style.display = 'inline';
					onclick = BoxGrid.Pagination.GetPreviousSet;
				} else {
					style.display = 'none';
				}
			}			
		}
		
		BoxGrid.Pagination.GetNextSet = function() {
			List.LoadSet(1);
		}
		
		BoxGrid.Pagination.GetPreviousSet = function() {
			List.LoadSet(-1);
		}
		
		BoxGrid.Pagination.MoveForward = function() {
			BoxGrid.Pagination.Move(-1);
		}
		
		BoxGrid.Pagination.MoveBack = function() {
			BoxGrid.Pagination.Move(1);
		}
		
		BoxGrid.Pagination.Move = function(direction) {
			if(FlirtXchange.Common.Busyness.IsBusy('ListPagination')) return;
			FlirtXchange.Common.Busyness.Set('ListPagination', true, 700);
			new Effect.Move(BoxGrid.Settings.GridWrapperId, {y: 0, x: (direction * BoxGrid.Settings.GridSinglePageWidth), duration: 0.6, mode: 'relative'});
			BoxGrid.Pagination.Settings.Details.CurrentPage = BoxGrid.Pagination.Settings.Details.CurrentPage - direction; 
			BoxGrid.Pagination.Update();
		}
		
		