var adir="panely/";

$(document).ready(function() { 
	
	$("a[rel^='lightbox']").prettyPhoto({ theme:'light_square' }); 
	
	// VKLADANI MODULU
	$('.drag div').draggable({ helper:'clone',connectToSortable:'.sort' }); 
	
	// PRESUNOVANI MODULU
	$('.sort').sortable({ 
		placeholder: "ui-state-highlight", helper: 'clone', 
		handle : '.move', 
		connectWith:'.sort',
		update : function () { 
			$( "#updatedialog p" ).text("Ukládám nastavení..."); $( "#updatedialog" ).dialog({ modal: true }); 
			var pan0 = $("#T1").sortable('serialize'); 
			var pan1 = $("#L").sortable('serialize'); 
			var pan2 = $("#R").sortable('serialize'); 
			var pan3 = $("#B").sortable('serialize'); 
			$("#info").load( adir+"win_sort.php", { "panely[]":[pan0,pan1,pan2,pan3], "job":"updatepanely" }); 
		} 
	}); 
	
// ZASUNOVACI ADD MENU
	$(".add").click(function(){ 
		pos=$(this).position(); 
		if(pos.left==-230) { $(this).animate({"left": "+=180px"}, "500"); } else { $(this).animate({"left": "-=180px"}, "500");  } 		
	}); 
	
	// ZASUNOVACI NAST MENU
	$(".nast").click(function(){ 
		pos=$(this).position(); 
		if(pos.left==-230) { $(this).animate({"left": "+=180px"}, "500"); } else { $(this).animate({"left": "-=180px"}, "500");  } 		
	}); 
	
	$(window).scroll(function(){
		$(".nast").css( "top",window.pageYOffset+25 ); 
		$(".add").css( "top",window.pageYOffset+190 ); 
		$("#info").text( window.pageYOffset ); 	   
	}); 
	
	// UPRAVIME VSECHNY EMAILY V OBSAHU STRANKY 
	$('.aemx').each( function () { $(this).attr("href","mailto:"+$(this).attr("class").substring(5,$(this).attr("class").length)); });  
	
}); 

// EDITACE MODULU
function editpanel(idx,wx) {
	pnx=window.open( adir+"win_edit.php?width="+wx+"&panid="+idx,"pnx","status=1,scrollbars=1,resizable=1,left=200,top=100,width=800,height=600"); pnx.focus(); 
} 

// EDITACE MODULU
function settpanel(idx) {
	pns=window.open( adir+"win_sett.php?panid="+idx,"pns","status=1,scrollbars=1,resizable=1,left=200,top=100,width=500,height=500"); pns.focus(); 
} 

// ODSTRANENI MODULU
function deletepanel(idx) {
	$( "#updatedialog p" ).text("Tento panel bude odstraněn ze stránky, později bude možné jej opět připojit."); 
	$( "#updatedialog" ).dialog({
		resizable: false,
		height:130,
		modal: true,
		buttons: {
			"Odstranit panel / modul ?": function() {
				$("#info").load( adir+"win_sort.php", { "panid":idx, "job":"deletepanel" }); 
			},
			Cancel: function() {
				$( this ).dialog( "close" );
			}
		}
	});	
} 

function opw_pages() {
	pag=window.open( adir+"s_pages/emod.php","pag","status=1,scrollbars=1,resizable=1,left=200,top=100,width=500,height=500"); pag.focus(); 
}

function opw_files() {
	fil=window.open( adir+"s_files/emod.php","fil","status=1,scrollbars=1,resizable=1,left=200,top=100,width=800,height=600"); fil.focus(); 
}

function opw_general() {
	gen=window.open( adir+"s_general/emod.php","gen","status=1,scrollbars=1,resizable=1,left=200,top=100,width=800,height=600"); gen.focus(); 
}

function opw_admin() {
	adm=window.open( adir+"s_admin/emod.php","adm","status=1,scrollbars=1,resizable=1,left=200,top=100,width=800,height=600"); adm.focus(); 
}




