<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://www.cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#------------------------------------------------------------------------------------
# Plugin		: 960_grid
# Function		: Generate 960 GRID CSS
# File		: /plugins/function.960_grid.php
# Version		: 3.0.2
#------------------------------------------------------------------------------------
# Dependances	: null
#------------------------------------------------------------------------------------
# Author : THOMAS Philippe
# Copyright : (c)2014 - AVIAPIC
#------------------------------------------------------------------------------------
# Description	: Generate 960 GRID CSS
#------------------------------------------------------------------------------------

/**********************************************************
	Main function
**********************************************************/

function smarty_function_css_960_grid($params, &$template)
{
	#---------------------------------------------
	# Set Parameters
	#---------------------------------------------
	//string
	$type				=	$params['type']			= isset($params['type']) ? $params['type'] : 'fluid'; // fixe fluid
	$align				=	$params['align']		= isset($params['align']) ? $params['align'] : 'center'; // left center right
	//$params['assign']
	
	//integer
	$containers_width	=	$params['width']		= isset($params['width']) ? $params['width'] : 960;
	$width_min			=	$params['width_min']	= isset($params['width_min']) ? $params['width_min'] : 'not_set';
	$width_max			=	$params['width_max']	= isset($params['width_max']) ? $params['width_max'] : 'not_set';
	$gutter				=	$params['gutter']		= isset($params['gutter']) ? $params['gutter'] : 20;
	
	//boolean
	$check				=	$params['check']		= isset($params['check']) ? $params['check'] : FALSE ;
	$css				=	$params['css']			= isset($params['css']) ? $params['css'] : 'grid';

	// integer or string with comma
	$columns			=	$params['columns']		= isset($params['columns']) ? $params['columns'] : 12;
	$handheld_devices	=	$params['handheld_devices']		= isset($params['handheld_devices']) ? $params['handheld_devices'] : 'not_set'; 
	
	//reset var $e to manage errors
	unset($e);

	//get language
	$lang = CmsNlsOperations::get_current_language();

	#--------------------------------------	
	# MANAGE ERRORS : function built_error
	#--------------------------------------	

	//function built error array
	if (!function_exists('built_error'))
	{
	function built_error($error_code, $param_key, $lang='en_EN')
	{
		//define ERRORS : languages, codes, values
		$errors_list = array(
			'en_EN'=>array(
			0			=>	'unknown error -> verify plugin core',
			1	=>	'Name : "'.$param_key.'" is not a valid NAME PARAMETER',
			20	=> 	'"'.$param_key.'" Parameter value must be a BOOLEAN and choose between true or false',
			31	=>	'"'.$param_key.'" Parameter value must be a STRING and choose between "left" or "right" or "center".',
			32	=>	'"'.$param_key.'" Parameter value must be a STRING and choose between "fluid" or "fixe".',
			33	=>	'"'.$param_key.'" Parameter value must be a STRING and choose between "reset", "text", "grid", "hack", "handheld_1", "handheld_2", "print", "all" or string width this values separated width comma .',
			42 	=>	'"'.$param_key.'" Parameter value must be an POSITVE INTEGER and not equal 0',
			41 	=>	'"'.$param_key.'" Parameter value must be an POSITVE INTEGER or 0',			
			43 	=>	'"'.$param_key.'" Parameter value must be an POSITVE INTEGER or a STRING packaging INTEGER separated with comma. ex: 12 or "12,14"',
			51	=>	'"width_max" Parameter value must be equal or upper than "width_min" and "width" prameters values ',
			61	=> 	'Bad RATIO result : '.$param_key.' must be an integer.',			
			62	=>	'Result Value of "'.$param_key.'" is negative or null !!! : Increase "with" parameter value or DECREASE "gutter" parameter value.',
			71	=>	'"css=handheld_1" need "'.$param_key.'" Parameter have values'
			),
			'fr_FR'=>array(
			1000	=> '' //todo translate
			)
		);

		//return error 
		if(!array_key_exists($error_code,$errors_list[$lang]) && !array_key_exists($error_code,$errors_list['en_EN'])) 
			{$error_code = 0;}

		if(!array_key_exists($lang,$errors_list) || !array_key_exists($error_code,$errors_list[$lang]))
			{$lang='en_EN';}
		
		return 'Plugin error_code '.$error_code.':<br/>'.$errors_list[$lang][$error_code];
	}
	}

	#--------------------------------------
	# PARAMETERS Validation
	#--------------------------------------

	//Verify Parameters and types of values
	unset($error_code,$param_key,$param_value);
	foreach ($params as $param_key=>$param_value)
	{
		//Verify PARAMETER VALUES
		switch ($param_key)
		{
		### Test boolean values
			case "check" : if(!is_bool($param_value)) {$error_code=20;}
			break;

		### Test strings values

			case "css" :

				$css_valid = array( "reset","text","grid" ,"hack" ,"handheld_1" ,"handheld_2" , "print" ,"all");
					
				$css_values = explode(',',$css);
				sort($css_values);
				foreach ($css_values as $css_val)
				{
					if (in_array($css_val,$css_valid,true))
					{
						${'css_'.$css_val}=true; // built dynamics var to manage css output
					}
	
					else
					{$error_code = 33;}
				}
			break;
			
			case "align" :
				switch ($param_value)
				{
					case "center" : $container_margin= "0 auto;";// default value
					break;
					
					case "left" : $container_margin= "0 auto 0 0;";
					break;
						
					case "right" : $container_margin= "0 0 0 auto;";
					break;
						
					default : $error_code = 31; // only center, left or right			
				}
			break;
				
			case "type" :
				switch ($param_value)
				{
					case "fixe" : $unit="px";
					break;
					
					case "fluid" : 
						$unit="%";
						$containers_width = "92";
						$gutter ="2";
					break;
					
					default : $error_code = 32; // only fixe or fluid
				}
			break;
				
		###	Test value integers
		
			// positive integer or 0
			case "gutter" : 
				if (!preg_match('/^[0-9]\d*$/',$param_value)) {$error_code = 41;}
				else 	$margin_with = $gutter /2;
			break;
			
			// positive integer and not 0
			case "width_min" :
			case "width_max" :				
			case "width" :  if ($param_value!='not_set' && !preg_match('/^[1-9]\d*$/',$param_value)) {$error_code = 42;}
			break;
			
			// ( positive integer   OR  STRING packaging INTEGER separated with comma )   and not 0
			case 'handheld_devices':
				
				if ($param_value !=='not_set' && !preg_match('/^[1-9]\d*(,?[1-9]\d*)*$/',$param_value)) {$error_code = 43;} 
			break;
			
			case 'columns' :
				if (!preg_match('/^[1-9]\d*(,?[1-9]\d*)*$/',$param_value)) {$error_code = 43;} 
				else 
				{	// Create an array to store columns values
					$columns_values = explode(',',$columns);
					sort($columns_values);

					// Number of columns
					//$columns_count = count($columns_values);

					// column widest value
					$column_widest = max($columns_values);
				}
			break;
		
		### test others cases in order to Verify PARAMETER KEY
			case 'assign' :
			break;
			
			default : $error_code = 1;
		}
		//end SWITCH
		
		// build error if exist
		if($error_code){$e[]= built_error($error_code,$param_key,$lang);}
		
		unset($error_code,$param_key,$param_value);
	}
	
	//test width_max coherence
	if( ($width_max < $containers_width || $width_max < $width_min) AND $width_max != 'not_set') { $e[] = built_error(51,'width_max',$lang);}

	//test $handheld_devices is set width css=handheld_1
	if($css_handheld_1)
	{
		if($handheld_devices ==='not_set') {$e[] = built_error(71,'handheld_devices',$lang);}
	}
	
	#--------------------------------------	
	# Test RATIO BEFORE CALCULATIONS
	#--------------------------------------	
	if(!$e)
	{	
	
		//test ratio
		if ($css_all || $css_grid || $css_handheld_1 || $css_handheld_2 || $css_print || $css_hack)
		{
			foreach ($columns_values as $col_val)
			{
				if ($type == 'fixe' AND	( !is_int($ratio=$containers_width/$col_val) || $ratio <1))
				
			
			 {$e[]=built_error(61,'"width": '.$containers_width.' divided by "columns" value: '.$col_val,$lang);}
			}
		}
	}
	
	#--------------------------------------	
	# CREATE CSS class VALUABLES SEQUENCES
	#--------------------------------------	
	
	if(!$e)
	{
		// create class sequence: .grid .push .pull
		for ($id=1; $id <= $column_widest ; $id++)
		{
			// .grid_IDs
			$grid_IDs .= ".grid_".$id;
			$grid_IDs_linearize .= ".grid_".$id.".linearize , .linearize .grid_".$id;
			if($id != $column_widest){$grid_IDs .=", ";$grid_IDs_linearize .=", ";}//separator
				
			//.push_IDs .pull_IDs
			if($type =="fixe")
			{
				$push_pull_IDs .= ".push_".$id.", .pull_".$id;
				if($id != $column_widest){$push_pull_IDs .=", ";}//separator
			}
		}
		unset($id);
		
		// Generate output class sequence: .grid_IDs {} // cf line 465
		$output_grid = $grid_IDs." { display: inline ; float: left ; margin-left : ".$margin_with.$unit." ; margin-right: ".$margin_with.$unit." ; } ";

		// Generate output class sequence: .push_IDs, .pull_IDs {} // cf line 466
		if($type =="fixe")
		{
			$output_push_pull = $push_pull_IDs." { position:relative; } ";
		}	
	
		// create class sequence: .container 
		unset ($col_val);
		foreach ($columns_values as $col_val)
		{
			$container_IDs .= ".container_".$col_val;
			if ($col_val != $column_widest){$container_IDs .= ", ";}//separator
		
			for ($id=1; $id <= $col_val ; $id++)
			{
				
				if ($type == "fluid")
				{
					$splited_width = str_replace(',','.',round((100/$col_val)*$id,3)); 
				}
				if ($type == "fixe")
				{
					$splited_width = str_replace(',','.',($containers_width/$col_val)*$id);
					
					$device_check[$col_val][$id] = $splited_width;// array use for handheld_1 css
				}
				
				$grid_width = str_replace(',','.',($splited_width - $gutter));
				
				if ($grid_width <=0  && ($css_all || $css_grid || $css_handheld_1 || $css_handheld_2))
				{
					$e[]=built_error(62,'Grid_'.$id,$lang);
				}
				
				$ouput_grid_width .= '.container_'.$col_val.' .grid_'.$id.' {width: '.$grid_width.$unit.' ;} '; // cf line 472
				
				if($id < $col_val)
				{
					$ouput_grid_prefix .= ".container_".$col_val." .prefix_".$id." {padding-left: ".$splited_width.$unit." ;} "; // cf line 473
					$ouput_grid_suffix .= ".container_".$col_val." .suffix_".$id." {padding-right: ".$splited_width.$unit." ;} "; // cf line 474
					$ouput_grid_push .= ".container_".$col_val." .push_".$id." {left: ".$splited_width.$unit." ;} "; // cf line 475
					$ouput_grid_pull .= ".container_".$col_val." .pull_".$id." {left: -".$splited_width.$unit." ;} "; // cf line 476
				}
				
				if ($id != $column_widest){$separator = ", ";} else {unset($separator);}

				$container_grid_IDs .= ".container_".$col_val." .grid_".$id.$separator." "; // cf line 576 590 639
				$container_prefix_IDs .= ".container_".$col_val." .prefix_".$id.$separator." "; // cf line 600
				$container_suffix_IDs .= ".container_".$col_val." .suffix_".$id.$separator." "; // cf line 601
				$container_push_IDs .= ".container_".$col_val." .push_".$id.$separator." "; // cf line 605
				$container_pull_IDs .= ".container_".$col_val." .pull_".$id.$separator." "; // cf line 606
				unset($separator);
			}
			unset($id);
			
			if ($col_val != $column_widest){$separator = ", ";} else {unset($separator);}

			//generate css -section : Clear Floated Elements
			$container_IDs_before .= ".container_".$col_val.":before".$separator." ";	//cf line 495		
			$container_IDs_after .= ".container_".$col_val.":after".$separator." ";	//cf line 496 509
			// use this output for IE6 IE7 fixe (see bottom of output css)
			$container_IDs_fixe .= ".container_".$col_val.$separator." "; //cf line 531

		unset ($col_val);
		}
		
		// Generate ouput : .container_IDs {} //cf line 464
		$output_container = $container_IDs.' {width:'.$containers_width.$unit.';';
		if($width_min !='not_set') {$output_container .= " min-width:".$width_min."px;";}
		if($width_max !='not_set') {$output_container .= " max-width:".$width_max."px;"; }
		$output_container .= " margin:".$container_margin."}"; 
	}

	#--------------------------------------	
	# CREATE OPTIONALS VALUABLES SEQUENCES
	#--------------------------------------	

	// specific AVIAPIC HANDHELD CSS (need specific viewport:  cf line 397 )
	if($css_handheld_1)
	{
		// create array to store handheld devices values
		$handheld_devices = explode(',',$handheld_devices);
		rsort($handheld_devices);

		// prevent missing device_width in case type=FIXE
		$auto_device_width = $containers_width - 1;
		
		if(  $type=='fixe' && !(in_array( $auto_device_width,$handheld_devices,true)) ) {$valid_device[$auto_device_width]=$auto_device_width; }

		
		//use $container_IDs create before
		foreach ($handheld_devices as $device_width )
		{
			if( $type=='fluid' || ( $width_min > 0 && ($device_width < $width_min) ) ) 	{$valid_device[$device_width]=$device_width; }


			// linearize grid if grid_width > device width In case type FIXE
			if($type=='fixe')
			{
				
				foreach($device_check as $cont_id=>$cont_grid_id)
				{
					foreach($cont_grid_id as $addgrid=>$grid_size)
					{
						if($device_width < $grid_size)
						{
							$valid_device[$device_width]=$device_width;
							$correct_grid[$device_width].=', .container_'.$cont_id.' .grid_'.$addgrid;
						}
					}
				}
			}
		}
		
		if($valid_device)
		{
			foreach($valid_device as $device_w)
			{
				$overgrid='';
				if($correct_grid && $correct_grid[$device_w])
				{
					$overgrid = $correct_grid[$device_w];
				}

				$handheld_aviapic_css .= '@media only screen and (max-width:'.$device_w.'px)
				{
					'.$container_IDs.' {min-width:'.$device_w.'px; width:'.$device_w.'px; max-width:'.$device_w.'px;overflow:hidden;}
					.no_handheld, .no_handheld_'.$device_w.' {display:none;}
					'.$grid_IDs_linearize.$overgrid.'  { float:none;display:block;clear:both;min-width:auto;max-width: 98%; width: 98%; margin: 0 1%;overflow:hidden;}
				}';
			}
		}
	}

	############################################################################
	####
	####      START OUPUT PLUGIN
	####
	############################################################################
	
	#---------------------------------------------------------------------------	
	# ERRORS STOP PLUGIN : only display errors (html formated) if exist AND "check" parameter is true )
	#---------------------------------------------------------------------------

	if ($e)
	{
		if($params['check']) {foreach($e as $error_output) {echo '<p style="font-weight:bolder; background:#fff;color:#f00;">'.$error_output.'</p>';} } // output HTML code for Template
		else {echo '/* ----- CSS_960_grid plugin errors ----- */';} // Output for CSS StyleSheet or Template 
	}

	#---------------------------------------------------------------------------	
	# OUTPUT ONLY PARAMETERS values (html formated)) check parameter = true
	#---------------------------------------------------------------------------
	
	// Display only values - don't generate or output any CSS  
	elseif($check)
	{
		// for old php <5.5.0 versions to use function boolval()
		if (!function_exists('boolval'))
		{
			function boolval($val)
			{
				if(is_bool($val)) {if($val===true) return 'true';else return 'false';};
			}
		}

		$output = '<h3>CSS 960 GRID PLUGIN PARAMETERS</h3><p>';
		foreach($params as $key=>$val)
		{
			if(is_bool($val)) {$output .= $key.' = '. boolval($val).'<br/>';}
			else {$output .= $key.' = '.$val.'<br/>';}
		}
			
		$output .= '</p><p>NO ERRORS<p>';
		
		if($type=='fixe' && $css_grid)
		{
			$output .='<h3>CSS 960 GRID PLUGIN Help For type Fixe</h3><p>With_max parameter takes the value of with_min</p>';
		}
		
		if($css_handheld_1)
		{
			$output .= '<h3>CSS 960 GRID PLUGIN Help For css_handheld_1</h3><p>Insert this meta viewport in your template into head part.</p>';
			$output .= '<p style="font-weight:bolder; background:#fff;color:#f00;">&lt;meta name="viewport" content="width=device-width, initial-scale=1,target-densitydpi=device-dpi"&gt;</p>';
		}
		echo $output;
	}

	#---------------------------------------------------------------------------	
	# OUTPUTs CSS
	#---------------------------------------------------------------------------	
	
	else
	{
	
	$CSS960_OUTPUT ='';
	
	//-------------------------------------------------
	// RESET CSS : true 
	
	if ($css_all||$css_reset)
	{
	$CSS960_OUTPUT .= '
/* =====================================
start RESET CSS_960_Plugin
===================================== */	
/* normalize.css v3 https://github.com/necolas/normalize.css
----------------------------------------------------------------------------------------------------*/
html { font-family: sans-serif; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } body { margin: 0; } article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary { display: block; } audio, canvas, progress, video { display: inline-block; vertical-align: baseline; } audio:not([controls]) { display: none; height: 0; } [hidden], template { display: none; } a { background: transparent; } a:active, a:hover { outline: 0; } abbr[title] { border-bottom: 1px dotted; }   b, strong { font-weight: bold; } dfn { font-style: italic; } h1 { font-size: 2em; margin: 0.67em 0; } mark { background: #ff0; color: #000; } small { font-size: 80%; } sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }  sup { top: -0.5em; }  sub { bottom: -0.25em; } img { border: 0; } svg:not(:root) { overflow: hidden; } figure { margin: 1em 40px; }  hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; } pre { overflow: auto; } code, kbd, pre, samp { font-family: monospace, monospace; font-size: 1em; } button, input, optgroup, select, textarea { color: inherit; font: inherit; margin: 0; } button { overflow: visible; } button, select { text-transform: none; } button, html input[type="button"], input[type="reset"], input[type="submit"] { -webkit-appearance: button; cursor: pointer; } button[disabled], html input[disabled] { cursor: default; } button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } input { line-height: normal; } input[type="checkbox"], input[type="radio"] { box-sizing: border-box; padding: 0; } input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { height: auto; } input[type="search"] { -webkit-appearance: textfield; -moz-box-sizing: content-box; -webkit-box-sizing: content-box; box-sizing: content-box; } input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }   fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } legend { border: 0; / padding: 0; } textarea { overflow: auto; } optgroup { font-weight: bold; } table { border-collapse: collapse; border-spacing: 0; }  td, th { padding: 0; }
/* =====================================
end RESET CSS_960_Plugin
===================================== */
';
	}
	
	//-------------------------------------------------
	// TEXT CSS 
	
	if ($css_all||$css_text)
	{
	$CSS960_OUTPUT .= "
/* =====================================
start TEXT CSS_960_Plugin
===================================== */	
/*  960 Grid System ~ Text CSS.
----------------------------------------------------------------------------------------------------*/
body{font:13px/1.5 'Helvetica Neue',Arial,'Liberation Sans',FreeSans,sans-serif}pre,code{font-family:'DejaVu Sans Mono',Menlo,Consolas,monospace}hr{border:0 solid #ccc;border-top-width:1px;clear:both;height:0}h1{font-size:25px}h2{font-size:23px}h3{font-size:21px}h4{font-size:19px}h5{font-size:17px}h6{font-size:15px}ol{list-style:decimal}ul{list-style:disc}li{margin-left:30px}p,dl,hr,h1,h2,h3,h4,h5,h6,ol,ul,pre,table,address,fieldset,figure{margin-bottom:20px}
/* =====================================
end TEXT CSS_960_Plugin
===================================== */
";
	}
	
	//-------------------------------------------------
	// MAIN GRID CSS 

	if ($css_all||$css_grid)
	{
	$CSS960_OUTPUT .= " 

/* =====================================
start MAIN GRID CSS_960_Plugin
===================================== */
/*----------  the wraping container ----------*/

$output_container
$output_grid 
$output_push_pull

/* alpha and omega classes remove margins, aplha = no margin left, omega = no margin right */
.alpha { margin-left: 0 }
.omega { margin-right: 0 }

$ouput_grid_width
$ouput_grid_prefix
$ouput_grid_suffix
$ouput_grid_push
$ouput_grid_pull

/*---------- Clear Floated Elements ----------*/

/* http://sonspring.com/journal/clearing-floats */

.clear {
  clear: both;
  display: block;
  overflow: hidden;
  visibility: hidden;
  width: 0;
  height: 0;
}

/* http://www.yuiblog.com/blog/2010/09/27/clearfix-reloaded-overflowhidden-demystified */

.clearfix:before,
.clearfix:after,
$container_IDs_before,
$container_IDs_after
 {
  content: '.';
  display: block;
  overflow: hidden;
  visibility: hidden;
  font-size: 0;
  line-height: 0;
  width: 0;
  height: 0;
}

.clearfix:after,
$container_IDs_after {
  clear: both;
}
/* =====================================
end MAIN GRID CSS_960_Plugin
===================================== */
";
	}
	
	//-------------------------------------------------	
	// HACK CSS

	if ($css_hack)
	{
	$CSS960_OUTPUT .= " 
/* =====================================
start HACK CSS_960_Plugin 
===================================== */
/*
The following zoom:1 rule is specifically for IE6 + IE7.
Move to separate stylesheet if invalid CSS is a problem.
*/
.clearfix, $container_IDs_fixe {  zoom: 1;};
/* =====================================
end HACK CSS_960_Plugin  
===================================== */
";
	}

	//-------------------------------------------------	
	// HANDHELD CSS
	
	if ($css_handheld_1)
	{
	$CSS960_OUTPUT .= " 
/* =====================================
start HANDHELD v1 CSS_960_Plugin  (from AVIAPIC)
===================================== */
$handheld_aviapic_css
/* =====================================
end HANDHELD v1 CSS_960_Plugin
===================================== */
";
	}	
	
	if ($css_all||$Ccss_handheld_2)
	{
	$CSS960_OUTPUT .= " 
/* =====================================
start HANDHELD v2 CSS_960_Plugin  (from Goran Ilic admin css)
===================================== */
/*---------- Tablet (Portrait) ----------*/
@media only screen and (min-width: 768px) and (max-width: 1024px) and (orientation : portrait) {
    $container_IDs {
        width: 92%;
        min-width: 768px;
        max-width: 1024px
    } 
}

/*---------- Smartphones (Portait) ----------*/
@media only screen and (max-width: 320px) {
    $container_IDs {
        width: 92%;
        min-width: 300px;
        max-width: 320px
    } 
$container_grid_IDs { 
        width: 98%;  
        margin: 0 1%;
        float: none
    }
}

/*---------- Smartphones (Landscape) ----------*/
@media only screen and (min-width: 321px) and (max-width: 767px) {
    $container_IDs {
        width: 92%;
        min-width: 321px;
        max-width: 767px
    } 
$container_grid_IDs { 
        width: 98%;
        margin: 0 1%;
        display: block;
        float: none
    }    
}

/*---------- Smartphones (Portrait & Landscape) ----------*/
@media only screen and (min-width: 300px) and (max-width: 767px) {
$container_prefix_IDs ,
$container_suffix_IDs { 
        padding-right: 0;
        padding-left: 0
    } 
$container_push_IDs ,
$container_pull_IDs {
        left: auto;
        right: auto
    }
}
/* =====================================
end HANDHELD v2 CSS_960_Plugin
===================================== */
";
	}
	
	//-------------------------------------------------	
	// PRINT CSS

	if ($css_all||$css_print) 
	{
	$CSS960_OUTPUT .= " 
/* =====================================
start PRINT CSS_960_Plugin
===================================== */
@media only print {

/* reset body background and color, just in case */
body { background: white;
    color: black;
    font-family: Georgia, Times New Roman, serif;
    font-size: 12pt;
}
/* any element with class noprint or listed below should not be printed */
.no_print { display: none;}
/* display image as block */
img {display: block; float: none;}
/* remove width and floats from elements */
$container_IDs , $container_grid_IDs {
    width: 100%;
    margin: 0;
    float: none    
}
/* links arent clickable on paper, lets display url */
a:link:after {
    content: ' (' attr(href) ') ';
}
a {
    text-decoration: underline
}

}
/* =====================================
end PRINT CSS_960_Plugin
===================================== */
";
	
	}
	
	#---------------------------------------------------------------------------	
	# ASSIGN CMSMS
	#---------------------------------------------------------------------------
	if( isset($params['assign']) )
    {
      $smarty = $template->smarty;
	  $smarty->assign($params['assign'],$CSS960_OUTPUT);
      return;
    }	
	return $CSS960_OUTPUT;

	}//end CSS OUPUT 
	
	
	//TODO auto refresh CMSMS StyleSheet width assign if a parameter have been changed

}//end MAIN function

/**********************************************************
	Help functions
**********************************************************/

function smarty_cms_help_function_css_960_grid() {
?>
<h3>What does this do?</h3>
<p>Generate a GRID CSS Framework base on <a href="http://960.gs/" target="_blank">960 GRID SYSTEM</a>, see examples here : <a href="http://960.gs/demo.html" target="_blank">12 and 16 columns 960 GRID DEMO</a></p>
<h3>How do I use it?</h3>
<p>Just insert the tag <code><strong>{css_960_grid}</strong> in your stylesheet, </code><br />
</p>
<p>or assign it in a template or a page <code><strong>{css_960_grid assign=var_name}</strong></code> and use it on desired stylesheet [[$var_name]]</p>
<p> Then construct your grid template using appropriate class. Look at the links above to see how works this grid framework.<br/>
&lt;div class="container_12"&gt;
<br />&lt;div class="grid_6"&gt;...&lt;/div&gt; &lt;div class="grid_6"&gt;...&lt;/div&gt;
<br />&lt;div class="grid_4"&gt;...&lt;/div&gt; &lt;div class="grid_4"&gt;...&lt;/div&gt; &lt;div class="grid_4"&gt;...&lt;/div&gt;
<br />&lt;div class="grid_3"&gt;...&lt;/div&gt; &lt;div class="grid_7"&gt;...&lt;/div&gt; &lt;div class="grid_2"&gt;...&lt;/div&gt;
<br />&lt;/div&gt;
</p>
<h3><strong>Type fluid or fixe : type =</strong></h3>
<p>You can choose between two types of grid : "fluid" or "fixe" </p>
<p><strong>Type fluid (default)</strong></p>
<p><code><strong>{css_960_grid type="fluid" columns=12 align=center css=&quot;grid&quot;}</strong></code>- shortcut : <code><strong>{css_960_grid}</strong></code> : <br />
    Generate a centered grid template having 92% wide divided in 12 columns. <br />
    Each column has 2%  of margin on the left and right, which create 4% wide gutters between columns.<br />
    <br />
    Needed parameters : columns (default 12)<br />
    <br />
</p>
<p><strong>Type fixe</strong></p>
<p><code><strong>{css_960_grid type="fixe" columns=12 width=960 gutter=20 align=center css=&quot;grid&quot;}</strong></code>- shortcut : <code><strong>{css_960_grid type=&quot;fixe&quot;}</strong></code> : <br />
    Generate a centered grid template having 960 pixels wide divided in 12 columns. <br />
    Each column has 10 pixels of margin on the left and right, which create 20 pixels wide gutters between columns.<br />
    <br />
    Needed parameters : columns (default 12), width (default 960), gutter (default 20)<br />
    <br />
    With parameter type=&quot;fixe&quot;, you aren't limited to only use 960  and you can use others values define by &quot;width&quot; parameter, but make sure that given parameters &quot;width&quot; divided by each &quot;columns&quot; values: result an integer.<br />
    example : <code><strong>{css_960_grid type="fixe" columns=16 width=1024}</strong></code><br/>
</p>
<h3>Multi grids : columns="12,16,24"</h3>
<p>Columns parameter accept integer as single value. <code><strong>{css_960_grid columns=12}</strong></code><br />
    You can also define multiple columns in one way in order to use severals grids system in same template.<br />
    In this case, columns parameter accept only string as multiple values separated by comma.<br/>
    <code><strong>{css_960_grid columns="12,16"}</strong></code> <br/>
	<code><strong>{css_960_grid columns="12,16,24"}</strong></code> but you can do same and reduce css lines code with 	<code><strong>{css_960_grid columns=48}</strong></code> <br/>
</p>
<h3><strong>Manage css output : css=</strong></h3>
<p> By default this plugin only output  grid css (css=&quot;grid&quot;).<br/>
    You can generate all css output  using <code><strong>{css_960_grid css=&quot;all&quot;}</strong></code> , return these css in this order : reset, text, grid, handheld_2, print.<br/>
    <br/>
    You can split css in order to include each one into specific stylesheet : <code><strong>{css_960_grid css=&quot;print&quot;}</strong></code><code><strong> {css_960_grid css=&quot;reset&quot;}</strong></code><br/>
</p>
<h3> <strong>which CSS select</strong></h3>
<p><strong>reset css</strong> : <br /></p>
<p>Reset css is a stylesheet is to reduce browser inconsistencies : <a href="https://github.com/necolas/normalize.css" target="_blank">https://github.com/necolas/normalize.css</a> <br /> <br /></p>
<p><strong>text css</strong> : <br /></p>
<p>Text css is stylesheet pre-formated. <br /> <br /></p>
<p><strong>grid css</strong> : <br /></p>
<p>Grid css is a stylesheet auto generated for grid template : <a href="http://960.gs/" target="_blank">960 GRID SYSTEM</a> <br /> <br /></p>
<p><strong>handheld css</strong> : <br /></p>
<p>handheld_css1 is a responsive css based on device screen target and this parameter need device-width targeted screen values: <br />
    It need &quot;handheld_devices&quot; parameter which is device-width targets.<br />
    It need columns parameter or use 12 columns by default<br/>
    <code><strong>example for width=960: {css_960_grid css=handheld_1 handheld_devices='959,854,800,768,720,600,540,480,320,240'}</strong></code> <br/>
    if you set "width_min" parameter, the generated ouput css will only include <code><strong>&quot;handheld_devices&quot; </strong></code>widths that are smaller than &quot;min_width&quot;. <br />
    It have class .no_handheld{display:none;} and for each values define in handheld_devices parameter ex: .no_handheld_480{display:none;} <br/><br/>
	You can linearize a floated grid using .linearize : ex in template &lt;div class="grid_4  linearize"&gt;...&lt;/div&gt;<br/>
	or linearize severals grids in one container : ex in template &lt;div class="container_12 linearize"&gt;&lt;div class="grid_6"&gt;...&lt;/div&gt;&lt;div class="grid_6"&gt;...&lt;/div&gt;&lt;/div&gt;
	<br/><br/>
</p>
To use it, you need to insert this meta viewport in your template into head part.:<br/>
<p style="font-weight:bolder; color:#f00;">&lt;meta name="viewport" content="width=device-width, initial-scale=1,target-densitydpi=device-dpi"&gt;</p>
<p><br/>
    handheld_css2 (true/false) is a responsive css for grid system from demo SIMPLEX template created by Goran ILIC.<br />
    It need columns parameter or use 12 columns by default<br />
    It have class .no_handheld{display:none;}<br/>
    <code><strong>example : {css_960_grid css=handheld_2}</strong></code><br/>
</p>
<p>Naturally width min is not include in handheld css code<br/>
    Both handheld css have class .no_handheld{display:none;} <br /> <br /></p>
<p><strong>print css</strong> : <br /></p>
<p>Print css is stylesheet print-friendly.<br />
    It have class .no_print{display:none;}</p>
<h3><strong>Test it before use it</strong></h3>
<p> To prevent misundertanding, you can test the plugin in your template or a page and set parameter check=true<br/>
    <code><strong>{css_960_grid check=true type='fixe' columns=12 width=960 gutter=20}</strong></code> in your template or a page, return all parameters or return detailed errors.<br/>
    <br/>
    <code><strong>{css_960_grid type='fixe' columns=12 width=960 gutter=20}</strong></code> in your template or a page, show the &quot;css code&quot; which would be produced if you had inserted  this tag in a stylesheet or a simple &quot;errors warning&quot; between /* */ to prevent  breaking your style sheet code.<br/>
</p>
<h3>What parameters does it take?</h3>
<p>GRID
<ul>
    <li><strong>type</strong>  (string "fixe" or "fluid") (default: "fluid" ) - Generate Fluid or fixe GRID CSS.</li>
    <li><strong>align</strong>  (string "center" or "left" or "right") (default: "center" ) - define template alignment.</li>
    <li> <strong>columns</strong>  - (string or integer) (default: 12 ) define numbers of columns. <br/>
        single value : columns=12 or multiple values separated with comma ex: columns="12,16"</li>
    <li><strong>width</strong>  (integer) (default: 960 ) - define container template width.</li>
    <li><strong>gutter</strong>  (integer) (default: 20 ) - define gutter width.</li>
</ul>
OUPUT CSS
<ul>
    <li><strong>css</strong>  (string) (default: &quot;grid&quot; ) - select output CSS reset text grid handheld_1 handheld_2 hack print</li>
   <li><strong>handheld_devices</strong>  (integer or string with comma) (default: not set ) - device-width targets ot use width handheld_1 </li>  
  <li><strong>assign</strong>  Assigns the content to a smarty parameter. Warning, you need to refresh cache stylesheet if you change a parameter value </li>
</ul>
Options
<ul>
    <li><strong> align</strong> = [ left / center / right ] (default: center) Allow to define which alignment apply for the template.</li>
    <li><strong> width_min </strong>= [ integer ] (default: not set) Allow to define template min width.</li>
    <li><strong>width_max </strong>= [ integer ] (default: not set) Allow to define template max width.</li>
    <li><strong> check </strong>= [ boolean ] (default: false) : Ouput parameters values or errors if exist.  Do not set TRUE in a stylesheet. but only in a template or page.</li>
</ul>
</p>
<h3>Exemples</h3>
<p><strong>GRID - 12 columns : </strong></p>
<p>{css_960_grid type="fluid" align="center" columns=12 css=grid} shortcut {css_960_grid}<br/>
    <br/>
</p>
<p><strong>fixe 960 GRID - 12 columns, gutter 20 : </strong></p>
<p>{css_960_grid type="fixe" align="center" columns=12 width=960  gutter=20 css=grid} shortcut {css_960_grid type="fixe"}<br/>
    <br/>
</p>
<p><strong>fixe 960 GRID - 12 14 16 columns, gutter 10 : </strong></p>
<p>{css_960_grid type="fixe" align="center" columns='12,16,24' width=960 gutter=10 css=grid} shortcut {css_960_grid type="fixe" columns='12,16,24'}<br/>
    <br/>
</p>
<p><strong>fixe 1024 GRID - 8 16 columns, gutter 10 :</strong></p>
<p>{css_960_grid type="fixe" columns="8,16" width=1024 gutter=10}<br/>
    <br/>
</p>
<p><strong>fluid GRID - 8 16 columns + width template min 960 max 1024: + reset css</strong></p>
<p>{css_960_grid type="fluid" columns="8,16" width_max=1024 width_min=960 css="grid,reset"}<br/>
    <br/>
</p>
<p><strong>fixe 1024 GRID - 8 16 columns gutter 10,  min width 960 , splited  css reset / css grid + css_print /  css handheld_1 for 480 320 240 scrren</strong></p>
<p>{css_960_grid css=reset} : tag include in a reset stylesheet<br/>
    {css_960_grid type='fixe' columns="8,16" width=1024 gutter=10 width_min=960 css="grid,print"} : tag include in first place in main stylesheet<br/>
    {css_960_grid  columns="8,16" css="handheld_1" handheld_devices='480,320,240' assign='mobile-css'} : tag include in template and call from specific stylesheet width [[$mobile-css]]<br/>
    don't forget to include specific viewport for handheld_1 css </p>
<?php
} // end HELP function

/**********************************************************
	ABOUT functions
**********************************************************/

function smarty_cms_about_function_css_960_grid() {
?>
<p>Author: Philippe THOMAS &lt;<a href="mailto:devteam@aviapic.com">devteam@aviapic.com</a>&gt;<br>
plugin based on 960 GRID SYSTEM + Goran Ilic CSS: <a href="http://960.gs/">http://960.gs/</a>
</p>
<p>Version: 3.0.1</p>
<p>Change History:<br /><br /></p>
<p>1.0.0 - Initial version released.<br /><br /></p>
<p>1.1.0 - Add parameters : mobile, print, css_hack, hack_only.<br />
next release will add parameters : mobile_only, print_only<br /><br /></p>
<p>2.0.0 - Check parameters and validation for outputed css<br />
Display warnings if parameter check is true and errors exists<br />
Add parameters : mobile_only, print_only<br />
</p>
<p>2.0.1 - Bug fixs for Fluid css values <br /><br />

<p>3.0.1 - new tag and update reset css <br />
<p>3.0.2 - fixe replace bad values with comma for  fluid grid css <br />
add class .linearize extend responsive output for css_handheld_1 
</p>
<?php
} // end ABOUT function
?>