
var dataContainer = function(){
					
    // create the Data Store
    ds = new Ext.data.Store({
        // create reader that reads the Topic records
        reader: new Ext.data.JsonReader({
			root: 'properties',
			totalProperty: 'totalCount'
        },[
		   {name: 'propprice', mapping: 'prop_price', type: 'float'},
		   {name: 'propid', mapping: 'prop_id', type: 'int'},
		   {name: 'displayid', mapping: 'display_id', type: 'int'},
		   {name: 'thumbid', mapping: 'thumb_id', type: 'int'},
           {name: 'propname', mapping: 'prop_name'},
		   {name: 'propbaths', mapping: 'prop_baths'},
		   {name: 'propbeds', mapping: 'prop_beds'},
           {name: 'proparea', mapping: 'prop_area'},
		   {name: 'propfeature', mapping: 'prop_feature'},
		   {name: 'featureicon', mapping: 'prop_featureimg'}
		]),
		
        // turn on remote sorting
        remoteSort: false
			
    });
	
	ds.setDefaultSort('featureicon', 'asc');
	
	function renderPropname(value){
        return String.format('<b>{0}</b>', value);
    }
	
	function renderNumber(value){
        return String.format('<b>{0}</b>', value);
    }
	
	function renderStatus(value){
        return String.format('<b>{0}</b>', value);
    }
	
	
	 // PROPERTY DETAILS SWF ***********************************************************************************
	
	function thisMovie(movieName){
	var isIE=navigator.appName.indexOf("Microsoft")!= -1;
	return (isIE)?window[movieName]:document[movieName];
	}
	
	function talkToFlash(popid,featured){	
	SetCookie('mlsid', popid,1);
	makeCall(popid,featured, 3);
	}

	function makeCall(propID,featured, frame){
	thisMovie("propertydetails").loadImage(propID,featured, frame);
	}
	
	function SetCookie(cookieName,cookieValue,nDays) {
	 var today = new Date();
	 var expire = new Date();
	 if (nDays==null || nDays==0) nDays=1;
	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+ ";path=/";
	 window.document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+ ";path=/";
	}

	//************************************************************************************************************
	
	
	
	function getImg(value, p, record) {
	return '<img src="http://images.mlsvallarta.com/foundset/' + value + '.jpg" width="80px" height="60px" style="margin-top:-3px; margin-bottom:-3px; margin-left:-5px;">';
	//if(featured = 2){return '<img src="/puerto-vallarta/imagebank/pru/' + value + '/' + value + '_thumb.jpg" width="80px" height="60px" style="margin-top:-3px; margin-bottom:-3px; margin-left:-5px;">' };
	}
	
	function getLogo(value, p, record) {
		return '<img src="/images/featured/' + value + '_logo.jpg" width="80px" height="60px" style="margin-top:-3px; margin-bottom:-3px; margin-left:-5px;">'; 
	}
	
	
    // the column model has information about grid columns
    // dataIndex maps the column to the specific data field in
    // the data store
    var cm = new Ext.grid.ColumnModel([{
		   header: "Thumbnail",
		   dataIndex: 'propid',
		   sortable: false,
		   resizable: false,
		   renderer: getImg,
           width: 80
        },{
           header: "Price USD",
           dataIndex: 'propprice',
		   sortable: true,
           width: 100,
		   align : "right",
		   renderer: Ext.util.Format.usMoney
        },{
           header: "Property Name",
           dataIndex: 'propname',
		   sortable: true,
		   renderer: renderPropname,
           width: 175
        },{
           header: "Beds",
           dataIndex: 'propbeds',
		   sortable: true,
           width: 45
        },{
           header: "Baths",
           dataIndex: 'propbaths',
		   sortable: true,
           width: 45
        },{
           header: "Property Region",
           dataIndex: 'proparea',
		   sortable: true,
           width: 172
        },{
           header: "Featured by",
           dataIndex: 'featureicon',
		   sortable: true,
		   resizable: false,
		   renderer: getLogo,
           width: 80
        },{
           header: "ID",
           dataIndex: 'displayid',
		   sortable: true,
		   renderer: renderNumber,
           width: 60
        }]);
	
// by default columns are sortable
    cm.defaultSortable = true;
	

    // create the editor grid
    var grid = new Ext.grid.Grid('prudential-grid', {
        ds: ds,
        cm: cm,
        selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
        enableColLock:false,
        loadMask: true
    });
	
	grid.on('rowclick', function(grid, rowIndex, e) {
		rec = ds.getAt(rowIndex);
		value = rec.get('propid');
		featured = rec.get('propfeature');
		talkToFlash(value,featured);
		//Ext.MessageBox.alert(value);
            });

    // make the grid resizable, do before render for better performance
    var rz = new Ext.Resizable('prudential-grid', {
        wrap:true,
        minHeight:100,
        pinned:true,
        handles: 's'
    });
	
    rz.on('resize', grid.autoSize, grid);
	

    // render it
    grid.render();
	

    var gridFoot = grid.getView().getFooterPanel(true);
	

    // add a paging toolbar to the grid's footer
    var paging = new Ext.PagingToolbar(gridFoot, ds, {
        pageSize: 25,
        displayInfo: true,
        displayMsg: 'Displaying properties {0} - {1} of {2}',
        emptyMsg: "No properties to display"
    });
	

    // trigger the data store load
	// load using script tags for cross domain, if the data in on the same domain as
    // this page, an HttpProxy would be better
	
	FP = function() {
		ds.proxy = new Ext.data.HttpProxy({url:'/cfm/featureproperties.cfm'});
		ds.load({params:{start:0, limit:25}});	
	}
	
	UUID = function() {
		ds.proxy = new Ext.data.HttpProxy({url:'/cfm/UUIDproperties.cfm'});
		ds.load({params:{start:0, limit:25}});	
	}
	
	UUIDpreconstruction = function() {
		ds.proxy = new Ext.data.HttpProxy({url:'/cfm/UUIDpreconstruction.cfm'});
		ds.load({params:{start:0, limit:25}});	
	}
	
	
	//********
	//******* TEST AREA
	


	//********
	//********
	
		 
};

Ext.onReady(function() {
			dataContainer();
			});


