/*
 * JS pro webovou cast
 *
 *
 */
var tree_path = '/';
var tree_expire = 1000;
var tree_secure = false;
var tree_data = {};
	
$(document).ready(function(){
	$('a[href$="jpg"], a[href$="jpeg"], a[href$="gif"], a[href$="png"], a[href$="JPG"], a[href$="JPEG"], a[href$="GIF"], a[href$="PNG"], a.banner').fancybox({'titlePosition': 'inside'});
	$('a.banner').fancybox({titleShow: false, autoScale: false});
	
	$('.search_input, .input-login').focus(function(){
		$(this).addClass('active').val('');
	});	
	
	$('div.text tr:odd td').each(function(){
		$(this).addClass('bgwhite');
	});
	$('div.text tr:even td').each(function(){
		$(this).addClass('bggray');
	});
	$('div.text tr td:even').each(function(){
		$(this).addClass('bgrose');
	});
	
	$("#hlmesto").val('Praha');
	
	$("div.strom ul li span.plus").each(function(){
		$(this).nextAll('ul:first').hide();	
		//console.debug($(this).parent('li').attr('id'));
	});
	
	$("div.strom2 ul#downloads li span.plus").each(function(){
		$(this).nextAll('ul:first').hide();	
	});
	
	data = $.cookie('web_tree');
	data = jQuery.parseJSON(data)
	if (data != null)
	{
		for (var i in data)
		{
			$("#item-"+i+" ul:first").show();
		}
	}
	
	
	$("ul#downloads li span, ul#downloads li strong").click(function(){
		var obj = $(this).parent('li').find('span:first');
		if ($(obj).hasClass('plus'))
		{
			$(obj).nextAll('ul').show();
			$(obj).removeClass('plus');
			$(obj).addClass('minus');									
		}
		else
		{
			$(obj).nextAll('ul').hide();
			$(obj).removeClass('minus');
			$(obj).addClass('plus');										
		}
	});	

	
	
	$("div.strom").each(function(){
		$("ul li span", this).click(function(){
			
			tree_data = $.cookie('web_tree');
			
			if (tree_data == null)
				tree_data = {};
			else
				tree_data = jQuery.parseJSON(tree_data);	
				
			id = $(this).parent('li').attr('id').split('-')[1];
			
			if ($(this).hasClass('plus'))
			{
				$(this).nextAll('ul').show();
				$(this).removeClass('plus');
				$(this).addClass('minus');
				tree_data[id] = true;							
			}
			else
			{
				$(this).nextAll('ul').hide();
				$(this).removeClass('minus');
				$(this).addClass('plus');	
				delete tree_data[id];								
			}
			
			$.cookie('web_tree', $.toJSON(tree_data), {expire: tree_expire, path: tree_path, secure: tree_secure});
		});	
	}); 
	
});

function sbalit_vse()
{
	tree_data = {};
	
	$("div.strom").each(function(){
		$("ul li span", this).each(function(){
			$(this).nextAll('ul').hide();
			$(this).removeClass('minus');
			$(this).addClass('plus');
		});			
	});
	$.cookie('web_tree', $.toJSON(tree_data), {expire: -tree_expire, path: tree_path, secure: tree_secure});
}

function rozbalit_vse() 
{
	tree_data = {};
	
	$("div.strom").each(function(){
		$("ul li span", this).each(function(){
			var id = $(this).parent('li').attr('id').split('-')[1];
			$(this).nextAll('ul').show();
			$(this).removeClass('plus');
			$(this).addClass('minus');
			tree_data[id] = true;	
		});	
	}); 	
	$.cookie('web_tree', $.toJSON(tree_data), {expire: -tree_expire, path: tree_path, secure: tree_secure});
}

