/**
 * View for the www.archiblox.com site.
 * 
 */
ArchibloxHomeView = function() {
}

ArchibloxHomeView.prototype = {
	mode: null,
	
	initializePage: function(defaultTabId){
	
		this.defaultTabId = defaultTabId;
		var viewPort = new Ext.Viewport({
			id: 'main-viewport',
			layout: 'fit',
			autoShow: true,
			bodyStyle: 'background-color: #e5e5e5',
			items: [this._getMainContent()]
		
		});
		
		this._setUpTabHandlers();
		
		if (this.defaultTabId == 'ab-tabitem-contact') {
			var googleMapIFrame = '<iframe width="500" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=411+E.+Wisconsin+Ave,+milwaukee+wi+53202&amp;sll=37.0625,-95.677068&amp;sspn=47.080837,59.853516&amp;ie=UTF8&amp;ll=43.048193,-87.902126&amp;spn=0.021361,0.029225&amp;z=14&amp;iwloc=addr&amp;output=embed&amp;s=AARTsJrO89qg_ufSDj-jmL4SiGtjIbsrbg"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q=411+E.+Wisconsin+Ave,+milwaukee+wi+53202&amp;sll=37.0625,-95.677068&amp;sspn=47.080837,59.853516&amp;ie=UTF8&amp;ll=43.048193,-87.902126&amp;spn=0.021361,0.029225&amp;z=14&amp;iwloc=addr&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small></iframe>';
			Ext.get('ab-map-div').update(googleMapIFrame);
		}
	}
	, _getMainContent : function () {
		Ext.form.Field.prototype.msgTarget = 'side';

		var homeHeaderHtml = 
		  '<div id="ab-home-header" style="padding: 9px 8px 3px 8px">'
          + '<table width="100%">'
          + ' <tr>'
          + '   <td><img src="images/logo_with_tagline_small_blue.png"></td>'
//          + '   <td align="right" width="100%"><a href="#">About Us</a> | <a href="#">Forum</a> </td>'               
          + '</tr>'
          + '</table>';        
       
	   
	    this.tabs = [
		    {
				name: 'Home',
				id: 'ab-tabitem-home',
				url: 'index.html'
			},
            {
                name: "Products",
                id: 'ab-tabitem-products',
                url: 'products.html'
            },
            {
                name: "About Us",
                id: 'ab-tabitem-about',
                url: 'about.html'
            },
            {
                name: "Contact",
                id: 'ab-tabitem-contact',
                url: 'contact.html'
            }
		];
	    var tabStripHtml = 
		 ' <div id="ab-content-tab-strip">'
         + '   <div class="ab-homepage-tab-strip">'
         + '           <table cellspacing="0" cellpadding="0" border="0"><tr>';
		 
		for (var i=0;i!=this.tabs.length;i++) {
			var tabInfo = this.tabs[i];
			tabStripHtml = tabStripHtml + 
			     '<td><a href="' + tabInfo.url + '">'
				 + '<div id="' + tabInfo.id + '" class="ab-homepage-tab-item">'
				 + '<span>' + tabInfo.name + '</span>'
				 + '</div></a>'
				 + '</td>' 
		}
		tabStripHtml = tabStripHtml + '           </tr></table>'
         + '   </div>'
         + '</div>';
	
		return {
            border: false,
            bodyBorder: false,
            layout: 'border',
            width: 760,
            items: [{
                region: 'center',
                autoWidth: false,
//              border: false,
//                bodyBorder: false,
                width: 760,
                layout: 'border',
                bodyStyle: 'border-color: #98AAB1',
                margins: {
                    top: 8,
                    left: 8,
                    right: 8,
                    bottom: 8
                },
                items: [{
                    border: false,
                    bodyBorder: false,
                    region: 'north',
                    height: 83,
                    html: homeHeaderHtml
                }, {
                    region: 'center',
                    layout: 'border',
                    border: false,
                    bodyBorder: false,
                    items: [
                        {
                            region: "north",
                            border: false,
                            cls: 'ab-tab-toolbar',
                            
                            bodyBorder: false,
                            height: 40,
							html: tabStripHtml
                        }, {
                            region: 'center',			
							autoScroll: true,				
							contentEl: 'ab-center-content',
                            border: false,
                            bodyBorder: false						
                        }
                    ]
                }, {
                    region: 'south',
                    border: false,
                    bodyBorder: false,
                    height: 28,
                    cls: 'ab-class-footer',
                    html: '<div id="ab-home-footer" style="padding: 8px">'
                         + '<center>Copyright © 2006-2009 Archiblox LLC. All Rights Reserved.</center>'
                         + '</div>' 
                
                }]
            }]
        
        }
	}
	
	/**
	 *
	 */
	,
	createMailingListForm: function(){
//		var form = new Ext.Panel(
//		{
//			layout: 'fit',
//			applyTo: 'mailinglist-form',
//			height: 90,
//			width: 350,
//
//			border: true,
//			bodyBorder: true,
//			items: [{
//				xtype: 'form',
//				border: false,
//				bodyBorder: false,
//
//				id: 'ab-homepage-mailform',
//				bodyStyle: 'padding:10px 10px 0',
//				labelWidth: 50,
//				items: [{
//					xtype: 'textfield',
//					fieldLabel: 'Email',
//					name: 'email',
//					vtype: 'email',
//					emptyText: 'your_email@host.com',
//					style: 'margin-right: 20px',
//					anchor: '-30',
//					allowBlank: false
//					//anchor:'-20'
//				}, {
//					xtype: 'checkbox',
//					boxLabel: 'Notify me of ProductStudio news',
//					checked: true,
//					name: 'notify',
//					style: 'margin-right: 20px',
//					anchor: '-30',
//					labelSeparator: ''
//					//anchor:'-20'
//				}],
//				buttons: [{
//					text: 'Send',
//					handler: function(){
//						Ext.getCmp('ab-homepage-mailform').form.submit({
//							url: '/scripts/store_mailinglist.php',
//							method: 'POST',
//							success: function(form, action){
//								var response = action.response;
//								var responseJsonString = response.responseText;
//								var responseJson;
//								if (responseJsonString) {
//									responseJson = eval("(" + responseJsonString + ")");
//								}
//								if (responseJson.success) {
//									Ext.getCmp('ab-homepage-mailform').form.reset();
//									Ext.Msg.alert("You are now signed up", "You have been added to our database.  Thanks for your interest.");
//								}
//								else {
//									this._handleSignupFailure();
//								}
//							},
//							failure: function(form, action){
//								if (action.failureType == 'client') {
//									return; // do no special handling when it is a client validation error.
//								}
//								this._handleSignupFailure();
//							},
//							scope: this
//						});
//					},
//					scope: this
//				}]
//			}
//			]
//		
//		
//		});
		
	},
	_setUpTabHandlers: function(){
		for (var i = 0; i != this.tabs.length; i++) {
			var tabInfo = this.tabs[i];
			if (tabInfo.id == this.defaultTabId) {
				Ext.get(tabInfo.id).removeClass('ab-homepage-tab-item');
				Ext.get(tabInfo.id).addClass('ab-homepage-tab-item-selected');
			}
		}
	},
	_handleSignupFailure: function(){
		Ext.Msg.alert("Sign up failed", "Sorry, sign up is not working at this time.  Please try again later.");
	}
}

