Location: PHPKode > projects > OpenWolf Guidelines Validator > openWolf 0.9.9/css_functions.php
<?php

/*************************************************

openWolf - an HTML accessibility guidelines validator
Author: Geoff Munn (hide@address.com)
Version: 0.9.9

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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

You may contact the author of openWolf by e-mail at: hide@address.com

The latest version of openWolf can be obtained from:
http://openwolf.sourceforge.net/

*************************************************/

function load_shorthands(){
	
	$shorthands=Array();
	
	$shorthands['font-style']['normal']='normal';
	$shorthands['font-style']['inherit']='inherit';
	$shorthands['font-style']['italic']='italic';
	$shorthands['font-style']['oblique']='oblique';
	
	$shorthands['font-variant']['inherit']='inherit';
	$shorthands['font-variant']['normal']='normal';
	$shorthands['font-variant']['small-caps']='small-caps';
	
	$shorthands['font-weight']['inherit']='inherit';
	$shorthands['font-weight']['100']='100';
	$shorthands['font-weight']['200']='200';
	$shorthands['font-weight']['200']='300';
	$shorthands['font-weight']['200']='400';
	$shorthands['font-weight']['200']='500';
	$shorthands['font-weight']['200']='600';
	$shorthands['font-weight']['200']='700';
	$shorthands['font-weight']['200']='800';
	$shorthands['font-weight']['200']='900';
	$shorthands['font-weight']['normal']='normal';
	$shorthands['font-weight']['bold']='bold';
	$shorthands['font-weight']['lighter']='lighter';
	$shorthands['font-weight']['bolder']='bolder';
	
	$shorthands['font-size']['inherit']='inherit';
	$shorthands['font-size']['xx-small']='xx-small';
	$shorthands['font-size']['x-small']='x-small';
	$shorthands['font-size']['small']='small';
	$shorthands['font-size']['medium']='medium';
	$shorthands['font-size']['large']='large';
	$shorthands['font-size']['x-large']='x-large';
	$shorthands['font-size']['xx-large']='xx-large';
	$shorthands['font-size']['smaller']='smaller';
	$shorthands['font-size']['larger']='larger';
	
	$shorthands['line-height']['inherit']='inherit';
	$shorthands['line-height']['normal']='normal';
	
	$shorthands['font-family']['inherit']='inherit';
	$shorthands['font-family']['serif']='serif';
	$shorthands['font-family']['sans-serif']='sans-serif';
	$shorthands['font-family']['cursive']='cursive';
	$shorthands['font-family']['fantasy']='fantasy';
	$shorthands['font-family']['monospace']='monospace';
	
	$shorthands['background-color']['inherit']='inherit';
	$shorthands['background-color']['transparent']='transparent';
	
	$shorthands['background-image']['inherit']='inherit';
	$shorthands['background-image']['none']='none';
	
	$shorthands['background-repeat']['inherit']='inherit';
	$shorthands['background-repeat']['repeat']='repeat';
	$shorthands['background-repeat']['repeat-x']='repeat-x';
	$shorthands['background-repeat']['repeat-y']='repeat-y';
	$shorthands['background-repeat']['no-repeat']='no-repeat';
	
	$shorthands['background-attachment']['inherit']='inherit';
	$shorthands['background-attachment']['scroll']='scroll';
	$shorthands['background-attachment']['fixed']='fixed';
	
	$shorthands['background-position']['inherit']='inherit';
	$shorthands['background-position']['left']='left';
	$shorthands['background-position']['center']='center';
	$shorthands['background-position']['right']='right';
	$shorthands['background-position']['top']='top';
	$shorthands['background-position']['center']='center';
	$shorthands['background-position']['bottom']='bottom';
	
	$shorthands['list-style-type']['inherit']='inherit';
	$shorthands['list-style-type']['none']='none';
	$shorthands['list-style-type']['disc']='disc';
	$shorthands['list-style-type']['circle']='circle';
	$shorthands['list-style-type']['square']='square';
	$shorthands['list-style-type']['decimal']='decimal';
	$shorthands['list-style-type']['decimal-leading-zero']='decimal-leading-zero';
	$shorthands['list-style-type']['lower-roman']='lower-roman';
	$shorthands['list-style-type']['upper-roman']='upper-roman';
	$shorthands['list-style-type']['lower-alpha']='lower-alpha';
	$shorthands['list-style-type']['upper-alpha']='upper-alpha';
	$shorthands['list-style-type']['lower-greek']='lower-greek';
	$shorthands['list-style-type']['lower-latin']='lower-latin';
	$shorthands['list-style-type']['upper-latin']='upper-latin';
	$shorthands['list-style-type']['armenian']='armenian';
	$shorthands['list-style-type']['georgian']='georgian';
	$shorthands['list-style-type']['hebrew']='hebrew';
	$shorthands['list-style-type']['cjk-ideographic']='cjk-ideographic';
	$shorthands['list-style-type']['hiragana']='hiragana';
	$shorthands['list-style-type']['katakana']='katakana';
	$shorthands['list-style-type']['hiragana-iroha']='hiragana-iroha';
	$shorthands['list-style-type']['katakana-iroha']='katakana-iroha';
	
	$shorthands['list-style-position']['inherit']='inherit';
	$shorthands['list-style-position']['outside']='outside';
	$shorthands['list-style-position']['inside']='inside';
	
	$shorthands['list-style-image']['inherit']='inherit';
	$shorthands['list-style-image']['none']='none';
	
	$shorthands['border-width']['inherit']='inherit';
	$shorthands['border-width']['thin']='thin';
	$shorthands['border-width']['medium']='medium';
	$shorthands['border-width']['thick']='thick';
	
	$shorthands['border-style']['inherit']='inherit';
	$shorthands['border-style']['none']='none';
	$shorthands['border-style']['hidden']='hidden';
	$shorthands['border-style']['dotted']='dotted';
	$shorthands['border-style']['dashed']='dashed';
	$shorthands['border-style']['solid']='solid';
	$shorthands['border-style']['groove']='groove';
	$shorthands['border-style']['ridge']='ridge';
	$shorthands['border-style']['inset']='inset';
	$shorthands['border-style']['outset']='outset';
	$shorthands['border-style']['double']='double';
	
	$shorthands['border-color']['inherit']='inherit';
	$shorthands['border-color']['transparent']='transparent';

	return $shorthands;
}
function get_css(&$_styles, $stylesheet, $default_media='', $is_inline=false, $inline_selector='', $location='', $cache_files=false, $imported_stylesheets=Array()){

	//Here we take a stylesheet' contents and split the styles into
	//selectors
	//styles
	//and values.

	//go through all the imported styles to see if this is already present...
	if(!$is_inline){
		if(is_array($imported_stylesheets)){
			foreach($imported_stylesheets as $key=>$this_stylesheet){
				if($key==$location){
					//echo '<strong>we are returning the imported CSS ' . $key . '</strong><br>';
					//append this stylesheet to the $_styles array:
					//$_styles=array_merge($_styles, $this_stylesheet);
					//$styles=$this_stylesheet['styles'];
					//$selectors=$this_stylesheet['selectors'];
					$_styles[]=$this_stylesheet;
					
					//return the number of this stylesheet:
					return $this_stylesheet;
				}
			}
		}
		//echo '<em>there is no record of  ' . $location . '</em><br>';
	}
	$styles=Array();
	//we will make the shorthands array a static to improve the flow a bit....
	static $shorthands=null;
	//If it is a shortcut style, we create long-hand values for the shortcut
	//This array contains a complete list of every short hand style and possible values
	if(is_null($shorthands))
		$shorthands=load_shorthands();
		
	//first things first, remove any comments from the stylesheet
	//remove anything between /* and */
	$stylesheet=strip_comments($stylesheet, false);
	
	//ok so now we have a stylesheet minus any comments
	//go through it all and get each selector and its contents

	$selector='';
	$stylesText='';
	$temp=Array();
	$media=Array();
	$hasMedia=false;
	$count=0;
	$selector_index=0;
	$stylesheet_count=sizeof($_styles);
	
	$applied_stylesheets=Array($stylesheet_count);
	
	//The default media variable is an array because multiple media can be specified
	if($default_media==''){
		$default_media=Array();
		$default_media[0]='all';
	} 
	$media=$default_media;
	
	//for parsing reasons, we need to wrap curly brackets around the style
	//(only necessary for inline styles)
	if($is_inline)
		$stylesheet=$inline_selector . ' {' . $stylesheet . '}';
	
	$css_length=strlen($stylesheet);
	for($i=0; $i<$css_length; $i++){
		//take each character and append it to $selector until a '{' character is found
		$char=substr($stylesheet, $i, 1);
		if($char!='\\'){
			
			//If this is the end of a @media declaration block, we want to revert back to the standard media rules (contained in $default_media)
			if($char=='}' && $hasMedia==true){
				$hasMedia=false;
				$media=$default_media;
				$char='';
			}
			
			//at-rules can cause problems.  This usually means that there is an import contained here
			if($char=='@'){
				//$isAtRule=true;
				//Possibilities:
				//@charset
				//@import
				//@media
				//@namespace
				//@page
				//@fontdef
				//@fontface
				$atRule='';
				for($j=$i+1; $j<$css_length; $j++){
					$char2=substr($stylesheet, $j, 1);
					//a bracket or space or tab indicates the end of the at-rule (should we include line breaks?)
					if($char2==' ' || $char2=='(' || ord($char2)==9)
						break;
					
					$atRule.=$char2;
				}
				
				//so now we have an @ selector:
				$property='';
				$hasMedia=false;
				$page=false;
				$fontFace=false;
				
				$filter=Array("\"", "'", ')', 'url', '(');

				switch(strtolower($atRule)){
					case 'charset':
						//Example: @charset "Shift-JIS";
						//go through to the next semi-colon:
						//the entire string will be the value
						for($j=$j+1; $j<$css_length; $j++){
							$char2=substr($stylesheet, $j, 1);
							if($char2==';')
								break;
							
							$property.=$char2;
						}
						//so now we have the $charset value:
						//replace any quote marks (for consistency's sake)
						$charset=trim(str_replace(Array("\"", "'"), '', $property));
						
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['selector']='@charset';
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['property']='@charset';
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['charset']=$charset;
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['media']=$media;
						$_styles[$stylesheet_count]['styles'][$selector_index]['selector']='@charset';
						
						$selector_index++;
						break;
					case 'import':
						//Examples: @import url("foo.css") screen, print;
						//			@import url("foo.css");
						//			@import "foo.css" screen, print;
						//go through to the next semi-colon:
						//the entire string will be the value
						for($j=$j+1; $j<$css_length; $j++){
							$char2=substr($stylesheet, $j, 1);
							if($char2==';')
								break;
							
							$property.=$char2;
						}
						
						$import_bits=explode(' ', trim($property));
						if(count($import_bits)>0){
							//clean up the first bit for consistency
							$import_bits[0]=str_replace($filter, '', $import_bits[0]);
								
							$_styles[$stylesheet_count]['styles'][$selector_index][0]['selector']='@import';
				 			$_styles[$stylesheet_count]['styles'][$selector_index][0]['property']='@import';
				 			$_styles[$stylesheet_count]['styles'][$selector_index][0]['url']=$import_bits[0];
				 			
							for($k=1;$k<count($import_bits);$k++)
								$_styles[$stylesheet_count]['styles'][$selector_index][0]['media'][]=trim($import_bits[$k], ',');
							
							if(count(@$styles[$selector_index][0]['media'])==0)
								$_styles[$stylesheet_count]['styles'][$selector_index][0]['media']=$media;
							
							$_styles[$stylesheet_count]['styles'][$selector_index]['selector']='@import';
						}
						$selector_index++;
						
						//ok, we need to go and get this imported stylesheet. There will be some recursion here...
						$protocol=get_protocol($import_bits[0]);
						if($protocol!='http' && $protocol!='https')
							$import_location=make_abs($import_bits[0], $location);
						else $import_location=$import_bits[0];
						
						$headers=fetch_file($import_location, $cache_files);
						
						if(is_response_good($headers, 'text/css')){
							$contents=$headers['contents'];
							$new_applied_stylesheets=get_css($_styles, $contents, $media, $is_inline, $inline_selector, $import_location, $cache_files, $imported_stylesheets);
							foreach($new_applied_stylesheets as $this_applied_stylesheet)
								$applied_stylesheets[]=$this_applied_stylesheet;
						}
						break;
					case 'media':
						//This media rule will probably contain a descriptor block, so we need to get everything to the { character
						/*Example:
						@media screen { 
							body {
								color: green; 
								background-color: yellow 
								}
							}
							*/
						
						for($j=$j+1; $j<$css_length; $j++){
							$char2=substr($stylesheet, $j, 1);
							
							if($char2=='{')
								break;
								
							$property.=$char2;
						}
						$media=Array();
						
						$bits=explode(',', trim($property));
						//Don't use $j here because we need it to update the $i counter later on
						for($k=0;$k<count($bits);$k++)
							$media[]=trim($bits[$k]);
											
						if(count($media)>0)
							$hasMedia=true;
						
						break;
					case 'namespace':
						//See http://www.blooberry.com/indexdot/css/syntax/atrules/namespace.htm for how this can be used
						//The namespace rule may look like this:
						//@namespace foo url("http://www.example.com/");
						// - or -
						//@namespace url("http://www.example.com/");
						
						//go through to the next semi-colon:
						//the entire string will be the value
						for($j=$j+1; $j<$css_length; $j++){
							$char2=substr($stylesheet, $j, 1);
							if($char2==';')
								break;
							
							$property.=$char2;
						}
						
						$namespace_bits=explode(' ', trim($property));
						
						$namespace_count=count(@$styles['namespace'])-1;
						if($namespace_count==-1)
							$namespace_count=0;
							
						if(count($namespace_bits)>0){
							$styles['namespace']['selector']='@namespace';
							switch (count($namespace_bits)){
								case 1:
									$namespace_bits[0]=str_replace($filter, '', $namespace_bits[0]);
									$_styles[$stylesheet_count]['styles']['namespace'][$namespace_count]['url']=$namespace_bits[0];
									
									break;
								case 2:	
									$namespace_bits[1]=str_replace($filter, '', $namespace_bits[1]);
									$_styles[$stylesheet_count]['styles']['namespace'][$namespace_count]['prefix']=$namespace_bits[0];
									$_styles[$stylesheet_count]['styles']['namespace'][$namespace_count]['url']=$namespace_bits[1];
									
									break;
							}
						}
						break;
						
					case 'page':
						//Example:	@page thin:first { size: 3in 8in }
						//			@page { size: 3in 8in }
						//This rule is quite different.  Here we carry on and let the the @page rule get picked up as a normal selector.
						//However, the first example will be parsed incorrectly in the selector array (a known bug, I'm not sure how best to handle this)
						//BUG: this will only let one such rule be included, since any following @page rules will overwrite the previous one.
						$page=true;
						break;
					case 'fontdef':
						//Example:	@fontdef url("http://www.example.com/sample.pfr");
						//go through to the next semi-colon:
						//the entire string will be the value
						for($j=$j+1; $j<$css_length; $j++){
							$char2=substr($stylesheet, $j, 1);
							if($char2==';')
								break;
							
							$property.=$char2;
						}
						
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['selector']='@fontdef';
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['property']='@fontdef';
						$_styles[$stylesheet_count]['styles'][$selector_index][0]['url']=$property;
						$_styles[$stylesheet_count]['styles'][$selector_index]['selector']='@fontdef';
						
						$selector_index++;
						break;
					case 'font-face':
						/*Example:
						@font-face {
					     font-family: dreamy;
					     font-weight: bold;
					     src: url(http://www.example.com/font.eot);
					     }
						*/
						//Just like the @page rule, we carry on and let the parser pick this up...
						//BUG: this will only let one such rule be included, since any following @font-face rules will overwrite the previous one.
						$fontFace=true;
						break;
						
					default:
						//ok, so it's something else.  In this case we shall ignore it altogether and move on.
						//This could cause problems for some kind of unidentified enclosing @selector (like @namespace {....} for instance)
						for($j=$j+1; $j<$css_length; $j++){
							$char2=substr($stylesheet, $j, 1);
							if($char2==';')
								break;
							
					}
													
				}
				
				//These two @at-rules are exceptions... we want the parser to pick them up
				if(!$fontFace && !$page){
					$i=$j;
					//clear this character so that it wont confuse the next bit
					$char='';
				}
				
			}
			
			if($char=='{'){
				$selector=trim($selector);
				$isAtRule=false;
				//so now we have a style(s)
				for($j=$i+1; $j<$css_length; $j++){
					$char2=substr($stylesheet, $j, 1);
					if($char2!='\\'){
						if($char2=='}'){
							//Here we have a complete set of styles for this selector
							//Split this into each style
							//Note: if a style did not end in a semi-colon (ie, is a mistake), then the following
							//styles will be appended to it - resulting in an inaccessible style
							
							//we shall create a temp version of this style to test to see if it's empty
							//NOTE: empty styles (eg, body {}) will NOT BE entered into the array (this is by design).
							//Could this cause problems?
							$stylesText_temp=trim(str_replace(Array('/n', '/t'), '', $stylesText));
							if($stylesText_temp!=''){
								$temp=split(';', $stylesText);
								foreach($temp as $this_property){
									if(trim($this_property)!=''){
										//We need to replace colons with a caret so they do not get picked up later on
										//NOTE: this needs to be fixed for https:// instances
										$this_property=str_replace('http://', 'http^//', $this_property);
										$temp2=split(':', $this_property);
										//Is this a shortcut?  If so, we need to create the longhand versions
										//get the style name:
										for($i=0; $i<sizeof($temp2); $i++)
											$temp2[$i]=trim($temp2[$i]);
										
										if(sizeof($temp2)>2){
											//combine all the remaining bits. CSS expressions use the colon.
											$remaining=$temp2;
											$temp2[1]=trim(implode(':', $remaining));
											//$temp2[1]=trim($temp2[1]);
										}
										//else 
										//	$temp2[1]='';	
										
										$isShorthand=false;
										//shorthand properties are font, border, border-width, border-color, border-style
										//background, margin, padding
										$this_property=str_replace('^', ':', $this_property);
										//is this necessary?...
										$temp2[0]=str_replace('^', ':', $temp2[0]);
										$temp2[1]=str_replace('^', ':', $temp2[1]);
										
										if(substr(strtolower($temp2[1]),-10)=='!important'){
											$temp2[1]=str_replace(' !important', '', strtolower($temp2[1]));
											$isImportant=true;
										} else 
											$isImportant=false;
										
										//use these names so things are clearer...
										$property_name=strtolower($temp2[0]);
										$property_value=strtolower($temp2[1]);
										
										//so now we have a complete property name/value combination
										if($property_name=='font'){
											//this is a font shorthand property...
											//we need to split it into the various bits
											
											$fontStyle=str_replace(',', ' ', $property_value);
											$fontStyle=str_replace('\'', "\"", $fontStyle);
											//we need to temporarily replace 
											$quotePos=strpos($fontStyle, "\"");
											
											if(strpos($fontStyle, "\"")!=''){
												//replace all spaces between quotes with tilders ~
												for($k=$quotePos+1;$k<=strlen($fontStyle);$k++){
													$char=substr($fontStyle, $k,1);
													
													if($char==' ')
														$fontStyle=substr_replace($fontStyle, '~', $k,1);
													
													if($char=="\"")
														break;
													
												}
											}
											//remove the speech marks
											$fontStyle=str_replace("\"", '', $fontStyle);
											
											$temp3=split(' ', $fontStyle);
											//These are all the possible values within the 'font' shorthand style:
											$font_bits=Array();
											$font_bits['font-style']='';
											$font_bits['font-variant']='';
											$font_bits['font-weight']='';
											$font_bits['font-size']='';
											$font_bits['line-height']='';
											$font_bits['font-family']='';
											
											foreach($temp3 as $this_value){
												//what is this value?
												//Font shorthand properties can be a combination of:
												//font-style
												//font-variant
												//font-weight
												//font-size
												//line-height
												//font-family
												//We will not check for CSS2 extensions for the font style
												
												//Sizes and lengths must be checked for as well
												
												$this_value=trim($this_value);
												if($this_value!=''){
													//$isMeasurement=is_measurement($this_value);
													
													$found=false;
													//can this value be a font-style?
													if(isset($shorthands['font-style'][$this_value])){
														$font_bits['font-style']=$this_value;
														$found=true;
													}
													if(isset($shorthands['font-variant'][$this_value])){
														$font_bits['font-variant']=$this_value;
														$found=true;
													}
													if(isset($shorthands['font-weight'][$this_value])){
														$font_bits['font-weight']=$this_value;
														$found=true;
													}
													$temp4=explode('/', $this_value);
													if(isset($shorthands['font-size'][$temp4[0]])){
														$font_bits['font-size']=$temp4[0];
														$found=true;
													}
													if(is_measurement($temp4[0])){
														$font_bits['font-size']=$temp4[0];
														$found=true;
													}
													
													if(count($temp4)>1){
														if(isset($shorthands['line-height'][$temp4[1]])){
															$font_bits['line-height']=$temp4[1];
															$found=true;
														}
														if(is_measurement($temp4[1])){
															$font_bits['line-height']=$temp4[1];
															$found=true;
														}
													}
													//This is really the default value... if all else fails, then it is assumed
													//to be a font family.  As a result, some weird crap can end up in here
													if(isset($shorthands['font-family'][$this_value]) || $found==false){
														$this_value=str_replace('~', ' ', $this_value);
														$font_bits['font-family'][]=$this_value;
													}
												}
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='font-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$font_bits['font-style'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='font-variant';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$font_bits['font-variant'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='font-weight';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$font_bits['font-weight'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='font-size';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$font_bits['font-size'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;						
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='line-height';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$font_bits['line-height'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='font-family';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$font_bits['font-family'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
																						
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='font';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;					
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='margin'){
											//Margins and paddings are a bit different...
											//we will not be checking for the type, just putting them in
											//their respective positions and moving on...
											$temp3=explode(' ', $property_value);
											switch (count($temp3)){
												case 0:
													$marginBits[0]='';
													$marginBits[1]='';
													$marginBits[2]='';
													$marginBits[3]='';
													break;
												case 1:
													$marginBits[0]=$temp3[0];
													$marginBits[1]=$temp3[0];
													$marginBits[2]=$temp3[0];
													$marginBits[3]=$temp3[0];
													break;
												case 2:
													$marginBits[0]=$temp3[0];
													$marginBits[1]=$temp3[1];
													$marginBits[2]=$temp3[0];
													$marginBits[3]=$temp3[1];
													break;
												case 3:
													$marginBits[0]=$temp3[0];
													$marginBits[1]=$temp3[1];
													$marginBits[2]=$temp3[2];
													$marginBits[3]=$temp3[1];
													break;
												case 4:
													$marginBits[0]=$temp3[0];
													$marginBits[1]=$temp3[1];
													$marginBits[2]=$temp3[2];
													$marginBits[3]=$temp3[3];
													break;
												default:
													$marginBits[0]=$temp3[0];
													$marginBits[1]=$temp3[1];
													$marginBits[2]=$temp3[2];
													$marginBits[3]=$temp3[3];
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='margin-top';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$marginBits[0];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;					
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='margin-right';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$marginBits[1];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='margin-bottom';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$marginBits[2];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;				
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='margin-left';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$marginBits[3];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='margin';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='padding'){
											//Margins and paddings are a bit different...
											//we will not be checking for the type, just putting them in
											//their respective positions and moving on...
											$temp3=explode(' ', $property_value);
											switch (count($temp3)){
												case 0:
													$paddingBits[0]='';
													$paddingBits[1]='';
													$paddingBits[2]='';
													$paddingBits[3]='';
													break;
												case 1:
													$paddingBits[0]=$temp3[0];
													$paddingBits[1]=$temp3[0];
													$paddingBits[2]=$temp3[0];
													$paddingBits[3]=$temp3[0];
													break;
												case 2:
													$paddingBits[0]=$temp3[0];
													$paddingBits[1]=$temp3[1];
													$paddingBits[2]=$temp3[0];
													$paddingBits[3]=$temp3[1];
													break;
												case 3:
													$paddingBits[0]=$temp3[0];
													$paddingBits[1]=$temp3[1];
													$paddingBits[2]=$temp3[2];
													$paddingBits[3]=$temp3[1];
													break;
												case 4:
													$paddingBits[0]=$temp3[0];
													$paddingBits[1]=$temp3[1];
													$paddingBits[2]=$temp3[2];
													$paddingBits[3]=$temp3[3];
													break;
												default:
													$paddingBits[0]=$temp3[0];
													$paddingBits[1]=$temp3[1];
													$paddingBits[2]=$temp3[2];
													$paddingBits[3]=$temp3[3];
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='padding-top';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$paddingBits[0];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='padding-right';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$paddingBits[1];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='padding-bottom';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$paddingBits[2];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='padding-left';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$paddingBits[3];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='padding';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											$isShorthand=true;
										}
										
										if($property_name=='background'){
											//this is a background shorthand property...
											//we need to split it into the various bits
											
											//RGB fix:
											$temp3=$property_value;
											while(strpos($temp3, '  ')!==false)
												$temp3=str_replace('  ', ' ', $temp3);
											
											$backgroundStyle=str_replace(', ', ',', $temp3);	
											$backgroundStyle=str_replace("\"", "'", $backgroundStyle);
											$quotePos=strpos($backgroundStyle, "'");
											
											if(strpos($backgroundStyle, "\'")!=''){
												//replace all spaces between quotes with tilders ~
												for($k=$quotePos+1;$k<=strlen($backgroundStyle);$k++){
													$char=substr($backgroundStyle, $k,1);
													
													if($char==' ')
														$backgroundStyle=substr_replace($backgroundStyle, '~', $k, 1);
													
													if($char=="\"")
														break;
													
												}
											}
											//remove the speech marks
											$temp3=split(' ', $backgroundStyle);
											$background_bits=Array();
											$background_bits['background-color']='';
											$background_bits['background-image']='';
											$background_bits['background-repeat']='';
											$background_bits['background-attachment']='';
											$background_bits['background-position']='';
													
											foreach($temp3 as $this_value){
												//what is this value?
												//Background shorthand properties can be a combination of:
												//background-color
												//background-image
												//background-repeat
												//background-attachment
												//background-position
												
												//we will check first for background-image
												//then background-repeat
												//then attachment
												//the position
												//anything left over will be a colour
												
												$this_value=trim($this_value);
												$isMeasurement=is_measurement($this_value, true);
												
												$found=false;
												
												if(substr(strtolower($this_value), 0, 4)=='url('){
													$background_bits['background-image']=$this_value;
													$found=true;
												}
												if(isset($shorthands['background-repeat'][$this_value])){
													$background_bits['background-repeat']=$this_value;
													$found=true;
												}
												if(isset($shorthands['background-attachment'][$this_value])){
													$background_bits['background-attachment']=$this_value;
													$found=true;
												}
												if($isMeasurement || isset($shorthands['background-position'][$this_value])){
													$background_bits['background-position'][]=$this_value;
													$found=true;
												}
												if(!$found)
													$background_bits['background-color']=$this_value;
																						
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='background-image';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$background_bits['background-image'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
												
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='background-repeat';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$background_bits['background-repeat'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='background-attachment';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$background_bits['background-attachment'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='background-position';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$background_bits['background-position'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='background-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$background_bits['background-color'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='background';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='list-style'){
											//this is a list shorthand property...
											//we need to split it into the various bits
											//remove all the commas
											
											$listStyle=str_replace(',', ' ', $property_value);
											$listStyle=str_replace("\"", "'", $listStyle);
											//we need to temporarily replace
											$quotePos=strpos($listStyle, "'");
											
											if(strpos($listStyle, "'")!=''){
												//replace all spaces between quotes with tilders ~
												for($k=$quotePos+1;$k<=strlen($listStyle);$k++){
													$char=substr($listStyle, $k, 1);
													
													if($char==' ')
														$listStyle=substr_replace($listStyle, '~', $k, 1);
													
													if($char=="\"")
														break;
													
												}
											}
											
											$temp3=split(' ', $listStyle);
											$list_bits=Array();
											$list_bits['list-style-type']='';
											$list_bits['list-style-position']='';
											$list_bits['list-style-image']='';	
											
											foreach($temp3 as $this_value){
												//what is this value?
												//list-style shorthand properties can be a combination of:
												//list-style-type
												//list-style-image
												//list-style-repeat
												
												$this_value=trim($this_value);
												
												$found=false;
												
												if(substr(strtolower($this_value), 0, 4)=='url('){
													$list_bits['list-style-image']=$this_value;
													$found=true;
												}
												if(isset($shorthands['list-style-type'][$this_value])){
													if($shorthands['list-style-type'][$this_value]!=''){
														$list_bits['list-style-type']=$this_value;
														$found=true;
													}
												}
												if(isset($shorthands['list-style-position'][$this_value])){
													if($shorthands['list-style-position'][$this_value]!=''){
														$list_bits['list-style-position']=$this_value;
														$found=true;
													}
												}
												//NO DEFAULT VALUE FOR THIS STYLE
												
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='list-style-image';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$list_bits['list-style-image'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='list-style-type';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$list_bits['list-style-type'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='list-style-position';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$list_bits['list-style-position'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
																	
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='list-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;					
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
								
											$isShorthand=true;
										}
										
										if($property_name=='border'){
											//this is a border shorthand property...
											//we need to split it into the various bits
											
											//RGB fix:
											$temp3=$property_value;
											while(strpos($temp3, '  ')!==false)
												$temp3=str_replace('  ', ' ', $temp3);
											
											$temp3=str_replace(', ', ',', $temp3);	
											
											$temp3=split(' ', $temp3);
											$border_bits=Array();
											$border_bits['border-width']='';
											$border_bits['border-style']='';
											$border_bits['border-color']='';	
											
											foreach($temp3 as $this_value){
												//what is this value?
												
												$this_value=trim($this_value);
												$isMeasurement=is_measurement($this_value, true);
												$found=false;
												
												if($isMeasurement){
													$border_bits['border-width']=$this_value;
													$found=true;
												}
												if(!$found){
													if(isset($shorthands['border-width'][$this_value])){
														if($shorthands['border-width'][$this_value]!=''){
															$border_bits['border-width']=$this_value;
															$found=true;
														}
													}
												}
												if(isset($shorthands['border-style'][$this_value])){
													if($shorthands['border-style'][$this_value]!=''){
														$border_bits['border-style']=$this_value;
														$found=true;
													}
												}
												if(isset($shorthands['border-color'][$this_value])){
													if($shorthands['border-color'][$this_value]!=''){
														$border_bits['border-color']=$this_value;
														$found=true;
													}
												}
												if(!$found){
													$border_bits['border-color']=$this_value;
													$found=true;
												}
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-width'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-style'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-color'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
																			
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$longhand=Array('top', 'right', 'bottom', 'left');
											foreach($longhand as $this_longhand){
												
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-' . $this_longhand . '-width';
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-width'];
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
												$count++;
												
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-' . $this_longhand . '-style';
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-style'];
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
												$count++;
												
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-' . $this_longhand . '-color';
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-color'];
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
												$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
												$count++;
												
											}
											
											$isShorthand=true;
										}
										
										if($property_name=='border-top'){
											
											//RGB fix:
											$temp3=$property_value;
											while(strpos($temp3, '  ')!==false)
												$temp3=str_replace('  ', ' ', $temp3);
											
											$temp3=str_replace(', ', ',', $temp3);	
											
											$temp3=split(' ', $temp3);
											$border_bits=Array();
											
											$border_bits['border-width']='';
											$border_bits['border-style']='';
											$border_bits['border-color']='';	
											
											foreach($temp3 as $this_value){
												//what is this value?
												$this_value=trim($this_value);
												$isMeasurement=is_measurement($this_value, true);
												
												$found=false;
												
												if($isMeasurement){
													$border_bits['border-width']=$this_value;
													$found=true;
												}
												if(!$found){
													if(isset($shorthands['border-width'][$this_value])){
														if($shorthands['border-width'][$this_value]!=''){
															$border_bits['border-width']=$this_value;
															$found=true;
														}
													}
												}
												if(isset($shorthands['border-style'][$this_value])){
													if($shorthands['border-style'][$this_value]!=''){
														$border_bits['border-style']=$this_value;
														$found=true;
													}
												}
												if(isset($shorthands['border-color'][$this_value])){
													if($shorthands['border-color'][$this_value]!=''){
														$border_bits['border-color']=$this_value;
														$found=true;
													}
												}
												if(!$found){
													$border_bits['border-color']=$this_value;
													$found=true;
												}
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-width'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-style'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-color'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-top';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='border-right'){
											//this is a border=right shorthand property...
											//we need to split it into the various bits
											
											//RGB fix:
											$temp3=$property_value;
											while(strpos($temp3, '  ')!==false)
												$temp3=str_replace('  ', ' ', $temp3);
											
											$temp3=str_replace(', ', ',', $temp3);	
											
											$temp3=split(' ', $temp3);
											$border_bits=Array();
											$border_bits['border-width']='';
											$border_bits['border-style']='';
											$border_bits['border-color']='';	
											
											foreach($temp3 as $this_value){
												//what is this value?
												//border-right shorthand properties can be a combination of:
												//please complete this list...
												
												$this_value=trim($this_value);
												$isMeasurement=is_measurement($this_value, true);
												
												$found=false;
												
												if($isMeasurement){
													$border_bits['border-width']=$this_value;
													$found=true;
												}
												if(!$found){
													if(isset($shorthands['border-width'][$this_value])){
														if($shorthands['border-width'][$this_value]!=''){
															$border_bits['border-width']=$this_value;
															$found=true;
														}
													}
												}
												if(isset($shorthands['border-style'][$this_value])){
													if($shorthands['border-style'][$this_value]!=''){
														$border_bits['border-style']=$this_value;
														$found=true;
													}
												}
												if(isset($shorthands['border-color'][$this_value])){
													if($shorthands['border-color'][$this_value]!=''){
														$border_bits['border-color']=$this_value;
														$found=true;
													}
												}
												if(!$found){
													$border_bits['border-color']=$this_value;
													$found=true;
												}
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-width'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-style'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-color'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-right';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='border-bottom'){
											
											//RGB fix:
											$temp3=$property_value;
											while(strpos($temp3, '  ')!==false)
												$temp3=str_replace('  ', ' ', $temp3);
											
											$temp3=str_replace(', ', ',', $temp3);	
											
											$temp3=split(' ', $temp3);
											$border_bits=Array();
											$border_bits['border-width']='';
											$border_bits['border-style']='';
											$border_bits['border-color']='';	
											
											foreach($temp3 as $this_value){
												
												$this_value=trim($this_value);
												$isMeasurement=is_measurement($this_value, true);
												
												$found=false;
												
												if($isMeasurement){
													$border_bits['border-width']=$this_value;
													$found=true;
												}
												if(!$found){
													if(isset($shorthands['border-width'][$this_value])){
														if($shorthands['border-width'][$this_value]!=''){
															$border_bits['border-width']=$this_value;
															$found=true;
														}
													}
												}
												if(isset($shorthands['border-style'][$this_value])){
													if($shorthands['border-style'][$this_value]!=''){
														$border_bits['border-style']=$this_value;
														$found=true;
													}
												}
												if(isset($shorthands['border-color'][$this_value])){
													if($shorthands['border-color'][$this_value]!=''){
														$border_bits['border-color']=$this_value;
														$found=true;
													}
												}
												if(!$found){
													$border_bits['border-color']=$this_value;
													$found=true;
												}
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-width'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-style'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-color'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-bottom';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='border-left'){
											//this is a border-left shorthand property...
											//we need to split it into the various bits
																				
											//RGB fix:
											$temp3=$property_value;
											while(strpos($temp3, '  ')!==false)
												$temp3=str_replace('  ', ' ', $temp3);
											
											$temp3=str_replace(', ', ',', $temp3);	
											
											$temp3=split(' ', $temp3);
											$border_bits=Array();
											$border_bits['border-width']='';
											$border_bits['border-style']='';
											$border_bits['border-color']='';	
											
											foreach($temp3 as $this_value){
												//what is this value?
												//Border-left shorthand properties can be a combination of:
												//please complete this list
												
												$this_value=trim($this_value);
												$isMeasurement=is_measurement($this_value, true);
												
												$found=false;
												
												if($isMeasurement){
													$border_bits['border-width']=$this_value;
													$found=true;
												}
												if(!$found){
													if(isset($shorthands['border-width'][$this_value])){
														if($shorthands['border-width'][$this_value]!=''){
															$border_bits['border-width']=$this_value;
															$found=true;
														}
													}
												}
												if(isset($shorthands['border-style'][$this_value])){
													if($shorthands['border-style'][$this_value]!=''){
														$border_bits['border-style']=$this_value;
														$found=true;
													}
												}
												if(isset($shorthands['border-color'][$this_value])){
													if($shorthands['border-color'][$this_value]!=''){
														$border_bits['border-color']=$this_value;
														$found=true;
													}
												}
												if(!$found){
													$border_bits['border-color']=$this_value;
													$found=true;
												}
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-width'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-style'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
										
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits['border-color'];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
																						
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-left';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$isShorthand=true;
										}
										
										if($property_name=='border-width'){
											$temp3=explode(' ', $property_value);
											switch (count($temp3)){
												case 0:
													$border_bits[0]='';
													$border_bits[1]='';
													$border_bits[2]='';
													$border_bits[3]='';
													break;
												case 1:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[0];
													$border_bits[2]=$temp3[0];
													$border_bits[3]=$temp3[0];
													break;
												case 2:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[0];
													$border_bits[3]=$temp3[1];
													break;
												case 3:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[1];
													break;
												case 4:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[3];
													break;
												default:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[3];
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-top-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[0];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
										
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-right-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[1];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-bottom-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[2];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-left-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[3];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-width';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											$isShorthand=true;
										}
										
										if($property_name=='border-style'){
											$temp3=explode(' ', $property_value);
											
											switch (count($temp3)){
												case 0:
													$border_bits[0]='';
													$border_bits[1]='';
													$border_bits[2]='';
													$border_bits[3]='';
													break;
												case 1:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[0];
													$border_bits[2]=$temp3[0];
													$border_bits[3]=$temp3[0];
													break;
												case 2:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[0];
													$border_bits[3]=$temp3[1];
													break;
												case 3:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[1];
													break;
												case 4:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[3];
													break;
												default:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[3];
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-top-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[0];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-right-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[1];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-bottom-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[2];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-left-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[3];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
																					
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-style';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											$isShorthand=true;
										}
										
										if($property_name=='border-color'){
											//fix for RGB colours:
											$temp3=$property_value;
											while(strpos($temp3, '  '))
												$temp3=str_replace('  ', ' ', $temp3);
												
											$temp3=str_replace(', ', ',', $temp3);
											$temp3=explode(' ', $temp3);
											switch (count($temp3)){
												case 0:
													$border_bits[0]='';
													$border_bits[1]='';
													$border_bits[2]='';
													$border_bits[3]='';
													break;
												case 1:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[0];
													$border_bits[2]=$temp3[0];
													$border_bits[3]=$temp3[0];
													break;
												case 2:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[0];
													$border_bits[3]=$temp3[1];
													break;
												case 3:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[1];
													break;
												case 4:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[3];
													break;
												default:
													$border_bits[0]=$temp3[0];
													$border_bits[1]=$temp3[1];
													$border_bits[2]=$temp3[2];
													$border_bits[3]=$temp3[3];
											}
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-top-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[0];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-right-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[1];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-bottom-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[2];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;

											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-left-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$border_bits[3];
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']='border-color';
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
											$isShorthand=true;
										}
										
										if(!$isShorthand){
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['selector']=$selector;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['property']=$property_name;
											switch($property_name){
												case 'font-family':
													$temp4=explode(',', $property_value);
													for($k=0; $k<count($temp4); $k++){
														$temp4[$k]=trim($temp4[$k]);
													}
													$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$temp4;
													break;
												default:	
													$_styles[$stylesheet_count]['styles'][$selector_index][$count]['value']=$property_value;
													break;
											}
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['important']=$isImportant;
											$_styles[$stylesheet_count]['styles'][$selector_index][$count]['media']=$media;
											$count++;
										}
										
										$_styles[$stylesheet_count]['styles'][$selector_index]['selector']=$selector;
									}
								}
								$_styles[$stylesheet_count]['styles'][$selector_index]['rule_text']=$stylesText;
								$_styles[$stylesheet_count]['styles'][$selector_index]['inline']=$is_inline;
		
								$selector_index++;
								break;
							} else 
								///This is triggered by empty styles.
								break;
							
							} else $stylesText.=$char2;
						} else $j++;
					}
					
					//Clear the values in preparation for the next selector...
					$stylesText='';
					$selector='';
					$count=0;
					$i=$j;
				} else
					//Keep building the selector...
					$selector.=$char;
				
			
		} else
			$i++;
				
	}
	//now we need to figure out how to handle the selectors.
	//This involves identifying what elements are affected by this style,
	//and what conditions there are
	
	//selectors can look like this:
	//DIV - redefined tag, no conditions
	//.class - class name for any element
	//#id - id name for any element
	//element.class
	//element.id
	//element1 element2
	//element1, element2
	
	//what we are needing is an a structure like this:
	
	/*
	selectors[selectorText][selectorGroup1][elementSelector1]
											[attributeSelector]
											[specialHTMLselector]
											[pseudoClassSelector]
											[pseudoElementSelector]
	selectors[selectorText][selectorGroup1][elementSelector2]
											[attributeSelector]
											[specialHTMLselector]
											[pseudoClassSelector]
											[pseudoElementSelector]
	selectors[selectorText][selectorGroup2][elementSelector1]
											[attributeSelector]
											[specialHTMLselector]
											[pseudoClassSelector]
											[pseudoElementSelector]
	selectors[selectorText][selectorGroup2][elementSelector2]
											[attributeSelector]
											[specialHTMLselector]
											[pseudoClassSelector]
											[pseudoElementSelector]
	*/
	
	
	
	/*NEW MODEL:
	selectors[style_index][elementSelector1]
	*/
	//so we're not generating this if it's an inline style because it's automatically applied to that style
	//ie, there is no selector
	
	//These are all the possible ways to end the search for an element selector (used further on):
	$selector_terminators=Array();
	$selector_terminators['.']=true;
	$selector_terminators['#']=true;
	$selector_terminators['+']=true;
	$selector_terminators['>']=true;
	$selector_terminators['[']=true;
	$selector_terminators[':']=true;
	
	$selector_index=0;
	if(!$is_inline){
		//Sometimes a stylesheet might be empty, so we need to check that anything is actually here:
		if(isset($_styles[$stylesheet_count])){
			foreach($_styles[$stylesheet_count]['styles'] as $this_style){
				//first of all, split the selector group into individual selectors (if there are any commas)
				//TODO: www.usatoday.com seems to return bad stylesheets for the next line (undefined index on 'selector')
				$selectors_group=explode(',', $this_style['selector']);
				$selector_group_count=0;
				foreach($selectors_group as $this_selector_group){
					$this_selector_group=strtolower(trim($this_selector_group));
					//replace multiple spaces for consistency:
					while(strpos($this_selector_group,'  ')!==false)
						$this_selector_group=str_replace('  ', ' ', $this_selector_group);
						
					//Fix up the child and adjacent selector options
					$this_selector_group=str_replace(Array(' > ', ' + '), Array('>', '+'), $this_selector_group);
					
					//we can't use the $this_selector_group as the value for the array entry because that will break the link between 
					//the styles and selectors dimensions, so we need a counter for this dimension
					
					$individual_selectors=explode(' ', $this_selector_group);
					
					$denary=Array('a'=>0, 'b'=>0, 'c'=>0);
					
					$selector_count=0;
					
					foreach($individual_selectors as $this_selector){
						//now inspect each selector for it's details
								
						//Posibilities:
						//* - wildcard
						//H1 - redefined element
						//H1 div - descendant selector
						//H1 > div - child selector
						//H1 + div - adjacent selector
						
						//reset the values
						$element_selector='';
						$child_selector='';
						$adjacent_selector='';
						$is_attribute_selector=false;
						$attribute_selector='';
						$is_id=false;
						$id='';
						$is_class=false;
						$class='';
						$is_pseudo=false;
						$pseudo='';
						
						$char=substr($this_selector,0,1);
						$this_selector_modified=$this_selector;
						
						//If there is no element selector, we need to append one.
						if($char=='.' || $char=='#'){
							$no_element_selector=true;
							$this_selector_modified='*' . $this_selector;
						} else $no_element_selector=false;
						
						//ok, so it's something, find out what the element selector is
						$selector_length=strlen($this_selector_modified);
							
						for($i=0;$i<$selector_length;$i++){
							$char=substr($this_selector_modified, $i, 1);
							
							if(!isset($selector_terminators[$char]) && !$is_attribute_selector && !$is_id && !$is_class && !$is_pseudo)
								$element_selector.=$char;
							else {
								//Here we will be identifying ids, classes, and pseudo selectors
								//When (if) we hit an adjacent selector or child selector, we move whatever we have into
								//the 'parent_' array entries and reset the values.
								
								if($is_id && $char!='.' && $char!=':' && $char!='>' && $char!='+')
									$id.=$char;
								
								if($is_class && $char!='#' && $char!=':' && $char!='>' && $char!='+')
									$class.=$char;
								
								if($is_pseudo)
									$pseudo.=$char;
								
								if($is_attribute_selector && $char!=']')
									$attribute_selector.=$char;
													
								switch($char){
									case '#':
										if(!$is_attribute_selector){
											$is_id=true;
											$is_class=false;
											$is_pseudo=false;
										}
										break;
									case '.':
										if(!$is_attribute_selector){
											$is_id=false;	
											$is_class=true;
											$is_pseudo=false;
										}
										break;
									case ':':
										if(!$is_attribute_selector){
											$is_id=false;
											$is_class=false;
											$is_pseudo=true;
										}
										break;
									case '[':
										$is_attribute_selector=true;
										$is_id=false;
										$is_class=false;
										$is_pseudo=false;
										break;
									case ']':
										$has_attribute_selector=false;
										break;
								}
								
								//if we have detected the start of an adjacent or child selector, then we put what we
								//have in the parent_ array elements
															
								if($char=='+' || $char=='>'){
									
									if($char=='+')
										$type='adjacent';
									else $type='parent';
									
									if($id!='')
										$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_id']=$id;
										
									if($class!=''){
										$all_classes=explode('.', $class);
										$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_class']=$all_classes;
									}
	
									if($pseudo!=''){
										$all_pseudos=explode(':', $pseudo);
										foreach($all_pseudos as $this_pseudo){
											if($this_pseudo!=''){
												//By default, everything is a pseudo class, with only four exceptions
												switch(strtolower($this_pseudo)){
													case 'before': 			$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_pseudoElement']=$this_pseudo;	break;
													case 'after': 			$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_pseudoElement']=$this_pseudo;	break;
													case 'first-letter': 	$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_pseudoElement']=$this_pseudo;	break;
													case 'first-line': 		$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_pseudoElement']=$this_pseudo;	break;
													default:				$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_pseudoClass']=$this_pseudo;		break;
												}
											}
										}
									}
									
									if($attribute_selector!='')
										$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['attribute_selector']=$attribute_selector;
									
									$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count][$type . '_selector']=$element_selector;
																	
									//reset these values:
									$is_id=false;
									$id='';
									$is_class=false;
									$class='';
									$is_pseudo=false;
									$pseudo='';
									$is_attribute_selector=false;
									$attribute_selector='';
									$element_selector='';
								}
									
							}
							
						}
						//simple selectors such as 'div { ... } will need to be set here:
						if(!isset($selectors[$selector_index][$selector_group_count][$selector_count]['element_selector']))
							$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['element_selector']=$element_selector;
											
						//now put in the remaining information:
						if($id!='')
							$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['id']=$id;
							
						if($class!=''){
							$all_classes=explode('.', $class);
							$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['class']=$all_classes;
						}
						
						if($pseudo!=''){
							$all_pseudos=explode(':', $pseudo);
							foreach($all_pseudos as $this_pseudo){
								if($this_pseudo!=''){
									//By default, everything is a pseudo class, with only four exceptions
									switch(strtolower($this_pseudo)){
										case 'before': 			$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['pseudoElement']=$this_pseudo;	break;
										case 'after': 			$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['pseudoElement']=$this_pseudo;	break;
										case 'first-letter': 	$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['pseudoElement']=$this_pseudo;	break;
										case 'first-line': 		$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['pseudoElement']=$this_pseudo;	break;
										default:				$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['pseudoClass']=$this_pseudo;	break;
									}
								}
							}
						}
						
						if($attribute_selector!='')
							$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count][$selector_count]['attribute_selector']=$attribute_selector;
												
						//According to http://juicystudio.com/article/selector-specificity.php, we are not including pseudo classes here
						//NOTE:  multiple classes such as .this.that will not be detected here if they're not adjacent...
						//for instance, .this#something.that will only count one class
						if(!$pseudo){
							if($id!='')
								$denary['a']++;
							if($class!='')
								$denary['b']+=sizeof($all_classes);
							if(!$no_element_selector)
								$denary['c']++;
							
						}
						
						$selector_count++;
					}
					
					$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count]=array_reverse($_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count]);	
					$_styles[$stylesheet_count]['selectors'][$selector_index][$selector_group_count]['specificity']=$denary;
					
					$selector_group_count++;
						
				}
				$selector_index++;
			}
		}
	} else {
		//this is an inline style, the selector is much simpler...
		$_styles[$stylesheet_count]['selectors'][$selector_index]['is_inline']=true;
		$_styles[$stylesheet_count]['selectors'][$selector_index]['element_index']=$inline_selector;
		$selector_index++;
	}
	
	$_styles[$stylesheet_count]['location']=$location;
	
	return $applied_stylesheets;
}

function strip_comments($element, $remove_javascript_comments=true){
	//remove anything between /* and */
	$new='';
	for($i=0; $i<strlen($element); $i++){
		$char=substr($element, $i, 1);
		if($char=='/'){
			if(substr($element, $i+1,1)=='*'){
				//we have an opening comment, go forth until a closing comment is found
				for($j=$i+2; $j<strlen($element); $j++){
					if(substr($element, $j, 1)=='*'){
						if(substr($element, $j+1, 1)=='/'){
							//we have a closing comment.
							break;
						} 
					}
				}
				$i=$j+1;
			} else {
				$new.=substr($element, $i, 1);
			}
		} else {
			$new.=$char;
		}
	}	
	
	$element=$new;
		
	return $element;
}

function check_char($char){
	$ascii=ord($char);
		
	switch(true){
		case ($ascii==45):
			return true;
			break;
		case ($ascii>47 && $ascii<58):
			return true;
			break;
		case ($ascii>64 && $ascii<91):
			return true;
			break;
		case ($ascii>96 && $ascii<123):
			return true;
			break;
		default:
			return false;
			break;
	}
	
}

function is_measurement($value, $check_numerics=true){
	if(is_relative($value)){
		return true;
	} else {
		if(is_absolute($value)){
			return true;
		} else {
			if(is_percentage($value)){
				return true;
			} else {
				if($check_numerics){
					if(is_numeric($value)){
						return true;
					} else {
						return false;
					}
				}
			}
		}
	}
}

function is_relative($value, $pixels_are_relative=true){
	
	if($value=='')
		return true;
		
	$is_relative=false;
	
	switch(substr($value,-2)){
		case 'em':
			$is_relative=true;
			break;
		case 'ex':
			$is_relative=true;
			break;
		case 'px':
			if($pixels_are_relative)
				$is_relative=true;
				
			break;
	}
	
	switch(substr($value, -1)){
		case '%':
			$is_relative=true;
			break;
	}
	
	switch(substr($value, 0, 1)){
		case '+':
			$is_relative=true;
			break;
		case '-':
			$is_relative=true;
			break;	
	}
	
	return $is_relative;
}

function is_absolute($value){
	
	switch(substr($value,-2)){
		case 'in':
			return true;
			break;
		case 'cm':
			return true;
			break;
		case 'mm':
			return true;
			break;
		case 'pt':
			return true;
			break;
		case 'pc':
			return true;
			break;
		default:
			return false;
	}
}

function is_percentage($value){
	
	if(substr($value,-1)=='%')
		return true;
	else
		return false;
	
}

function is_unit_relative($value, $is_html_attribute=false){
	//get the measurement unit from a number.
	
	//First spit it into components - some values may be like 12px 20px
	if(is_array($value)){
		$temp=Array();
		foreach($value as $this_value){
			$bits=explode(' ', $this_value);
			
			foreach($bits as $this_bit)
				$temp[]=$this_bit;
				
			//sometimes fonts might be described as a size/line-height combo:
			if(sizeof($temp)==0){
				$bits=explode('/', $this_value);
				foreach($bits as $this_bit)
					$temp[]=$this_bit;
			}
			
		}
	} else $temp=explode(' ', $value);
	
	$relative=true;
	
	static $all_values=null;
	if(is_null($all_values)){
		$all_values=Array();
		$all_values[]='0';
		$all_values[]='xx-small';
		$all_values[]='x-small';
		$all_values[]='small';
		$all_values[]='medium';
		$all_values[]='large';
		$all_values[]='x-large';
		$all_values[]='xx-large';
		$all_values[]='smaller';
		$all_values[]='larger';
		$all_values[]='left';
		$all_values[]='center';
		$all_values[]='right';
		$all_values[]='top';
		$all_values[]='bottom';
		$all_values[]='middle';
		$all_values[]='inherit';
		$all_values[]='transparent';
		$all_values[]='normal';
		$all_values[]='auto';
		$all_values[]='';
		$all_values[]='none';
	}
	
	foreach($temp as $this_value){
		
		$bit1=substr($this_value, -1);
		$bit2=strtolower(substr($this_value, -2));
		
		if($bit1!='%' && $bit2!='em' && $bit2!='ex' && !in_array($this_value, $all_values)){
			$relative=false;
			break;
		}
	}
	
	//if we are checking an HTML attribute, standard numbers are actually absolute units
	if($is_html_attribute){
		if(is_numeric($value))
			$relative=false;
	}
	
	return $relative;
}
?>
Return current item: OpenWolf Guidelines Validator