<div id="primary_header">
    <h1><?php print $this->translate('Plugin Settings')?></h1>

</div>

<div id="primary_content">
    <div id="primary_content_inner">
        <div id="Flash" class="flash_notice">The Plugin Settings have been updated. </div>
        <form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/plugins/savesettings">
            <input type="hidden" name="save" value="1" />
            <table class="settings">
                <tr>
                    <td class="label"><label for="replyTo"><?php print $this->translate('Enable Plugins')?></label></td>
                    <td>
                        <input type='hidden' name='allowPlugins' value='0'/>
                        <input type="checkbox" value="1" name="allowPlugins" id="allowPlugins" <?php echo ($this->global['allowPlugins']) ? 'checked' : '' ?> />
                        <small><?php print $this->translate('Toggle to enable or disable the plugin engine.')?></small>
                    </td>
                </tr>
            </table>
            <div class='divider'/>
            <table class="settings" style="width=auto !important;">
                <?php if (isset($this->filter)): ?>
                <tr><td class="label"><small><?php echo $this->translate("Filter active") ?> (<?php echo $this->filter ?> = <?php echo $this->key ?>):</small></td><td colspan="2"><a href="javascript:showAllPlugins()"><?php echo $this->translate("show all plugins") ?></a></td></tr>
                <?php endif; ?>
                <?php foreach($this->plugins as $p): ?>
                <tr>
                    <td class="label">
                        <label for="replyTo">
                        <a class="pluginFilter" title="<?php echo $this->translate("filter by module") ?>" href="javascript:filterPlugins('module', '<?php echo $p['module'] ?>')"><?php echo $p['module'] ?></a> &gt; 
                        <a class="pluginFilter" title="<?php echo $this->translate("filter by company") ?>" href="javascript:filterPlugins('company', '<?php echo $p['company'] ?>')"><?php echo $p['company'] ?></a> &gt; 
                        <a id="toggleInfo2-<?php echo $p['id'] ?>" class="pluginFilter" title="<?php echo $this->translate("display plugin info") ?>" href="javascript:togglePluginInfo('<?php echo $p['id'] ?>')"><?php echo $p['name'] ?></a></label></td>
                    <td class="iphoneToggle">
                        <input type='hidden' name='plugins[<?php echo $p['id'] ?>]' value='0'/>
                        <input type="checkbox" value="1" name="plugins[<?php echo $p['id'] ?>]" <?php echo ($p['status']) ? 'checked' : '' ?> class="pluginSwitch" />
                    </td>
                    <td>
                        <a class="plugin-more" id="toggleInfo-<?php echo $p['id'] ?>" href="javascript:togglePluginInfo('<?php echo $p['id'] ?>')" title="<?php echo $this->translate('display info') ?>"><?php echo $this->translate("display info") ?></a>
                    </td>
                </tr>
                <tr class="pluginInfos">
                <td colspan="3"><div id="plugin-<?php echo $p['id'] ?>"></div></td>    
                </tr>
                <?php endforeach; ?>
                <?php if (isset($this->filter) && count($this->plugins) > 9): ?>
                <tr><td colspan="3"><a href="javascript:showAllPlugins()"><?php echo $this->translate("show all plugins") ?></a></td></tr>
                <?php endif; ?>
            </table>
		<div class="divider"></div>
        </form>
	    <div id="back_button">
	        <a href="#">
	            <span>
	                <strong>Save</strong>
	                <strong> Settings</strong>
	            </span>
	        </a>
	    </div>
    </div>
</div>

<script type="text/javascript">

function togglePluginInfo(pluginId) {
    if ($('#plugin-' + pluginId).html() == '') {
        $("#toggleInfo2-" + pluginId).attr('title', "<?php echo $this->translate("hide info") ?>");
        $("#toggleInfo-" + pluginId).attr('title', "<?php echo $this->translate("hide info") ?>");
        $("#toggleInfo-" + pluginId).html("<?php echo $this->translate("hide info") ?>");
		$("#toggleInfo-" + pluginId).removeClass("plugin-more").addClass("plugin-less");
        $('#plugin-' + pluginId).load("<?php echo $this->moduleBaseUrl ?>/plugins/info/id/" + pluginId).slideDown('slow');
    } else {
        if ($('#plugin-' + pluginId).css("display") == "none") {
            $("#toggleInfo2-" + pluginId).attr('title', "<?php echo $this->translate("hide info") ?>");
            $("#toggleInfo-" + pluginId).attr('title', "<?php echo $this->translate("hide info") ?>");
            $("#toggleInfo-" + pluginId).html("<?php echo $this->translate("hide info") ?>");
			$("#toggleInfo-" + pluginId).removeClass("plugin-more").addClass("plugin-less");
            $('#plugin-' + pluginId).slideDown('slow');
        } else {
            $("#toggleInfo2-" + pluginId).attr('title', "<?php echo $this->translate("display info") ?>");
            $("#toggleInfo-" + pluginId).attr('title', "<?php echo $this->translate("display info") ?>");
            $("#toggleInfo-" + pluginId).html("<?php echo $this->translate("display info") ?>");
			$("#toggleInfo-" + pluginId).removeClass("plugin-less").addClass("plugin-more");
            $('#plugin-' + pluginId).slideUp('slow');
        }
    }
}

function filterPlugins(filter, key) {
	$("#Plugin_Settings").load("<?php echo $this->moduleBaseUrl ?>/plugins/settings/filter/" + filter + "/key/" + key);
}

function showAllPlugins(filter, key) {
	$("#Plugin_Settings").load("<?php echo $this->moduleBaseUrl ?>/plugins/settings/");
}

$(function() 
{
    // bind to the form's submit event and cancel legacy submit
    $('#settingsForm', '#Plugin_Settings').submit(function() {
        $("#Flash", "#Plugin_Settings").hide();
        $.php($("#settingsForm", '#Plugin_Settings').attr("action"),$("#settingsForm", '#Plugin_Settings').serializeArray());
        return false;
    });
    
    $('#back_button a', '#Plugin_Settings').bind("click", function() { return $('#settingsForm', '#Plugin_Settings').submit()});
    
    $('#allowPlugins').iphoneStyle();
    $('.pluginSwitch').iphoneStyle();
});
</script>