<?php
/*
# ------------------------------------------------------------------------
# Extensions for Joomla 2.5.x - Joomla 3.x
# ------------------------------------------------------------------------
# Copyright (C) 2009-2014 za-studio.net, za-studio.ru. All Rights Reserved.
# @license - PHP files are GNU/GPL V2.
# Author: Za Studio
# Websites:  http://www.za-studio.net
# Date modified: 10/03/2014
# ------------------------------------------------------------------------
*/
defined('_JEXEC') or die('Restricted access');

class modSlider3dHelper {

    static function getScript($params) {

        $orientation = $params->get('orientation');

        $autoplay = ($params->get('autoplay') == '0') ? 'false' : 'true';
		$cuboidsCount = $params->get('cuboidsCount');

        $cuboidsRandom = ($params->get('cuboidsRandom') == '0') ? 'false' : 'true';

        $maxCuboidsCount = $params->get('maxCuboidsCount');

        $disperseFactor = $params->get('disperseFactor');
     

        $javascript = "
                jQuery(function() {
                            var Page = (function() {

                                    var navArrows = jQuery( '#nav-arrows' ).hide(),
                                            navDots = jQuery( '#nav-dots' ).hide(),
                                            nav = navDots.children( 'span' ),
                                                                                                            navOptions = jQuery( '#nav-options' ).hide()
                                            shadow = jQuery( '#shadow' ).hide(),
                                            slicebox = jQuery( '#sb-slider' ).slicebox( {
                                                    onReady : function() {

                                                            navArrows.show();
                                                            navDots.show();
                                                                                                                                                 navOptions.show();
                                                            shadow.show();

                                                    },
                                                    onBeforeChange : function( pos ) {

                                                            nav.removeClass( 'nav-dot-current' );
                                                            nav.eq( pos ).addClass( 'nav-dot-current' );

                                                    },
                                                    // (v)ertical, (h)orizontal or (r)andom
                                                    orientation : '" . $orientation . "',
													 cuboidsCount : " . $cuboidsCount . ",
                                                    // if true then the number of slices / cuboids is going to be random (cuboidsCount is overwitten)
                                                    cuboidsRandom : " . $cuboidsRandom . ",
                                                    // the range of possible number of cuboids if cuboidsRandom is true
                                                    // it is strongly recommended that you do not set a very large number :)
                                                    maxCuboidsCount : " . $maxCuboidsCount . ",
                                                    // each cuboid will move x pixels left / top (depending on orientation). The middle cuboid doesn't move. the middle cuboid's neighbors will move disperseFactor pixels
                                                    disperseFactor : " . $disperseFactor . ",
                                                  
                                                    // if true the slicebox will start the animation automatically
                                                    autoplay : " . $autoplay . "
                                            } ),

                                            init = function() {

                                                    initEvents();

                                            },
                                            initEvents = function() {

                                                    // add navigation events
                                                    navArrows.children( ':first' ).on( 'click', function() {

                                                            slicebox.next();
                                                            return false;

                                                    } );

                                                    navArrows.children( ':last' ).on( 'click', function() {

                                                            slicebox.previous();
                                                            return false;

                                                    } );

                                                    nav.each( function( i ) {

                                                            jQuery( this ).on( 'click', function( event ) {

                                                                    var dot = jQuery( this );

                                                                    if( !slicebox.isActive() ) {

                                                                            nav.removeClass( 'nav-dot-current' );
                                                                            dot.addClass( 'nav-dot-current' );

                                                                    }

                                                                    slicebox.jump( i + 1 );
                                                                    return false;

                                                            } );


                                                    } );

                                                    jQuery( '#navPlay' ).on( 'click', function() {

                                                            slicebox.play();
                                                            return false;

                                                    } );

                                                    jQuery( '#navPause' ).on( 'click', function() {

                                                            slicebox.pause();
                                                            return false;

                                                    } );

                                            };

                                            return { init : init };

                            })();

                            Page.init();

                    });
            ";
        return $javascript;
    }

    static function SetCSS() {
        $document = JFactory::getDocument();
        //$document->addStyleDeclaration();
        $document->addStyleSheet('modules/mod_slider3d/css/slicebox.css');
        $document->addStyleSheet('modules/mod_slider3d/css/custom.css');
        //$document->addStyleSheet( 'modules/mod_slider3d/css/demo.css' );
    }

    static function SetScript($params) {
        $document = JFactory::getDocument();
        $load = $params->get('load');
        $jver = $params->get('jver');
        $show_jquery = $params->get('show_jquery');

        $jquerypath = ($jver == "1.9.1") ? "modules/mod_slider3d/js/jquery-1.9.1.min.js" : ("http://ajax.googleapis.com/ajax/libs/jquery/" . $jver . "/jquery.min.js");

        if ($load == "onmod") {
            if ($jver == '1.9.1')
                $jquerypath = JUri::root() . $jquerypath;
            if ($show_jquery == '1')  echo "<script src='" . $jquerypath . "' type='text/javascript'></script>";
            echo "<script src='" . JUri::root() . "modules/mod_slider3d/js/modernizr.custom.46884.js' type='text/javascript'></script>" .
            "<script src='" . JUri::root() . "modules/mod_slider3d/js/jquery.slicebox.js' type='text/javascript'></script>" .
            "<script type='text/javascript'>" .
            modSlider3dHelper::getScript($params) .
            "</script>";
        } else {
            if ($show_jquery == "1")
                $document->addScript($jquerypath);
            $document->addScript('modules/mod_slider3d/js/modernizr.custom.46884.js');
            $document->addScript('modules/mod_slider3d/js/jquery.slicebox.js');
            $document->addScriptDeclaration(modSlider3dHelper::getScript($params));
        }
    }

}

?>