<?
/*
    $armor = DressingRoom::getArmor($xml);
    echo 'link <a href="'.DressingRoom::linkUri($armor).'">'.$armor."</a>\n";
    echo 'image <img src="'.DressingRoom::imageUri($armor)."\" width='200px' align='right' border=1 />\n";
*/

class DressingRoom {
	
	function imageUri($armor, $base='http://ballisticmystix.net/api/dressingroom.php'){
		if(strpos($base, '?')===false){
			return $base.'?'.$armor;
		}else{
			return $base.'&'.$armor;
		}
	}

	function linkUri($armor, $base='http://ballisticmystix.net/?p=dressingRoom;'){
		if(strpos($base, '?')===false){
			return $base.'?'.$armor;
		}else{
			return $base.'&'.$armor;
		}
	}
	
	function getArmor(SimpleXMLElement $xml){
		$url=array();
		
		// race
		switch(strtolower($xml->race)){
			case 'zorai':
			case 'fyros':
			case 'matis':
			case 'tryker': // fall thru
				$race=strtolower($xml->race);
				break;
			default:
				$race='tryker';
		}
		$url[]='race='.$race;
		// gender
		if(strtolower($xml->gender)=='f') $gender='f'; else $gender='m';
		$url[]='gender='.$gender;
		// hair
		$hair_type  = (int)$xml->body->hair_type;
		$hair_color = (int)$xml->body->hair_color;
		$url[]='hair='.$hair_type.'/'.$hair_color;
		// tattoo
		$tattoo=(int)$xml->body->tattoo;
		$url[]='tattoo='.$tattoo;
		// eye color
		$eye_color = (int)$xml->body->eyes_color;
		$url[]='eyes='.$eye_color;
		
		// armor
		foreach($xml->equipments->item as $node){
            // if it's one of armor parts
            $part = (string) $node['part'];
            if(in_array($part, array('hands', 'chest', 'arms', 'legs','feet','head'))){
                $color = (int) $node['c'];
                $url[]=$part.'='.(string) $node.'/'.$color;
            }
        }

		// join the URL and return it
		return join('&',$url);
	}
    

}// DressingRoom
//eof
