﻿var ticker = null; /* ticker object */
function setTickerSpeed() {
	ticker.changeInterval(45);
}

function startticker()
{
	ticker = new Ticker('ticker', 'ticker', 1, 45);
	ticker.start();
}

var profilWeb  = {
   mainBox : "profil-pavouk",
   treeBox : "profil-tree",
   treeElm : "li",
   contactBox : "profil-kontakty",
   contactBoxActiveClass : "profil-kontakty-active",
   contactBoxInActiveClass : "profil-kontakty-inactive",
   contactElm : "item",
   triggerPrefix : "tr-",
   hiddenClass : "hidden",
   offerBox : "profil-off",

   init : function () {
      this.main = getElem(this.mainBox)
      if(!this.main) return;
      
      /* získá triggery */
      this.tree = getElem(this.treeBox)
      if(!this.tree) return;
      this.treeItems = this.tree.getElementsByTagName(this.treeElm);
      
      /* získá výstup */
      this.contactTree = getElem(this.contactBox)
      if(!this.contactTree) return;
//      this.contactItems = this.contactTree.getElementsByTagName(this.contactElm);
      this.contactItems = getElementsByClass(this.contactElm,'div',this.contactTree);

      /* skrije kontakty */
      addClass(this.contactTree,this.contactBoxInActiveClass);
      
      /* zavírač okna */
      this.offer = getElem(this.offerBox)
      this.offer.onclick = function () {
         for(var i=0;i<profilWeb.contactItems.length;i++) {
            addClass(profilWeb.contactItems[i],profilWeb.hiddenClass);
            remClass(profilWeb.contactTree,profilWeb.contactBoxActiveClass);
         }
         addClass(this,profilWeb.hiddenClass);
      }

      for(var i=0;i<this.treeItems.length;i++) {
         addClass(this.contactItems[i],this.hiddenClass);
         this.treeItems[i].onclick = function() {
            elemString = this.id.substring(profilWeb.triggerPrefix.length,this.id.length);
            el = getElem(elemString);
            if(!hasClass(el.parentNode,profilWeb.contactBoxActiveClass)){
               remClass(el,profilWeb.hiddenClass);
               addClass(el.parentNode,profilWeb.contactBoxActiveClass);
               remClass(getElem(profilWeb.offer),profilWeb.hiddenClass);
            }else{
               for(var i=0;i<profilWeb.contactItems.length;i++) {
                  addClass(profilWeb.contactItems[i],profilWeb.hiddenClass);
               }
               remClass(el,profilWeb.hiddenClass);
            }
            return false;
         }         
      }
   }
}

var showAsTabs = {
   tabHeadTag : "h4",
   tabDefault : 0,
   tabBox_className : "tabbox",
   tab_className : "tab",
   tab_activeClass : "active",
   tab_overClass : "over",
   
   init : function(tabDiv) {
      this.tabDiv = getElem(tabDiv)
      if(!this.tabDiv) return;
   	addClass(this.tabDiv,this.tabBox_className);
      
      this.tabHead = this.tabDiv.getElementsByTagName(this.tabHeadTag);
      if(!this.tabHead) return;
      
      for(var t=0;t<this.tabHead.length;t++) {
   	   addClass(this.tabHead[t].parentNode,this.tab_className);
   	   addClass(this.tabHead[t].parentNode,this.tab_className+[t]);
      }
      
      if(this.tabHead.length < this.tabDefault) this.tabDefault = this.tabHead.length -1;      
   	
      addClass(this.tabHead[this.tabDefault].parentNode,this.tab_activeClass);
      
      for(var t=0;t<this.tabHead.length;t++) {
         this.tabHead[t].onmouseover = function() {
            swapClass(this,showAsTabs.tab_overClass);
         }
         this.tabHead[t].onmouseout = function() {
            swapClass(this,showAsTabs.tab_overClass);
         }
         this.tabHead[t].onclick = function() {
            tabDiv = getElem(this.parentNode.parentNode);
            siblings = tabDiv.getElementsByTagName(showAsTabs.tabHeadTag);
            if(!siblings) return;
            for(var t=0;t<siblings.length;t++) {
               remClass(siblings[t].parentNode,showAsTabs.tab_activeClass);
            }
            addClass(this.parentNode,showAsTabs.tab_activeClass);
         }
      }
   }
}
