var win;
var winvideo;
var videobutton;
var button;
var reviewWindow;
var reviewListWindow;
var theForm;
var reviewGrid;
var reviewStore;

/*
function openScene(){
if(!reviewWindow){
		theForm = new Ext.form.FormPanel({
        url:'/index.php?action=addScene',
        frame:true,
        title: 'Add Event',
        bodyStyle:'padding:5px 5px 0',
	autoScroll       : true,
        width: 350
	
	});
       theForm.add(new Ext.form.TextField({
		name : 'sceneName',
		fieldLabel : 'Name'
		//applyTo : 'sceneName'
		    }));
       theForm.add(new Ext.form.TextField({
		name : 'sceneStartdate',
		fieldLabel : 'Start Date'
		//applyTo : 'sceneStartdate'
		    }));
       theForm.add(new Ext.form.TextField({
		name : 'sceneEnddate',
		fieldLabel : 'End Date'
		//applyTo : 'sceneEnddate'
		    }));
       theForm.add(new Ext.form.TextField({
		name : 'sceneAddress',
		fieldLabel : 'Address'
		//applyTo : 'sceneAddress'
		    }));
       theForm.add(new Ext.form.TextField({
		name : 'sceneZip',
		fieldLabel : 'Zip',
		//applyTo : 'sceneZip',
		value : '97330'
		    }));
        theForm.add(new Ext.form.ComboBox({
		name : 'sceneType',
		fieldLabel : 'Type',
		hiddenName : 'sceneType',
		store: new Ext.data.SimpleStore({
                            fields: ['code', 'sceneType'],
                            data : [['Arts & Culture','Arts &amp; Culture'],
					['Culinary & Wineries','Culinary &amp; Wineries'],
					['Fairs & Festivals','Fairs &amp; Festivals'],
					['Outdoors & Nature','Outdoors &amp; Nature'],
					['Conferences, Meetings & Lectures','Conferences, Meetings &amp; Lectures'],
					['Sports','Sports'],
					['Night Life','Night Life']]
                        }),
		mode: 'local',
		emptyText: 'Select a type...',
		displayField: 'sceneType',
		valueField: 'code'
		//applyTo : 'sceneType'
		    }));
       theForm.add(new Ext.form.TextArea({
        fieldLabel : 'Description',
        name : 'sceneDescription',
        height : 100,
	width : 200
	//applyTo : 'sceneDescription'
	    }));
       var submit = theForm.addButton({
        text: 'Submit',
        handler: function(){
		theForm.getForm().submit({ url:'/index.php?action=addScene', waitMsg:'Submitting Event...'});
	    //reviewWindow.close();
        }
    });
            reviewWindow = new Ext.Window({
              // applyTo     : 'popup',
               layout      : 'fit',
	       //items       : new Ext.TabPanel({
               //     applyTo        : 'popuptabs',
                //    autoTabs       : true,
		 //   autoScroll       : true,
               //     activeTab      : 0,
               //     deferredRender : false,
               //     border         : false,
		//    id		: 'popuptabs'
		   
               // }),
	       items : theForm,
               width       : 530,
               height      : 300,
               closeAction :'hide',
               plain       : true,
	       modal	   : false,
	       buttons: [{
                   text     : 'Close',
                   handler  : function(){
                       reviewWindow.hide();
                   }
               }]
           });
       }
       
       //theForm.render(document.getElementById('theSceneInfo'));
	reviewWindow.show();	
}
*/
function openReviewList(){
	if(!reviewListWindow){
	
	reviewStore = new Ext.data.Store({
			proxy: new Ext.data.HttpProxy({
			    url: 'index.php?action=listReviews&rowid='+rowid
			}),
		
			reader: new Ext.data.JsonReader({
			    root: "rows",
			    totalProperty: "totalCount",
			    id: "rowid"
			}, [
			    {name: 'rowid', mapping: 'rowid'},
			    {name: 'title', mapping: 'title',type: 'string'},
			    {name: 'review', mapping: 'review',type: 'string'},
			    {name: 'name', mapping: 'name',type: 'string'}
			    
			])
		    });	
	reviewStore.load();
	
	var reviewGrid = new Ext.grid.GridPanel({
        store: reviewStore,
        columns: [
            
	    {id: 'title', header: "Title", width:150, sortable: true, dataIndex: 'title'},
            {header: "Review", width: 225, sortable: true, dataIndex: 'review'},
            {header: "Name", width: 150, sortable: true, dataIndex: 'name'}
            
        ],
	enableHdMenu: false,
        stripeRows: true,
        autoExpandColumn: 'title',
        height:350,
        width:600
	});
	
	reviewListWindow = new Ext.Window({
               layout      : 'fit',
	       items : reviewGrid,
               width       : 550,
               height      : 300,
               closeAction :'hide',
               plain       : true,
	       modal	   : false,
	       title	   : 'Reviews',
	       buttons: [{
                   text     : 'Close',
                   handler  : function(){
                       reviewListWindow.hide();
                   }
               }]
           });	
	}
		
	reviewListWindow.show();
}
function openReview(){
	if(!reviewWindow){
		theForm = new Ext.form.FormPanel({
        url:'/index.php?action=addReview',
        frame:true,
        title: 'Add Review',
        bodyStyle:'padding:5px 5px 0',
	autoScroll       : true,
        width: 350
	
	});
       theForm.add(new Ext.form.TextField({
		name : 'title',
		fieldLabel : 'Title'
		    }));
       
       
       theForm.add(new Ext.form.TextArea({
        fieldLabel : 'Review',
        name : 'review',
        height : 100,
	width : 200
	    }));
       theForm.add(new Ext.form.TextField({
		name : 'name',
		fieldLabel : 'Name'
		    }));
       var submit = theForm.addButton({
        text: 'Submit',
        handler: function(){
		theForm.getForm().submit({success: reviewWindow.hide(), params:{reviewfor:rowid,section: section}, url:'/index.php?action=addReview', waitMsg:'Submitting Review...'});
        }
    });
            reviewWindow = new Ext.Window({
               layout      : 'fit',
	       items : theForm,
               width       : 530,
               height      : 300,
               closeAction :'hide',
               plain       : true,
	       modal	   : false,
	       buttons: [{
                   text     : 'Close',
                   handler  : function(){
                       reviewWindow.hide();
                   }
               }]
           });
       }
       
	reviewWindow.show();
}
function getY(obj)
{
  var curtop = obj.offsetHeight + 5;
  var border;
  if (obj.offsetParent)
  {
    do
    {
      // XXX: If the element is position: relative we have to add borderWidth
       curtop += obj.offsetTop;
    }
    while (obj = obj.offsetParent)
  }
  else if (obj.x)
  {
    curtop += obj.y;
  }
  curtop = curtop-150;
  return curtop;
}


function openVideo(videoid,videoObj){
	document.getElementById('popuppanel').innerHTML = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/'+videoid+'&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'+videoid+'&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>';
	//alert(getY(videoObj));
	 if(!winvideo){
           winvideo = new Ext.Window({
               applyTo     : 'videopopup',
               layout      : 'fit',
	       items       : new Ext.Panel({
                    applyTo        : 'popuppanel',
                    autoTabs       : true,
		    autoScroll       : true,
                    activeTab      : 0,
                    deferredRender : false,
                    border         : false
                }),
	       width       : 450,
               height      : 400,
               closeAction :'hide',
               plain       : true,
	       modal	   : false,
	       y	: videoObj.y,
	       //y	   : 50,
	       buttons: [{
                   text     : 'Close',
                   handler  : function(){
                       winvideo.hide();
                   }
               }]
           });
       }
       winvideo.y = getY(videoObj);
	winvideo.show();
}
/*
function openAddReview(){
	win.show();
	Ext.getCmp('popuptabs').activate(Ext.get('addTab').id);
}
*/
Ext.onReady(function(){
   if(document.getElementById('reviewbutton'))
	   button = Ext.get('reviewbutton');
   if(document.getElementById('videobutton'))
	   videobutton = Ext.get('videobutton');

});

