function print_overview(){
	with (screen){
	  sirka = (availWidth < 700)? availWidth : 700;
	  vyska = 700;
  }
  okno = window.open("../../../print_article.php","okno","width=" + (sirka) + ",height=" + (vyska) + ",menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes");
  //okno.focus();
}

function getObj(objName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[objName] : document[objName];
}

function sendOver(sp_id){
  getObj("heading_flash").sendOver(sp_id);
}
function sendOut(sp_id){
  getObj("heading_flash").sendOut(sp_id);
}

function switchLangDealer() {
  a = $('#select_lang_dealer option:selected').val();
  location.replace(a);
}

function showHideText(id) {
	$('#'+id+'_short').toggle();
	$('#'+id+'_whole').toggle();
}

function hideSearchText() {
	$('#search_text').val('');
}

$(document).ready(function(){

  controls_set_functionality();

  $.ajaxSetup({
    complete: function(XMLHttpRequest, textStatus) {
      controls_set_functionality(); // the options for this ajax request
    }
  });

  /**
   * odkazy do nového okna
   */
  $("a.t_out").live("click", function(){
    open($(this).attr("href"));
    return false;
  });
  

  /**
   * rozbalovací texty po kliknutí na odkaz
   */
  $('a.showbox').live("click", function(){
    $($(this).attr('href') + ' p:first-child').css('margin-top','0px');
    $($(this).attr('href')).toggle(100);
    return false;
  });

  /**
   * vložení flashe do záhlaví stránky
   */
  var flashvars = {};
  var flashparams = {
    quality: "high",
    bgcolor: "transparent",
    allowScriptAccess: "sameDomain",
    allowFullScreen: "false",
    wmode: "transparent"
  };
  var flashattributes = {
    id: "heading_flash",
    name: "heading_flash"
  };  
  swfobject.embedSWF("/flash/homer_kalas5.swf", "heading_flash", "950", "279", "9.0.0", "", flashvars, flashparams, flashattributes);  

  /**
   * vložení flashe
   */
  var flashvars = {};
  var flashparams = {
    quality: "high",
    bgcolor: "transparent",
    allowScriptAccess: "sameDomain",
    allowFullScreen: "false",
    wmode: "transparent"
  };
  var flashattributes = {
    id: "mapa_prodejen5",
    name: "mapa_prodejen5"
  };  
  swfobject.embedSWF("/mapa_prodejen5.swf", "mapa_prodejen5", "480", "570", "9.0.0", "", flashvars, flashparams, flashattributes);

  /**
   * ----------------- FORMULARE obecne ------------------------------
   */
  $("input.numbersonly").live("keypress", function(e){
    return numbersonly(e, false);
  });

  $("input.numbersonly_dec").live("keypress", function(e){
    return numbersonly(e, true);
  });

  $("input.psconly").live("keypress", function(e){
    return psconly(e);
  });

  $("input.static").live("keypress", function(e){
     return false;
  });
  /**
   * ----------------- FORMULARE obecne KONEC------------------------------
   */
   

  /**
   * -------------------------------- MENU ----------------------------------------------
   */
  $("#menu_main ul.submenu")
    .append('<li class="last-child"><span class="last-child_left"></span><span class="last-child_right"></span></li>');

  /**
   * ---- menu v horní liště ----
   */
  $("ul#menu_main a").hover(
    function() {
      menu_reset_timeout(); /*ošetřuje speciální případ, kdy se z rozbaleného menu vrací zpět na tlačítko na liště*/
      var position = $(this).position();
      var submenu = $(this).siblings('ul.submenu');
      var my_parent_menu = $(this).closest('ul');
      skryj_menu(my_parent_menu, submenu);
      if ( submenu.length ) {
      
        var menu_main = my_parent_menu.attr('id') == 'menu_main' ? true : false;
        
        /**
         * stylování - není pro funkčnost menu potřeba - uvedeno zde kvůli složité grafice
         */
        var submenu_width = submenu.outerWidth();
        var spans_width = 13;
        submenu.children('li.last-child').css('left', spans_width + 'px').css('width', (submenu_width - (2 * spans_width)) + 'px');
        /**
         * END stylování
         */
         
        if ( menu_main ) {
          var left_offset = 0;
          submenu.css("left", (position.left - left_offset) + "px");
        }
        else {
          var left_offset = $(this).outerWidth() + 20;
          submenu.css("left", (position.left + left_offset) + "px");
          submenu.css("top", position.top + "px");
          /**
           * kvůli složité grafice výjimka pro IE 6:
           */
          if ( $.browser.msie && parseInt($.browser.version) <= 6 ) {
            submenu.css("left", (position.left + left_offset - 10) + "px");
          }
        }
        if ( $.browser.msie && parseInt($.browser.version) <= 6 ) {
          submenu.css('display','block');
          /**
           * nastavení šířky rozbalovaného submenu - vzhledem k chybám v IE6 se musí řešit takto, protože IE6 není schopen dynamicky přizpůsobit šířku submenu jeho obsahu
           * proto je ve stylech pro IE6 nastaveno ul#menu_main ul.submenu { width:0px; }
           */
          var submenu_width = 0;
          submenu.children('li').each(function(){
            if ( $(this).width() > submenu_width ) {
              submenu_width = $(this).width();
            }
          });
          submenu.width(submenu_width);
        }
        else {
          submenu.slideDown("fast");
        }
      }
    },
    function() {
      var my_parent_menu = $(this).closest('ul');
      menu_skryt_timeout(my_parent_menu);
    }
  );
  
  $("#menu_main ul.submenu").hover(
    function() {
      $(this).prev().addClass('active');
      menu_reset_timeout();
    },
    function() {
      var my_parent_menus = $(this).closest('ul'); //protože jsme v "ul", je to včetně aktuálního "ul"
      menu_skryt_timeout(my_parent_menus[1]); //proto chceme až jeho rodiče "my_menu[1]"
    }
  );
  /**
   * ---- menu v horní liště konec ----
   */

  /**
   * -------------------------------- MENU konec ----------------------------------------------
   */


  /**
   * odeslání ajaxového formuláře
   */
  $("form.ajax_form").submit(function(){
    var form_obj = this;
    var ajax_ident = $(form_obj).find('input:hidden[name=ajax]');
    if ( !ajax_ident.length ) {
      $(this).append('<input type="hidden" name="ajax" value="ajax" />');
    }
    $(this).ajaxSubmit(
      {
        success: function(data){
          $(form_obj).find(".form_err").remove();
          $(form_obj).find(".form_done").remove();
          $(form_obj).find(".form_err_main").remove();
          if ( data.zpracovano=='ok' ) {
            $(form_obj).before('<p class="form_done">' + data.ok_msg + '</p>');
            $(form_obj).clearForm();
            $(form_obj).css('display','none');
          }
          else {
            if ( data.err_msg.length ) {
              $(form_obj).prepend('<p class="form_err_main">' + data.err_msg + '</p>');
            }

            for ( var i=0;i<data.err_elements.length;i++ ) {
              $(form_obj).find('#' + data.err_elements[i].err_msg_elem_id).html('<span class="form_err">' + data.err_elements[i].err_msg + '</span>');
            }
          }
        },
        dataType: 'json'
      }
    );
    return false;
  });
  


  /**
   * homepage - oranžový rámeček obrázku po najetí myší na odkaz
   */
  /*
  $('#hp_news_box_content a').hover(
    function() {
      $(this).closest('div.item').find('img.tn').addClass('hover');
    },
    function() {
      $(this).closest('div.item').find('img.tn').removeClass('hover');
    }
  );
  */
  
  /**
   * homepage - novinky
   */
  $('#hp_news_navi a').live('click', function(){
    var navi_id = $(this).attr('id');
    if ( navi_id == 'hp_news_navi_prev' ) {
      var news_box_id = $('#hp_news_box_container div.item:visible').prev('div.item').attr('id');
    }
    else if ( navi_id == 'hp_news_navi_next' ) {
      var news_box_id = $('#hp_news_box_container div.item:visible').next('div.item').attr('id');
    }
    else {
      var news_box_id = $(this).attr('rel');
    }
    
    show_hp_news(news_box_id);
    /**
     * pokud se ručně vyžádá změna novinky, automatické rolování se zastavuje
     */
    clearTimeout(change_hp_news_p_timeout);
    return false;
  });
  
  /**
   * spuštění automatické změny novinek na homepage
   */
  if ( $('#hp_news_box_container').length ) {
    change_hp_news_p_timeout = setTimeout("change_hp_news()", change_hp_news_interval);
  }

  /**
   * spuštění automatické změny design boxů
   */
  $('div[id^="design_box_position_"]').each(function(){
	  var total_items = $(this).children('div.item').length;
	  if ( total_items > 1 ) {
	    var pos_id = $(this).attr('id');
	    var pos_change_interval = $(this).attr('rel') * 1;
        //var pos_idx = actual_news_box_id.substr('hp_news_item_'.length) * 1;	    
	    setTimeout("change_designbox_position('" + pos_id + "')", pos_change_interval);
	  }
  });


	$("a[rel^='lightbox']").slimbox(
    {
      overlayFadeDuration:100,
      resizeDuration:100,
      imageFadeDuration:100,
      captionAnimationDuration:50,
      counterText: "Obrázek {x} z {y}",
      closeKeys: [27, 90] /*Esc Z*/
    }, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
  
});


function controls_set_functionality() {

  /**
   * původní nápad, jak nahrazovat znak ® za horní index, ale v IE dochází k probliknutí,
   * protože nejprve se zobrazí původní znak a pak teprve zmenšený
  $("h1,h2,h3,h4,h5,h6,p,li").filter(":contains('®')").each(function(){
    var content = $(this).html();
    content = content.replace("®", "<sup>&reg;</sup>");
    $(this).html(content);
  });
  */


  /**
   * *************************** FORMULARE obecne ***********************************
   */
  /**
   * zmizení defaultního textu po získání focusu
   */
  $("input.default_text")
    .addClass('default_text_style')
    .attr("default_text",function(){return $(this).val();})
    .focus(function(){
      $(this).removeClass('default_text_style');
      $(this).attr("before_click_text",$(this).val());
      if ( $(this).val()==$(this).attr("default_text") ) {
        $(this).val("");
      }
    })
    .blur(function(){
      if ( !$.trim($(this).val()) && $(this).attr("before_click_text") ) {
        $(this).addClass('default_text_style');
        $(this).val($(this).attr("before_click_text"));
      }
    });
  /**
   * *************************** FORMULARE obecne KONEC ***********************************
   */
}



/**
 * -------------------------------- MENU ----------------------------------------------
 */
var menu_timeout = 150; /*timeout, po kterém bude menu zrušeno - může být klidně nula, tzn. ihned po opuštění kurzorem - používá se vlastně jen ve funkci skryt_timeout*/
var menu_p_timeout = null; /*ukazatel na volání fukce setTimeout - používá se ve fci skryt_timeout a reset_timeout*/

function menu_skryt_timeout(menu_obj, except_obj) { /*tato funkce nastavuje timeout pro schování*/
  menu_p_timeout = setTimeout(function() { skryj_menu(menu_obj, except_obj); }, menu_timeout);
}
function menu_reset_timeout() { /*a tato funkce ho ruší*/
  clearTimeout(menu_p_timeout);
}


function skryj_menu(menu_obj, except_obj) {
  if ( !menu_obj ) { menu_obj = $("#menu_main"); }
  var submenus_obj = ( except_obj && except_obj.length ) ? menu_obj.find('ul.submenu').not(except_obj) : menu_obj.find('ul.submenu');
  submenus_obj.each(function() {
    if ( $(this) != $(except_obj) ) {
      if ( $.browser.msie && parseInt($.browser.version) <= 6 ) {
        $(this).css('display','none');
        $(this).prev().removeClass('active');
      }
      else {
        $(this).slideUp(50, function() { /*hodnota 50 pouze kvůli složité grafice, lépe "fast"*/
          $(this).prev().removeClass('active');
        });
      }
    }
  });
}
/**
 * -------------------------------- MENU konec ----------------------------------------------
 */


/**
 * automatická změna novinek na homepage
 */
var change_hp_news_p_timeout = null; /*ukazatel na volání fukce setTimeout*/
var change_hp_news_interval = 4000;

function change_hp_news() {
  var total_news = $('#hp_news_box_container div.item').length;
  var actual_news_box_id = $('#hp_news_box_container div.item:visible').attr('id');
  var actual_news_box_idx = actual_news_box_id.substr('hp_news_item_'.length) * 1;
  
  var next_news_box_idx = actual_news_box_idx + 1;
  if ( next_news_box_idx > total_news ) {
    next_news_box_idx = 1;
  }
  
  var show_news_box_id = 'hp_news_item_' + next_news_box_idx;

  show_hp_news(show_news_box_id);
  
  change_hp_news_p_timeout = setTimeout("change_hp_news()", change_hp_news_interval);
}
function show_hp_news(news_box_id) {
  var news_box = $('#' + news_box_id);
  if ( news_box.length ) {
    $('#hp_news_box_container div.item:visible').hide();
    $('#hp_news_navi a').removeClass('active');
    $('#hp_news_navi a[rel="' + news_box_id + '"]').addClass('active');
    news_box.slideDown();
  }
}
/**
 * konec automatická změna novinek na homepage
 */


/**
 * automatická změna prvků v design boxech
 */
function change_designbox_position(pos_id) {
	 //alert(pos_id);
  var pos_change_interval = $('#' + pos_id).attr('rel') * 1;
  var total_boxes = $('#' + pos_id + ' div.item').length;
  var pos_idx = pos_id.substr('design_box_position_'.length) * 1;
  var actual_box_id = $('#' + pos_id + ' div.item:visible').attr('id');
  var id_prefix = 'position_' + pos_idx + '_box_';
  var actual_box_idx = actual_box_id.substr(id_prefix.length) * 1;
  
  var next_box_idx = actual_box_idx + 1;
  if ( next_box_idx > total_boxes ) {
    next_box_idx = 1;
  }
  
  var show_box_id = id_prefix + next_box_idx;
//alert(next_box_idx);
 //alert(show_box_id);
  show_designbox_item(pos_id, show_box_id);
  
  setTimeout("change_designbox_position('" + pos_id + "')", pos_change_interval);
}
function show_designbox_item(pos_id, box_id) {
  var box = $('#' + box_id);
  //alert(box_id);
  if ( box.length ) {
	  //alert(box_id);
    $('#' + pos_id + ' div.item:visible').hide();
    box.show();
  }
}
/**
 * konec automatická změna prvků v design boxech
 */

//pouze čísla a případně desetinný oddělovač
function numbersonly(e, dec) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;

  keychar = String.fromCharCode(key);

  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;
  else if ( ("0123456789").indexOf(keychar) > -1 )
    return true;
  else if ( dec && ((".,").indexOf(keychar) > -1) ) {
    return true;
  }
  else
   return false;
}


//pouze čísla a mezera
function psconly(myfield, e) {
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;

  keychar = String.fromCharCode(key);

  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;
  else if (((' 0123456789').indexOf(keychar) > -1))
    return true;
  else
   return false;
}




