/* 
 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 listControllerMain = {
    // This object acts as a controller for the list UI.
    // It implements the dataSource methods for the list.
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
        return mainHelpLinks.length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements)
    {
        // The List calls this dataSource method for every row.  templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
        if (templateElements.rowTitle1)
        {
            templateElements.rowTitle1.innerText = mainHelpLinks[rowIndex].name;
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        var handler = function()
        {
            var helpLink = mainHelpLinks[rowIndex];
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            if(helpLink.name == "Introduction")
            {
                browser.goForward(document.getElementById('introduction'), helpLink.name);
            }
            else if(helpLink.name == "Reference")
            {
                browser.goForward(document.getElementById('listLevelTopicsWaveform'), helpLink.name);
            }
            else if(helpLink.name == "General Tasks")
            {
                browser.goForward(document.getElementById('listLevelTopicsGeneral'), helpLink.name);
            }
        };
        rowElement.onclick = handler;
    }
};

var topics = [
    { name: "Start/Stop", question: "Start the sound level meter", 
                    answer: "When dB launches, it will start measuring the sound level automatically. " +
                    "However, after one of the capture functions is selected, the meter will be paused " +
                    "to ensure that the desired reading is captured. After performing a capture, you can " +
                    "re-start the meter by pressing the reset button and confirming the reset action."},
    { name: "Save a photo", question: "Associate the current sound level with a photo",
                    answer: "Tap the capture button once to bring up the capture options menu. " +
                    "At the top of the menu, tap the Save Photo button. If you are using an iPhone, another " +
                    "menu will appear, which gives you the option to take a new photo with the built-in camera " +
                    "or to pick a photo from your photo library. On the iPod touch, you will automatically be " +
                    "presented with your photo library to pick an existing photo. Once you have selected a new or " +
                    "existing photo, a new view will appear, which will give you the option to enter descriptive " +
                    "text to be included at the bottom of the image. You can preview the final image by tapping " +
                    "the Preview button in the navigation bar. When previewing the image, you can either go back " +
                    "to the text entry view, to modify your text, or save the image. " +
                    "If you tap the Save button in the navigation bar, " +
                    "the image will be saved in your device's photo album. By exiting " +
                    "dB and viewing the image in the Photos application, you can " +
                    "use it as wallpaper, email it, or assign it to a contact."},
    { name: "Save an image of the sound level meter", question: "Save the current sound level with an image of the " +
                    "meter display",
                    answer: "Tap the capture button once to bring up the capture options menu. " +
                    "Tap the Save Graph button. A new view will appear, which will give you the option to enter " +
                    "descriptive text to be included at the bottom of the image. You can preview the final image " +
                    "by tapping the Preview button in the navigation bar. When previewing the image, you can " +
                    "either go back to the text entry view, to modify your text, or save the image. " +
                    "If you tap the Save button in the navigation bar, " +
                    "the image will be saved in your device's photo album. By exiting " +
                    "dB and viewing the image in the Photos application, you can " +
                    "use it as wallpaper, email it, or assign it to a contact."},
    { name: "Email the sound level", question: "Send the current sound level in an email",
                    answer: "Tap the capture button once to bring up the capture options menu. " +
                    "Tap the Email button. A new view will appear, which will give you the option to enter " +
                    "descriptive text to be included in the body of the email. You can preview the final message " +
                    "by tapping the Preview button in the navigation bar. When previewing the message, you can " +
                    "either go back to the text entry view, to modify your text, or proceed to the Mail app " +
                    "to finish composing and sending your email."},
    { name: "Include the sound level in a Twitter update", question: "Post the sound level to Twitter",
                    answer: "Tap the capture button once to bring up the capture options menu. " +
                    "Tap the Post to Twitter button. A new view will appear, which will give you the option to enter " +
                    "descriptive text to be included in the Twitter update. When entering your text, the number of " +
                    "characters available for your update will appear above the text area (remember that Tweets are " +
                    "limited to 140 characters, and your pre-filled data, such as date/time and location, will account " +
                    "for some of the available characters). You can preview the final message " +
                    "by tapping the Preview button in the navigation bar. When previewing the message, you can " +
                    "either go back to the text entry view, to modify your text, or post your update " +
                    "to your Twitter account. You will need to have your Twitter login information entered in the " +
                    "relevant text fields in dB's options. If your login information is not accepted by Twitter, " +
                    "you will be prompted to update it in the Options panel."},
    { name: "Select pre-filled capture data", question: "Choose which data to include in my captures",
                    answer: "In the dB Options panel, you can select whether dB should automatically " +
                    "include date and time and/or location information in data captures, including saved " +
                    "images, email messages, and Twitter updates. To reveal the options panel, tap the Options " +
                    "button in the main screen."}
];

var listControllerTopics = {
    // This object acts as a controller for the list UI.
    // It implements the dataSource methods for the list.
    
    numberOfRows: function() {
        // The List calls this dataSource method to find out how many rows should be in the list.
        return topics.length;
    },
    
    prepareRow: function(rowElement, rowIndex, templateElements) {
        // The List calls this dataSource method for every row.  templateElements contains references to all elements inside the template that have an id. We use it to fill in the text of the rowTitle element.
        if (templateElements.rowTitle) {
            templateElements.rowTitle.innerText = topics[rowIndex].question + "?";
        }

        // We also assign an onclick handler that will cause the browser to go to the detail page.
        var self = this;
        var handler = function() {
            var topic = topics[rowIndex];
            detailControllerTopics.setTopic(topic);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevelTopics'), topic.name);
        };
        rowElement.onclick = handler;
    }
};

var detailControllerTopics = {
    // This object acts as a controller for the detail UI.
    
    setTopic: function(topic) {
        this._topic = topic;
        this._representedObject = topic.name;
        
        // When the topic is set, this controller also updates the DOM for the detail page appropriately.  As you customize the design for the detail page, you will want to extend this code to make sure that the correct information is populated into the detail UI.
        var detailTitle = document.getElementById('detailTitle');
        detailTitle.innerHTML = this._topic.name;
        var detailLocation = document.getElementById('detailLocation');
        detailLocation.innerHTML = this._topic.question;
        var detailDescription = document.getElementById('detailDescription');
        detailDescription.innerHTML = this._topic.answer;
    }
    
};

//
// Function: load()
// Called by HTML body element's onload event when the web application is ready to start
//
function load()
{
    dashcode.setupParts();
}

var mainHelpLinks = [
    { name: "Introduction"},
    { name: "General Tasks"},
//    { name: "Waveform Tasks"}
    { name: "Reference"}
];

var referenceTopics = [
    { name: "Spectrum"},
    { name: "Waveform"},
    { name: "Options"}
];

// calibration topics
var spectrumTopics = [
];

// This object implements the dataSource methods for the list.
var listControllerTopicsSpectrum = {
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		 return spectrumTopics.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
		// templateElements contains references to all elements that have an id in the template row.
		// Ex: set the value of an element with id="label".
		if (templateElements.rowTitle3) {
			templateElements.rowTitle3.innerText = spectrumTopics[rowIndex].question + "?";
		}

		// Assign a click event handler for the row.
		var handler = function()
        {
            var topic = spectrumTopics[rowIndex];
            detailControllerTopics.setTopic(topic);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevelTopics'), topic.name);
        };
        rowElement.onclick = handler;
	}
};

// reference topics
var waveformTopics = [
    { name: "Accuracy", question: "Measurement accuracy",
                    answer: "Out of the box, few options exist for getting sound into the iPhone OS device. " +
                    "The most obvious " +
                    "is the iPhone's built-in microphone. The frequency response of the iPhone's built-in " +
                    "microphone is actually quite flat, which is not uncommon for inexpensive electret " +
                    "condenser microphones (ECM's). However, the built-in microphone on the original " +
                    "iPhone seems to be routed through a speech codec that significantly affects the " +
                    "frequency content of the signal, before it reaches the dB software. For " +
                    "this reason, using the built-in microphone on the original iPhone is not recommended " +
                    "for measuring sound levels. The headset " +
                    "included with each iPhone (original and 3G) and Apple's headsets for the iPod touch " +
                    "also employ ECM's, which will work " +
                    "for measuring sound levels. Default sensitivities for the built-in and headset mics " +
                    "are included in dB. These sensitivities should allow dB to measure " +
                    "sound levels to within 1 to 3 dB as soon as you use it, although the sensitivity of "+
                    "your particular microphone may cause the measured level to be off by as much as 6 dB. " +
                    "It should also be noted that " +
                    "peak sound levels of up to approximately 105 dB and 100 dB can be measured with the " +
                    "built-in and headset microphones, respectively. The maximum average level, " +
                    "that may be measured accurately without input clipping, " +
                    "will be lower."},
    { name: "Microphones", question: "Working with different microphones",
                    answer: "Third-party headset microphones, or measurement microphones, which can " +
                    "be connected to the device's headset or dock connector, may be used, although care should " +
                    "be taken to ensure that the frequency response and sensitivity of such microphones are " +
                    "suitable for sound level measurements with dB (microphone sensitivity " +
                    "calibration is only available in SoundMeter)."},
    { name: "Level Types", question: "Sound level types",
                    answer: "The exponential-time-weighted sound level, Lp, gives an estimate of the current " +
                    "average sound level. This is the only sound level type available in dB."},
    { name: "Frequency Weighting", question: "Frequency weighting",
                    answer: "Frequency weighting is only available in SoundMeter. " +
                    "SoundMeter provides a means of weighting the spectral content of input signals " +
                    "according to standard A and C frequency weighting curves. These A and C weighting curves " +
                    "are intended to mimic human perception of loudness at two different loudness levels. If " +
                    "Flat is selected, no frequency weighting is applied."},
    { name: "Time Weighting", question: "Time Weighting",
                    answer: "dB employs fast time weighting to compute the average sound level. " +
                    "Different time weighting options are only available in SoundMeter. " +
                    "SoundMeter offers three time weightings for the Lp sound level measurement: " +
                    "Fast, Slow, and Impulse. Fast time weighting computes the exponential-time-weighted " +
                    "average sound level with a time constant of 125 ms. The slow time weighting uses a " +
                    "time constant of 1000 ms, or 1 second. The impulse time weighting uses a rise time " +
                    "constant of 35 ms and a decay time constant of 1500 ms."},
    { name: "Max & Peak levels", question: "Max and peak sound levels",
                    answer: "Max refers to the maximum time-weighted average sound level that has been " +
                    "observed during the " +
                    "current measurement time. Peak refers to the maximum instantaneous sound pressure " +
                    "that has occurred during the current measurement time. The peak level will always be " +
                    "higher than the max level, and the max level will always be greater than or equal to " +
                    "the average level."},
    { name: "Reset", question: "Reset",
                    answer: "The Reset button clears out any previous peak and max sound levels and restarts " +
                    "the sound level computation for all sound level types."},
    { name: "Input Clipping", question: "Input Clipping",
                    answer: "When the input signal has been clipped, because it was too high for the device's " +
                    "audio input circuitry, the word 'clip' appears in red to the right of the average " +
                    "sound level display. The word 'clip' remains visible until the reset button is pressed, " +
                    "or until the meter is stopped and restarted. When the input is currently being clipped, " +
                    "a red box appears around the word 'clip'."}
];

// This object implements the dataSource methods for the list.
var listControllerTopicsWaveform = {
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		 return waveformTopics.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
		// templateElements contains references to all elements that have an id in the template row.
		// Ex: set the value of an element with id="label".
		if (templateElements.rowTitle4) {
			templateElements.rowTitle4.innerText = waveformTopics[rowIndex].question + "?";
		}

		// Assign a click event handler for the row.
		var handler = function()
        {
            var topic = waveformTopics[rowIndex];
            detailControllerTopics.setTopic(topic);
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevelTopics'), topic.name);
        };
        rowElement.onclick = handler;
	}
};


// This object implements the dataSource methods for the list.
var listControllerReference = {
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		 return referenceTopics.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
		// templateElements contains references to all elements that have an id in the template row.
		// Ex: set the value of an element with id="label".
		if (templateElements.rowTitle5) {
			templateElements.rowTitle5.innerText = referenceTopics[rowIndex].name;
		}

		// Assign a click event handler for the row.
		var handler = function()
        {
            var topic = referenceTopics[rowIndex];
            var browser = document.getElementById('browser').object;
            // The Browser's goForward method is used to make the browser push down to a new level.  Going back to previous levels is handled automatically.
            browser.goForward(document.getElementById('detailLevelReference'), topic);
        };
        rowElement.onclick = handler;
	}
};


function gotoMainPage(event)
{
    var browser = document.getElementById('browser').object;
    browser.goBack();
    browser.goBack();
    browser.goBack();
}

var resourceLinks = [
    { name: "Product Home Page", link: "http://www.faberacoustical.com/products/iphone/db"},
    { name: "Technical Support", link: "http://www.faberacoustical.com/products/iphone/db/support"},
    { name: "Other Faber Products", link: "http://www.faberacoustical.com/products"}
];

// This object implements the dataSource methods for the list.
var listControllerResources = {
	
	// The List calls this method to find out how many rows should be in the list.
	numberOfRows: function() {
		return resourceLinks.length;
	},
	
	// The List calls this method once for every row.
	prepareRow: function(rowElement, rowIndex, templateElements) {
		// templateElements contains references to all elements that have an id in the template row.
		// Ex: set the value of an element with id="label".
		if (templateElements.rowTitle2) {
			templateElements.rowTitle2.innerText = resourceLinks[rowIndex].name;
		}

		// Assign a click event handler for the row.
		var handler = function()
        {
            var resource = resourceLinks[rowIndex];
            document.location = resource.link;
        };
        rowElement.onclick = handler;
	}
};

