$(document).ready(function() {
  tooltip = {};
  $('#top_categories').find('.violet, .green, .yellow').each(function() { 
    var color = '';
    if ($(this).hasClass('violet')) color = 'violet';
    if ($(this).hasClass('green')) color = 'green';
    if ($(this).hasClass('yellow')) color = 'yellow';
    $(this).tooltip({
      delay: 0, showURL: false, track: true, opacity: 1, fixPNG: true, showBody: ' - ', extraClass: 'pretty fancy', top: 15, left: 5,
      bodyHandler: function() { 
        if (typeof tooltip[color] == 'undefined') tooltip[color] = $.ajax({'url': ROOT_BASE+'/sk/index-tooltip?color='+color, 'async': false}).responseText;
        return tooltip[color];
      }
    });
  });
  
  // droplinemenu.buildmenu("menu");
});

$(document).ready(function() { set_wrapper_height(); });
$(window).resize(function() { set_wrapper_height(); });


function mail_to(address, subject, body) {
  if (typeof subject == 'undefined') subject = 'Z webstránky www.wai.sk ...';
  if (typeof body == 'undefined') body = '';
  var location = 'mai'+'lto:'+address+'@'+'wai.sk?subject='+encodeURI(subject)+(body == '' ? '' : '&'+'b'+'ody='+encodeURI(body));
  window.location = location;
};

function get_screen_size() {
  var winH = 0;
  var winW = 0;
  if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=='Netscape') {
    winW = window.innerWidth;
    winH = window.innerHeight;
   } else if (navigator.appName.indexOf('Microsoft')!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
   } else {
    winW = window.offsetWidth;
    winH = window.clientHeight;
   };
  };
  return [winW, winH];
};

function set_wrapper_height() {
  var scrres = get_screen_size();
  // if (!jQuery.browser.msie) {
    // $('#wrapper').css({'width': '100%', 'height': (scrres[1] - 180) + 'px', 'overflow': 'auto'});
  // };
};

function check_email(email) {
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
  return email.search(re) == 0;
}


function homepage_tab_selector_init() {
  $(".TabContainer .TabMenu span:first").addClass("TabSelector");

  //Basic hover action
  $(".TabContainer .TabMenu div").mouseover(function(){
    $(this).addClass("TabHovering");
  });
  $(".TabContainer .TabMenu div").mouseout(function(){
    $(this).removeClass("TabHovering");
  });
  
  //Add click action to tab menu
  $(".TabContainer .TabMenu span.TabTitle").click(function(){
    //Remove the exist selector
    $(".TabSelector").removeClass("TabSelector");
    //Add the selector class to the sender
    $(this).addClass("TabSelector");
    
    //Find the width of a tab
    var TabWidth = $(".TabContent:first").width();
    if(parseInt($(".TabContent:first").css("margin-left")) > 0)
      TabWidth += parseInt($(".TabContent:first").css("margin-left"));
    if(parseInt($(".TabContent:first").css("margin-right")) >0)
      TabWidth += parseInt($(".TabContent:first").css("margin-right"));
    //But wait, how far we slide to? Let find out
    var newLeft = -1* $("span.TabTitle").index(this) * TabWidth;
    //Ok, now slide
    $(".AllTabs").animate({
      left: + newLeft + "px"
    },1000);
  });
};
