<?php
  
class Head{
	
	public function Head(){        

		#Doctype
		printf('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">');

		printf('<HTML>');
				
		printf('<HEAD>');
		
		#Title
		printf('<title>%s</title>', _web_title);

		#Charset
		printf('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');

		#CSS
		$this->addTemplateCSS();

        #JS
        $this->addTemplateJS();


        printf('</HEAD>');
   
	}

    private function addTemplateCSS(){
        $css = '';
        $handle = '';
        $file = '';

        // open the "css" directory
        if ($handle = opendir('./templates/'. _template . '/css')) {
            // list directory contents
            while (false !== ($file = readdir($handle))) {
                // only grab file names
                if (is_file('./templates/'. _template . '/css/' . $file)) {
                    // insert HTML code for loading Javascript files
                     if ($file=="pizza.css")
                        $css .= '<link rel="stylesheet" media="screen, projector, print" rel="stylesheet href="./templates/'. _template . '/css/' . $file .
                        '" type="text/css" media="all" />' . "\n";
                    else
                        $css .= '<link rel="stylesheet" href="./templates/'. _template . '/css/' . $file .
                        '" type="text/css" media="all" />' . "\n";
                }
            }
            closedir($handle);
            echo $css;
        }

    }

    private function addTemplateJS(){
        $js = '';
        $handle = '';
        $file = '';

        //JQuery
        printf('<script src="./js/jquery.js" type="text/javascript"></script>');

        // open the "js" directory
        if ($handle = opendir('./templates/'. _template . '/js')) {
            // list directory contents
            while (false !== ($file = readdir($handle))) {
                // only grab file names
                if (is_file('./templates/'. _template . '/js/' . $file)) {
                    // insert HTML code for loading Javascript files
                    $js .= '<script src="./templates/'. _template . '/js/' . $file . '" type="text/javascript"></script>' . "\n";
                }
            }
            closedir($handle);
            printf($js);
        }

    }

}
		
?>