var trackCases = new Array();
trackCases["popup_life1"] = 'life1';
trackCases["popup_life2"] = 'life2';
trackCases["popup_egi1"] = 'egi1';
trackCases["popup_egi2"] = 'egi2';
trackCases["popup_comm"] = 'comm'; 
trackCases["popup_gc1"] =  'gc1';
trackCases["popup_gc2"] =  'gc2';
trackCases["popup_hp"] = 'hp';

function dcsMultiTrack(key, value){
  //alert(key+ ' - '+value);
}
function track_popup(case_popup){
  dcsMultiTrack('DCS.dcsuri', trackPath+trackCases[case_popup]+'/'+trackTitles[case_popup]);
}

function checkCase(){
  var get_vars = location.href.split("?")[1] || '';;
    
  if(get_vars.indexOf('startCase=')!=-1) {
    if(g_case = get_vars.split('startCase=')[1].split('&')[0]){
      return cases[g_case-1];
    }
  }
}

function checkPopUp(){
  if(a_case = checkCase()) popup(true,'popup_'+a_case);
}

function checkPopUpHtml(){
  if(a_case = checkCase()){
     window.open('popup_'+a_case+'.html', 'case_popup', 'width=550, height=580, scrollbars=yes, menubar=yes, location=no, resizable=yes');
  }
}

/* adds a tooltip */
Tooltip = Behavior.create({
  initialize: function() {
    this.text = this.element.getAttribute('title');
    this.tip = $div({ id : 'case-tooltip' }, this.text);
  },
  onmousemove: function(e) {
   this.tip.style.left = e.pointerX()-55 + 'px';
   this.tip.style.top = e.pointerY()-70 + 'px';
  },
  onmouseout: function(e) {
  	this.tip.remove();
    this.element.title = this.text;
  },
  onmouseover: function(e) {
    document.body.appendChild(this.tip);
    // remove title to disable browser's default tooltip
    this.element.title = '';
  }
});

/* manages links */
Link = Behavior.create({
  initialize: function() {
  	this.url = this.element.getAttribute('href');
  	this.rel = this.element.getAttribute('rel');
  },
  onclick: function(e) {
    // open link in opener window
  	if (this.rel == 'opener') {
      if (opener) {
        opener.location.href = this.url;
        e.stop();
      }
    // popup
	} else if (this.rel == 'popup') {
      window.open(this.url, 'case_popup', 'width=550, height=580, scrollbars=yes, menubar=yes, location=no, resizable=yes');
      e.stop();
    // blank
	} else if (this.rel == 'blank' || this.rel == '_blank') {
      window.open(this.url, 'case_blank', '');
      e.stop();
    } else {
      // normal link, do nothing and let the browser handle it
    }
  }
});

/* add tooltip rule to all case links */
Event.addBehavior({ 
  '.cases a.case' : Tooltip
});

/* add link rule to all case links */
Event.addBehavior({ 
  '.cases a' : Link
});

/* add link rule to all links in case popups */
Event.addBehavior({ 
  '.case-popup a' : Link
});

/* add link rule to HelpPoint link */
Event.addBehavior({ 
  '.hp .link a' : Link
});
