
/** login **/

var finalWidth;
var currentWidth;
var interval;

var finalWidth2;
var currentWidth2;
var interval2;

$().ready(function () {
	currentWidth = 37;
	currentWidth2 = 37;

	$('#login').click(function () {
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
			animateTo(37);
		} else {
			$(this).addClass('open');
			animateTo(150);
		}
	});

	$('#search').click(function () {
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
			animateTo2(37);
		} else {
			$(this).addClass('open');
			animateTo2(274);
		}
	});
	
	$('#searchcont').click(function (e) {
		e.stopPropagation();		
	});
});

function animateTo(fin) {
	finalWidth = fin;

	if (finalWidth > currentWidth) currentWidth = Math.min(finalWidth, currentWidth + 7);
	else if (finalWidth < currentWidth) currentWidth = Math.max(finalWidth, currentWidth - 7);
	else return;

	$('#login').css('width', currentWidth + 'px'); //css('right', '-' + currentWidth + 'px');
	if ($.browser.msie && $.browser.version < 7) $('#logincont').css('width', (currentWidth - 41) + 'px');
	setTimeout("animateTo(finalWidth)", 50);
}

function animateTo2(fin) {
	finalWidth2 = fin;

	if (finalWidth2 > currentWidth2) currentWidth2 = Math.min(finalWidth2, currentWidth2 + 10);
	else if (finalWidth2 < currentWidth2) currentWidth2 = Math.max(finalWidth2, currentWidth2 - 10);
	else return;

	$('#search').css('width', currentWidth2 + 'px'); 
	if ($.browser.msie && $.browser.version < 7) $('#searchcont').css('width', (currentWidth2 - 41) + 'px');
	setTimeout("animateTo2(finalWidth2)", 40);
}

/** menu **/

$().ready(function () {
	//inicializuje šířky elementů pro nechápavé prohlížeče
	$('#topmenu .sub').each(function (i) {
		$('.subl', this).width($(this).width()).height(11);
		$('ul', this).width($(this).width()-40);
	});
	
	$('#topmenu .sub ul').css('display', 'none');
	
	$('#topmenu>li').hover(
		function () {
			$(this).addClass('hover');
			$('.sub ul',this).stop(true, false).css({height: 'auto', padding: '15px 20px 4px 20px'}).slideDown(500);
		},
		function () {
			if ($.browser.opera) {
				// zkurvená Opera!
				$('.sub',this).css({ visibility: 'hidden', height: '500px'});
				var li = this;
				setTimeout(function () {$(li).removeClass('hover'); $('.sub',li).css({ visibility: 'visible', height: 'auto'}); },050);
			} else {
				$(this).removeClass('hover');
			}
	
			$('.sub ul',this).stop(true, true).css({display: 'none'});
		}
	);
});

/** externí linky **/

$().ready(function () {
	$('a.external').click(function () {
		window.open($(this).attr('href'));
		return false;
	});
});