/*
 * Ext JS Library 2.0.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

    var myData = [
        ['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=6" target="_blank" style="color:#15428b;">Quinn, A.</a>',36,21,4,11,1,5,1,23,6,6,.541],
        ['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=9" target="_blank" style="color:#15428b;">Kumpf, J.</a>',10,0,0,0,0,0,0,2,5,5,.000],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=7" target="_blank" style="color:#15428b;">Christian, B.</a>',5,3,1,1,0,1,0,6,5,0,.601],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=11" target="_blank" style="color:#15428b;">Whitmer, D.</a>',13,10,4,1,2,3,1,12,5,1,.769],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=1" target="_blank" style="color:#15428b;">Garner, C.</a>',34,15,4,5,1,5,1,21,16,11,.441],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=2" target="_blank" style="color:#15428b;">Bozack, T.</a>',6,3,1,2,0,0,0,9,10,3,.500],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=4" target="_blank" style="color:#15428b;">Golden, K.</a>',25,11,8,3,0,0,0,7,13,6,.431],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=3" target="_blank" style="color:#15428b;">Swolfs, J.</a>',14,4,1,2,0,1,0,7,7,6,.273],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=10" target="_blank" style="color:#15428b;">Lenci, D.</a>',7,1,0,0,0,1,0,4,2,1,.142],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=8" target="_blank" style="color:#15428b;">Kertesz, D.</a>',10,2,1,0,0,1,0,1,4,2,.200],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=5" target="_blank" style="color:#15428b;">Tomson, D.</a>',21,11,2,3,1,5,1,20,11,4,.536],
		['<a href="http://spreadsheets.google.com/ccc?key=t_3ZsuA_jFgThjkWa4h9AgQ&output=html&gid=0" target="_blank" style="color:#15428b;">Clancy, J.</a>',16,9,6,2,0,1,0,10,5,5,.532]
    ];

    // example of custom renderer function
    function change(val){
        if(val > 0){
            return '<span style="color:black;">' + val + '</span>';
        }else if(val < 0){
            return '<span style="color:black;">' + val + '</span>';
        }
        return val;
    }

    // example of custom renderer function
    function pctChange(val){
        if(val > 0){
            return '<span style="color:black;">' + val + '%</span>';
        }else if(val < 0){
            return '<span style="color:black;">' + val + '%</span>';
        }
        return val;
    }

    // create the data store
    var store = new Ext.data.SimpleStore({
        fields: [
           {name: 'player'},
           {name: 'ab', type: 'float'},
           {name: 'h', type: 'float'},
           {name: '1b', type: 'float'},
		   {name: '2b', type: 'float'},
		   {name: '3b', type: 'float'},
		   {name: 'hr', type: 'float'},
		   {name: 'cyc', type: 'float'},
		   {name: 'rbi', type: 'float'},
		   {name: 'bb', type: 'float'},
		   {name: 'ko', type: 'float'},
		   {name: 'ba', type: 'float'}
        ]
    });
    store.loadData(myData);

    // create the Grid
    var grid = new Ext.grid.GridPanel({
        store: store,
        columns: [
            {id:'player',header: "Player", width: 75, sortable: true, dataIndex: 'player'},
            {header: "AB", width: 38, sortable: true, dataIndex: 'ab'},
            {header: "H", width: 38, sortable: true, dataIndex: 'h'},
            {header: "1B", width: 38, sortable: true, dataIndex: '1b'},
            {header: "2B", width: 38, sortable: true, dataIndex: '2b'},
            {header: "3B", width: 38, sortable: true, dataIndex: '3b'},
            {header: "HR", width: 38, sortable: true, dataIndex: 'hr'},
			{header: "CYC", width: 38, sortable: true, dataIndex: 'cyc'},
            {header: "RBI", width: 38, sortable: true, dataIndex: 'rbi'},
            {header: "BB", width: 38, sortable: true, dataIndex: 'bb'},
            {header: "KO", width: 38, sortable: true, dataIndex: 'ko'},
            {header: "BA", width: 38, sortable: true, dataIndex: 'ba'}
        ],
        stripeRows: true,
        //autoExpandColumn: 'player',
        height:315,
        width:500,
        title:'2008 Batters'
    });

    grid.render('batters');

    grid.getSelectionModel().selectFirstRow();
});
