/**
 * UI.Layout creates a 'page-layout' that has auto-sizing 'center pane'
 * surrounded by up to four collapsible and resizable 'border panes'
 * (north, south, east & west). It can also create multiple headers &
 * footers inside each pane.
 * @param string $layoutName The layout name
 * @param string $selector jQuery Selector
 * @param array() $configurations Array. See the options and events in
 *        http://layout.jquery-dev.net/documentation.html#Options
 */
function ui_layout_configure_to($layoutName, $selector, $configurations = array())
{
    $configurations = get_default_widget_configuration('app_ys_jquery_ui_layout_defaults', $configurations);
    if (isset($configurations['yml'])) {
        $ymlItems = sfYaml::load($configurations['yml']);
        $ymlIndex = isset($configurations['ymlKey']) ? $configurations['ymlKey'] : 'layout';
        $ymlConfigurations = isset($ymlItems[$ymlIndex]) ? $ymlItems[$ymlIndex] : array();
        $configurations = array_merge($ymlConfigurations, $configurations);
        unset($configurations['yml'], $configurations['ymlKey']);
    }
    $support = core_init_javasacript_tag();
    $support .= 'var ' . $layoutName . ';';
    $pattern = ui_layout_pattern($configurations);
    $utilityMethods = '';
    if (!is_array($configurations) || !sizeof($configurations) > 0) {
        $configurations = array('applyDefaultStyles' => true);
    } else {
        if (!isset($configurations['name'])) {
            $configurations['name'] = $layoutName;
        }
        $utilityMethods = ui_layout_utility_methods_pattern($layoutName, $configurations);
    }
    if (isset($configurations['cache']) && $configurations['cache'] === true) {
        echo add_jquery_support('window', 'unload', like_function("layoutState.save('{$layoutName}')"));
        $pattern = "\$.extend( {$pattern} , layoutState.load('{$layoutName}'))";
    }
    $jsVar = like_function($layoutName . ' = ' . jquery_support($selector, 'layout', $pattern, true, $utilityMethods));
    $support .= jquery_support($selector, 'ready', $jsVar);
    echo $support .= core_end_javasacript_tag();
}
echo add_jquery_support("#btnDestroyProgressbar", 'click', like_function(ui_progressbar_destroy('#progressbar')));
echo add_jquery_support("#btnDisableProgressbar", 'click', like_function(ui_progressbar_disable('#progressbar')));
echo add_jquery_support("#btnEnableProgressbar", 'click', like_function(ui_progressbar_enable('#progressbar')));
echo add_jquery_support("#btnSetValueProgressbar", 'click', like_function('changeValue()'));
echo add_jquery_support("#btnGetValueProgressbar", 'click', like_function('getValue()'));
echo add_jquery_support("#btnAnimateProgressbar", 'click', like_function(ui_progressbar_animate('#progressbar2', 5)));
?>

<script type="text/javascript" language="javascript">
  function changeValue(){
    value = Math.ceil(Math.random() * 99);
    <?php 
echo ui_progressbar_set_value('#progressbar', 'value');
?>
    <?php 
echo jquery_support('#lblValue', 'html', "value + '%'");
?>
  }

  function getValue(){
    value = <?php 
echo ui_progressbar_get_option('#progressbar', 'value');
?>
    alert('The value: ' + value);
  }
</script>

  <br>
  <?php 
echo link_to('jquery UI (progressbar) documentation', 'http://jqueryui.com/demos/progressbar');
?>
/**
 * Get any slider option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 */
function ui_slider_get_option($selector, $option)
{
    return jquery_support($selector, 'slider', "'option' , '{$option}'");
}
/**
 * Get any accordion option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 */
function ui_accordion_get_option($selector, $option)
{
    return jquery_support($selector, 'accordion', "'option' , '{$option}'");
}
/**
 * Disable to select a section
 * @param string $selector jQuery Selector
 */
function ui_disable_selection($selector, $isInternal = false)
{
    if ($isInternal) {
        return jquery_support($selector, 'disableSelection');
    } else {
        return add_jquery_support($selector, 'disableSelection');
    }
}
/**
 * Get any datepicker option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 */
function ui_datepicker_get_option($selector, $option)
{
    return jquery_support($selector, 'datepicker', "'option' , '{$option}'");
}
/**
 * Get any selectable option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 */
function ui_selectable_get_option($selector, $option)
{
    return jquery_support($selector, 'selectable', "'option' , '{$option}'");
}
/**
 * Flush (empty) the cache of matched input's autocompleters.
 * @param string $selector A jQuery Selector
 */
function jquery_autocomplete_flush_cache($selector)
{
    return jquery_support($selector, 'flushCache', '');
}
/**
 * Get any progressbar option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 */
function ui_progressbar_get_option($selector, $option)
{
    return jquery_support($selector, 'progressbar', "'option' , '{$option}'");
}
function ui_context_menu_enable($selector, $isInternal = true)
{
    $response = $isInternal ? jquery_support($selector, 'enableContextMenu') : jquery_execute(jquery_support($selector, 'enableContextMenu'));
    return $response;
}
/**
 *
 * @param string $selector A jQuery Selector
 * @param string $events An event type to unbind
 * @param string $args Arguments or a javascript function sintax.
 * @param bollean $unescapeId The jQUery selector without "'"
 * @param string $accesors Accesor for the jQuery object
 * @return string jQuery syntax
 */
function add_jquery_support($selector, $event = 'ready', $args = "function(){return false;}", $unescapeId = true, $accesors = '', $addSeparator = true)
{
    $support = core_init_javasacript_tag();
    if ($event === 'ready') {
        $support .= jquery_support($selector, 'ready', $args);
    } else {
        $support .= jquery_support($selector, 'ready', like_function(jquery_support($selector, $event, $args)));
    }
    $support .= core_end_javasacript_tag();
    return $support;
}
/**
 * Get any tab option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 * @return <type> 
 */
function ui_tabs_get_option($selector, $option)
{
    return jquery_support($selector, 'tabs', "'option' , '{$option}'");
}
/**
 * Get any dialog option.
 * @param string $selector jQuery Selector
 * @param string $option The widget option to get
 */
function ui_dialog_get_option($selector, $option)
{
    return jquery_support($selector, 'dialog', "'option' , '{$option}'");
}