// LIKE BUTTON HANDLING
function hideLikeButton() {
    $('#fb_like').hide();
}

function showLikeButton() {
    $('#fb_like').show();
}

function positionLikeButton(xLoc, yLoc) {
    $('#fb_like').css('left', xLoc + 'px');
    $('#fb_like').css('top', yLoc + 'px');
}

function isLikeButtonVisible() {
    var isVisible = true;
    if ($('#fb_like').css('display') == "none") {
        isVisible = false;
    }
    return isVisible;
}

// Allow popups in Safari 3
function openWindow(pageUrl) {
  var winName = Math.round(9999*Math.random()) + new Date().getTime();
  var winNew = window.open(pageUrl, winName);

  if(!winNew){ // opening window failed (Safari 3)
    document.getElementById("flashContent").openWindowFromSwf(pageUrl);
        }else{
    winNew.focus();
        }
}

function openSizedWindow(pageUrl, p){
  var winName = Math.round(9999*Math.random()) + new Date().getTime();
  var winNew = window.open(pageUrl, 'twitterShare', p);

  if(!winNew){ // opening window failed (Safari 3)
    document.getElementById("flashContent").openWindowFromSwf(pageUrl);
        }else{
    winNew.focus();
        }
}

// Get the total height of the page
function getBodyHeight()
{ if (window.innerHeight && window.scrollMaxY) // Firefox
    return window.innerHeight + window.scrollMaxY;
  else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
    return document.body.scrollHeight;
  else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    return document.body.offsetHeight;
}

// Get the height of the window.
function getWindowHeight()
{ if (typeof window.innerHeight == 'number') // non-ie
      return window.innerHeight;
    return document.documentElement.clientHeight;
}

// Set the height of Main.swf
function setSwfHeight(h) {
  document.getElementById('flashContainer').style.height = h;
  document.getElementById('flashContent').style.height = h; // req'd for ie
  document.getElementById('flashContent').style.height = '100%'; // req'd for ie
}

// Call navEvent in Main.swf
function navEvent(type, page)
{ document.getElementById('flashContent').navEvent(type, page);
}

function trackingEvent(url) {
  document.getElementById('flashContent').trackingEvent(url);
}

// Handler function to call dcsMultiTrack
function wbTrack(args) {
    if (args.length % 2 == 1)
        return;

    var fn = "dcsMultiTrack("

    for (var i = 0; i < args.length; i++) {
        fn += "'" + args[i] + "'";
        fn += (i < args.length - 1) ? "," : "";
    }
    fn += ")";

    eval(fn);
}

// Get the width of scrollbars
function getScrollBarWidth()
{ if (typeof getScrollBarWidthResult != 'undefined') // cached result in global var
    return getScrollBarWidthResult;

  var inner = document.createElement('p');
  inner.style.width = "100%";
  inner.style.height = "200px";
  var outer = document.createElement('div');
  outer.style.position = "absolute";
  outer.style.top = "0px";
  outer.style.left = "0px";
  outer.style.visibility = "hidden";
  outer.style.width = "200px";
  outer.style.height = "150px";
  outer.style.overflow = "hidden";
  outer.appendChild(inner);
  document.body.appendChild (outer);
  var w1 = inner.offsetWidth;
  outer.style.overflow = 'scroll';
  var w2 = inner.offsetWidth;
  if (w1 == w2) w2 = outer.clientWidth;
    document.body.removeChild (outer);
  return getScrollBarWidthResult = (w1 - w2);
};

function showPopup(path)
{
  var popups = [
    '/swf/PrivacyPolicy.swf',
    '/swf/TermsAndConditions.swf',
    '/swf/History.swf',
    '/swf/FAQ.swf'
  ];
  for (var i=0; i<popups.length; i++)
    if (path!= popups[i])
      navEvent('hide', popups[i]);
  window.scrollTo(0, 0);
  navEvent('show', path);

}
