﻿var sliderOptions;
var to;

function setGraphTop(actual) {
   var vyskaBoxu = $('#currencies').height() + 5;
   var vyskaGrafu = $('#curGraph').height();
   var ofsetBoxu = $('#currencies').offset().top;
   var ofsetPolozky = actual.offset().top;
   var max = ofsetBoxu + vyskaBoxu - vyskaGrafu;
   var setTop = ofsetPolozky - ofsetBoxu;

   if ( ofsetPolozky > max ) {
      setTop = vyskaBoxu - vyskaGrafu + 10;
   }
//		console.debug('polozka:', ofsetPolozky, 'max: ', max, 'graf: ', vyskaGrafu, 'box:', vyskaBoxu);
   
	$('#curGraph').css('top',setTop);
}
function urlencode(str) {  
   str = escape(str);
   str = str.replace('+', '%2B');
   str = str.replace('%20', '+');
   str = str.replace('*', '%2A');
   str = str.replace('/', '%2F');
   str = str.replace('@', '%40');
   return str;
}

function reSetCurrencyTable(el, actual){ //
   var actual = $('#'+actual);
   var element = $('#'+el+' table');
   $('#'+el+' tr.active').removeClass('active');
   actual.addClass('active');
   var vyskaBoxu = element.height();
   var vyskaGrafu = $('#curGraph').height();
   var ofsetBoxu = element.offset().top;
   var ofsetPolozky = actual.offset().top;
   var max = ofsetBoxu + vyskaBoxu - vyskaGrafu;
   var setTop = ofsetPolozky - ofsetBoxu;
   
   if ( ofsetPolozky > max ) {
      setTop = vyskaBoxu - vyskaGrafu;
   }

   $('#curGraph').css('top',setTop);
}

function highlightContent(searchText) {
    var options = {
		exact:"partial",
		style_name_suffix:false,
		highlight:"#content",
		keys:searchText
	}
	highlightReset();
  $('#search form').removeClass('load');
	jQuery(document).SearchHighlight(options);
}



function highlightReset() {
   	$('span.hilite').each(function () {
   	    $(this).replaceWith($(this).html());
   	});
}

function getReady() {
    // switch between clasic search and onpage search (highlite)
    $('#search #ch').click(function(){
        if ($(this).attr('checked'))  {
            highlightContent($('#q').val());
            $('body').addClass('inSearch');
        } else {
            highlightReset();
            $('body').removeClass('inSearch');
        }
    });
    
    
    // hightlight the text
    $("#q").keypress(function (e) {
        if ($('#search #ch').attr('checked'))  {
            if (e.which == 32 || e.which == 13 || e.which == 44 || e.which == 46) { // space, enter, ",", delete
                highlightContent($(this).val());
            }
            if (e.which == 13) { // enter
                return false;
            }
            window.clearTimeout(to);
            to = window.setTimeout("highlightContent($('#q').val())", 1000);
            $('#search form').addClass('load');
        }
    });
    
    
    $('.infoTitle').cluetip({splitTitle: '|'});


    $('.sortingTable tr, table.small tr').not($(".article .sortingTable tr")).each(function() {
         $(this).mouseover(function() {
            $(this).addClass('over');   
         });
         $(this).mouseout(function() {
            $(this).removeClass('over');   
         });
    });
    $('.addCompare').each(function() {
         $(this).click(function() {
            try {
               eval($(this).attr('rel'));
               if ($(this).attr('checked'))  {
                  $(this).attr('checked','checked');
               } else {
                  $(this).attr('checked','');
               }
            } catch(e) {}
         });
    });
   // $('.datePick').datepicker({yearRange: '1918:2020', firstDay: 1, changeFirstDay: false, dateFormat: 'd.m.yy', showOn: 'button', buttonImage: 'images/ico/calendar.gif', buttonImageOnly: true, showOtherMonths:true});

    $('#prepinacKalkulacekParent .calculatorsWithMenu li a').each(function() {
         $(this).click(function() {
            var id = $(this).parent().attr('id');
            id = id.substring(id.indexOf('_'),id.length);
            $('#prepinacKalkulackyBox'+id).addClass('countForm');
            //$(this).parent().addClass('active');
            var calcHeight = $('#prepinacKalkulackyBox'+id).height() + 12;
            var ulTop = $('#prepinacKalkulacekParent ul').offset().top - $('#prepinacKalkulacekParent .in').offset().top;
            var ulHeight = $('#prepinacKalkulacekParent ul').height() + ulTop;
            if (calcHeight > ulHeight)   {
               height = calcHeight;
               $('#prepinacKalkulackyBox'+id).css('top', 10);
            } else {
               height = ulHeight;
               
               var liHeight = $(this).parent().height();
               var liTop = $(this).parent().offset().top;
               var liBottom = liHeight + liTop;
               var calcTop = $('#prepinacKalkulacekParent .in').offset().top - 15;
               var calcBottom = calcTop + calcHeight;
               
               if (liBottom > calcBottom) {
                  var diff = liBottom - calcBottom;
                  $('#prepinacKalkulackyBox'+id).animate({ top: diff },500);
               } else {
                  $('#prepinacKalkulackyBox'+id).css('top', 10 );
               }

            }
            $('#prepinacKalkulacekParent > .in').animate({ height: height}, 500 );
         });
    });
}


$(document).ready(function(){


  // $.datepicker.setDefaults($.datepicker.regional['cs']);



   $('#menu .moje').mouseover(function() {
      $('#menu #microLogin').removeClass('hidden');   
   });
   $('#ribbon').mouseover(function() {
      $('#menu #microLogin').addClass('hidden');   
   });

   setTimeout("getReady();", 300); 
   
   $(".extList span").click(function(){
       $(this).parent().next().slideToggle("normal");
       $(this).toggleClass("plus");
    });
    $(".extList span").each(function(){
       $(this).parent().next().slideToggle("fast");
       $(this).toggleClass("plus");
    });
    $(".toggle p.plus").click(function(){
       $(".extList span").each(function(){
          $(this).parent().next().slideDown("fast");
          $(this).removeClass("plus");
       });
    });
    $(".toggle p.minus").click(function(){
       $(".extList span").each(function(){
          $(this).parent().next().slideUp("fast");
          $(this).addClass("plus");
       });
    });
});
