var currentPart = 1;

$(document).ready(function() {

	$('a.delete').css('color','red').click(function(){
		if (confirm('Czy napewno usunąć ten element ?'))
		{
			return true;
		}
		
		return false;
	});
	
	// edycja struktury - obrazki top  - workaround
	if($('#edit-structure').length){
		
		$('#edit-structureelement10', '#edit-structure').parent().parent().hide();
		$('#edit-structureelement9i', '#edit-structure').css('visibility','hidden');
		$('#edit-structureelement10', '#edit-structure').css('text-align','center').insertBefore('#edit-structureelement9i');	
	} 	
		
		$("#systemMessageClose").click(function () {
		  $("#systemMessage").slideUp(500, function () {
			$("#systemMessage").remove();
		  });
		});
	   	
});

function nextPart(obj){
	var parent = obj.parentNode;
	var next = parent.nextSibling;
	while(next != undefined && next.nodeType != 1){
		next = next.nextSibling;
	}
	$(parent).slideUp('slow');
	$(next).slideDown('slow');
}

function prevPart(obj){
	var parent = obj.parentNode;
	var prev = parent.previousSibling;
	while(prev != undefined && prev.nodeType != 1){
		prev = prev.previousSibling;
	}
	$(parent).slideUp('slow');
	$(prev).slideDown('slow');
}

function showPart(partNo){
	var i = 1;
	var obj = null;
	var toFadeIn = null;
	while( obj = document.getElementById('part_'+i) ){
		if( i == partNo ){
			toFadeIn = obj;
		} else {
			$(obj).css('display','none');
		}
		i++;
	}
	if( toFadeIn != null ){
		$(toFadeIn).fadeIn('slow');
		$(document).scrollTop(0);
		
		$('#page_'+currentPart).css('font-weight','normal');
		currentPart = partNo;
		$('#page_'+currentPart).css('font-weight','bold');
	}
	return false;
}


function showMenu(partNo){
	$("#menu_"+partNo).slideDown('slow');	
}

function showSearch(partNo){
	var i = 1;
	var obj = null;
	var toFadeIn = null;
	while( obj = document.getElementById('item_'+i) ){
		if( i == partNo ){
			toFadeIn = obj;
		} else {
			$(obj).css('display','none');
		}
		i++;
	}
	if( toFadeIn != null ){
		$(toFadeIn).fadeIn('slow');
		//$(document).scrollTop(0);
		
		$('#itempos_'+currentPart).css('font-weight','normal');
		currentPart = partNo;
		$('#itempos_'+currentPart).css('font-weight','bold');
	}
}

function showFaq(partNo){
	var i = 1;
	var obj = null;
	var zaj = null;
	var toFadeIn = null;
	var toFadeZaj = null;
	
	$('.question .pointer').css('visibility','visible');
	$('.pointer-' +  partNo).css('visibility','hidden');
	while( obj = document.getElementById('element_'+i) ){
		zaj = document.getElementById('intro_'+i);
		if( i == partNo ){
			toFadeIn = obj;
			toFadeZaj = zaj;
		} else {
			$(obj).css('display','none');
			$(zaj).css('display','block');
		}
		i++;
	}
	if( toFadeIn != null ){
		$(toFadeZaj).css('display', 'none');
		$(toFadeIn).fadeIn('slow');
			
	}
}
function topSelector()
{
	var selector = 	document.getElementById('topSelector');
	$(selector).fadeIn('slow');
	
}
function topSelectorClose()
{
	var selector = 	document.getElementById('topSelector');
	$(selector).fadeOut('slow');
	
}
function topAssign(topId)
{
	var topField = document.getElementById('edit-structureelement9i');
	var selector = document.getElementById('topSelector');
	var topOld	 = document.getElementById('topPreview');
	var topNew	=	document.getElementById('top'+topId);
	topField.value=topId;
	topOld.src=topNew.src;
	$(selector).fadeOut('slow');
}
function executeSearch()
{
	
	var word = document.getElementById('searchWord').value;
	document.location.href='/wyszukiwarka.html?searchWord='+word;
	//alert(word);
}


function buildTinyMce(selector, theme)
{
	height = '380';
	if(theme == 'simple') height = '20';
   $( selector ).tinymce({
                        // Location of TinyMCE script
                        script_url : '../lib/tiny_mce/tiny_mce.js',
                        language: 'pl',
                        height: height,

                        // General options
                        theme :  theme,
                        plugins : "pagebreak,style,table,save,advhr,advimage,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

                        // Theme options
                        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                        theme_advanced_buttons4 : "moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
                        theme_advanced_toolbar_location : "top",
                        theme_advanced_toolbar_align : "left",
                        theme_advanced_statusbar_location : "bottom",
                        theme_advanced_resizing : true,
                        
                        theme_advanced2_buttons1 : "bold,italic,underline,strikethrough,|,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,image,hr",
                        theme_advanced2_buttons2 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,removeformat,cleanup",
                        theme_advanced2_buttons3 : "",
                        
                        theme_advanced2_toolbar_location : "top",
                        theme_advanced2_toolbar_align : "left",
                        theme_advanced2_statusbar_location : "none",
                        theme_advanced2_resizing : false,

                        theme_advanced_faq_buttons1 : "bold,italic,underline,strikethrough,|,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,image,hr",
                        theme_advanced_faq_buttons2 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,|,removeformat,cleanup",
                        theme_advanced_faq_buttons3 : "",
                        
                        theme_advanced_faq_toolbar_location : "top",
                        theme_advanced_faq_toolbar_align : "left",
                        theme_advanced_faq_statusbar_location : "none",
                        theme_advanced_faq_resizing : false,

                        // Example content CSS (should be your site CSS)
                     

                        // Drop lists for link/image/media/template dialogs
                        //template_external_list_url : "lists/template_list.js",
                        external_link_list_url : "js/link_list.js",
                        //external_image_list_url : "lists/image_list.js",
                        //media_external_list_url : "lists/media_list.js",
												relative_urls : false,//Tiny upload returns absolute urls, we dont want tinymce changing them to relative.
												file_browser_callback:tinyupload//Hookup tinyupload the the filebrowser call back.
                       
                });
        
}

