
/*window.onscroll = function () {
	var side_panel_left = document.getElementById('side-panel-left');
	side_panel_left.style.top = window.pageYOffset+"px";
	//alert(window.pageYOffset);
}
*/
	
function side_panel_create_item(key,val,prefix){
	var item_li = document.createElement('li');
	var item = document.createElement('a');
	item.setAttribute('class','side-panel-item');
	item.setAttribute('href',prefix+'/'+key);

	var itemImg = document.createElement('img');			
	itemImg.setAttribute('src','/getthumb/'+val.cover_id+"/20");
	item.appendChild(itemImg);
			
	var itemText = document.createElement('span');
	itemText.innerHTML=val.name;
	item.appendChild(itemText);
			
	item_li.appendChild(item);
	return item_li;

}

$(document).ready(function(data) {
	var content = document.getElementById('left');
	var progress=create_progress_element("left_side_progress","");
	content.appendChild(progress);

	$.getJSON('/get_data_left_side_panel', function(data)
	{
		


		// USER sekce
		var user_section_dl =	document.createElement('dl');
		user_section_dl.setAttribute('class','side-panel left-panel');
		var user_section_dt =	document.createElement('dt');
		var user_section_dd =	document.createElement('dd');
		
		var user_section_title = document.createElement('a');
		user_section_title.setAttribute('class','side-panel-item side-panel-header');
		user_section_title.setAttribute('href','/gallery/');
		user_section_title.innerHTML=data.user.username+"'s galleries";

		var user_section_ul = document.createElement('ul');
		$.each(data.user_section, function(key, val) {
			user_section_ul.appendChild(side_panel_create_item(key,val,'/gallery'));
		});

		user_section_ul.appendChild(side_panel_create_item("",{"name":"..."},'/gallery'));
		user_section_ul.appendChild(side_panel_create_item("create_empty_gallery/",{"name":"+ new gallery"},'/gallery'));

		user_section_dt.appendChild(user_section_title);
		user_section_dd.appendChild(user_section_ul);
		user_section_dl.appendChild(user_section_dt);
		user_section_dl.appendChild(user_section_dd);
		content.appendChild(user_section_dl);

		


		// GROUP sekce
		var group_section_dl =	document.createElement('dl');
		group_section_dl.setAttribute('class','side-panel left-panel last');
		var group_section_dt =	document.createElement('dt');
		var group_section_dd =	document.createElement('dd');

		var group_section_title = document.createElement('a');
		group_section_title.setAttribute('class','side-panel-item side-panel-header');
		group_section_title.setAttribute('href','/group/');
		group_section_title.innerHTML="Groups";

		var group_section_ul = document.createElement('ul');
		$.each(data.group_section, function(key, val) {
			group_section_ul.appendChild(side_panel_create_item(key,val,'/group'));
		});
		group_section_ul.appendChild(side_panel_create_item("",{"name":"..."},'/group'));
		group_section_ul.appendChild(side_panel_create_item("new/",{"name":"+ new group"},'/group'));

		group_section_dt.appendChild(group_section_title);
		group_section_dd.appendChild(group_section_ul);
		group_section_dl.appendChild(group_section_dt);
		group_section_dl.appendChild(group_section_dd);

		$(progress).hide();

		content.appendChild(group_section_dl);

	  });
});
