// Copyright 2010 Google Inc.  All Rights Reserved.

/**
 * @fileoverview Provides some functions for the Chrome more site.
 * Some functions require gweb library.
 * @author mleotta@google.com (Mike Leotta)
 */

 /**
  * Display appropriate screenshots depending on platform.
  * Requires gweb library.
  */
var init = function() {
  var winOnly = gweb.dom.getElementsByTagNameAndClass('p', 'win-only');
  var macOnly = gweb.dom.getElementsByTagNameAndClass('p', 'mac-only');
  if (gweb.userAgent.MAC) {
    for (var i = 0, e; e = winOnly[i]; i++) {
      e.style.display = 'none';
    }
    for (i = 0, e; e = macOnly[i]; i++) {
      e.style.display = 'block';
    }
  }
}();


/**
 * Called to toggle video containing divs.
 * @param {number} id The id of selected video.
 */
function toggleVideo(id) {
  var vidbox = document.getElementById('hidden-video-' + id);
  if (vidbox.style.display == 'block') {
    vidbox.style.display = 'none';
  } else {
    vidbox.style.display = 'block';
  }
}


/**
 * Called to check and get a brand code from window.location.
 * @return {string} The matched brand code from window.location.
 */
var getBrand = function() {
  if (match = String(window.location).match(/[&#?]brand=([A-Z]{4})[&#?]*/)) {
    return (match[1]);
  }
  return '';
};


/**
 * Called to append a brand code a clicked element's href value.
 * @param {Element} el The element clicked.
 * @return {boolean} True. To allow for default href to be followed.
 */
var trackBrand = function(el) {
  var brand = getBrand();
  if (brand) {
    if (String(el.href).indexOf('?') == -1) {
      el.href += '?brand=' + brand;
    } else {
      el.href += '&brand=' + brand;
    }
 }
 return true;
};

