<?php

class Fiktiv_View_Helper_Fancybox extends Zend_View_Helper_Abstract
{
    protected $_enabled = false;

    protected $_transition = 'elastic';

    protected $_titlePosition = 'outside';

    protected $_fancy = array();

    public function fancybox()
    {
        return $this;
    }

    public function enable()
    {
        $this->_enabled = true;
    }

    public function disable()
    {
        $this->_enabled = false;
    }

    public function headScript()
    {
        if (!$this->_enabled)
            return;

        $start = "<script type=\"text/javascript\">\n\t$(document).ready(function() {\n\t\t";

        $body = join("\n\t\t", $this->_fancy);

        $end = "\n\t});\n    </script>\n";

        return $start . $body . $end;
    }

    public function registerFancyness($access, $titlePosition = null, $transition = null)
    {

        $titlePosition = ($titlePosition) ? $titlePosition : $this->_titlePosition;
        $transition    = ($transition)    ? $transition    : $this->_transition;

        return $this->_fancy[] = '$("' . $access . '").fancybox({\'titlePosition\'  : \'' . $titlePosition . '\', \'transitionIn\' : \'' . $transition . '\'});';
    }
}