var demo_pages;

function init_demo(status) {
  demo_pages = {
    'start': 'NameFuse helps you build the perfect domain name, using several groups of interchangeable words.<br /><br />Try the demo to see how it works!<br /><br /><div style="text-align: center;"><input type="button" class="big_button" value="Start Demo" onclick="demo_page(\'widget1\');" /></div>',
    'widget1': 'You\'re starting an e-commerce site that sells widgets. Let\'s see if widgets.com is available.<br /><br /><fieldset id="query_example"><legend>Query</legend><div style="padding: 4px;">widgets<br />.com</div></fieldset><br /><div style="text-align: center;"><input type="button" class="big_button" value="Try It" onclick="q(\'widgets;.com\');" />&nbsp;&nbsp;<input type="button" class="big_button" value="Next" onclick="demo_page(\'widget2\');" /></div>',
    'widget2': 'Alright, it won\'t be that easy. Let\'s try a few variations, widgetshop.com and widgetstore.com.<br /><br />Instead of entering each domain by hand, just split the query into two lines, and seperate each suffix with a comma.<br /><br /><fieldset id="query_example"><legend>Query</legend><div style="padding: 4px;">widget<br /><span class="hi">shop,store</span><br />.com</div></fieldset><br /><div style="text-align: center;"><input type="button" class="big_button" value="Try It" onclick="q(\'widget;shop,store;.com\');" />&nbsp;&nbsp;<input type="button" class="big_button" value="Next" onclick="demo_page(\'widget3\');" /></div>',
    'widget3': 'No luck? That\'s OK. The more we build, the better domains we\'ll find.<br /><br />Let\'s add another line at the top. This time, we\'ll make the entire group optional, by adding a comma at the beginning of the line. There\'s no magic here; NameFuse just treats this as a blank term.<br /><br /><fieldset id="query_example"><legend>Query</legend><div style="padding: 4px;"><span class="hi">,the,web</span><br />widget<br />shop,store<br />.com</div></fieldset><br /><div style="text-align: center;"><input type="button" class="big_button" value="Try It" onclick="q(\',the,web;widget;shop,store;.com\');" />&nbsp;&nbsp;<input type="button" class="big_button" value="Next" onclick="demo_page(\'widget4\');" /></div>',
    'widget4': 'Why stop now? We found a few domains, but most of them are taken. Let\'s add two more domain extensions, and triple our results.<br /><br /><fieldset id="query_example"><legend>Query</legend><div style="padding: 4px;">,the,web<br />widget<br />shop,store<br />.com<span class="hi">,.net,.biz</span></div></fieldset><br /><div style="text-align: center;"><input type="button" class="big_button" value="Try It" onclick="q(\',the,web;widget;shop,store;.com,.net,.biz\');" />&nbsp;&nbsp;<input type="button" class="big_button" value="Next" onclick="demo_page(\'widget5\');" /></div>',
    'widget5': 'That was easy! With a few short queries, we\'ve generated several domain names, and found out which ones are available to purchase.<br /><br />Notice the rating bar next to each domain name. This helps you pick the best domain by assigning each one a rank, with the most valuable domains at the top.<br /><br />Each query term is scored based on how frequently it occurs in registered domains. Domains are then ranked by the combined score of their component terms.<br /><br /><div style="text-align: center;"><input type="button" class="big_button" value="Next" onclick="demo_page(\'whatsnext\');" /></div>',
    'whatsnext': 'That\'s it for the demo. Time to try out your own queries, and start building the perfect domain name!<br /><br />If you need further assistance, try our <a href="http://groups.google.com/group/namefuse" target="_blank">discussion group</a>.'
  }
  demo_titles = {
    'start': 'NameFuse Demo',
    'widget1': 'NameFuse Demo &ndash; Getting Started',
    'widget2': 'NameFuse Demo &ndash; Creating Combinations',
    'widget3': 'NameFuse Demo &ndash; Adding an Optional Group',
    'widget4': 'NameFuse Demo &ndash; Adding Domain Extensions',
    'widget5': 'NameFuse Demo &ndash; Understanding Ratings',
    'whatsnext': 'NameFuse Demo &ndash; What\'s Next?'
  }
  
  if (status != 'min' && status != 'closed') {
    new Effect.BlindDown('demo_body');
    demo_open = 1;
  } else {
    demo_open = 0;
  }
}

function demo_page(str) {
  $("demo_title_text").innerHTML = demo_titles[str];
  $("demo_body_inner").innerHTML = demo_pages[str];
}

function two_step(o, query, page) {
  if (o.value == 'Continue') {
    demo_page(page);
  } else {
    q(query);
    o.value = 'Continue';
  }
}

function toggle_demo() {
  if (demo_open == true) {
    $("span_image").src = "/images/span_closed.gif";
    new Effect.BlindUp('demo_body');
    demo_open = false;
    set_demo_cookie("min");
  } else {
    $("span_image").src = "/images/span_open.gif";
    new Effect.BlindDown('demo_body');
    demo_open = true;
    set_demo_cookie("open");
  }
}

function hide_demo() {
  $("demo_container").style.display = "none";
  new Effect.Highlight('demo_link', { duration: 0.6, startcolor: '#ffff00', endcolor: '#f6f6f6' } );
  $("query").focus();
  set_demo_cookie("closed");
}

function show_demo() {
  $("demo_container").style.display = "block";
  demo_page('start');
  $("span_image").src = "/images/span_open.gif";
  new Effect.BlindDown('demo_body');
  demo_open = true;
  set_demo_cookie("open");
}

function set_demo_cookie(str) {
  new Ajax.Request('/setcookie.php?action=demo&demo=' + str + '&' + (new Date).getTime(), { method: 'get' } );
}
