<?php $block = $this->getCurrentBlock(); ?>
<div id="cms_block_<?php echo $this->getPosition(); ?>" class="category inner_content cms_block address" rel="<?php echo $this->getPosition(); ?>">
    <div class="left">
        <a class="handle" href="javascript:void(0);"><i class="icon-move"></i></a>
    </div>
    <div class="left" style="width:540px">
        <div class="description_cont" rel="<?php echo $this->getPosition() ?>">
            <table class="list list-input">
                <tr>
                    <td class="label"><label for="label_<?php echo $this->getPosition(); ?>"><?php echo $this->_('Label:') ?></label></td>
                    <td><input type="text" id="label_<?php echo $this->getPosition(); ?>" class="input" name="block[<?php echo $this->getPosition(); ?>][label]" value="<?php echo $block->getLabel(); ?>" placeholder="<?php echo $this->_('Label') ?>" /></td>
                </tr>
                <tr>
                    <td class="label"><label for="cms_address_<?php echo $this->getPosition(); ?>"><?php echo $this->_('Address:') ?></label></td>
                    <td><textarea rows="4" rel="<?php echo $this->getPosition(); ?>" id="cms_address_<?php echo $this->getPosition(); ?>" name="block[<?php echo $this->getPosition(); ?>][address]" class="gmaps_address input" placeholder="<?php echo $this->_('Address') ?>"><?php echo $block->getAddress(); ?></textarea></td>
                </tr>
                <tr>
                    <td class="label"><label for="cms_latitude_<?php echo $this->getPosition(); ?>"><?php echo $this->_('Latitude:') ?></label></td>
                    <td><input type="text" id="cms_latitude_<?php echo $this->getPosition(); ?>" class="input" name="block[<?php echo $this->getPosition(); ?>][latitude]" value="<?php echo $block->getLatitude(); ?>" placeholder="<?php echo $this->_('Latitude') ?>" /></td>
                </tr>
                <tr>
                    <td class="label"><label for="cms_longitude_<?php echo $this->getPosition(); ?>"><?php echo $this->_('Longitude:') ?></label></td>
                    <td><input type="text" id="cms_longitude_<?php echo $this->getPosition(); ?>" class="input" name="block[<?php echo $this->getPosition(); ?>][longitude]" value="<?php echo $block->getLongitude(); ?>" placeholder="<?php echo $this->_('Longitude') ?>" /></td>
                </tr>
                <tr>
                    <td colspan="2" class="label">
                        <label for="cms_address_container_<?php echo $this->getPosition(); ?>" id="label_cms_address_container_<?php echo $this->getPosition(); ?>" class="checkbox<?php if($block->getShowAddress()) : ?> checked<?php endif; ?>">
                            <span class='icon'></span><span class='icon-to-fade'></span>
                            <input type="checkbox" id="cms_address_container_<?php echo $this->getPosition(); ?>" name="block[<?php echo $this->getPosition(); ?>][show_address]" value="1"<?php if($block->getShowAddress()) : ?> checked="checked"<?php endif; ?> />
                            <?php echo $this->_("Display address") ?>
                        </label>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="label">
                        <label for="cms_geolocation_button_<?php echo $this->getPosition(); ?>" id="label_cms_geolocation_button_<?php echo $this->getPosition(); ?>" class="checkbox<?php if($block->getShowGeolocationButton()) : ?> checked<?php endif; ?>">
                            <span class='icon'></span><span class='icon-to-fade'></span>
                            <input type="checkbox" id="cms_geolocation_button_<?php echo $this->getPosition(); ?>" name="block[<?php echo $this->getPosition(); ?>][show_geolocation_button]" value="1"<?php if($block->getShowGeolocationButton()) : ?> checked="checked"<?php endif; ?> />
                            <?php echo $this->_("Display location button") ?>
                        </label>
                    </td>
                </tr>
            </table>
        </div>
        <input type="hidden" name="block[<?php echo $this->getPosition(); ?>][block_id]" value="<?php echo $block->getBlockId(); ?>" />
        <input type="hidden" name="block[<?php echo $this->getPosition(); ?>][value_id]" value="<?php echo $block->getValueId(); ?>" />
        <input type="hidden" name="block[<?php echo $this->getPosition(); ?>][type]" value="<?php echo $block->getType(); ?>" />
        <input type="hidden" name="block[<?php echo $this->getPosition(); ?>][position]" value="<?php echo $this->getPosition(); ?>" class="hidden_pos" rel="<?php echo $this->getPosition(); ?>"  />
    </div>
    <div class="right">
        <a class="remove" href="javascript:void(0);"><i class="icon-remove"></i></a>
    </div>
    <div class="clear"></div>
    <script type="text/javascript">

        if(window.google) {
            bindGmapsSearchBox($('#cms_address_<?php echo $this->getPosition(); ?>'));
        }

        $('.cms_block[rel="<?php echo $this->getPosition(); ?>"] .remove').click(function(){
            removeElem(<?php echo $this->getPosition(); ?>);
        });

        /*
        $('#address_<?php echo $this->getPosition() ?>').keyup(function() {
            var address = "page.showGoogleMaps('"+$(this).val().replaceAll("\n", "")+"');";
            iframe.content.find('#cms_geolocation_button_<?php echo $this->getPosition() ?>').attr('onclick', address);
            iframe.content.find('#cms_address_<?php echo $this->getPosition() ?>').html($(this).val().nl2br());
        });

        $('#label_<?php echo $this->getPosition() ?>').keyup(function() {
            iframe.content.find('#cms_label_<?php echo $this->getPosition() ?>').html($(this).val());
        });
         */

        $('.cms_block[rel="<?php echo $this->getPosition(); ?>"] .handle').mousedown(function(){
            dragTransformMouseDown($(this));
        }).mouseup(function(){
            dragTransformMouseUp($(this));
        });

        var fields = ['cms_address_container_<?php echo $this->getPosition() ?>', 'cms_geolocation_button_<?php echo $this->getPosition() ?>'];
        for(var i in fields) {
            var field = fields[i];
            bindLabel($('#label_'+field));
            setupLabel($('#label_'+field));
            /*
            $('#'+field).change(function() {
                if($(this).is(':checked')) {
                    iframe.content.find('#'+this.id).slideDown();
                } else {
                    iframe.content.find('#'+this.id).stop().slideUp();
                }
            })
            */
        }

    </script>
</div>
