/*--setup--*/
/*window.onload=function() {*/
$(document).ready(function(){
if(!(document.getElementById('tab'))){
} else {
tab.setup = {
   tabs: document.getElementById('tab').getElementsByTagName('li'),
   pages: [
      document.getElementById('tab1'),
      document.getElementById('tab2'),
      document.getElementById('tab3'),
	  document.getElementById('tab4'),
      document.getElementById('tab5'),
      document.getElementById('tab6'),
	  document.getElementById('tab7'),
      document.getElementById('tab8'),
      document.getElementById('tab9'),
	  document.getElementById('tab10'),
      document.getElementById('tab11'),
      document.getElementById('tab12'),
	  document.getElementById('tab13'),
      document.getElementById('tab14'),
      document.getElementById('tab15')
	  
   ]
}
tab.init();
}
});

/*--setup end--*/
  
var tab = {
   init: function(){
      var tabs = this.setup.tabs;
      var pages = this.setup.pages;
  
      var tabList = document.getElementById('tab');

      for(i=0; i<pages.length; i++) {
         try{
             /* if the tab is defined but no content exists, remove it */
             if( pages[i]=== null) {
                 tabs[i].style.display="none"; //parentNode.removeChild(tabs[i]);
             }

         if(i !== 0) pages[i].style.display = 'none';
         tabs[i].onclick = function(){ 
              /* add the call to the click tracker */
              tab.showpage(this); return false; };
         } catch(e) {
         }
      }
   },
  
   showpage: function(obj){
      var tabs = this.setup.tabs;
      var pages = this.setup.pages;
      var num;
  
      for(num=0; num<tabs.length; num++) {
         if(tabs[num] === obj) break;
      }
  
      for(var i=0; i<pages.length; i++) {
         if(i == num) {
            pages[num].style.display = 'block';
            tabs[num].className = 'selected';
         }
         else{
         try{
            pages[i].style.display = 'none';
            tabs[i].className = null;
         } catch(e) {
         }
         }
      }
   },

   showtab: function(tabId){
      var tabs = this.setup.tabs;
      var pages = this.setup.pages;
      var loopIdx=0;
      for(loopIdx=0; loopIdx <= pages.length; loopIdx++){
        if( loopIdx == tabId ){
		pages[loopIdx].style.display='block';
		tabs[loopIdx].className = 'selected';
	}else{
		try{
		pages[loopIdx].style.display='none';
		tabs[loopIdx].className = null;
		}catch(e){}
	}
      }
   }

};

/***********************************************
 *
 * Support to click links in-between tabs
 */
/* set this up once the wiki page content is ready */
addOnloadHook(linkSniffer);

/*
 * This finds all of the "a" links in a page..if in the same tab, then look for the
 * eventual tab parent, and flip over to that place and scroll to the anchor 
 * target.
 */
function linkSniffer(){

    /* if the "tab" element isn't in here, who cares */
   if(!(document.getElementById('tab'))){
        return;
   }


   $("a").click(function(event){
        internalLinkRE = new RegExp("\#.*");
        tabNameRE = new RegExp("tab[0-9]*");

	var tgt = document.activeElement.hash;
	if( tgt == null)
	    tgt = event.currentTarget.hash;
        // If this is an internal link...
        if(internalLinkRE.test(tgt)){
            //get the parent Tab
            var parent = document.activeElement.parentNode;
            while(parent !== null){
                if( tabNameRE.test(parent.id))
                {
                     // get out of loop
                     break;
                }
                parent = parent.parentNode;
            }
            var target = document.getElementById(tgt.replace("#",''));
            var targetParent = target.parentNode;
            while(targetParent !== null){
                if( tabNameRE.test(targetParent.id))
                {
                     // get out of loop
                     break;
                }
                targetParent = targetParent.parentNode;
            }
            if(parent != targetParent) {
                //alert("new tab"); //document.getElemntById(targetParent);
                tabNumberRe = /[0-9]/;
                var tabId = tabNumberRe.exec(targetParent.id);
                if(tabId!= null) tab.showtab(tabId -1);
                //different tabs
            }else{
                //same tab, so ..
                //alert("same tab"); //document.getElemntById(targetParent);
                window.location.hash=target;
            }
        }
   });};

/* Make the floating tabchange menu that pops up, etc. */
var name = "#floatMenu";
var menuYloc = null;

$(document).ready(function(){

    /* if this isn't a "tab" containing page, EJECT!EJECT!EJECT! */
    if(!document.getElementById("tab"))
        return;

    /* if this is an old copy of the page (and oldid is in the URL || args)
     * or a "diff" of the page, dump out
     */
    if(window.location.href.indexOf("oldid") >0 )
        return;

                $('<div />',{
                    id:"floatMenu"}).appendTo($('body'));
		    $('#floatMenu').css({
			'background-color':'#efefef',
			'padding':'2px',
			'height':'275px',
			'width':'165px',
			'margin':'0px',
			'display':'none',
			'top':'200px',
			'position':'absolute',
			'border':'2px solid black'});

                $('body').append($('floatMenu'));

                var e = document.getElementById('floatMenu');
                if(e == null)
                        alert("floatmenu does not exist");
                $('<img>',{
                    "id":"closeButton",
                    "src":"/sr_img/sr_close_button.gif",
                    "position":"absolute",
	            "style":"cursor:pointer",
                    "right":"0"
                }).appendTo($(name));

                $('#closeButton').click(function(){$(name).remove();});


                        var x = $(name).css("top");
                        var y = $(name);
                        menuYloc = parseInt(x.substring(0,x.indexOf("px")));
                        $(window).scroll(function () {

			    if($(document).scrollTop() < 750)
			    {
			        $(name).css({'display':'none'});
			        return;
			    }
                            var menu = document.getElementById('floatMenu');
			    $(name).css({'display':'block'});
                            offset = menuYloc+$(document).scrollTop()+"px";
                            $(name).animate({top:offset},{duration:500,queue:false});
                        });

                var tabElt = document.getElementById("tab");
                $(tabElt).each(function(){
                        var aTags = tabElt.getElementsByTagName('a');
                        if(aTags){
                            for(var i=0; i< aTags.length; i++){

    /* don't add a button if the tab has been 'removed/hidden from the tab */
    if ($(aTags[i].parentNode).css('display') == 'none')
        continue;

                                var compareText = aTags[i].text;
                                if (compareText == null) //IE 6 hack
                                        compareText = aTags[i].innerText;
				var button = $('<p>'+compareText+'</p>');
				$(button).css({'class':'hoverbuttons',
					id:'button-'+i,
					'cursor':'pointer',
					'height':'35px',
					'line-height':'2em',
					'color':'white',
					'text-align':'center',
					'font-family':'Tahoma',
					'font-size':'14',
					'font-weight':'bold',
					/*'width':'140px',*/
					//'vertical-align':'center',
					'margin-top':'1px',
					'margin-bottom':'1px',
					'padding-top':'1px',
					'padding-bottom':'1px',
					'background':'url(/sr_img/sr_hoverbuttons.gif) no-repeat',
					'background-position':'center'
					});
				$(button).appendTo($(name)); //.append($(button));
				$(button).click(function(){
                        	    var tabName = $(this).text();
                        	    var tabElt = document.getElementById("tab");
                        	    $(tabElt).each(function(index){
                                	    var aTags = tabElt.getElementsByTagName('a');
                                	    if(aTags){
                                    	    for(var i=0; i< aTags.length; i++){
                                       	        var compareText = aTags[i].text;
                                       	        if (compareText == null) //IE 6 hack
                                           	    compareText = aTags[i].innerText;
                                                if(compareText == tabName)
						{
                                           	    fireEvent(aTags[i], 'click');
						    window.scroll(0,0);
                                                    $(name).animate({top:0},{duration:500,queue:false});
						}
                                            }
                                            }else alert("couldnt find the tabs");

				    });
                                });
			    } //for each aTag
                        }else alert("couldnt find the tabs");
                }); //each tab anonymous function

});

/* Emulate an actual finger depressing on an actual electric rodent */
function fireEvent(element,event) {
   if (document.createEvent) {
       // dispatch for firefox + others
       var evt = document.createEvent("HTMLEvents");
       evt.initEvent(event, true, true ); // event type,bubbling,cancelable
       return !element.dispatchEvent(evt);
   } else {
       // dispatch for IE
       var evt = document.createEventObject();
       return element.fireEvent('on'+event,evt);
   }
}

/***********************************************************************
 *
 * If the IrCalendar exists inside the page, copy it & put it on the first tab
 */

$(document).ready(function(){

    if((document.getElementById('tab'))){
	var ic = document.getElementById("IrCalendar");

	/* if there is an IrCalendar in there... */
	if (ic){
            var IrCal = ic.cloneNode(true);

            var bdImage = document.getElementById("basicdata_img");

            if(IrCal && bdImage)
                bdImage.appendChild(IrCal);
	}
    }
});


