/* 
 This file was generated by Dashcode.  
 You may edit this file to customize your widget or web page 
 according to the license.txt file included in the project.
 */
 
var baseUrl = '/vision2020';
var panel='';

function init_attendee()
{
	vision2020.log("init");
	panel = $('panel').value;

    vision2020.getLogin();
   initPanel();

}

function initPanel()
{
	document.getElementById('login_button').onclick = vision2020.login_button_handler;
	document.getElementById('login_submit').onclick = vision2020.login_submit;
	switch (panel)
	{
		case 'welcome':
			vision2020.getRegistrationSummary();
			break;
		case 'sessions':
			CreateList('session_menu_list', { dataSourceName: 'session_days', useDataSource: true}).reloadData();
			CreateList('programs_list', { dataSourceName: 'programSchedule', useDataSource: true}).reloadData();
			CreateList("session_links_list", { dataSourceName: "session_links",  useDataSource: true }).reloadData();
			CreateList("session_questions_list", { dataSourceName: "session_questions",  useDataSource: true }).reloadData();
			CreateList("session_presenters_list", { dataSourceName: "session_presenters",  useDataSource: true }).reloadData();
			CreateList("session_discussion_list", { dataSourceName: "session_chat",  useDataSource: true }).reloadData();
			CreateList("question_responses", { dataSourceName: "session_question",  useDataSource: true }).reloadData();
			CreateList("question_answers", { dataSourceName: "session_question_answers",  useDataSource: true }).reloadData();			
			CreateList("evaluation0_responses", { dataSourceName: "session_evaluation",  useDataSource: true }).reloadData();
			CreateList("evaluation1_responses", { dataSourceName: "session_evaluation",  useDataSource: true }).reloadData();
			CreateList("evaluation2_responses", { dataSourceName: "session_evaluation",  useDataSource: true }).reloadData();
			CreateList("evaluation3_responses", { dataSourceName: "session_evaluation",  useDataSource: true }).reloadData();
			document.getElementById('session_info_button').onclick = function() { session.setPanel('info') };
			document.getElementById('session_links_button').onclick = function() { session.setPanel('links') };
			document.getElementById('session_questions_button').onclick = function() { session.setPanel('questions') };
			document.getElementById('session_discussion_button').onclick = function() { session.setPanel('discussion') };
			document.getElementById('session_add_link_button').onclick = function() { session.setPanel('links_add') };
			document.getElementById('post_submit').onclick = session_chat.submit;
			document.getElementById('submit_response').onclick = session_question.submit;
			document.getElementById('view_results').onclick = session_question.view_results;
			document.getElementById('session_rate_button').onclick = session.start_evaluation;
			document.getElementById('submit_evaluation').onclick = session_evaluation.submit;
			document.getElementById('links_save_button').onclick = session_links.submit;
			vision2020.getSchedule();
			break;
		case 'directory':
		    document.getElementById('searchfield').onkeyup = directoryController.search;
		    document.getElementById('directory_back').onclick = directoryController.showDirectoryList;
			CreateList("directoryList", { dataSourceName: "directoryController",  useDataSource: true }).reloadData();
			directoryController.loadAttendees();
			break;
		case 'local':
		    document.getElementById('local_uc').onclick = function(e) { localController.loadContent('local_uc', 'About UC'); }
		    document.getElementById('local_daap').onclick = function(e) { localController.loadContent('local_daap', 'About DAAP'); }
			break;		
		case 'freedomis':
			CreateList("freedom_is_list", { dataSourceName: "freedom_is",  useDataSource: true }).reloadData();
			break;
	}
}	
	

var vision2020 = {
	LOGGING: false,
    ERROR_NO_USER:-1,
    ERROR_USER_ALREADY_SUBMITTED:-2,
    login_form_visible: false,
    user: {},
	log: function(msg) {
		if (!vision2020.LOGGING) return;
		try { console.log(msg); } catch (e) {}		
	},
	prepareList: function(elementOrID, dataSource) {
		var spec= { dataSourceName: dataSource, useDataSource: true};

		var listElement = elementOrID;
		if (elementOrID.nodeType != Node.ELEMENT_NODE) {
			listElement = document.getElementById(elementOrID);
		}
		
		if (listElement && !listElement.loaded) {
			listElement.loaded = true;
			listElement.object = new List(listElement, spec);
			
			return listElement.object;
		}
	
	},
    is_loggedIn: function() {
        return this.user.vision2020_userID ? true : false;
    },
    getUserID: function() {
        return this.user.vision2020_userID;
    },
    getLogin: function() {
        vision2020.loadURL(baseUrl + '/js?get=user', vision2020.processUser);
    },
    orientationchanged: function() {
        //vision2020.log("Orientation changed, now: " + window.orientation);
    },
    show_login_form: function() {
        //turn on visibility first
        document.getElementById('login_form').style.visibility='visible';
		document.getElementById('login_form').style.display='block';
        document.getElementById('login_userID').value='';
        document.getElementById('login_form').style.webkitTransform='translateY(0)';    
        document.getElementById('login_result').innerHTML='';
        document.getElementById('login_button').innerHTML = 'Cancel';
        vision2020.login_form_visible = true;;
        //scrollTo(0,1);
    },
    hide_login_form: function() {
		document.getElementById('login_form').style.display='none'
        document.getElementById('login_button').innerHTML = vision2020.is_loggedIn() ? 'Logout' : 'Login';
        vision2020.login_form_visible = false;
    },
    currentView:function() {
        return document.getElementById('browser').object.getCurrentView().id;
    },
    toggle_login_form: function() {
        if (this.login_form_visible) {  
            this.hide_login_form();
        } else {
            this.show_login_form();
        }
    },
	login_button_handler: function()
	{
		if (vision2020.is_loggedIn()) {
			vision2020.logout();
		} else {
			vision2020.toggle_login_form();
		}
	},
    
    //handler for processing user JSON
    processUser: function(xhr) {
        try {
            var user = eval("(" + xhr.responseText + ")");
            vision2020.user = user;
            
            //set cookie to persist login
            if (vision2020.user.vision2020_userID) {
                document.cookie = 
                'vision2020_userID=' + vision2020.user.vision2020_userID+ '; expires=Sun, 11 Oct 2037 00:00:00 UTC; path=/vision2020/';
            } else {
                document.cookie = 
                'vision2020_userID=; expires=Sun, 9 Jul 2006 00:00:00 UTC; path=/vision2020/';
            }
        } catch (e) {
            vision2020.log(e);
            vision2020.log("Error loading " + xhr.url);
            vision2020.log(xhr.responseText);
        }
        
        vision2020.updateUserElements();
    },
    //update elements based on login status
    updateUserElements: function() {
        if (vision2020.is_loggedIn()) {
            document.getElementById('login_status').innerHTML='<span id="vision2020_userID">' + vision2020.user.user.FirstName + ' '+ vision2020.user.user.LastName + '</span> logged in';
            document.getElementById('login_status').style.display='block';
            document.getElementById('login_button').innerHTML = 'Logout';
        } else {
            document.getElementById('login_status').style.display='none';
            document.getElementById('login_button').innerHTML = 'Login';
        }
    },
    //figure out what AJAX method to use. This allows us to use this in other, cough cough IE, cough cough, browsers
 	getXMLHttpRequest: function() {
 		var funcs = [
		  function() {return new XMLHttpRequest()},
		  function() {return new ActiveXObject('Msxml2.XMLHTTP')},
		  function() {return new ActiveXObject('Microsoft.XMLHTTP')}
		];
		var transport = false;
		
		for (var i=0; i<funcs.length; i++) {
			var lambda = funcs[i];
			try {
				transport = lambda();
				break;
			} catch (e) { }
		}
		
		return transport;
	},
	//generic ajax function that takes a url, callback function and some options.
    loadURL: function(url, callback, options) {
    	
        var xhr = vision2020.getXMLHttpRequest();
        
        //options are basically method and params to handle POST requests
        if (typeof options=='undefined') {
        	options = { method: 'GET', params: '', synchronous: false}
        }

        options.method = options.method ? options.method : 'GET';
        options.params = options.params ? options.params : '';
        options.asynchronous = options.synchronous ? options.synchronous : false;

        vision2020.log('loading (' + options.method + '/' + (options.synchronous ? 'S' : 'A') +'): ' + url + ' (' + options.params + ')');

    	xhr.open(options.method, url, !options.synchronous);
    	
    	//add the post header
        if (options.method == 'POST') {
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        }

		//if we have a callback, set it
        if (callback) {
            xhr.onreadystatechange = function() {
            	if (xhr.readyState==4) {
					callback(xhr);
				}
            }
        }

        xhr.send(options.params);        
            
    },
    
    logout: function()
    {
        var url=baseUrl+ '/login?action=logout&js=true';
        vision2020.loadURL(url, vision2020.processUser);
    },
    login_submit: function() {
		var login_userID = document.getElementById('login_userID').value;
		
		if (vision2020.login(login_userID)) {
			document.getElementById('login_result').innerHTML='Logging in...';    
		}
    },
    login: function(login_userID)
    {
        if (login_userID.length==0) {
            return false;
        }
        var url=baseUrl+ '/login';
        var params='login_userID=' + escape(login_userID) + '&login_submit=js&js=true';
        
        var options = { method: 'POST', params: params };
        
        vision2020.loadURL(url, vision2020.processLogin, options);
        return true;
    },
    processLogin: function(xhr) {
    	//get the result, pass it to the login_result element
        try {
            var result = eval("(" + xhr.responseText + ")");
            if (result.error_message) {
                document.getElementById('login_result').innerHTML=result.error_message;
                return;
            } else {
                document.getElementById('login_result').innerHTML='';
            }
        } catch (e) {    
            vision2020.log(xhr.responseText);
            return;
        }
        
        //hide the form and then update the user var
        vision2020.hide_login_form();
        vision2020.processUser(xhr);
    },
    
    //figure out what today is.
    getCurrentDay: function()
    {
    	//set it to "today" at midnight
        var now = new Date();
        now.setHours(0);
        now.setMinutes(0);
        now.setSeconds(0);
        now.setMilliseconds(0);
        var schedule_data = this.getSchedule();
        for (var i=0; i< schedule_data.length;i++) {
            if (now.getTime()==schedule_data[i].date.getTime()) {
            	
            	//the day matches
                return schedule_data[i].day;
            }
        }

		//return the first day
        return schedule_data[0].day;
    },
    getDaySchedule: function(day)
    {
        if (typeof day=='undefined' || day.length==0) {
            return null;
        }
        var schedule_data = this.getSchedule();
        for(var i=0; i < schedule_data.length; i++) {
            if (schedule_data[i].day==day) {
                return schedule_data[i];
            }
        }
        vision2020.log("Can't find schedule for " + day);
        return null;
    },
    schedule_loaded: false,
    schedule_loading: false,
    getSchedule: function() 
    {
    	//don't try and load the schedule more than once or while its already loading
        if (!this.schedule_loaded && !this.schedule_loading) {
            this.schedule_loading=true;
            var url = baseUrl+'js?get=schedule';
            vision2020.loadURL(baseUrl + '/js?get=schedule', vision2020.processSchedule);
        }
        return this.schedule_data;
    },
    processSchedule: function(xhr)
    {
        try {
            var schedule_data = eval("(" + xhr.responseText + ")");
            for (var i=0; i<schedule_data.length; i++) {                
                schedule_data[i].date = new Date(schedule_data[i].date);
                
            }
        } catch (e) {
            vision2020.log(xhr.responseText);
            var schedule_data = [];
        }
        
        vision2020.setSchedule(schedule_data);
        vision2020.schedule_loading=false;
        vision2020.schedule_loaded = true;
    },
    setSchedule: function(schedule_data)
    {
        this.schedule_data = schedule_data;
        document.getElementById('session_menu_list').object.reloadData();
        programSchedule.setDay();
    },
    //bare bones static schedule so we can load the schedule lazily, but still have the structure
    schedule_data: [ 
        { day: 'wed', date: new Date(2008, 7, 6), schedule: [] },
        { day: 'thurs', date: new Date(2008, 7, 7), schedule: [] },
        { day: 'fri', date: new Date(2008, 7, 8), schedule: [] }
    ],
    
    registration_summary: {},
    getRegistrationSummary: function() {
        vision2020.loadURL(baseUrl + '/js?get=registration_summary', vision2020.processRegistrationSummary);
    },
    processRegistrationSummary: function(xhr) {
        try {
            var registration_summary = eval("(" + xhr.responseText + ")");
        } catch (e) {
            vision2020.log(xhr.responseText);
            var registration_summary = {};
        }
        vision2020.setRegistrationSummary(registration_summary);
    },
    setRegistrationSummary: function (registration_summary)
    {
        this.registration_summary = registration_summary;
        document.getElementById('demo_text').innerHTML="There are " + this.registration_summary.total + ' attendees representing ' + this.registration_summary.organizations_count + ' organizations from ' + this.registration_summary.states_count + ' states attending this conference';

        var img = document.getElementById('demo_img');
        if (!img) {
            img = document.createElement('img');
            img.id = 'demo_img';
            document.getElementById('demo_container').appendChild(img);
        }
        img.src = this.getChartDemoURL();
    },
    getChartDemoURL: function() {
        var src = 'http://chart.apis.google.com/chart?chtm=usa&chs=332x166&cht=t&chco=22222200,eeeeee,FECD66&chf=bg,s,000000';
        var states = [];
        var values = [];
        for (var state in this.registration_summary.states) {
            states.push(state);
            values.push(Math.floor(this.registration_summary.states[state]*100/this.registration_summary.total));
        }
        src += '&chd=t:' + values.join(',');
        src += '&chld=' + states.join('');
        
        return src;
    },
	showSessionDetail: function() {
		document.getElementById('programs_list').style.display='none';
		document.getElementById('session_page').style.display='block';
		session.setPanel('info');
		//browserController.goForward('sessions_page', session.session_title);
	},
	//generic handler to just replace the contents of an element with the results of the "template" defined in the js script
    loadContent: function(element, template) {
        if (!document.getElementById(element)) {
            return;
        }
        vision2020.loadURL(baseUrl + '/js?get=' + template, function(xhr) { vision2020.processContent(xhr, element)});
    },
    processContent: function(xhr, element) {
        try {
            var content = eval("(" + xhr.responseText + ")");
            document.getElementById(element).innerHTML=content;
        } catch (e) {
            vision2020.log(xhr.responseText);
        }
    }
}

//controller for attendee diretory
var directoryController = {
	_loaded: false,
	_loading: false,
    attendees: [],
    rowElements: [],
    detail_attendee: null,    
    reloadView: false,
    browserHandler: function(view) {
        if (!this._loaded) {
            directoryController.loadAttendees();
        }
    },
    _processAttendees: function(xhr) {
        try {
            var attendees = eval("(" + xhr.responseText + ")");
        } catch (e) {
            vision2020.log(xhr.responseText);
            var attendees = [];
        }
        directoryController._loading = false;
        directoryController.setAttendees(attendees);
        if (directoryController.reloadView) {
            browserController.setCurrentView(directoryController.reloadView);
            directoryController.reloadView = false;
        }
    },
    setAttendees: function(attendees)
    {
    	this.attendees = attendees;
        this.rowElements = [];
        this._loaded = attendees.length>0 ? true : false;
        document.getElementById('directoryList').object.reloadData();
    },
    loadAttendees: function() {
        if (this._loading) return;
        this._loading = true;
        var url = baseUrl + '/js?get=attendees';
        vision2020.loadURL(url, directoryController._processAttendees, { synchronous: true} );
    },
    setDirectoryDetail: function(attendee)
    {
        this.detail_attendee=attendee;
        this.updateDetail();
		document.getElementById('directory_list').style.display='none';
		document.getElementById('directory_detail').style.display='block';

    },
    showDirectoryList: function() {
		document.getElementById('directory_detail').style.display='none';
		document.getElementById('directory_list').style.display='block';
    },
    updateDetail: function()
    {
        document.getElementById('directory_detail_name').innerHTML = this.detail_attendee.FirstName + ' ' + this.detail_attendee.LastName;
        document.getElementById('directory_detail_image').src = baseUrl + '/' + this.detail_attendee.image_url;
        document.getElementById('directory_detail_organization').innerHTML = this.detail_attendee.organization;
        document.getElementById('directory_detail_email').innerHTML = this.detail_attendee.email;
        document.getElementById('directory_detail_email').onclick = function() {
            window.location='mailto:' + directoryController.detail_attendee.email;
        }
        document.getElementById('directory_detail_title').innerHTML = this.detail_attendee.title;
        document.getElementById('directory_detail_dept').innerHTML = this.detail_attendee.dept;
        
        if (this.detail_attendee.discussion) {
            document.getElementById('directory_detail_discussion').style.display='block';
            document.getElementById('directory_detail_discussion_topic').innerHTML = this.detail_attendee.discussion.discussion_topic;
            document.getElementById('directory_detail_discussion_room').innerHTML = this.detail_attendee.discussion.discussion_room;
        } else {
            document.getElementById('directory_detail_discussion').style.display='none';
        }
    },
    
    search: function() {
        var searchValue = document.getElementById('searchfield').value.toLowerCase();
        
        //turn on or off cancel button depending on length
        //document.getElementById('searchCancel').style.display = searchValue.length>0 ? 'block' : 'none';
        
        //match each row
        for (var i=0; i< directoryController.attendees.length; i++) {
            if (directoryController.attendees[i].FirstName.toLowerCase().match(searchValue) ||
                directoryController.attendees[i].LastName.toLowerCase().match(searchValue) ||
                directoryController.attendees[i].organization.toLowerCase().match(searchValue)) {
                directoryController.rowElements[i].style.display='';
            } else {
                directoryController.rowElements[i].style.display='none';
            }
        }
    },

	//called by list part	
	numberOfRows: function() {
		if (!this._loaded) {
			//directoryController.loadAttendees();
		}
		return this.attendees.length;
	},
	
	prepareRow: function(rowElement, rowIndex, templateElements) {
		//set the row so we can possibly hide it when searching
        this.rowElements[rowIndex] = rowElement;
        rowElement.attendee = this.attendees[rowIndex];
        //set list template
        templateElements.name.innerHTML = rowElement.attendee.FirstName + ' ' + rowElement.attendee.LastName;
        templateElements.organization.innerHTML = rowElement.attendee.organization;

		//set click handler
		rowElement.onclick = function(event) {
            directoryController.setDirectoryDetail(rowElement.attendee);
            browserController.goForward('directory_detail', rowElement.attendee.FirstName + ' ' + rowElement.attendee.LastName);
		};
	}
};

//handler for session schedule
var programSchedule = {	
    day: '',
    date: new Date(),
    schedule: [],
    setSchedule: function(data)
    {
        this.schedule=data;
        
    },
    getSchedule: function() {
        return this.schedule;
    },	
	numberOfRows: function() {
		return this.schedule.length;
	},
    setDay: function(day)
    {
    	//get the schedule for that day
        var daySchedule = vision2020.getDaySchedule(day);
        //if we cant find it, use "today's" schedule
        if (!daySchedule) {
            daySchedule = vision2020.getDaySchedule(vision2020.getCurrentDay());
        }
       
        this.day = daySchedule.day;
        this.date = daySchedule.date;
        this.setSchedule(daySchedule.schedule);
        document.getElementById('session_day').innerHTML = this.date.formatDate('l F j');
        
        var schedule_data = vision2020.getSchedule();
        
        //set the day menu to the current day
        for (var i=0; i<schedule_data.length; i++) {
            if (this.day == schedule_data[i].day) {
                addClassName(document.getElementById('session_menu_' + schedule_data[i].day), 'active');
            } else {
                removeClassName(document.getElementById('session_menu_' + schedule_data[i].day), 'active');
            }
        }
        
        //load the list
        document.getElementById('programs_list').object.reloadData();

    },
	prepareRow: function(rowElement, rowIndex, templateElements) {
        var event_data = this.schedule[rowIndex];
        var time = new Date(event_data.start_date);
        templateElements.programList_time.innerHTML = time.formatDate('h:i');     

		//if it's a session it'll have a click handler, show the arrow etc		
        if (event_data.session_id) {
        	// don't show the number for registration, etc
            if (event_data.session_id==100) {
                templateElements.programList_title.innerHTML = event_data.title;
            } else {
                templateElements.programList_title.innerHTML = event_data.session_id + ' ' + event_data.title;
            }
            templateElements.programList_arrow.style.display='block';
            
            rowElement.onclick = function() {
            	//set the title before loading
                session.setTitle(event_data.title);
                session.loadSessionData(event_data.session_id);
                vision2020.showSessionDetail();
            }
        } else {
            templateElements.programList_title.innerHTML = event_data.title;
            templateElements.programList_arrow.style.display='none';            
        }

        if (event_data.detail) {
            templateElements.programList_detail.innerHTML = event_data.detail;
            templateElements.programList_detail.style.display='block';
        } else {
            templateElements.programList_detail.innerHTML = '';
            templateElements.programList_detail.style.display=event_data.room ? 'block' : 'none';
        }
            
        templateElements.programList_room.innerHTML = event_data.room ? event_data.room : '';
        
	}
};

//handler for the "local info"
var localController = {

	//deal with logo on or off, etc.
    browserHandler: function(view) {
        switch (view)
        {
            case 'local_uc':
            case 'local_daap':
                browserController.setLogo(false);
                vision2020.loadContent(view +'_text', view);                
                break;
            case 'local_maps_daap':
                browserController.setLogo(false);
                daapmap.init();
                break;
            case 'local_freedom_is':
                document.getElementById('freedom_is_list').object.reloadData();
            case 'local_freedom':
                browserController.setLogo(false);
                break;
            default:
                browserController.setLogo(true);
                break;
        }
    },	
    
    loadContent: function(view, heading) {
		document.getElementById('local_heading').innerHTML = heading;
		vision2020.loadContent('local_text', view);                
		document.getElementById('local_menu').style.display='none';
		document.getElementById('local_content').style.display='block';
		return false;
    },
    showMenu: function() {
		document.getElementById('local_menu').style.display='';
		document.getElementById('local_content').style.display='none';
    },

	_rowData: [
        { tag: 'local_uc', label:'About UC'},
        { tag: 'local_daap', label:'About DAAP'},
        { tag: 'local_maps', label:'Maps'},        
        { tag: 'local_freedom', label:'Freedom Center'}
    ],
	
	numberOfRows: function() {
		return this._rowData.length;
	},
	
	prepareRow: function(rowElement, rowIndex, templateElements) {
        rowElement.data = this._rowData[rowIndex];
        templateElements.local_label.innerHTML = this._rowData[rowIndex].label;

		rowElement.onclick = function(event) {
            browserController.goForward(rowElement.data.tag, rowElement.data.label);			
		};
	}
};

//handler for the maps
var maps_controller = {
	
	_rowData: [ 
        { label: 'Campus Map (pdf)', url: 'http://www.uc.edu/architect/documents/Logistics/logisticsbw.pdf', new_window:true }, 
        { label: 'East Campus/Marriott (pdf)', url: 'http://www.uc.edu/architect/documents/Logistics/logisticsbw_east.pdf', new_window: true},
        { label: 'Campus Map (Google)', url: 'http://maps.google.com/maps?ll=39.131791,-84.515011&z=16', new_window:false },
        { label: 'Downtown Cincinnati', url: 'http://maps.google.com/maps?ll=39.101025,-84.511728&z=15', new_window:false },
        { label: 'DAAP Interactive Map', view: 'local_maps_daap', title:'DAAP' },
        
	],
	numberOfRows: function() {
		return this._rowData.length;
	},
	
	prepareRow: function(rowElement, rowIndex, templateElements) {
        templateElements.maps_list_label.innerHTML = this._rowData[rowIndex].label;
        rowElement.data = this._rowData[rowIndex];
		rowElement.onclick = function(event) {
			//for maps app to work you have to load in same window, otherwise be nice and load in new window 
            if (rowElement.data.url) {
                if (rowElement.data.new_window) {
                    window.open(rowElement.data.url);
                } else {
                    window.location=rowElement.data.url;
                }
            } else if (rowElement.data.view) {
                browserController.goForward(rowElement.data.view, rowElement.data.title);
            }
		};
	}
};

//handler for session. the big boy
var session = {
    SESSION_RELOAD_INTERVAL: 60,
    _loading:false,
    current_panel: null,
    active_button: '',
    session_id: '000',
    session_title: 'Session',
    session_abstract: '',
    session_question: null,
    session_links: [],
    session_questions: [],
    session_presenters: [],
    session_chat:[],
    session_userdata: [],
    last_chat: 0,
    browserBackHandler: function(view) {
        vision2020.log('session.browserBackHandler (' + view + ')');
        switch (view)
        {
            case 'sessions_page':
            case 'sessions_question_ask':
            case 'sessions_question_response':
                return;
        }
        
        session.stopReload();
    },
    browserHandler: function(view) {
        vision2020.log('session.browserHandler (' + view + ')');
        switch (view)
        {
            case 'sessions':
                vision2020.getSchedule();
                break;
            case 'sessions_page':
            case 'sessions_question_ask':
            case 'sessions_question_response':
                session.startReload(session.SESSION_RELOAD_INTERVAL);
                break;
        }
    },
    processSessionData: function(xhr) {
        try {
            var session_data = eval("(" + xhr.responseText + ")");
            if (session_data.session_id) {
                session.setSessionData(session_data);
                session._loading = false;
            }
        } catch (e) {
            vision2020.log(e);
            vision2020.log("Error loading " + xhr.url);
            vision2020.log(xhr.responseText);
            session._loading = false;
        }
    },    
    setSessionData: function(session_data) {
        this.session_id = session_data.session_id;
        this.setTitle(session_data.session_title);
        this.setAbstract(session_data.session_abstract);
        this.setUserData(session_data.session_userdata);
        this.setLinks(session_data.session_links);
        this.setQuestions(session_data.session_questions);
        this.setPresenters(session_data.session_presenters);
        this.setChat(session_data.session_chat);
    },
    reloadTimer: null,
    reloadInterval: null,
    startReload: function(reloadInterval)
    {
        if (session.reloadTimer && reloadInterval == session.reloadInterval) {
            return;
        }
        session.stopReload();
        session.reloadInterval = reloadInterval;
        vision2020.log("Starting session reload timer of " + session.reloadInterval + " seconds");
        session.reloadTimer = setInterval(session.refresh, session.reloadInterval*1000);
    },
    stopReload: function()
    {
        if (!session.reloadTimer) {
            return;
        }
        vision2020.log('Stopping session reload timer');
        clearInterval(session.reloadTimer);
        session.reloadTimer=null;
    },
    refresh: function()
    {
        session.loadSessionData(session.session_id);
    },
    loadSessionData: function(session_id) {
        if (this._loading) {
            return;
        }
        this._loading = true;
        if (session_id != session.session_id) {
            session.session_question_index = null;
            document.getElementById('session_title').innerHTML='Loading...';
            document.getElementById('session_abstract').innerHTML='Loading...';
        }
        vision2020.loadURL(baseUrl + '/js?get=session&session_id=' + session_id, session.processSessionData);
   },
   showQuestion: function() {
        if (this.session_userdata.questions[session_question.question_id]) {
           session.setPanel('question_response');
           //browserController.goForward('sessions_question_response', session_question.question_text);
        } else {
           session.setPanel('question_ask');
           //browserController.goForward('sessions_question_ask', session_question.question_text);
        }
    },

    setPanel: function(panel) {
        var active_button = panel;
        var reloadInterval = session.SESSION_RELOAD_INTERVAL;
        switch (panel)
        {
            case 'info':
                break;
            case 'links_add':
                active_button='links';
            case 'links':
                break;
            case 'question_response':
            case 'question_ask':
                active_button='questions';
            case 'questions':
                if (this.session_questions.length==0) {
                    return;
                }
                break;
            case 'evaluation':
            case 'evaluation_thanks':
                active_button='info';
                break;
            case 'discussion':
                reloadInterval = 10;
                break;
            default:
                vision2020.log("We didn't handle setPanel for " + panel);
                break;
        }
        
        if (this.active_button) {
			removeClassName('session_' + this.active_button + '_button', 'button_active');
		}

        addClassName('session_' + active_button + '_button', 'button_active');
        
        if (this.current_panel) {
			$('session_' + this.current_panel + '_panel').style.display='none';
		}
        $('session_' + panel + '_panel').style.display='block';
        this.current_panel = panel;
        this.active_button = active_button;
        session.startReload(reloadInterval);
        //scrollTo(0,1);
    },
    setTitle: function(title) {
        this.session_title = title;
        if (this.session_id==100 || !this.session_id) {
            document.getElementById('session_title').innerHTML=this.session_title;
        } else {
            document.getElementById('session_title').innerHTML=this.session_id + ' ' + this.session_title;
        }
        
    },
    setAbstract: function(abstract) {
        this.session_abstract = abstract;
        document.getElementById('session_abstract').innerHTML=this.session_abstract;
    },
    setLinks: function(links) {
        this.session_links = links;
        document.getElementById('session_links_list').object.reloadData();
        document.getElementById('session_links_list').style.display=this.session_links.length>0 ? 'block' : 'none';
    },
    setQuestion: function(question_index) 
    {
        if (this.session_questions[question_index]) {
            this.session_question = this.session_questions[question_index];
            session_question.setQuestion(this.session_question);
        } else {
            this.session_question = null;
        }
    },
    setQuestions: function(questions) {
        this.session_questions = questions;
        document.getElementById('session_questions_list').object.reloadData();
        document.getElementById('session_questions_list').style.display=this.session_questions.length>0 ? 'block' : 'none';
        if (questions.length>0) {
            removeClassName('session_questions_button', 'button_disabled');
        } else {
            addClassName('session_questions_button', 'button_disabled');
        }
        
        if (this.session_question) {
            this.setQuestion(this.session_question.index);
        }
    },
    session_chat_last_post_id: null,
    setChat: function(chat) {
        if (chat[0] && chat[0].post_id==this.session_chat_last_post_id) {
            return;
        }
    
        this.session_chat = chat;
        this.session_chat_last_post_id = this.session_chat[0] ? this.session_chat[0].post_id : null;
        for (var i=0; i<this.session_chat.length; i++) {
            this.session_chat[i].date = new Date(this.session_chat[i].date);
        }

        
        document.getElementById('session_discussion_list').object.reloadData();
        document.getElementById('session_discussion_list').style.display = this.session_chat.length>0 ? 'block' : 'none';
        document.getElementById('session_discussion_count').innerHTML = 'There have been ' + this.session_chat.length + ' posts.';

    },

    setPresenters: function(presenters) {
        this.session_presenters = presenters;
        document.getElementById('session_presenters_list').object.reloadData();
        document.getElementById('session_presenters_list').style.display = this.session_presenters.length>0 ? 'block' : 'none';
    },
    
    post_chat: function(post_text) {
        var url = baseUrl + '/js?post=chat';
        var params='session_id=' + session.session_id+'&post_text=' + escape(post_text);
		var options = { method: 'POST', params: params}
        vision2020.loadURL(url, session.processChat, options);
        return true;
    },
    processChat: function(xhr)
    {
        try {
            var session_chat = eval("(" + xhr.responseText + ")");
            if (session_chat.error_message) {
                if (session_chat.error_code==vision2020.ERROR_NO_USER) {
                    vision2020.show_login_form();
                    document.getElementById('login_result').innerHTML='You must login to post';
                    return;
                } else {
                    alert(session_chat.error_message);
                }
            } else {
                session.setChat(session_chat);
                document.getElementById('post_text_field').value='';
            }
        } catch (e) {
            vision2020.log(e);
            vision2020.log("Error loading " + xhr.url);
            vision2020.log(xhr.responseText);
        }
    },
    setUserData: function(userdata)
    {
        this.session_userdata = userdata;
    },
	show_add_link: function()
	{
		if (!vision2020.is_loggedIn()) {
			vision2020.show_login_form();
			document.getElementById('login_result').innerHTML='You must login to post';
			return;
		}
		document.getElementById('link_url_field').value='http://';
		document.getElementById('link_title_field').value='';
		session.setPanel('links_add');
	},
	start_evaluation: function() {
		if (!vision2020.is_loggedIn()) {
			vision2020.show_login_form();
			document.getElementById('login_result').innerHTML='You must login to post';
			return;
		}
		if (session.session_userdata.evaluation) {
			session.setPanel('evaluation_thanks');
		} else {
            session_evaluation.setQuestion(0);
			session.setPanel('evaluation');
		}
	}	
    
};

var session_links = {
    processSessionLinks: function(xhr)
    {
    	//we'll get back an error object if a post failed
        try {
            var session_links = eval("(" + xhr.responseText + ")");
            if (session_links.error_message) {
                if (session_links.error_code==vision2020.ERROR_NO_USER) {
                    vision2020.show_login_form();
                    document.getElementById('login_result').innerHTML='You must login to post';
                    return;
                } else {
                    alert(session_links.error_message);
                    return;
                }
            } else {
                session.setLinks(session_links);
            }
        } catch (e) {
            vision2020.log(e);
            vision2020.log("Error loading " + xhr.url);
            vision2020.log(xhr.responseText);
        }
    },
    submit: function() {
        var link_url = document.getElementById('link_url_field').value;
        if (!link_url.match("^https?://.+")) {
            alert("Invalid url.");
            return;
        }
        var link_text = document.getElementById('link_title_field').value;
        if (link_text.length==0) {
            alert("Please include a title");
            return;
        }
        var url = baseUrl + '/js?post=link&session_id=' + session.session_id + '&link_url=' + escape(link_url)+'&link_text='+escape(link_text);
        vision2020.loadURL(url, session_links.processSessionLinks);
        session.setPanel('links');
    },
    numberOfRows: function() {
        return session.session_links.length;
    },

    prepareRow: function(rowElement, rowIndex, templateElements) {
        addClassName(rowElement, "link_type_" + session.session_links[rowIndex].link_type);
        rowElement.url = session.session_links[rowIndex].link_url;
        templateElements.session_links_label.innerHTML = session.session_links[rowIndex].link_text;
        rowElement.onclick = function(event) {
            window.open(rowElement.url);
        };
    }
};

var session_questions = {
    numberOfRows: function() {
        return session.session_questions.length;
    },

    prepareRow: function(rowElement, rowIndex, templateElements) {
        rowElement.question_id = session.session_questions[rowIndex].question_id;
        var index = session.session_questions[rowIndex].index+1;
        templateElements.session_question_num.innerHTML = index+'.';
        templateElements.session_question_text.innerHTML = session.session_questions[rowIndex].question_text;
        // Assign a click event handler for the row.
        rowElement.onclick = function(event) {
            session.setQuestion(rowIndex);
            session.showQuestion();
        };
    }
	
};

var session_question_answers = {
	
	numberOfRows: function() {
		return session_question.responses.length;
	},
	
	prepareRow: function(rowElement, rowIndex, templateElements) {
        templateElements.question_response_text_label.innerHTML = session_question.responses[rowIndex].response_text;
        templateElements.question_response_count.innerHTML = session_question.answers[session_question.responses[rowIndex].response_value];

	}
};

var session_presenters = {

    numberOfRows: function() {
        return session.session_presenters.length;
    },

    prepareRow: function(rowElement, rowIndex, templateElements) {
        rowElement.presenter=session.session_presenters[rowIndex];
        templateElements.presenter_name.innerHTML=rowElement.presenter.FirstName + ' ' + rowElement.presenter.LastName;
        templateElements.presenter_organization.innerHTML=rowElement.presenter.organization;
		rowElement.onclick = function(event) {
            directoryController.setDirectoryDetail(rowElement.presenter);
            browserController.goForward('directory_detail', rowElement.presenter.FirstName + ' ' + rowElement.presenter.LastName);
        }
        
    }
	
};

var session_evaluation = {
	
	_responses:[        
     ["Exceptional", "Good", "Fair", "Poor"],
     ["Exceptional", "Good", "Fair", "Poor"],
     ["Exceptional", "Good", "Fair", "Poor"],
     ["Definitely Yes", "Maybe", "Possibly", "Unlikely"],
     ],
     selected_responses: [],
     rows: [],
                               	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		return 4;
	},
    _fixing: false,
    _oldclass: 'listRowTemplate_template',
    currentQuestion: 0,
    setQuestion: function(questionIndex) 
    {
    	return;
        if (questionIndex>=0 && questionIndex<=4) {
            document.getElementById('session_evaluation_stack').object.setCurrentView('question' + questionIndex);
            this.currentQuestion = questionIndex;
        } else {
            vision2020.log("Invalid evaluation question: " + questionIndex);
        }
        
        document.getElementById('submit_evaluation_prev').style.display = this.currentQuestion>0 ? '' : 'none';
        document.getElementById('submit_evaluation_next').object.setText(this.currentQuestion<4 ? 'Next' : 'Finish');
    },
    next: function() 
    {
        if (session_evaluation.currentQuestion<4) {
            session_evaluation.setQuestion(session_evaluation.currentQuestion+1);
        } else {
            session_evaluation.submit();
        }
    },
    previous: function() 
    {
        if (session_evaluation.currentQuestion>0) {
            session_evaluation.setQuestion(session_evaluation.currentQuestion-1);
        }
    },
    selectResponse: function(questionIndex, rowIndex)
    {
    	
        vision2020.log("Selecting " + rowIndex + " from question " + questionIndex);
        for (var i=0; i<this.rows[questionIndex].length; i++) {
            removeClassName(this.rows[questionIndex][i], 'row_selected');
        }

        addClassName(this.rows[questionIndex][rowIndex], 'row_selected');
        i = questionIndex;
        for (var j=0; j<this.rows[i].length; j++) {
            if (hasClassName(this.rows[i][j], 'row_selected')) {
                this.selected_responses[i]=this.rows[i][j].response_value;
            }
        }
    },
	
	prepareRow: function(rowElement, rowIndex, templateElements) {
		//pretty hackish, I know
        if (templateElements.evaluation0_response) {
            var questionIndex=0;
        } else if (templateElements.evaluation1_response) {
            var questionIndex=1;
        } else if (templateElements.evaluation2_response) {
            var questionIndex=2;
        } else if (templateElements.evaluation3_response) {
            var questionIndex=3;
        } else {
            return;
        }

        if (rowIndex==0) {
            this.rows[questionIndex]=[];
        }

		//add row to elements array so we can style it later when selecting        
        this.rows[questionIndex].push(rowElement);
        
        rowElement.questionIndex = questionIndex;
        rowElement.response_value = rowIndex+1;
        
        templateElements['evaluation' + questionIndex + '_response'].innerHTML=this._responses[questionIndex][rowIndex];
		rowElement.onclick = function() {
            session_evaluation.selectResponse(questionIndex, rowIndex);
		};
	},
    processEvaluation: function(xhr) {
        try {
            var result = eval("(" + xhr.responseText + ")");
            if (result.error_message) {
                switch (result.error_code)
                {
                    case vision2020.ERROR_NO_USER:
                        vision2020.show_login_form();
                        document.getElementById('login_result').innerHTML='You must login to post';
                        return;
                    case vision2020.ERROR_USER_ALREADY_SUBMITTED:
                        break;
                    default:
                        alert(result.error_message);
                        return;
                }
            } else {
            	//evaluation has been submitted
            	session.setUserData(result);
            }
            
            //show thanks panel, then go back to info panel in a few seconds.
            session.setPanel('evaluation_thanks');
            //setTimeout(function() { session.setPanel('info'); }, 3000);
        } catch (e) {
            vision2020.log(e);
            vision2020.log("Error loading " + xhr.url);
            vision2020.log(xhr.responseText);
        }    
    },
    submit:function()
    {
        //build up the url to send. 
        var url = baseUrl + '/js?post=evaluation';
        
        var params='session_id=' + session.session_id;
        
        for (var i=0; i<4; i++) {
            if (typeof session_evaluation.selected_responses[i]!='undefined') {
                params+='&responses['+i+']='+session_evaluation.selected_responses[i];
            }
        }
        params+='&responses[4]='+ escape(document.getElementById('evaluation_comments').value);
        
        var options = { method: 'POST', params: params };   
        vision2020.loadURL(url, session_evaluation.processEvaluation, options);
        return;
    }
};

var session_days = {
    
	numberOfRows: function() {
        //var schedule_data = vision2020.getSchedule();
        return vision2020.schedule_data.length;
	},
	
	prepareRow: function(rowElement, rowIndex, templateElements) {
        //var schedule_data = vision2020.getSchedule();
        var data = vision2020.schedule_data[rowIndex];
        rowElement.id='session_menu_' + data.day;
        rowElement.day = data.day;
        templateElements.session_menu_label.innerHTML=data.date.formatDate('l');

		rowElement.onclick = function(event) {
            programSchedule.setDay(rowElement.day);
		};
	}
};

var session_chat = {
	numberOfRows: function() {
		return session.session_chat.length;
	},
	prepareRow: function(rowElement, rowIndex, templateElements) {
        templateElements.post_timestamp.innerHTML = session.session_chat[rowIndex].date.formatDate("m/d h:i:s");
        templateElements.post_user.innerHTML = session.session_chat[rowIndex].post_name;
        templateElements.post_text.innerHTML = session.session_chat[rowIndex].post_text;
	},
	submit:function() {
			var post_text = document.getElementById('post_text_field').value;
		if (post_text.length==0) {
			return;
		}
		session.post_chat(post_text);
	}	
};

//this is the active question
var session_question = {
    rowElements: [],
    setQuestion: function(question) {
        this.session_id = question.session_id;
        this.question_id = question.question_id;
        this.setResponses(question.responses);
        this.setAnswers(question.answers);
        this.setQuestionText(question.question_text);
        this.question_minchoices = question.question_minchoices;
        this.question_maxchoices = question.question_maxchoices;
        this.chart_type = question.chart_type;
        this.response_type = question.response_type;
        this.updateResults();
        return;
    },
    answers: [],
	responses: [],
    selected_responses: [],
	numberOfRows: function() {
		return this.responses.length;
	},
	prepareRow: function(rowElement, rowIndex, templateElements) {
        this.rowElements[rowIndex] = rowElement;
        rowElement.response_value = this.responses[rowIndex].response_value;
        templateElements.question_response_label.innerHTML = this.responses[rowIndex].response_text;
		rowElement.onclick = function(event) {
            session_question.selectResponse(rowIndex);
		};
	},
    setQuestionText: function(text)
    {
        this.question_text = text;
        document.getElementById('question_text').innerHTML = this.question_text;
        document.getElementById('question_response_text').innerHTML = this.question_text;
    },
    setAnswers: function(answers)
    {
        this.answers = answers;
        document.getElementById('question_answers').object.reloadData();
        document.getElementById('question_response_total').innerHTML=this.answers.total+ " responses";
    },
    setResponses: function(responses)
    {
        this.responses = responses;
        this.rowElements = [];
        document.getElementById('question_responses').object.reloadData();
    },
    selectResponse: function(rowIndex) {
        if (this.question_maxchoices>1) {
            toggleClassName(this.rowElements[rowIndex], 'row_selected');
        } else {
            for (var i=0; i<this.rowElements.length; i++) {
                if (i==rowIndex) {
                    addClassName(this.rowElements[i], 'row_selected');
                } else {
                    removeClassName(this.rowElements[i], 'row_selected');
                }
            }
        }

        this.selected_responses=[];
        for (var i=0; i<this.rowElements.length; i++) {

            if (hasClassName(this.rowElements[i], 'row_selected')) {
                this.selected_responses.push(this.responses[i].response_value);
            }
        }        
    },
    submit: function() {
        if (!vision2020.is_loggedIn()) {
            vision2020.show_login_form();
            document.getElementById('login_result').innerHTML='You must login to post';
            return;
        }       
        
        //check to make sure right number of responses selected
        if (session_question.selected_responses.length < session_question.question_minchoices ||session_question.selected_responses.length>session_question.question_maxchoices) {
            if (session_question.question_minchoices==0) {
                alert("Please select up to " + session_question.question_maxchoices + " choices.");
            } else {
                alert("Please select between " + session_question.question_minchoices + " and " + session_question.question_maxchoices + " choices.");
            }
            return;
        }

        //build the url
        var url = baseUrl + '/js?post=question&question_id=' + session_question.question_id;
        
        for (var i=0; i<session_question.selected_responses.length; i++) {
            url+='&response[]='+session_question.selected_responses[i];
        }
        
        vision2020.loadURL(url, session_question.processSubmitQuestion);
        return;
    },
    processSubmitQuestion: function(xhr) {
        try {
            var result = eval("(" + xhr.responseText + ")");
            if (result.error_message) {
                switch (result.error_code)
                {
                    case vision2020.ERROR_NO_USER:
                        vision2020.show_login_form();
                        document.getElementById('login_result').innerHTML='You must login to post';
                        return;
                    case vision2020.ERROR_USER_ALREADY_SUBMITTED:
                        alert(result.error_message);
                        break;
                    default:
                        alert(result.error_message);
                        return;
                }
            } else {
                session.refresh();
                session_question.setAnswers(result.answers);
            } 
            
            session_question.view_results();

        } catch(e) {
            vision2020.log(e);
            vision2020.log(xhr.responseText);
            alert("Error saving answer");
            return;
        }
    },
    updateResults: function() {
        var img = document.getElementById('question_response_chart');

        //create the chart
        if (!img) {
            var img = document.createElement('img');
            img.id = 'question_response_chart';
            document.getElementById('question_response_box').appendChild(img);
        }

        if (this.answers.total==0) {
            img.style.display='none';
            return;
        }
        
        img.style.display='';
        var src = this.getChartURL();
        if (img.src != src) {
            img.src=src;
        }
    },
    
    //build the chart based on the answers
    getChartURL: function() {
        
        var data = [];
        var labels = [];
        var max_data = 0;
        var add_zero = this.chart_type != 'p';
        
        //go through the responses, for pie charts, don't include responses with zero answers
        //max_data value represents the highest value and is used to scale the bar charts
        for (var i=0; i<this.responses.length; i++) {
            if (this.answers[this.responses[i].response_value]>0 || add_zero) {
                data.push(this.answers[this.responses[i].response_value]);
                if (this.answers[this.responses[i].response_value] > max_data) {
                    max_data = this.answers[this.responses[i].response_value];
                }
                
                labels.push(escape(this.responses[i].response_text));
            }
        }

		// base url with type, size and background
        var src = 'http://chart.apis.google.com/chart?cht=' + this.chart_type + '&chf=bg,s,00000000';

		// add the data using text encoding
		src +='&chd=t:'+data.join(",");
        
        //to make the legends easier on bar charts, use the next even number as 100%
        var even_total = this.answers.total % 2 ? (this.answers.total+1) : this.answers.total;
        var even_max = max_data % 2 ? (max_data+1) : max_data;
        
        switch (this.chart_type)
        {
            case 'p':
                src +='&chs=280x140';
                src +='&chl=' + labels.join("|");
                break;
            
            case 'bhs':
                src +='&chs=280x' + ((this.responses.length*33)+20);
                src +='&chxt=x,y';
                src +='&chds=0,' + even_max;
                labels.reverse();
                var range=[];
                for (i=0; i<=even_max; i+=2) {
                    range.push(i);
                }               
                                                
                src +='&chxl=0:|' + range.join("|") + '|1:|' + labels.join("|");
                break;
        }
        
        return src;
    },

    view_results: function() {
		session_question.updateResults();
        session.startReload(10);
		//browserController.setCurrentView('sessions_question_response');
        session.setPanel('question_response');
    }
    
};

var welcomeController = {
    browserHandler: function() {
        vision2020.getRegistrationSummary();
    }
}

var aboutController = {
    browserHandler: function() {
        vision2020.loadContent('about_text', 'about_site');
    }
}

var issues = {
    _issues: [],
    _loading: false,
    loadIssues: function() {
        if (this._loading) {
            return;
        }
        this._loading = true;
        vision2020.loadURL(baseUrl + '/js?get=issues', issues.processIssues);
    },
    processIssues: function(xhr) {
        try {
            var data = eval("(" + xhr.responseText + ")");
            issues._issues = data;
        } catch (e) {
            vision2020.log(e);
            vision2020.log("Error loading " + xhr.url);
            vision2020.log(xhr.responseText);
        }
        document.getElementById('issues_list').object.reloadData();
        issues._loading = false;    
    },
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
        if (this._issues.length==0) {
            this.loadIssues();
        }
		return this._issues.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
        templateElements.issue.innerText = this._issues[rowIndex].issue_text;
	}
};

var daapmap = {
    oldfloor: null,
	floor: null,
    setFloor: function(floor) {
        this.floor = parseInt(floor);
        if (this.floor != this.oldfloor) {
            this._setupParts();
        }
    },
	_rowData: ['3000','4000', '5000','6000'],
    //,'7000','8000'],
	
	numberOfRows: function() {
		return this._rowData.length;
	},
	orientationchanged: function() {
        daapmap._setupParts();
    },
    _setupParts: function() {
        document.getElementById('daapmap_map_img').src='maps/' + this.floor + '.png';
        if (this.oldfloor) {
            removeClassName(document.getElementById('daap_map_floor_' + this.oldfloor), 'floor_active');        
        }
        addClassName(document.getElementById('daap_map_floor_' + this.floor), 'floor_active');
        switch (window.orientation)
        {
            case 0:
                document.getElementById('local_maps_daap').className='portrait';
                var y = vision2020.is_loggedIn() ? 68 : 53; 
                scrollTo(0,68);
                break;
            case 90:
            case -90:
                document.getElementById('local_maps_daap').className='landscape';
                var y = vision2020.is_loggedIn() ? 75 : 60; 
                break;
        }
        scrollTo(0,y);
        
        this.oldfloor=this.floor;
    },
	prepareRow: function(rowElement, rowIndex, templateElements) {
        rowElement.floor = this._rowData[rowIndex];
        rowElement.id='daap_map_floor_' + rowElement.floor;
        templateElements.floor_label.innerText = this._rowData[rowIndex];

		// Assign a click event handler for the row.
		rowElement.onclick = function(event) {
            daapmap.setFloor(rowElement.floor);
		};
	},
    
    init: function(floor) {
        window.addEventListener('orientationchange', daapmap.orientationchanged);
        if (typeof floor=='undefined') {
            floor = 4000;
        }
        daapmap.setFloor(floor);
    }
};

var local_freedom = {
	
	_rowData: [
        { label: 'freedomcenter.org', url: 'http://www.freedomcenter.org/' },
        { label: 'Freedom is...', view: 'local_freedom_is', title: 'Freedom is...' }
    ],
	numberOfRows: function() {
		return this._rowData.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
        templateElements.freedom_label.innerText = this._rowData[rowIndex].label;
        rowElement.data = this._rowData[rowIndex];

		rowElement.onclick = function(event) {
            if (rowElement.data.url) {
                window.open(rowElement.data.url);
            } else if (rowElement.data.view) {
                browserController.goForward(rowElement.data.view, rowElement.data.title);
            }
		};
	}
};

var freedom_is = {
	
	_rowData: [
        { tag: 'Coloring', title:'Coloring', team:'Caireaux', organization:'Full Sail University', detail:'Grand Prize Winner'},
        { tag: 'Freedom_Video', title:  'Freedom', team:'JMU SMAD 2009', organization: 'James Madison University', detail:'Honorable Mention'},
        { tag: 'FreedomIs', title:'Freedom for Education', team:'Joi M. Sears', organization: 'New York University', detail:'Honorable Mention'},   
        { tag: 'FreedomIsBelief', title:'Freedom is Belief', team:'We Still Believe', organization: 'Brandeis University', detail:'Honorable Mention'},
        { tag: 'InDreamsKalimah', title:'In Dreams', team:'The People Could Fly', organization: 'Hollins Universtiy', detail:'Honorable Mention'},
        { tag: 'politicallyfree', title:'Politically Free', team:'Politically Free', organization: 'School of the Art Institute of Chicago', detail:'Honorable Mention'},
    ],
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		return this._rowData.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
        rowElement.data = this._rowData[rowIndex];
        templateElements.freedom_is_poster.src=baseUrl+'/freedomis/posters/' + rowElement.data.tag + '-poster.jpg';
        templateElements.freedom_is_title.innerHTML = rowElement.data.title;
        templateElements.freedom_is_detail.innerHTML = rowElement.data.detail;
        templateElements.freedom_is_team.innerHTML = rowElement.data.team;
        templateElements.freedom_is_organization.innerHTML = rowElement.data.organization;

		// Assign a click event handler for the row.
		rowElement.onclick = function(event) {
            window.location=baseUrl+'/freedomis/video/' + rowElement.data.tag + '/' + rowElement.data.tag + '.mov';
		};
	}
};

var browserController = {
    goForward: function(toView, title) {        
    	return;
        vision2020.hide_login_form();
        var browser = document.getElementById('browser').object;
        browser.goForward(toView, title, this.browserBackHandler);
        browserController.browserHandler(toView);
    },
	setCurrentView: function(toView)
	{
		document.getElementById('stackLayout').object.setCurrentView(toView);
	},
    _sections: [ 
        { tag:'home', name:'Vision2020', showLogo:true, scroll:true, home:false},
        { tag:'welcome', name:'Welcome', showLogo:false, scroll:true, home:true, controller: welcomeController},
        { tag:'sessions', name:'Sessions', showLogo:false, scroll:true, home:true, controller: session},
        { tag:'directory', name: 'Attendee Directory', showLogo:false, scroll:false, home:true, controller: directoryController},
        { tag:'local', name: 'Local Information', showLogo:true, scroll:true, home:true, controller: localController},
        { tag:'about', name:'About this site', showLogo: false, scroll: true, home:true, controller: aboutController},
        { tag:'issues', name:'Known Issues', showLogo:false, scroll: true, home:true}
    ],
    _homeSections:[],
     getSections:function() {
        if (this._homeSections.length) {
            return this._homeSections;
        }
        
        var sections = [];
        for (var i=0; i<this._sections.length; i++) {
            if (this._sections[i].home) {
                sections.push(this._sections[i]);
            }
        }
        this._homeSections = sections;
        return sections;
    },
    
    getSectionByTag:function(tag)
    {
        for (var idx in this._sections) {
            var section = this._sections[idx];
            if (tag.match('^' + section.tag)) {
               return section;
            }
        }
                
        vision2020.log("Couldn't find section: " + tag);
    },
    logoState: true,
    hideLogo: function()
    {
        var logo = document.getElementById('uc_logo');
        logo.style.visibility='hidden';
        logo.removeEventListener('webkitTransitionEnd', browserController.hideLogo);
    },
    setLogo: function(state)
    {
        var logo = document.getElementById('uc_logo');

        if (!this.logoState && state) {
            logo.style.visibility='visible';
        }

        this.logoState = state ? true : false;

        logo.style.opacity=this.logoState ? 1 : 0;

        if (!this.logoState) {
        	//actually hide the logo so it doesn't interfere with touching events
            logo.addEventListener('webkitTransitionEnd', browserController.hideLogo);
        }
    },
    browserBackHandler: function()
    {
        vision2020.hide_login_form();
        var browser = document.getElementById('browser').object;

        // we need to use timers until a valid call back is made once the selection has been changed
        var startView = browser.getCurrentView().id;
        var changed = function(prevView) {
            var view = browser.getCurrentView().id;        
            if (startView==view) {
                setTimeout(changed, 20, prevView);
                return;
            }

            var section = browserController.getSectionByTag(prevView);
            if (section && section.controller && section.controller.browserBackHandler) {
                section.controller.browserBackHandler(view);
            }

            browserController.browserHandler(view);
        }
        
        changed(startView);
        return;        
    },

    browserHandler: function(toView)
    {
        var browser = document.getElementById('browser').object;
        var view = browser.getCurrentView();
        var section = this.getSectionByTag(view.id);
        if (section) {

            browserController.setLogo(section.showLogo);
            if (section.scroll) {
                scrollTo(0,1);
            }
            
            if (section.controller) {
                if (section.controller.browserHandler) {
                    section.controller.browserHandler(view.id);
                }
            }
        }
    },
    
    numberOfRows: function() {
        return this.getSections().length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements) {
        var sections = this.getSections();
        if (templateElements.listTitle) {
            templateElements.listTitle.innerHTML = sections[rowIndex].name;
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        rowElement.onclick = function() {
            var section = sections[rowIndex];
            browserController.goForward(section.tag, section.name);
        };
    }
};

if (typeof DAAP !='undefined') {
	DAAP.onDOMReady(init_attendee);
}
