﻿var maploadded = false;

function ShowTab(tabnbr)
{    
    var tabs = document.getElementById('tabs').getElementsByTagName("a");
    var contents = document.getElementById('contents').getElementsByTagName("div");
    for (var i=0; i < tabs.length; i++)
    {
        tabs[i].className = "notselected";
        tabs[i].style.color = "#352415";
        contents[i].style.display = "none";
    }
    document.getElementById('tab' + tabnbr).className = "selected";
    document.getElementById('tab' + tabnbr).style.color = "Black";
    document.getElementById('content' + tabnbr).style.display = "block";
    
    if (tabnbr == 2)
    {
        LoadMap();
    }
	
    return false;
}
function showpopup()
{
    document.getElementById('popup').style.display = "block";

}
function closepopup()
{
    document.getElementById('popup').style.display = "none";

}
function Init()
{
    var querystring = location.toString().toLowerCase().substring(location.toString().indexOf('#') + 1);
    
    var options = new Array(2);
        options[0] = "findevents";
        options[1] = "offers";
    
    var tab = 'none'
    for (var i=0; i<options.length; i++)
    {
        if(querystring == options[i]) {tab = querystring;}
    }
    
    if (tab != 'none')
    {
        if (tab == 'findevents') {ShowTab(2);}    
        if (tab == 'offers') {ShowTab(3);}
    }
    else 
    {
        setHashPath("Welcome");   
        pageEventsTracking.initialize();
        ShowTab(1);     
    }
}
function LoadMap()
{
    if (maploadded == false)
    {
        var Map = document.getElementById('embeddedmap');
        Map.src = "http://www.viavirtualearth.com/sblmaps/";
        Map.style.position = "relative";
        Map.style.display = "block";
        maploadded = true;
    }
}
function setHashPath(hash) 
{
    var path = location.protocol + "//" + location.hostname + location.pathname;
      location.assign(path + location.search + "#" + hash);
      initLocation =  location.toString();
}  


/* Code for Collapsible Lists Below */
CLOSED_IMAGE='images/closed.gif';
OPEN_IMAGE='images/open.gif';

/* makeCollapsible - makes a list have collapsible sublists
 * 
 * listElement - the element representing the list to make collapsible
 */
function makeCollapsible(listElement){

  // removed list item bullets and the sapce they occupy
  listElement.style.listStyle='none';
  listElement.style.marginLeft='0';
  listElement.style.paddingLeft='0';

  // loop over all child elements of the list
  var child=listElement.firstChild;
  while (child!=null){

    // only process li elements (and not text elements)
    if (child.nodeType==1){

      // build a list of child ol and ul elements and hide them
      var list=new Array();
      var grandchild=child.firstChild;
      while (grandchild!=null){
        if (grandchild.tagName=='OL' || grandchild.tagName=='UL'){
          grandchild.style.display='none';
          list.push(grandchild);
        }
        grandchild=grandchild.nextSibling;
      }

      // add toggle buttons
      var node=document.createElement('img');
      node.setAttribute('src',CLOSED_IMAGE);
      node.setAttribute('class','collapsibleClosed');
      node.onclick=createToggleFunction(node,list);
      child.insertBefore(node,child.firstChild);

    }

    child=child.nextSibling;
  }

}

/* createToggleFunction - returns a function that toggles the sublist display
 * 
 * toggleElement  - the element representing the toggle gadget
 * sublistElement - an array of elements representing the sublists that should
 *                  be opened or closed when the toggle gadget is clicked
 */
function createToggleFunction(toggleElement,sublistElements){

  return function(){

    // toggle status of toggle gadget
    if (toggleElement.getAttribute('class')=='collapsibleClosed'){
      toggleElement.setAttribute('class','collapsibleOpen');
      toggleElement.setAttribute('src',OPEN_IMAGE);
    }else{
      toggleElement.setAttribute('class','collapsibleClosed');
      toggleElement.setAttribute('src',CLOSED_IMAGE);
    }

    // toggle display of sublists
    for (var i=0;i<sublistElements.length;i++){
      sublistElements[i].style.display=
          (sublistElements[i].style.display=='block')?'none':'block';
    }

  }

}


var namesVec = new Array("images/closed.gif", "images/open.gif");
var root='images/';
function swapImg(ima){
// divides the path
nr = ima.getAttribute('src').split('/');
// gets the last part of path, ie name
nr = nr[nr.length-1]
// former was .split('.')[0];
 
if(nr==namesVec[0]){ima.setAttribute('src',root+namesVec[1]);}
else{ima.setAttribute('src',root+namesVec[0]);}

}









