jQuery(document).ready(function($) {
		$('.hidden').livequery(function(){
	    $(this).removeClass('required');
	});
	
	    $('input.user-mail').livequery(function(){
        $(this).removeClass('text');
    });

		$('label.required').livequery(function(){
	    $(this).each(function() {
	        $(this).after('<span class="required-item" title="Tato položka je povinná">&nbsp;*<\/span>');
	    });
	});

		$('label.verify').livequery(function(){
	    $(this).each(function() {
	        $(this).after('<span class="verify-text" title="Tato položka je ověření jiné">&nbsp;(pro kontrolu)<\/span>');
	    });
	});
	
	    $('input.phone').livequery(function(){
        $(this).each(function() {
            $(this).before('<span class="phone-text" title="Zadejte telefonní číslo ve tvaru +420 XXXXXXXXX">&nbsp;+420&nbsp;<\/span>');
        });
    });
	
	    $('input.disabled').livequery(function(){
        $(this).attr('disabled', 'disabled');
    });
	
		$('.unselectable').livequery(function(){
        $(this).each(function() {
            $(this).attr('unselectable', 'on');
        });
    });
	
		$('.numeric').livequery(function(){
        $(this).numeric();
    });
	 
		$('.combobox').livequery(function(){
        $(this).sexyCombo();
    });
	
		$.datepicker.setDefaults($.datepicker.regional['cs']);
    $('input.datepicker').livequery(function(){
        $(this).datepicker({
			dateFormat: 'dd/mm/yy',
			showButtonPanel: true,
            minDate: -0,
            maxDate: '+1Y',
            showAnim: 'fadeIn',
            duration: 'fast',
            currentText: 'Dnes',
            closeText: 'OK'
        });
    });
    
    	$('input.datetimepicker').livequery(function(){
        $(this).datepicker({
            dateFormat: 'dd/mm/yy',
			showButtonPanel: true,
			duration: '',
            //changeMonth: true,
            //changeYear: true,
            minDate: -0,
            maxDate: '+1Y',
            showAnim: 'fadeIn',
            //            showTime: true,
            time24h: true,
            currentText: 'Dnes',
            closeText: 'OK'
        });
    });

    	$('input.timepicker').livequery(function(){
        $(this).timepickr({
            convention: 24,
            //format: "{h:02.d}:{m:02.d}",
            animSpeed: 'fast'
            //hoverIntent: true
        });
    });

    	$('input.spinbox').livequery(function(){
        $(this).SpinButton({
            min: 0
        });
    });

		$.cleditor.defaultOptions.width = 900;
	$.cleditor.defaultOptions.height = 300;
	$("textarea.html").cleditor({
		//width:        500, // width not including margins, borders or padding
		//height:       250, // height not including margins, borders or padding
		controls:     // controls to add to the toolbar
		             "bold italic underline strikethrough subscript superscript | font size " +
		             "style | color highlight removeformat | bullets numbering | outdent " +
		             "indent | alignleft center alignright justify | undo redo | " +
		             "rule image link unlink | cut copy paste pastetext | print source",
		colors:      "" // colors in the color popup
		             ,    
		fonts:        // font names in the font popup
		             "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," +
		             "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
		sizes:        // sizes in the font size popup
		             "1,2,3,4,5,6,7",
		styles:       // styles in the style popup
		             [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"],
		             ["Header 3", "<h3>"],  ["Header 4","<h4>"],  ["Header 5","<h5>"],
		             ["Header 6","<h6>"]],
		useCSS:       false, // use CSS to style HTML when possible (not supported in ie)
		docType:      // Document type contained within the editor
		             '',
					  //'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
		docCSSFile:   // CSS file used to style the document contained within the editor
		             "", 
		bodyStyle:    // style to assign to document body contained within the editor
		             "margin:4px; font:10pt Arial,Verdana; cursor:text"
	});
	
	    $('form .empty').livequery(function(){
        $(this).click(function() {
            if($(this).hasClass('text') && $(this).hasClass('empty')) $(this).val('');
            if($(this).hasClass('numeric') && $(this).hasClass('empty')) $(this).val('0');
            if($(this).hasClass('empty')) $(this).removeClass('empty');
        });
    });
	
	    $('ul.error').each(function() {
        $(this).addClass('ui-widget');
    });
    $('ul.error li').each(function() {
        $(this).addClass('ui-state-error').addClass('ui-corner-all');
        $(this).prepend('<span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>');
    });
    
		$("a.confirm").each(function(){
        $(this).click(function(e) {
            var href = $(this).attr('href');
			$.chimera.custom_confirm(
                'Vybraná položka bude odstraněna. Tuto operaci není možné vrátit. Jste si opravdu jisti?',
                function() {location.href = href;},
                'Opravdu chcete odstranit vybranou položku?',
                'Ano',
                'Ne'
            );
			if($.browser.msie) window.event.cancelBubble = true;
			return false;
        });
    });
	$("a.ajaxConfirm").livequery(function(){
        $(this).click(function(e) {
            e.preventDefault();
            var href = $(this).attr('href');
            $.chimera.custom_confirm(
                'Vybraná položka bude odstraněna. Tuto operaci není možné vrátit. Jste si opravdu jisti?',
                function(){$.get(href);},
                'Opravdu chcete odstranit vybranou položku?',
                'Ano',
                'Ne'
            );
        });
    });
});

