/* 
 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 questionController = {
    // 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 questions.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.QrowTitle) {
            templateElements.QrowTitle.innerText = questions[rowIndex].name;
        }
        if (templateElements.rowTitle) {
            templateElements.rowTitle.innerText = questions[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 q = questions[rowIndex];
            detailController.setPark(q);
            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('Answers'), q.name);
        };
        rowElement.onclick = handler;
    }
};


var categoryController = {
    // 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 categories.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 = categories[rowIndex].name;
        }

        // We also assign an onclick handler that will cause the browser to go to the questions page.
        var self = this;
        var handler = function() {
            var c = categories[rowIndex];
            //listController.setPark(park);
            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('Questions'), c.name);
        };
        rowElement.onclick = handler;
    }

};



var detailController = {
    // This object acts as a controller for the detail UI.
    
    setPark: function(park) {
        this._park = park;
        this._representedObject = park.name;
        
        // When the park 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._park.name;
        var detailLocation = document.getElementById('detailLocation');
        detailLocation.innerHTML = "<hr />";//this._park.question;
        var detailDescription = document.getElementById('detailDescription');
        detailDescription.innerHTML = this._park.answer;
        
//        "The scenery in " + this._park.name + " is amazing this time of year!";
    }
    
};

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

    var sear, debg;
	sear= window.location.search;
    var pi = 0;
    var rr = "rr=1";
	debg = sear.lastIndexOf(rr);
    debug = -1;// enable this if I decide to later... // make a countdown timer to do this automatically?  
    if (debg != -1){

        //alert('argg, matey!');
        pi = 1;
        // 
        questions.push({ name: "Why you should buy ooTunes?", answer: "<a href='' onclick='document.location='ext:http://click.linksynergy.com/fs-bin/stat?id=l8FszLOIbhQ&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252Fphobos.apple.com%252FWebObjects%252FMZStore.woa%252Fwa%252FviewSoftware%253Fid%253D302782364%2526mt%253D8%2526partnerId%253D30';>Here's a few reasons:<br><ol><li>It's the right thing to do.</li><li>It's a great app!</li><li>It's costs about as much as lunch at McDonalds</li><li>It supports future development.</li><li>Karma</li><li>It's not going to work forever if you don't</li></ol></a>"})
    }
    
    
    dashcode.setupParts();
    if (pi){
        gotoquestion(questions.length -1);
        return;
    }
  	var ql ="question=";
	debg = sear.lastIndexOf(ql);
    
	if (debg != -1){
    
    
        // parse out a given question from the query string and go right to it
        // also parse out whether the app is pirated and show a different set of help...
        var goto=0;
        var num = sear.substring(debg+ql.length);
        var end = num.lastIndexOf('&');
        if (end < debg)
            end = num.length;
        num = num.substring(0,end);
        goto = parseInt(num);
//        alert(goto);
        gotoquestion(goto);
            
    }
    
    
  //  alert('setup done');
}

function gotoquestion(qnum){
    var q = questions[qnum];
    detailController.setPark(q);
    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('Answers'), q.name);
    return false;
}

// Sample data.  Some applications may have static data like this, but most will want to use information fetched remotely via XMLHttpRequest.
var questions = [
    { //1
    name: "The basics...", answer:"Welcome to ooTunes! My name is Steven, and I'm the developer, customer support, technical writer, server admin, and everything-else person for ooTunes. <br><br> I want to explain 3 things here. <br><br> 1) <b>What's a stream?</b> <br> 'Stream' refers to an audio 'feed' or just a 'stream' of data on the internet that contains the audio for a radio station. Just because a radio station plays something over the air, does not mean that they have an online 'stream'.  ooTunes can only play stations that have an internet 'stream' since there is no other way to 'tune in' to a station from an app.<br><br> 2) <b>Problems with a stream</b><br>ooTunes is a radio stream player (much like winamp or iTunes or Windows Media Player).  Neither I nor ooTunes owns or controls ANY of the streams that can be played in the app.  What this means is that streams can come and go.  Reliability and sound quality are entirely out of my control, as is what's played on a stream.  Every effort is made to ensure that all streams are working at all times, but due to the number of streams in the ooTunes database, and the fact that they are maintained by someone else, there will be times when a stream doesn't work, isn't working well, or may even disappear forever.  Don't hesitate to contact me when this happens, but don't be too surprised if you're told that it's a problem I can't personally solve.  I will, of course, make every effort to fix them when possible (and the best 'test' of when I can do something is if the stream works on the station's own website, but doesn't work in the app) <br><br> Finally 3) <b>How do I get help?</b><br>The App Store and iTunes are NOT the place to report problems or give suggestions to me.  They are NOT the place to get help either.  I cannot respond to you there, I may not even see your message there depending on what country you are in.  PLEASE don't use that as a forum to get help, it's not the right place!  I'm here to help you, so please <a href='mailto:ooTunes Help<logs@ootunes.com>?subject=I need help!&body=(Please be as specific as possible (ie, what stream(s) you are having problems with, etc.)'>email me</a> or use the many feedback/help buttons from within the app, or from my website at <a href='http://help.ootunes.com/contact'>ootunes.com</a> if you need anything!<br>  Thanks for reading this, I hope you enjoy ooTunes! <br><br>Steve<br>ooTunes Nerd"},
    //2
    {name: "How do I get help from a human?", answer:"Hi, I'm Steve.  I'm a human.  If your question is not answered here, please <a href='mailto:ooTunes Help<logs@ootunes.com>?subject=I need help!&body=(Please be as specific as possible (ie, what stream(s) you are having problems with, etc.)'>email me!</a> I'll usually respond within 24 hours, often much faster.  If you don't hear back within 2 days, check your junkmail box, or email me again, and leave a phone number.  I ALWAYS respond to your emails (just ask my wife ;), so if you don't hear back, the response landed in your junkmail, or was lost in the ether."},
    //3
    {name: "How do I record what I'm listening to?", answer:"Pick the stream, and if it's playing, it's recording (as long as you have 'Recording' enabled in the app's settings and it's not a 'rtsp' stream).  If you're ever unsure, if it's recording, the 'elapsed time' indicator is yellow when the app is recording.  Recordings are saved (temporarily) in the 'Recordings' list on the app's Home screen.  Recordings can be saved permanently or renamed by tapping 'Edit' and then tapping on the recording you want to save."},
    //4
    {name: "How do I use ooTunes as an alarm clock?", answer: "Pick what it is you want to wake up to (a stream, a track, a recording, etc.).  Push stop on the controls (or you can set the sleep timer first so that you can fall asleep listening, then wake up to the same thing!).  Now tap the 'clock' icon in the bottom right of the player window and pick 'Set Alarm'.  Be sure you have a reliable network connection if you are planning to wake up to an internet stream!  Also, you must leave the app open to that screen for the alarm to work! (<a href='javascript:gotoquestion(4);'>Why?</a>)" }, 
//5
{name: "Why does it stop playing when locked or in the background?", answer: "It's a memory issue.  When the iPhone (or iPod touch, iPad)  gets low on memory, weird things start happening.  Hopefully Apple will be addressing that with a future update, but in the meantime, closing other apps, webpages or rebooting the phone should get it back to playing even in sleep."},   
//6
    { name: "How do I close the app and keep listening?", answer: "Only with the latest version of the operating system on your iPod touch or iPhone (and in November the OS 4.2 for iPad too) does Apple allow more than one non-Apple app to run at a given time.  This feature also doesn't work on the original iPhone or the iPhone 3G (or the first 2 generations of iPod touch).  There are two 'workarounds' for older devices or the older OS for background listening.  <br><br>1) With iPhone OS 3.0, some mp3 and aac+ streams can be played in Safari on the iPhone (which DOES run in the background!).  When you're listening to one of these streams, you'll see a small white checkmark on the 'background' button on the bottom left of the player.<br> 2) Using the ooTunes Server, other streams can be converted to mp3 streams which can play in Safari.  See more information on the ooTunes Media Server <a href='http://ootunes.com'>at ootunes.com</a><br><br>Please express your interest in this feature by suggesting it on their <a href='http://www.apple.com/feedback/iphone.html'>iPhone Feedback page.</a>"}, 
    //7
    { name: "How do I report a non-working stream?", answer: "Tap the '!?' button near the bottom right of the now playing screen then choose 'Help!' to diagnose and report problematic streams."/*"Use the <img src=''/> icon from the \"Now Playing\" screen when the stream has failed."*/
    },//8
    { name: "Why does my stream rebuffer?", answer: "There are 3 reasons a stream has to rebuffer. <br><br> 1) Your network connection is not fast enough for a given stream.<br>2) Your internet connection is unreliable <br>or<br> 3) The stream is overloaded or having technical difficulties.<br> <br> To diagnose why your particular stream has this problem, tap the '!?' button on the bottom right of the player, then choose 'Help!' after having this problem. <br><br> Please note, ooTunes as an internet streaming app has no control over these three problems, but attempts to minimize their effects by reconnecting to the problematic stream.<br> However, if you feel that ooTunes is to blame for an interrupted listening experience, please do send your debug log from the same '!?' menu with a description of the problem."},
    //9
    { name: "Why doesn't my stream connect?", answer: "Assuming you have a good internet connection, there are several reasons why a stream may fail to connect. <br><br> 1) The stream could be down. <br> 2) The stream may be overwhelmed with too many listeners.<br>  3) The stream could be blocked from your listening location.<br> 4) The stream may have a new link which hasn't yet been updated in the ooTunes stream database.<br><br> Nearly all of these can be diagnosed by attempting to listen on your computer from the station's homepage.  <br><br>PLEASE report this (along with what you've found by listening on their website)  using the '!?' button on the player and choosing 'Help!' after the stream has failed to connect."},
    //10
    { name: "Why is the stream different from what I hear on the radio?", answer: "Internet radio is subject to different rules than 'over the air' radio, at least in part due to the fact that one is a global audience, and the other is a geographically confined audience.<br><br>  The most common reason why you hear something different in ooTunes than over the air is that a station doesn't have the 'rights' to stream the current program.  This is (unfortunately) VERY common for live sporting events.  Typically the station will have information about this on their website (though it's not uncommon for them to simply play 'silence' during this time).  Other differences between the internet stream and 'over the air' station are <br>a) commercials that are only relevant locally <br>and<br> b) a sometimes long 'delay' caused by the encoding and transmission process. <br> The best way to diagnose such problems is to listen on your computer to a station's own online stream (which is the same as what ooTunes uses).  If their online stream doesn't play a certain program, ooTunes won't either."},
        // why does it play something different?
        //11
    { name: "Why is the stream connected but silent?", answer: "A silent stream almost always indicates that the station is not allowed to 'stream' the same program that they are playing over the air.  This is very common for live sporting events, but also some syndicated talk shows and even some commercials are not allowed to be on the internet stream.  Check the stations' website or their own online stream page for more information, or you can ask me about it too."},
    //11
        // why is it silent during this game!?
    { name: "Why doesn't this stream show what's playing?", answer: "Only stations that stream in mp3 and aac audio formats 'broadcast' what's playing in a format that ooTunes can display.  Unfortunately at this time that means only about half of the available stations will show what's playing, lyrics, album art, etc.  If your favorite station doesn't, please contact them and ask them to provide an mp3 or aac stream!"},
        // why doesn't this stream show what's playing?
        //13
{ name: "Why does this stream sound terrible?", answer: "Since ooTunes doesn't have control over the format or 'bitrate' that a stream uses, it's not possible for the app to 'make it sound better'.  However, many stations provide more than one stream format or bitrate, so search for another entry in the list and pick one with a higher bitrate, if your internet connection is fast enough.  Contact the station if you'd like a better sounding stream!  Same thing goes for volume.  ooTunes has the volume all the way up, so if it's too quiet and you've got the volume at max, you'll need to ask the station to crank their amp's up to 11.  If you know that the station has a better sounding stream, please contact me and show me where the better sounding stream is."},
//14
    // volume?
    // sound quality?
    { name: "Can you add a missing station?", answer: "If the station has an online stream, then probably.  Please <a href='mailto:ooTunes Streams<streams@ootunes.com>?subject=Can you add this stream?&body=(please include a link to their homepage or stream, as well as the genre and where the station is located if possible)'>send me a link</a> to the stream or their homepage or both (and if you really want to help, the location, and genre too)."},
    //15
    //AT&T.  Just kidding (or am I?)  Seriously though, 
    { name: "What causes a lost connection?", answer: "If you are driving your car listening to ooTunes and the connection drops, this is most likely due to 1 of 2 things. <br> 1) Your connection is spotty.  Moving around at high speeds when cell towers are stationary is a modern day miracle.  However occasionally the 'handoff' between two towers or passing through areas with poor reception causes a temporary break in your signal.  Once the station detects that you're not connected (even if for a second) you will have to reconnect.  Please note, a larger buffer doesn't do anything in these cases, except delay the break in audio from when the disconnect actually happened. <br> 2) the second most common reason that a stream will disconnect is a change from one network to another.  For instance, moving from WiFi to 3G or 3G to EDGE MUST disconnect the stream.  This is because your ip address changes completely, so you have to reconnect to the stream.  So, if you are in an area where your phone switches from 3G to EDGE or from WIFI to 3G, it's actually better to disable one or the other, so that the connection is at least constant."},
    //16
    { name: "I'm on WiFi and the stream still drops!?", answer: "The most frequent cause of this is a technical problem with the stream's server (for instance it's simply overwhelmed by the number of listeners).  However there have been several reports of problems with a good stream still not connecting reliably on WiFi.  Here are a few things to check:<br><br>a) make sure your WiFi router is upgraded to the latest firmware.<br>b) reboot the router<br>c) make sure there's not a lot of interference (if you have lots of other competing wifi networks in the area, consider changing the 'channel' the hotspot is using)<br>d) try a different router.<br><br>All four of those have resolved similar issues for others so those are where to start.  Use the help! link from the player to get additional help or report such problems."},
    //17
    { name: "How can I listen to my own stream?", answer: "For public streams, please <a href='mailto:ooTunes Streams<streams@ootunes.com>?subject=Please add this stream...&body=(Please provide the website or stream link, genre and location if possible!)'>request it</a> and I'll add it a.s.a.p. if it's compatible with ooTunes.  If it's a 'private' stream, usually you can simply paste the link to the stream into the app's built in browser.  If that doesn't work for your particular stream, try putting ootunes:// instead of http:// (if it's a windows media stream) or aac:// instead of http:// (if it's an aac stream), or vorbis:// instead of http:// (if it's an ogg vorbis stream).  And NO, your private stream links are NEVER sent to me unless you choose to send it."}, 
    
    
    //18
     { name: "Can I 'Favorite' a Sirius Stream?", answer: "Yes! When the \"loading\" window first opens after choosing it from the streams list, tap \"Done\" on the top left, then mark it a favorite by tapping the heart, then push play again and it should continue loading/playing (and now be saved in your favorites)."},
    

    
     //19
     { name: "I have a suggestion...", answer: "Great!  I want you to know that this app would not exist in current form if it wasn't for the suggestions of thousands of great users!  That being said some things are impossible for me to do (given the the laws of nature, and restrictions that Apple imposes, for instance).  Exporting recordings is one such feature, which is unsurprisingly, one of the most requested.  Unfortunately Apple's reviewers have in the past rejected apps for doing that and as such, I can't enable it in ooTunes."},
//However, iTunes itself makes a backup/copy of all of the app's settings, and recordings.  <a href='http://supercrazyawesome.com/'>supercrazyawesome.com</a> for mac and it works great.  They can then all be played (or converted to mp3) using the free/open source <a href='http://www.videolan.org/vlc/'>VLC</a> program. (Windows users have reported <a href='http://www.iphonebackupextractor.com'>www.iphonebackupextractor.com</a> works and is free but registration is required for advanced use).  However, I'm open to other ideas, so please <a href='mailto:ooTunes Suggestions<suggestions@ootunes.com>?subject=A suggestion for ooTunes...&body=(Please be as specific as possible)'>send them my way!</a>"},
 //20
     { name: "I just got the ooTunes Server, how do I login with the app?", answer: "By default, the ooTunes app loads into Radio Mode when launched.  To connect to your ooTunes server, go to the app's settings (either in apple's global Settings app, or from the now playing screen, tap the 'More' tab on the bottom right).  Then put in your username and password, and be sure to disable 'Radio Mode'.  Then close the app and on launch it again.  The app will then launch and allow you to login to your server."},

// 21
     { name: "Do you plan to release a non-english version?", answer: "Yes, si, oui, sim, ja, tak, да, نعم, 是, ano, kyllä, ναι, כן, हाँ, sì, はい, 예, Da.  If you want to help translate to one of these (or any others, excluding Klingon, you geeks), please <a href='mailto:ooTunes Localizations<localizations@ootunes.com>?subject=Can I help localize ooTunes?&body=I would like to help with the translation to '>let me know!</a>"},

//22
     { name: "Is there a mailing list to notify me of important updates?", answer: "Funny you should ask... Hilarious even. Yes, there is! See <a href='http://ootunes.com/updates/'>the ooTunes Radio Mailing List</a>.  (Very low volume 6 emails in 8 months)."},

//23    
{ name: "I LOVE your app! Can you make an app for me?", answer: "No.<br>  Well, maybe.  Contact me and tell me what you have in mind.  If you're a radio station, or a Texas billionaire, then the answer may just be 'yes'.  Maybe ;)"}
    // this app is AWESOME can you make one for me/my station?
    // is there a Mailing list to find out when new updates are around?
    // localized in my language?
    

    // adding a private stream?
    // Thank you Thank you!  I can't say it enough!
    // how to schedule a recording 
    
    // how to clear cookies...
    
    
    /*
    Hi Paul,
Yes, the app has to be running (Apple's choice, not mine).  See this for a bit more information on that "restriction"

http://help.ootunes.com/app/index.htm?question=4 (also available from the help link in the app, by tapping the "!?" button on the app's home screen).

As for how to schedule it, just tap the clock icon when the stream is playing or was just playing and it will let you set the time.
In the future, I plan to add a way to get a "notification" when it's time to start recording, so you can close the app and do other things, but apple's limitations is severe for many reasons, especially with an app like mine!

*/


    // track if they're using a pirated version and say so at the top :)
    // why ooTunes?
    // login for a subuser?
    // where are all the stations for X_ country? (canadian review that says "no us stations") // add the list of US stations to the dynamic list?
];

var categories = [
    { name: "How do I record something?"}, 
    { name: "Why can\'t I..."},
    { name: "Help!"}

];

