<?php

class Intense_Masonry_Item extends Intense_Shortcode {

	function __construct() {
		parent::__construct();

		global $intense_visions_options;

		$this->title = __( 'Masonry Item', 'intense' );
		$this->category = __( 'Layout', 'intense' );
		$this->show_preview = true;
		$this->hidden = true;
		$this->parent = 'intense_masonry';
		$this->is_container = true;		
	}

	function shortcode( $atts, $content = null ) {
		global $intense_visions_options;
		extract( shortcode_atts( $this->get_shortcode_defaults( null, $atts ), $atts ) );

		global $intense_masonry_gutter;

		$size_class = '';

		if ( empty( $width ) && empty( $size ) && empty( $medium_size ) && empty( $small_size ) && empty( $extra_small_size ) ) {
			$width = 50 * ( rand(0,1) ? .5 : 1 ); //50% or 25% randomly
		}

		if ( is_numeric( $width ) ) $width .= '%';

		if ( !empty( $size ) || !empty( $medium_size ) || !empty( $small_size ) || !empty( $extra_small_size ) ) {
			$size_class = " intense col-lg-$size " .
				( isset( $extra_small_size ) ? "col-xs-$extra_small_size ": "col-xs-12 " ) .
				( isset( $small_size ) ? "col-sm-$small_size " : "col-sm-12 " ) .
				( isset( $medium_size ) ? "col-md-$medium_size " : "col-md-$size " ) .
				"nogutter ";
			$width = null;
		}

		return '<div class="item' . $size_class . '" style="float:left; ' . ( !empty( $width ) ? 'width: ' . $width  . ';' : '' ) . '"><div style="margin: 0 ' . $intense_masonry_gutter / 2 . 'px ' . ( $intense_masonry_gutter ). 'px;">' . do_shortcode( $content ) . '</div></div>';
	}
}
