var admin = false;

$(function(){

	admin = $("#amina-panel").length == 0 ? false : true;
	
	var $smA = $('#mainmenu .active a[href*=kurz-pro-deti]'),
		$smLi = $smA.parent();
	
	$smA.append('<span class="smajlik" />');
	$smLi.css('position', 'relative');
		

	$(".galerie > span > a").fancybox({modal: true});

// PROMO
	if(admin) {
		$('#promo').addClass('off');
	} else {
		$('#promo').addClass('on').innerfade({
			speed: 'slow',
			timeout: 4000,
			type: 'sequence',
			containerheight: '151px'
		});
		$('.predmet').hide();
	}

// FAQ
	$('.faq').addClass('active');
	$('.faq h2').click(function(){
		$(this).next('.text').toggle(300);
	});

	var	_h = parseInt( $('#main').height() );
	$('<span id="line" />').appendTo('#main').css({'height': _h + 'px' });

	$(".plan #content tr").each(function(){
		var _num = $(this).children("*").length;
		if(_num == 9)
			$(this).children("td:nth-child(1), td:nth-child(3), td:nth-child(5), td:nth-child(7), td:nth-child(8)").addClass("line");
		else if (_num == 8)
			$(this).children("td:nth-child(1), td:nth-child(3), td:nth-child(5), td:nth-child(7)").addClass("line");
	});
	
	$("table a").addClass("popup-switch");
	
	$('.popup-switch')
	.hover(function(){
		var _href = $(this).attr("href");
		var _class = _href.substring(1);
		var _html = $("#" + _class + " .text").html();
		$(this).addClass('toadd');
		if(_html != null)
			$('<div class="popup">' + _html + '</div>').appendTo('.toadd');
		$('.toadd .amina-toolbar').remove();
		return false;
	},
	function(){
		$(this).removeClass('toadd');
		$('.popup').remove();
		return false;
	})
	.click(function(){
		return false;
	});
	;
	
	$("#header input[type=text]")
	.focus(function(){
		searchInit("focus");
	})
	.blur(function(){
		searchInit("blur");
	});
	
	searchInit("blur");

	if($(".noside").length == 0) { 
		$("#main").wrapInner("<div id=\"line\"></div>");
	}
	if($("#promo").length != 0) { 
		$("#aside").css("top", "-151px");
	}
	
});

function searchInit(akce){

	var _txt = $("#header input[type=text]").val();
	var _sub = $("#header input[type=submit]").attr("title");
	
	if(akce == "focus" && _txt == _sub) {
		$("#header form input[type=text]").val("");
	}
	else if(akce == "blur" && _txt == "") {
		$("#header form input[type=text]").val(_sub);
	}

}
