var removeText;

function showLogotype(id, blockid) {
  var logoId = id;
  if (previousLogoId == logoId) return;

  $('#clients_slider'+blockid+' #logotype'+blockid+logoId).show();
  if (document.getElementById('logotable'+blockid+logoId))
    document.getElementById('logotable'+blockid+logoId).style.left = '-20px';
  $('#clients_slider'+blockid+' #logotype'+blockid+previousLogoId).hide();
  if (document.getElementById('logotable'+blockid+previousLogoId))
    document.getElementById('logotable'+blockid+previousLogoId).style.left = '-3500px';
  previousLogoId = logoId;
}   

function _checkVal() {
    if (document.getElementById('fulltext'))
        if (document.getElementById('maininput1'))
            document.getElementById('fulltext').value = document.getElementById('maininput1').value;
    var simpleFilter = true;
    
    if (!simpleFilter) {
        $('#region_id').attr("value", $('#region_id2').val());
        $('#specialization_id').attr("value", $('#specialization_id2').val());
    }
    
    if($('#search-ad').serialize() != previousSerialize) {
        $.post(
            path + "inzeraty/found",
            $('#search-ad').serializeArray(),
            function(response) {
                var results = parseInt(response);
                if(results == NaN)
                    results = 0;
                if (simpleFilter)
                    $('#simpleFilter strong').text(results);
                else
                    $('#advancedFilter strong').text(results);
            }
        );
        previousSerialize = $('#search-ad').serialize();
    }
}

function checkEmptyForm() {
    document.getElementById('fulltext').value = document.getElementById('maininput1').value;
    if ($('.bit-box').size() == 0 && ($('#maininput1').val() == helpMe || $('#maininput1').val() == '') && ($('#region_id').val() == 0) && ($('#specialization_id').val() == 0)) {
      alert('Musíte vyplnit alespoň některé z kritérií pro vyhledávání!');
      //e.stopPropagation();
      return false;
    }
    return true;
}

function submitSearchForm(e) {
    
    if (document.getElementById('fulltext'))
        document.getElementById('fulltext').value = document.getElementById('maininput1').value;

    if (e.which == 13) {

        if ($('#search-ad').attr('action') != null) {
            $('#search-ad').submit();
        }
        else if ($('#search-form').attr('action') != null) {
            $('#search-form').submit();
        }
    }
}

function bar(url){
    wasOpen  = false;
    win = window.open(url);
    return (typeof(win)=='object')?true:false;
}

function loader() {
  return '<div class="loader"><span>Načítám</span></div>';
}

/*
 * showOverlay() - Zobrazi informacni zpravu v nove vrstve
 * @param title    Titulek vrstvy
 * @param text     Text zpravy (muze obsahovat HTML tagy)
 * @param width    Sirka okna se zpravou (nepovinne)
 **/
function showOverlay(title, text, width, buttons) {
    
	if(!$('#overlay').length) {
		// generate HTML code
		var html = '<div id="overlay">'+
							 '<div class="lightbox">'+
									'<div class="top"><b></b></div>'+
									'<div class="inside">'+
										'<h2></h2>'+
										'<div class="msg">'+
											'<p></p>'+
										'</div>'+
										'<a class="close xclose" href=""></a>'+
										'<p class="buttons"></p>'+
										'<div class="clear1px"></div>'+
									'</div>'+
									'<div class="bottom"><b></b></div>'+
								'</div>'+
								'<div class="lightbox_overlay"></div>'+
								'</div>';

		$('body').append(html);

		$('#overlay').click(function() {
			hideOverlay();
                        window.scrollBy(0,1);
		});

		$('#overlay .lightbox').click(function(event) {
			event.stopPropagation();
			return;
		});
	}

	// remove all old buttons
	$('#overlay .buttons a').remove();

	if(buttons) {
        
		// custom buttons
		for(button in buttons) {
			var cssClass = '';
			if(buttons[button].close) {
				cssClass = ' xclose';
			}
            else
                cssClass = ' xbutton';

            
			if(!buttons[button].link)
				buttons[button].link = '';

			$('#overlay .buttons').append(' &nbsp; <a class="button button-overlay '+cssClass+'" href="'+buttons[button].link+'"><span><span>'+buttons[button].text+'</span></span></a>');
		}
	} else {
		// default button
		$('#overlay .buttons').append('<a class="button button-overlay xclose"><span><span>OK</span></span></a>');
	}

	// add actions to close buttons
	$('#overlay a.xclose').click(function(event) {
		hideOverlay();
                event.stopPropagation();
                window.scrollBy(0,1);
		return false;
	});

	// reset css
	$('#overlay .inside').css('height', 'auto');
	$('#overlay .lightbox').css('margin-top', 0);

	// show title & text
	$('#overlay .inside h2').text(title);
	$('#overlay .inside .msg').html(text);

	// show overlay
	$('#overlay').show();

	// calculate position of the box
	if(!$('#overlay .lightbox').data('defaultWidth')) {
		$('#overlay .lightbox').data('defaultWidth', $('#overlay .lightbox').width());
	}

	if(width) {
		// user defined width
		$('#overlay .lightbox').css('width', width);
		$('#overlay .lightbox').css('margin-left', -Math.round(width/2));

	} else {
		// default width
		$('#overlay .lightbox').css('width', '');
		$('#overlay .lightbox').css('margin-left', -Math.round($('#overlay .lightbox').data('defaultWidth')/2));
	}

	centerOverlay();

	return false;
}

function showOverlayContent(title, url, width, height, buttons) {
        
	if(!buttons)
		buttons = new Array({
									'text': 'OK',
									'href': '',
									'close': true
							})
	// zobrazeni overlay (zatim prazdne)
	showOverlay(
		title,
		loader(),
		width,
		buttons
	);

	if(height == 'max') {
		height = getWindowSize().height - 150;
	}

	$('#overlay .inside').css('height', height);
	//$('#overlay .lightbox').css('margin-top', -Math.round(height/3));
	$('#overlay .inside .msg').css('height', height-120);

	centerOverlay();

	// nacteni dat
	$.get(url, null, function(data) {
		$('#overlay .inside .msg').html(data);
	});

	return false;
}

function hideOverlay() {
    
	$('#overlay .inside .msg').html('');
	$('#overlay').hide();
        window.scrollBy(0,1);
}

function centerOverlay() {
	//if($.browser.msie && $.browser.version < 7)
		//return;

	height = getWindowSize().height;

  $.browser.msie6 =
    $.browser.msie
    && /MSIE 6\.0/i.test(window.navigator.userAgent)
    && !/MSIE 7\.0/i.test(window.navigator.userAgent);

	if ($.browser.msie6) {
		$('#overlay .lightbox').css('top', Math.round($('#overlay .lightbox').height()/2 + (height-$('#overlay .lightbox').height())/2));

		return;
	}

	//alert($('#overlay .lightbox').height() + ' - ' + height);
	if($('#overlay .lightbox').height() > height) {
		$('#overlay .lightbox').css('top', 50);
		$('#overlay .inside').css('height', height);
		$('#overlay .inside .msg').css('height', height - 120);

		//$('#overlay .lightbox').css('margin-top', -Math.round(height/3));

	} else {
		$('#overlay .lightbox').css('top', Math.round((height-$('#overlay .lightbox').height())/2));
	}
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	return {'width': myWidth, 'height': myHeight};
}

/*
 * Vytvori graficky <select> prvky
 **/
$(document).ready(function (){
     $('.newwindow').click(function() {
        return !bar(this.href);
     });

     $('#tip').mouseover(function() {
         $('#tip').css('background', 'white');
         document.getElementById('tip_show').style.display = 'none';
         document.getElementById('tip_hide').style.display = 'block';
     });
     $('#tip').mouseout(function() {
         $('#tip').css('background', 'none');
         document.getElementById('tip_show').style.display = 'block';
         document.getElementById('tip_hide').style.display = 'none';
     });

     make_select('selectbox');
     $(document).click(function() {
            $('div.selectbox-open').hide();
     });

     if ((typeof(scroll_to) !== 'undefined') && scroll_to) {
        $('#'+scroll_to).scrollTo(1000);
     }

     if ($('#robots')) $('#robots').attr('checked', true);
     
});

jQuery.fn.extend({
  scrollTo : function(speed, easing) {
    return this.each(function() {
      var targetOffset = $(this).offset().top;
      $('html,body').animate({scrollTop: targetOffset}, speed, easing);
    });
  }
});

function make_select(class_to) {
	$('div.'+class_to).each(function() {
		var select = $(this).find('select')[0];
		if(select) {
			// show selected option (text)
			$(this).append('<p>'+$(select).children(':selected').text()+'</p>');

			// create new DIV for all options
			var newDiv = document.createElement('div');
			$(newDiv).addClass('selectbox-open');
			var newUl = document.createElement('ul');

			// copy options from <select> to the new <ul>
			for(var i=0; i<select.options.length; i++) {
				var newLi = document.createElement('li');
				$(newLi).append(select.options[i].text);
				$(newLi).data('value', select.options[i].value);
				$(newUl).append(newLi);
			}

			// create new hidden input for selected option
			var newInput = document.createElement('input');
			newInput.type = 'hidden';
			newInput.name = $(select).attr('name');
			var id = $(select).attr('id');
			$(select).attr('id', '');
			newInput.id = id;
			newInput.value = $(select).val();

			// remove original select and append new hidden input
			$(select).remove();
			$(this).append(newInput);

			// add action to new list of options
			$(newUl).find('li').click(function(event) {
				$(this).parents('div').children('input:hidden').val($(this).data('value'));
				$(this).parents('div').children('input:hidden').trigger('change');

				$(this.parentNode.parentNode.parentNode).children('p').text($(this).text());
				$(this).parents('div').children('.selectbox-open').fadeOut('fast');
				event.stopPropagation();
			});

			// hover effect for MSIE
			if($.browser.msie) {
				$(newUl).find('li').hover(function(){$(this).addClass('hover')}, function(){$(this).removeClass('hover');});
			}

			// add action to show the list
			$(this).find('p').click(function() {
				$(this.parentNode).find('.selectbox-open').slideDown();
			});

			// append whole list to the form
			$(newDiv).append(newUl)
			$(this).append(newDiv);

			$(select).hide();
		}

	});
}

/*
 * Pruhovane tabulky
 */
$(document).ready(function() {
	$('table.stripped tr').each(function(i) {
		if(!(i%2))
			$(this).addClass('odd');
		});
});

/*
 * Hover tabulky
 */
if($.browser.msie && $.browser.version < 7) {
	$(document).ready(function() {
		$('table.hover tr').hover(function(){$(this).addClass('hover');}, function(){$(this).removeClass('hover');});
	});
}

/*
 * Klikatelne tabulky
 */
$(document).ready(function() {
	$('table.clickable tr').click(function() {
		var a = $(this).find('a');
		if(a.length) {
			document.location = a[0].href;
		}
	});
	$('table.clickable tr a').click(function(event) {
		event.stopPropagation();
	});
});

/*
 * Zatrhavaci tabulky
 */
$(document).ready(function() {
	$('table.selectable tbody tr').click(function() {
		var c = $(this).find(':checkbox');
		if(c.length) {
			c.get(0).checked = !c.get(0).checked;
		}
	});
	$('table.selectable :checkbox').click(function(event) {
		event.stopPropagation();
		return true;
	});
	
});

/*
 * Nacteni stranky
 */
$(document).ready(function() {
    
	$('#login-open').click(function() {
		$('#login .inside').slideToggle('slow');
		return false;
	});

        $('#login_help_link').click(function() {
                $('.popuplink').each(function () {
                    $(this).hide();
                });
		$('#login_help .login_help_inside').slideToggle();
		return false;
	});
        
	$('#login_form a.button').click(function() {
		$('#login_form').submit();
			 return false;
	});

    $('.formBox .submit').click(function() {
        if ($('#search-ad')) {
            if (checkEmptyForm())
                $('#search-ad').submit();
                        //if($('#region_id').val() == 1000) $('#region_id').attr("value", 0);
        }
        
        if ($('#search-candidate')) {
            if (!simpleFilter) {
                $('#region_id').attr("value", $('#region_id2').val());
                $('#specialization_id').attr("value", $('#specialization_id2').val());
            }
            $('#search-candidate').submit();
        }
            
        return false;
    });
     
    $('#search-suggest').mouseout(function() {
        hidefacebook = true;
        setTimeout('hideFace();', 200);
    });
    $('#search-suggest').mouseover(function() {
       hidefacebook = false;
    }); 
    
    //if (newLogoId)
      //  showLogotype(newLogoId);
	/*if($.browser.msie) {
		$('#login input').keyup(function(e) {
			if(e.keyCode == 13) {
				$('#login_form').submit();
			}
		});
	}*/

    $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 200;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popuplink', this).css('display', 'none');


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: -20,
                        right: 0,
                        display: 'block',
                        width: '100px',
                        height: '15px'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
    });
});

function hideFace() {
   if (hidefacebook) { 
        $('#search-suggest').hide('fast');      
   }
}

function resizeLogin() {
   $('#head #user').css('height', '150px');
}

/*
 * Odkazy na homepage
 */
$(document).ready(function() {
	$('#hp-overview div').hover(function() {$(this).addClass('hover')}, function() { $(this).removeClass('hover');});
	$('#hp-overview div').click(function() {document.location=$(this).find('a').attr('href');});
});

/*
 * Klienti na HP
 */
$(document).ready(function() {
	if(!$('#clients').length)
		return;

	// celkova sirka vsech log (obrazku)
	var totalWidth = 0;
	var imgs = $('#clients img')
	for(var i=0; i<imgs.length; i++) {
		totalWidth += imgs[i].width;
	}

	// mezery, ktere tedy zbyvaji
	newPadding = Math.floor((925-totalWidth)/(imgs.length-1));

	// nastaveni mezer vsem logum, krome posledniho (to tak bude zarovnane doprava)
	for(var i=0; i<imgs.length-1; i++) {
		$(imgs[i]).css('margin-right', newPadding+'px');
	}

});



/*
 * Inplace formulare
 */
$(document).ready(function() {
	$('.editlink').click(function() {
		// vypocitame ID DIVu s udaji
		var box = '#'+$(this).attr('id').replace(/^editlink/g, 'editbox');
		if(!$(box).length) {
			// DIV neexistuje
			alert('debug: neexistuje DIV id '+box);

			return true;
		}

		if($(box).find('.active-editing-form').length) {
			// formular je jiz zobrazen
			return false;
		}

		// editujici box
		$(box).addClass('active-editing');

		dataForm = document.createElement('div'); // vytvorime novy DIV pro formular
		dataOriginal = document.createElement('div'); // i pro soucasny obsah

		$(dataForm).addClass('active-editing-form');
		$(dataOriginal).addClass('active-editing-original');

		$(dataOriginal).append($(box).children()); //soucasny obsah presuneme do tmp divu
		$(dataForm).html(loader()); // zobrazime loader

		$(box).append($(dataForm)); // oba DIVy (pro formular a se soucasnym obsahem)
		$(box).append($(dataOriginal)); // pak priradime opet do rodicovskeho DIVu

		// rodicovskemu nadpisu H3 zrusime margin
		if(this.parentNode.tagName.toLowerCase() == 'h3') {
			$(this.parentNode).addClass('grey-nomargin');
		}

		// nacteme formular
		$(dataForm).load($(this).attr('href'), null, function() {
			inPlaceFormInit(box, dataForm, dataOriginal);
			return false;
		});

		return false;
	});
});

function inPlaceFormInit(box, dataForm, dataOriginal) {
	$(dataForm).find('input[type=reset]').click(function() {
		// klikem na reset button se vratime do puvodniho stavu
		$(dataForm).remove();
		$(box).append($(dataOriginal).children());
		$(dataOriginal).remove();
		$(box).removeClass('active-editing');

		// obnovime margin u rodicovskeho H3
		$('#'+$(box).attr('id').replace(/editbox/g, 'editlink')).parent().removeClass('grey-nomargin');
	});

	$(dataForm).find('form').submit(function() {
		// osetreni odesilani formulare AJAXem
		$(dataForm).html(loader());
		$.ajax({
			type: $(this).attr('method'),
			url: $(this).attr('action'),
			data: $(this).serializeArray(),
			success: function(response) {
				if(response.indexOf('<form') >= 0) {
					// chybne vyplneny formular, musime ho zobrazi znovu
					$(dataForm).html(response);
					// znovu inicializujeme tlacitka
					inPlaceFormInit(box, dataForm);
				} else {
					// data ulozena, obnovime je na strance
					$(dataForm).remove();
					$(dataOriginal).remove();
					$(box).html(response+'<div class="clear1px"></div>');
					$(box).removeClass('active-editing');

					simpleHighlight(box);
					//setTimeout(function(){$(box).removeClass('active-editing-saved');}, 2000);

					// obnovime margin u rodicovskeho H3
					$('#'+$(box).attr('id').replace(/editbox/g, 'editlink')).parent().removeClass('grey-nomargin');
				}
			}
		});
		return false;
	});
}

var simpleH = new Array('FFFDC8', 'FFFDD1', 'FFFEDA', 'FFFEE3', 'FFFEED', 'FFFFF6', 'FFFFFF');
var simpleHI = 0;
function simpleHighlight(element) {
	var interval = 80;

	if(simpleHI == 0)
		interval = 1200;

	if(simpleHI < simpleH.length) {
		$(element).css('background-color', '#'+simpleH[simpleHI]);
		simpleHI++;
		setTimeout(function() {simpleHighlight(element);}, interval);
	} else {
		simpleHI = 0;
		$(element).css('background-color', '');
	}
}


/*
 * Odesilani formularu pomoci grafickeho odkazu
 **/
$(document).ready(function() {
    /*$('.submit').mouseover(function() {
        

    });    */
	//$('.submit-no-js').hide();
	$('.submit-no-js').addClass('submit-no-js-hide');
	$('.submit-js').click(function() {
		$(this).parents('form').submit();
		return false;
	});
});

/*
 * Zalozky (taby)
 */
$(document).ready(function() {
	$('.tabs a').click(function() {
		// nejprve vse schovame
		$(this).parents('.tabs').find('a').each(function() {
			$(this).parent().removeClass('active');
			$($(this).attr('href')).hide();
		});
		// a pak zobrazime jednu jedinou spravnou cast
		$($(this).attr('href')).show();
		$(this).parent().addClass('active');
		return false;
	});
	$('.tabs a:first').click();
});

/*
 * Klikaci detail inzeratu (cela plocha inzeratu je link)
 */
$(document).ready(function() {
	$('.list .odd, .list .even').each(function() {
		if($(this).find('a').length == 1) {
			$(this).click(function(event) { window.location = $(this).find('a').attr('href'); event.stopPropagation(); return false;});
			$(this).hover(function() {$(this).addClass('hover')}, function(){$(this).removeClass('hover')});
		}
	});
});

/*
 * Napovedy k formularum
 */
if($.browser.msie && $.browser.version < 7) {
	$(document).ready(function() {
		$('form .info').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});
	});
}

/*
 * FAQ
 */
$(document).ready(function() {
	$('.faq dd').hide();
	$('.faq dt').click(function() {
		$(this).next().toggle();
	});
	$('.faq dt').addClass('activated');
	$('.faq dt').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});

	// zobrazeni i nejake otazky?
	if(window.location.hash && window.location.hash.match(/^#q[0-9]+$/g)) {
		$(window.location.hash).click();
	}
});

function select_schools(){
	var value = $('#education_id').val();
        
	$.ajax({
		url: path + 'ucet/' + 'schools/'+value,
		type: 'GET',
		dataType: 'text',
		timeout: 10000,
		success: function(text){
		$('#educations_school_id').html(text);
		if($('#educations_school_id option').size()<=1){
			$('#educations_school_id').parent().addClass('hidden');
		 }
		 else {
			$('#educations_school_id').parent().removeClass('hidden');
		 }

		}
	 });

	 $.ajax({
		url: path + 'ucet/' + 'schools/'+value + '/1',
		type: 'GET',
		dataType: 'text',
		timeout: 10000,
		success: function(text){
		 $('#educations_field_id').html(text);
		 if($('#educations_field_id option').size()<=1){
			$('#educations_field_id').parent().addClass('hidden');
		 }
		 else {
			$('#educations_field_id').parent().removeClass('hidden');
		 }
		}
	 });
}


/*
 * Aktivace Flash
 */
//$(document).ready(function() {
$(window).bind('load', function() {
 //fix_eolas();
});

function fix_eolas() {
	$("object").each(function(){
		$(this).html($(this).html());
	})
}

function applicant_add_item(id){
        if (typeof removeText == "undefined") {
            removeText = 'odebrat';
        }
	selectboxes = $('#' + id +' p:first #span_'+id).html().replace(/selected="selected">/gi, '>').replace(/selected>/gi, '>');
	$('#'+id).append('<p class="padding">'+selectboxes+' <a href="#" onclick="return applicant_remove_item(this)">'+removeText+'</a></p>');
	return false;
}

function applicant_remove_item(el) {
	 $(el).parent().remove();

	return false;
}


function advertisement_add_item(id){
	selectboxes = $('#' + id +' div.source_select:first').html().replace(/_source\[\]/gi, '[]');
	$('#'+id).append('<div class="padding ">'+selectboxes+' <a href="#" onclick="return advertisement_remove_item(this)">odebrat</a></div>');
	make_select('padding div.selectbox_source');
	return false;
}

function agent_add_item(id){
	selectboxes = $('#' + id +' div.source_select:first').html().replace(/_source\[\]/gi, '[]');
	$('#'+id).append('<div class="padding ">'+selectboxes+' <a href="#" onclick="return advertisement_remove_item(this)">odebrat</a></div>');
	make_select('padding div.selectbox_source');
	return false;
}

function advertisement_remove_item(el, id) {
	 $(el).parent().remove();

	return false;
}



/*
 * Klikaci oblast kandidatu
 */
$(document).ready(function() {
	$('.results-cand .box a').click(function(event) {
		event.stopPropagation();
		return true;
	});

	$('.results-cand .box').click(function() {
		if($(this).find('.detail').length)
			document.location = $(this).find('.detail').attr('href');
	});
});

/*
 * Klikaci oblast tutorialu
 */
$(document).ready(function() {
	$('.tutorial a').click(function(event) {
		event.stopPropagation();
		return true;
	});

	$('.tutorial').click(function() {
		if($(this).find('h4 a').length)
			document.location = $(this).find('h4 a').attr('href');
	});

	$('.tutorial').hover(function() {$(this).addClass('tutorial-hover')}, function(){$(this).removeClass('tutorial-hover')});
});

/*
 * Jobdays na HP
 */
$(document).ready(function() {
	hpSlide = {i: 1, data: new Array('jobdays-hp', 'dzobpoints-hp'), get: function(){return this.data[this.i]}};

	$('#jobdays-hp').hide();
	$('#jobdays-hp, #jobdays-hp a').click(function(e){e.stopPropagation();return !window.open('http://www.jobdays.cz', '');});

	//setInterval(hpSlideShow, 5000);
});

function hpSlideShow() {
	$('#'+hpSlide.get()).fadeOut();
	hpSlide.i = (hpSlide.i+1)%hpSlide.data.length;
	setTimeout(function(){$('#'+hpSlide.get()).fadeIn()}, 300);
}


/*
 * Maskovani e-mailu
 */
$(document).ready(function() {
	$('.js-email').each(function() {
		var txt = $(this).attr('href').substring(7, $(this).attr('href').indexOf('(zavinac)'))+'@'+$(this).attr('href').substring($(this).attr('href').indexOf('(zavinac)')+9, 100);
		$(this).attr('href', 'mailto:'+txt);
		$(this).text(txt);
	});
});

/*
 * Zkraceni vypisu klicovych slov ve vysledku vyhledavani kandidatu
 */
$(document).ready(function() {
	$('.results-cand .box .desc .tags').each(function() {
		if($(this).text().length > 100) {
			$(this).data('full-text', $(this).text());
			$(this).html($(this).text().substring(0,80)+'&hellip; <a href="">všechny</a>');
			$(this).find('a').click(function(e) {e.stopPropagation();$(this).parent().text($(this).parent().data('full-text'));return false;});
		}
	});
});

 $(function () {
    $('.bubbleInfo').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 200;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger', this);
            var info = $('.popup', this).css('display', 'none');


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    /*info.css({
                        top: -90,
                        left: -33,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1  
                    }, time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });*/
                    //info.css({display: 'block'});
                    info.show('fast');
                    beingShown = false;
                    shown = true;
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    /*info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });*/
                    shown = false;
                    //info.css({display: 'none'});
                    info.hide('fast');
                    
                }, hideDelay);

                return false;
            });
    });
});

function hidePopup() {
    $('.popup').each(function () {
        $(this).hide();
    });    
}

jQuery.fn.outerHTML = function(s) {
    return (s)
    ? this.before(s).remove()
    : jQuery("<p>").append(this.eq(0).clone()).html();
} 


$(function() {
    $( "#news_slider1" ).accessNews({
            headline : "Novinky",
            speed : "slow",
            slideBy : 1
    });
});

$(function() {
    $( "#news_slider2" ).accessNews({
            headline : "Poradna",
            speed : "slow",
            slideBy : 1
    });
    $( "#news_slider2" ).hide();
});

$(function() {
    $( "#news_slider3" ).accessNews({
            headline : "Promoakce",
            speed : "slow",
            slideBy : 1
    });
    $( "#news_slider3" ).hide();
});

function set_tab(type, id) {
    for (i = 1; i <= 3; i++) {
        $("#"+type+"_slider"+i).hide();
    }
    if (id >= 1 && id <= 3) {
        $("#"+type+"_slider"+id).show();
    }
    return false;
}