/* 
 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('referenceTop'), helpLink.name);
            }
            else if(helpLink.name == "Periodic Signals")
            {
                browser.goForward(document.getElementById('listLevelTopicsPeriodic'), helpLink.name);
            }
            else if(helpLink.name == "Noise Signals")
            {
                browser.goForward(document.getElementById('listLevelTopicsNoise'), helpLink.name);
            }
            else if(helpLink.name == "Frequency Sweeps")
            {
                browser.goForward(document.getElementById('listLevelTopicsSweeps'), helpLink.name);
            }
        };
        rowElement.onclick = handler;
    }
};

var periodicTopics = [
    { name: "Signal A/B", question: "Selecting periodic signal A or B", 
                    answer: "Tap the A or B button at the top of the Periodic tab view to select " +
                    "periodic signal A or B. Each signal has its own set of parameters, enabling you " +
                    "to generate two completely different periodic signals simultaneously."},
    { name: "Signal On/Off", question: "Turning a periodic signal on or off",
                    answer: "Tap the Signal switch at the top of the Periodic tab view to turn the " +
                    "current periodic signal (A or B) on or off. Both signals can be on at the same " +
                    "time."},
    { name: "Waveform Type", question: "Selecting the periodic waveform type",
                    answer: "Tap one of the four buttons in the segment control, beneath the Signal " +
                    "switch, to select a waveform type. The four available types are Sinusoid, Rectangle " +
                    "Triangle, and Sawtooth."},
    { name: "Duty Cycle", question: "Adjusting the rectangle wave duty cycle",
                    answer: "When Rectangle is the selected waveform type, a text box appears in which a " +
                    "duty cycle can be chosen for the rectangular wave. The duty cycle refers to the " +
                    "percentage of one period of the waveform in which the voltage is high."},
    { name: "Relative Phase", question: "Adjusting the relative phase between signals A and B",
                    answer: "When both periodic signals are switched on, the phase relationship between " +
                    "the two signals is determined by the value in the Relative Phase text box (given in " +
                    "units of degrees). Periodic Signal B lags behind Periodic Signal A by the chosen " +
                    "Relative Phase. The Relative Phase text box is only visible when signal B is selected."},
    { name: "Frequency", question: "Adjusting the fundamental frequency",
                    answer: "The current fundamental frequency of the selected periodic signal is displayed " +
                    "in the text box to the right of the Frequency label. You can adjust the frequency " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from 20 to 20,000 Hz."},
    { name: "Amplitude", question: "Adjusting the peak amplitude",
                    answer: "The current amplitude of the selected periodic signal is displayed " +
                    "in the text box to the right of the Amplitude label. You can adjust the amplitude " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from 0.0 to 100.0 %."},
    { name: "Pan", question: "Balancing the output between left and right channels",
                    answer: "The current balance (pan) of the selected periodic signal is displayed " +
                    "in the text box to the right of the Pan label. You can adjust the balance " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from -1.0 (full left) to +1.0 (full right). The Pan controls can "+
                    "be used to output a completely different signal from each channel. When the built-in " +
                    "speaker of the iPhone is the current output device, Pan controls have no effect."}
];

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 periodicTopics.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 = periodicTopics[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 = periodicTopics[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: "Periodic Signals"},
    { name: "Noise Signals"},
    { name: "Frequency Sweeps"}
//    { name: "Reference"}
];


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

var noiseTopics = [
    { name: "Noise Types", question: "Changing the type of noise signal",
                    answer: "The segment control at the top of the Noise tab view contains three buttons " +
                    "for selecting the type of noise signal to be generated. The three noise types include " +
                    "random noise (Random) and two types of deterministic pseudorandom noise signals (MLS " +
                    "and PseudoRnd). MLS orders 5 through 20 are supported. The PseudoRnd signal consists " +
                    "of a number of fixed-length sequences that " +
                    "are tailored to yield a perfectly flat magnitude with an FFT of the same length."},
    { name: "Frequency Weighting", question: "Changing the frequency weighting",
                    answer: "The Weighting segment control, in the Noise tab view, " +
                    "enables you to select between White and Pink " +
                    "frequency weightings. White weighting is equivalent to flat weighting, or no weighting. " +
                    "Pink weighting slopes an otherwise white frequency spectrum by 3 dB per octave, giving " +
                    "more weight to lower frequencies."},
    { name: "Signal On/Off", question: "Turning a noise signal on or off",
                    answer: "Tap the Signal switch at the top of the Noise tab view to turn the " +
                    "current noise signal on or off. Only one of the noise signals can be on at one " +
                    "time."},
    { name: "Sequence Length", question: "Changing the noise sequence length",
                    answer: "When either MLS or PseudoRnd is the selected noise type, a Sequence Length picker" +
                    "control appears near the middle of the window. Use the picker control to select the desired "+
                    "MLS or pseudorandom noise sequence length."},
    { name: "Amplitude", question: "Adjusting the peak amplitude",
                    answer: "The current amplitude of the selected noise signal is displayed " +
                    "in the text box to the right of the Amplitude label. You can adjust the amplitude " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from 0.0 to 100.0 %."},
    { name: "Pan", question: "Balancing the output between left and right channels",
                    answer: "The current balance (pan) of the selected noise signal is displayed " +
                    "in the text box to the right of the Pan label. You can adjust the balance " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from -1.0 (full left) to +1.0 (full right). The Pan controls can "+
                    "be used to output a completely different signal from each channel. When the built-in " +
                    "speaker of the iPhone is the current output device, Pan controls have no effect. " +
                    "Please note that only one type of noise signal can be generated at a time."}
];

// 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 noiseTopics.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 = noiseTopics[rowIndex].question;
		}

		// Assign a click event handler for the row.
		var handler = function()
        {
            var topic = noiseTopics[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 sweepTopics = [
    { name: "Sweep Repeat", question: "Repeating the frequency sweep",
                    answer: "Tap the Repeat switch at the top of the Sweep tab view to enable or disable " +
                    "periodic repetition of the swept sine."},
    { name: "Signal On/Off", question: "Turning the frequency sweep on or off",
                    answer: "Tap the Swept Sine switch at the top of the Sweep tab view to turn the " +
                    "swept sine signal on or off."},
    { name: "Lower Frequency", question: "Adjusting the bottom frequency",
                    answer: "The current bottom frequency of the sweep is displayed " +
                    "in the text box underneath the Lower Freq label. You can adjust the frequency " +
                    "by entering a new value in the text box. " +
                    "Valid values range from 0 Hz to half the sample rate (typically 24,000 Hz)."},
    { name: "Upper Frequency", question: "Adjusting the top frequency",
                    answer: "The current top frequency of the sweep is displayed " +
                    "in the text box underneath the Upper Freq label. You can adjust the frequency " +
                    "by entering a new value in the text box. " +
                    "Valid values range from 0 Hz to half the sample rate (typically 24,000 Hz)."},
    { name: "Sweep Duration", question: "Adjusting the sweep duration",
                    answer: "The current duration of the sweep is displayed " +
                    "in the text box underneath the Duration label in the Sweep tab view. " +
                    "The duration of the sweep can be entered (and shown) in units of seconds or samples " +
                    "(at a sampling rate of 48000 Hz, 48000 samples corresponds to 1 second). The duration " +
                    "itself is entered in the text box and units are chosen from the segment control to " +
                    "the right of the text box. When either U/D (up, then down) or D/U (down, then up) is " +
                    "selected in the sweep direction segment control, below the duration units control, " +
                    "the duration applies to each sweep direction (up and down), so the total sweep " +
                    "duration is twice the duration shown."},
    { name: "Sweep Type", question: "Selecting the sweep type",
                    answer: "Tap a button in the segment control below the sweep duration text box, in " +
                    "the Sweep tab view, to select between linear (Lin) or logarithmic (Log) sweep types. " +
                    "The sweep type determines whether the frequency of the signal is sweep between the " +
                    "lower and upper frequencies in a linear or logarithmic fashion. Linear sweeps exhibit " +
                    "a flat magnitude spectrum, while the log sweep's magnitude spectrum rolls off by 3 dB " +
                    "per octave, like pink noise."},
    { name: "Sweep Direction", question: "Selecting the sweep direction",
                    answer: "The sweep direction segment control is located just above the Amplitude " +
                    "text box in the Sweep tab view. Choosing Up will cause the sweep to begin at the " +
                    "frequency shown in the Lower Frequency text box and sweep to the frequency shown " +
                    "in the Upper Frequency text box. Choosing Dwn will cause the frequency to sweep in " +
                    "the opposite direction. Choosing U/D (up, then down) or D/U (down, then up) will " +
                    "cause the frequency to be swept twice--first in one direction, then the other."},
    { name: "Amplitude", question: "Adjusting the peak amplitude",
                    answer: "The current amplitude of the sweep is displayed " +
                    "in the text box to the right of the Amplitude label. You can adjust the amplitude " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from 0.0 to 100.0 %."},
    { name: "Pan", question: "Balancing the output between left and right channels",
                    answer: "The current balance (pan) of the sweep is displayed " +
                    "in the text box to the right of the Pan label. You can adjust the balance " +
                    "either by moving the slider control knob or entering a new value in the text box. " +
                    "Valid values range from -1.0 (full left) to +1.0 (full right). The Pan controls can "+
                    "be used to output a completely different signal from each channel. When the built-in " +
                    "speaker of the iPhone is the current output device, Pan controls have no effect. " +
                    "Please note that only one type of noise signal can be generated at a time."}
];

// 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 sweepTopics.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 = sweepTopics[rowIndex].question;
		}

		// Assign a click event handler for the row.
		var handler = function()
        {
            var topic = sweepTopics[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/signalscope"},
    { name: "Technical Support", link: "http://www.faberacoustical.com/products/iphone/signalscope/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;
	}
};
