// uzivatelska funkce; zobrazovani a skryvani zprav

function showMsg(text,nextAction){

      hs.Expander.prototype.onBeforeClose = function(sender) { eval(nextAction)};
      return hs.htmlExpand(null, { objectType: 'ajax', src: '/ajax/showmsg.php?text='+utf8encode(text), wrapperClassName: 'draggable-header', headingText: 'Informace', preserveContent: false } );

}

function hideMsg(){
      hs.close();
      hs.Expander.prototype.onBeforeClose = '';
}

$(document).ready(function(){

    // lighter
    menuContainerWidth = document.getElementById('menuContainer').offsetWidth;
    menuContainerWidthHalf = Math.round( menuContainerWidth / 2 );
    menuPos = findPos(document.getElementById('menuContainer'));
    lighterWidth = document.getElementById('lighter').offsetWidth;
    lighterHeight = document.getElementById('lighter').offsetHeight;
    lighterWidthHalf = Math.round( lighterWidth / 2 );

    var menu = document.getElementById('menu');

    addEvent(menu,'mousemove',getMouseXY);

    addEvent(menu,'mouseout',hide);
    //addEvent(menu,'mouseover',show);

    markActive();

    // hyphenator
    Hyphenator.config({
        		displaytogglebox : false
        	});
    Hyphenator.addExceptions('cs','FORTRAN, Michal, Bumbálek, webhit, Webhit, WEBHIT');
    Hyphenator.run();

})

function searchForm(val){
   if (val=='vyhledat...') document.getElementById('inputSearch').value = '';
}

function quickContactForm(val){
   if (val=='Prostor pro váš text'){ document.getElementById('quickContactText').value = '';
   document.getElementById('quickContactText').style.color='black'; }
}

// uzivatelska funkce; obarvovani vstupnich formularovych poli pro ucely kontrolnich funkci

function iActive(stav,elem){

  switch(stav){
  case 'on':      elem.style.borderColor='#00A0E3'; elem.style.backgroundColor='#ffffff'; break;
  case 'off':     elem.style.borderColor='#AFAFAF'; elem.style.backgroundColor='#ffffff'; break;
  case 'err':     elem.style.borderColor='#BE1F2D'; elem.style.backgroundColor='#f4acb1'; break;
  }

}

// uzivatelska funkce; inicializace obarvovani vstupnich poli
function inputColorInit(){

    var inputs=document.getElementsByTagName("input");
    for (var i=0;i<inputs.length;i++){
         addEvent(inputs[i], 'focus', function(){ iActive('on',this) });
         addEvent(inputs[i], 'blur', function(){ iActive('off',this) });

    }

    var selects=document.getElementsByTagName("select");
    for (var i=0;i<selects.length;i++){
         addEvent(selects[i], 'focus', function(){ iActive('on',this) });
         addEvent(selects[i], 'blur', function(){ iActive('off',this) });
    }

    var textareas=document.getElementsByTagName("textarea");
    for (var i=0;i<textareas.length;i++){
         addEvent(textareas[i], 'focus', function(){ iActive('on',this) });
         addEvent(textareas[i], 'blur', function(){ iActive('off',this) });
    }

}

addLoadEvent(inputColorInit);

function boxControl(state,name){
  if(state){ document.getElementById(name+'Modules').style.display='';
             document.getElementById(name+'Bottom').style.display='';
           }
  else     { document.getElementById(name+'Modules').style.display='none';
             document.getElementById(name+'Bottom').style.display='none';
           }
}

function checkDomain(){
   domain = document.srcDomain.domain.value;
   if (domain!='') hs.htmlExpand(null,{src: '/ajax/whois.php?action=check&domain='+utf8encode(domain), wrapperClassName: 'draggable-header', headingText: 'Ověření domény '+domain+'.cz', objectType: 'ajax', width: 400})
   else showMsg('Zadejte prosím název domény.');

}

var actLeft;

function goAhead(){
   if (document.getElementById('Wdetect').style.marginLeft=='') actLeft = 0;
   actLeft = (actLeft - 1);
   document.getElementById('Wdetect').style.marginLeft = actLeft + 'px';
   if ( actLeft > ((document.getElementById('Wdetect').offsetWidth - document.getElementById('progress').offsetWidth) * (-1)) )
   setTimeout("goAhead()",50);
   else
   setTimeout("goBack()",2000);
}

function goBack(){
   if (document.getElementById('Wdetect').style.marginLeft=='') actLeft = 0;
   actLeft = (actLeft + 1);
   document.getElementById('Wdetect').style.marginLeft = actLeft + 'px';
   if ( actLeft < 0 )
   setTimeout("goBack()",50);
   else
   setTimeout("goAhead()",2000);
}

var actRef = 0;

function reference(){
   refs = document.getElementsByClassName('refProject');
   fadeOutElementNum = actRef;
   fadeInElementNum = actRef + 1;
   actRef += 1;
   if (actRef>=refs.length) { actRef = 0; fadeInElementNum = 0; }
   fadeOutElement = refs[fadeOutElementNum];
   fadeInElement = refs[fadeInElementNum];
   setTimeout('fadeSwitch(fadeOutElement,fadeInElement)',10000);
}

function fadeSwitch(fadeOutElement,fadeInElement){

   $(fadeOutElement).fadeOut( 'fast', function(){ $(fadeInElement).fadeIn('fast', reference())} )

}
