/*
 * JS pro webovou cast
 *
 *
 */
var tree_path = '/';
var tree_expire = 1000;
var tree_secure = false;
var tree_data = {};
	
$(document).ready(function(){
	//	----- JS petr
	$('#email2').parent().parent().hide();
	$('#hlmesto').parent().parent().hide();
    $('#hlmesto').val('Praha');
    $('#captcha').hide();
    
    $('a:not([href^="/partner"])[href$="jpg"], a:not([href^="/partner"])[href$="jpeg"], a:not([href^="/partner"])[href$="gif"], a:not([href^="/partner"])[href$="png"], a:not([href^="/partner"])[href$="JPG"], a:not([href^="/partner"])[href$="JPEG"], a:not([href^="/partner"])[href$="GIF"], a:not([href^="/partner"])[href$="PNG"]').fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'outside',
		'showNavArrows'		: true,
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$("a.external").click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	
	$('a.banner').fancybox({titleShow: false, autoScale: false});
	
	
	$("#tabs").tabs();
	//urceni last tabu
	$("#tabs-navigation li:last a").addClass('last');
	
	// initialize scrollable
	$(".scrollable").scrollable({circular: true}).autoscroll({ 
		autoplay: true,
		interval: 5000
		});
	
	//kategorie a produktu - hover na hover
	 $("div.detail.kategorie,div.detail-half").hover(
	 	function () {
    		$(this).find('a').toggleClass('hover');
    		$(this).css('cursor','pointer');
  		}, 
  		function () {
    		$(this).find('a').toggleClass('hover');
  		}
	 );
	 $("div.detail.kategorie,div.detail-half").click(function () {
	 		location.href = $(this).find('a:first').attr('href');
		});
	//	------ //JS petr
	
	$('.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');
	});
	
	
	
	$("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});
}

