<?php

class Intense_Gallery_Type {
	public $id;

	function __construct( $id ) {
        $this->id = $id;
    }

	public function init() {

	}

	public function before_items() {

	}

	public function item( $atts ) {

	}

	public function after_items() {

	}
}

class Intense_Gallery_Type_Standard extends Intense_Gallery_Type {
	public function item( $atts ) {
		extract( $atts );

		if ( $no_link == 1 ) {
            $photo_markup = "<span class='$type $grouping gallery-item' title='" . esc_attr( $title ) . "' data-content='" . esc_attr( $description ) . "'>" .
                                $individual_photo_markup . "</span>";
        } else {
            $photo_markup = "<a class='$type $grouping gallery-item' title='" . esc_attr( $title ) . "' data-content='" . esc_attr( $description ) . "' href='" . esc_attr( $link ) . "'>" .
                                $individual_photo_markup . "</a>";
        }

        return array( 
        	'markup' => $photo_markup,
			'script' => ''
		);
	}
}

class Intense_Gallery_Type_Lightbox extends Intense_Gallery_Type {
	private $lightbox;

	public function init() {
		global $intense_visions_options;
		require_once INTENSE_PLUGIN_FOLDER . '/inc/tools/lightboxes.php';

		$lightbox_type = get_class( $this );
		$lightbox_type = strtolower( $lightbox_type );
		$lightbox_type = str_replace( 'intense_gallery_type_', '', $lightbox_type );

        $this->lightbox = Intense_Lightboxes::create( $lightbox_type, '#' . $this->id . ' a' );

        return array( 
        	'script' => $this->lightbox->get_image_script(),
        	'style' => $this->lightbox->get_css(),
        	'additional_script' => ''
    	);
	}

	public function item( $atts ) {
		extract( $atts );

		return array( 
			'markup' => $this->lightbox->get_image( $grouping, $title, $description, $original_photo_url, $individual_photo_markup ),
			'script' => '' 
		);
	}
}

class Intense_Gallery_Type_Photoswipe extends Intense_Gallery_Type_Lightbox { }
class Intense_Gallery_Type_Thickbox extends Intense_Gallery_Type_Lightbox { }
class Intense_Gallery_Type_Colorbox extends Intense_Gallery_Type_Lightbox { }
class Intense_Gallery_Type_Magnificpopup extends Intense_Gallery_Type_Lightbox { }
class Intense_Gallery_Type_Prettyphoto extends Intense_Gallery_Type_Lightbox { }
class Intense_Gallery_Type_Swipebox extends Intense_Gallery_Type_Lightbox { }
class Intense_Gallery_Type_Touchtouch extends Intense_Gallery_Type_Lightbox { }

class Intense_Gallery_Type_Galleria extends Intense_Gallery_Type {

	public function init() {
		global $intense_visions_options;

		intense_add_script( 'galleria' );
        intense_add_script( 'galleriatheme' );
        intense_add_style( 'galleria' );

        return array( 
    		'script' => "Galleria.configure({
	                        lightbox: " . ( $intense_visions_options['intense_galleria_lightbox'] != null ? $intense_visions_options['intense_galleria_lightbox'] : "true" ) . ",
	                        transition: '" . ( $intense_visions_options['intense_galleria_transition'] != null ? $intense_visions_options['intense_galleria_transition'] : "fade" ) . "',
	                        trueFullScreen: true,
	                        fullscreenDoubleTap: true,
	                        imageCrop: false,
	                        fullscreenCrop: false,
	                        autoplay: " . ( $intense_visions_options['intense_galleria_slideshow'] != null && $intense_visions_options['intense_galleria_slideshow'] ? "5000" : "false" ) . ",
	                    });

	                    Galleria.run('#" . $this->id . "');

	                    Galleria.ready(function() {
	                        var gallery = this;
	                        this.addElement('fscr');
	                        this.appendChild('stage','fscr');
	                        var fscr = this.$('fscr').append('" . intense_run_shortcode( 'intense_icon', array( 'source' => $intense_visions_options['intense_fullscreen_icon']['source'], 'type' => $intense_visions_options['intense_fullscreen_icon']['type'], 'color' => '#fff', 'width' => '14' ) ) . "')
	                            .click(function() {
	                                gallery.toggleFullscreen();
	                            });
	                        this.addIdleState(this.get('fscr'), { opacity:0 });
	                    });",
			'style' => $this->get_style(),
			'additional_script' => ''
		);
        //$size = ( $size != '' ? $size : 'medium640' );
	}

	private function get_style() {
		 return "
		 	#" . $this->id . " {
                width: 100%;
                height: 500px;
                background: #000;               
            }
            .galleria-stage {
                position: absolute !important;
            }
            .galleria-fscr {
                width:20px;
                height:20px;
                position:absolute;
                bottom:15px;
                right: 0px;
                padding-left: 2px;
                background: black;
                z-index:4;
                cursor: pointer;
                opacity: .7;
                color: white;
            }

            .galleria-fscr:hover {
                opacity:1;
            }

            .galleria-lightbox-box {
                direction: ltr;
            }
        ";  
	}

	public function item( $atts ) {
		extract( $atts );

		return array( 
			'markup' => intense_get_template( '/gallery/galleria/' . $galleria_template . '.php', array(                                
			                'url' => $sized_photo_url,
			                'original_url' => $original_photo_url,
			                'title' => $title,
			                'description' => $description,
			                'photo' => $photo                             
			            ) ),
			'script' => ''
		);
	}

	public function after_items() {

	}
} 

class Intense_Gallery_Type_Supersized extends Intense_Gallery_Type {
	public function init() {
		global $intense_visions_options;

		intense_add_script( 'easing' );
        intense_add_script( 'supersized_js' );
        intense_add_script( 'supersized_shutter_js' );

        intense_add_style( 'supersized_style' );
        intense_add_style( 'supersized_shutter_style' );
        intense_add_style( 'supersized_theme' );

        $additionalscript = " $('#supersizedcontrols').show();
                $.supersized({

                    //Functionality
                    slideshow               :   " . ( $intense_visions_options['intense_supersized_slideshow'] != null ? $intense_visions_options['intense_supersized_slideshow'] : 1 ) . ", //Slideshow on/off
                    autoplay                :   " . ( $intense_visions_options['intense_supersized_autoplay'] != null ? $intense_visions_options['intense_supersized_autoplay'] : 1 ) . ", //Slideshow starts playing automatically
                    start_slide             :   1,      //Start slide (0 is random)
                    slide_interval          :   5000,   //Length between transitions
                    transition              :   " . ( $intense_visions_options['intense_supersized_slideshow_transition'] != null ? $intense_visions_options['intense_supersized_slideshow_transition'] : 1 ) . ", //0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
                    transition_speed        :   1000,    //Speed of transition
                    new_window              :   1,      //Image links open in new window/tab
                    pause_hover             :   " . ( $intense_visions_options['intense_supersized_pause_hover'] != null ? $intense_visions_options['intense_supersized_pause_hover'] : 0 ) . ", //Pause slideshow on hover
                    keyboard_nav            :   " . ( $intense_visions_options['intense_supersized_keyboard_nav'] != null ? $intense_visions_options['intense_supersized_keyboard_nav'] : 1 ) . ", //Keyboard navigation on/off
                    performance             :   1,      //0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
                    image_protect           :   " . ( $intense_visions_options['intense_supersized_image_protect'] != null ? $intense_visions_options['intense_supersized_image_protect'] : 1 ) . ",      //Disables image dragging and right click with Javascript
                    //image_path              :   '" . get_stylesheet_directory_uri() . "/supersized/img/', //Default image path
                    stop_loop               :   " . ( $intense_visions_options['intense_supersized_stop_loop'] != null ? $intense_visions_options['intense_supersized_stop_loop'] : 0 ) . ",      //Pauses slideshow upon reaching the last slide.

                    //Size & Position
                    min_width               :   0,      //Min width allowed (in pixels)
                    min_height              :   0,      //Min height allowed (in pixels)
                    vertical_center         :   1,      //Vertically center background
                    horizontal_center       :   1,      //Horizontally center background
                    fit_portrait            :   1,      //Portrait images will not exceed browser height
                    fit_landscape           :   0,      //Landscape images will not exceed browser width

                    //Components
                    navigation              :   " . ( $intense_visions_options['intense_supersized_slideshow_navigation'] != null ? $intense_visions_options['intense_supersized_slideshow_navigation'] : 1 ) . ", //Slideshow controls on/off
                    thumbnail_navigation    :   " . ( $intense_visions_options['intense_supersized_thumbnail_navigation'] != null ? $intense_visions_options['intense_supersized_thumbnail_navigation'] : 0 ) . ",      //Thumbnail navigation
                    slide_counter           :   " . ( $intense_visions_options['intense_supersized_slide_counter'] != null ? $intense_visions_options['intense_supersized_slide_counter'] : 1 ) . ", //Display slide numbers
                    slide_captions          :   " . ( $intense_visions_options['intense_supersized_slide_captions'] != null ? $intense_visions_options['intense_supersized_slide_captions'] : 1 ) . ", //Slide caption (Pull from title in slides array)
                    progress_bar            :   " . ( $intense_visions_options['intense_supersized_progress_bar'] != null ? $intense_visions_options['intense_supersized_progress_bar'] : 1 ) . ",
                    mouse_scrub             :   0,
                    thumbnail_links         :   " . ( $intense_visions_options['intense_supersized_thumbnail_links'] != null ? $intense_visions_options['intense_supersized_thumbnail_links'] : 2 ) . ",
                    slides                  :   [       ";

        return array( 'additional_script' => $additionalscript, 'script' => '', 'style' => '' );
	}

	public function item( $atts ) {
		extract( $atts );

		$photo_script = "{ image:'" . $original_photo_url . "', title:" . json_encode( wptexturize( $title ) ) . ", caption:" . json_encode( wptexturize( $description ) ) . ", url:'" . $link . "' },";

		return array( 
			'markup' => '',
			'script' => $photo_script
		); 
	}
}