<?php

/*
Script: class.packito.php
    Show the Components you need.

License:
    MIT-style license.

Copyright:
    copyright (c) 2007 Daniel Mota, <http://icebeat.bitacoras.com>
    
Example:
    (start code)
    $pack = new Packito('js.js');
    print_r($pack->Get());
    (end)
*/

class Packito {
    
    var 
$version '1.1';
    var 
$js '';
    var 
$dependecies = array();
    var 
$pack = array();
    var 
$files = array(
        
'Core' => array('Core'),
        
'Class' => array('Class','Class.Extras'),
        
'Native' => array('Array','String','Function','Number','Element'),
        
'Element' => array('Element.Event','Element.Filters','Element.Selectors','Element.Form','Element.Dimensions'),
        
'Window' => array('Window.DomReady','Window.Size'),
        
'Effects' => array('Fx.Base','Fx.CSS','Fx.Style','Fx.Styles','Fx.Elements','Fx.Scroll','Fx.Slide','Fx.Transitions'),
        
'Drag' => array('Drag.Base','Drag.Move'),
        
'Remote' => array('XHR','Ajax','Cookie','Json','Json.Remote','Assets'),
        
'Plugins' => array('Hash','Hash.Cookie','Color','Scroller','Slider','SmoothScroll','Sortables','Tips','Group','Accordion')
    );
    
    function 
Packito($file ''$string false) {
        if(
$string || $string = @file_get_contents($file)) {
            
$this->js $string;
            
$items array_reverse(array_slice(get_class_methods($this), 4));
            foreach(
$items as $item) {
                
call_user_func(array(&$this$item));
            }
        }
    }
    
    function 
contains($array = array()) {
        foreach(
$array as $item) {
            if(
strpos($this->js,$item) !== false)     return true;
        }
        return 
false;
    }
    
    function 
Add($force false$deps = array() , $test = array(), $pack '') {
        
$in_array = !in_array($pack,$this->dependecies);
        if((
$force && $in_array) || ($in_array && $this->contains($test))) {
            
$this->dependecies[] = $pack;
            foreach(
$deps as $dep) {
                
call_user_func(array(&$this'MT_'.$dep),true);
            }
        }
    }
    
    function 
Get() {
        if(
count($this->pack)) return $this->pack;
        foreach(
$this->files as $file => $items) {
            foreach(
$items as $item) {
                
$this->pack[$file][$item] = in_array($item,$this->dependecies) ? true false;
            }
        }
        return 
$this->pack;
    }
    
    function 
MT_Core($force false) {
        
$deps = array();
        
$test = array('Mootools','$defined','$type','$merge','$extend','Abstract',
        
'document.head','$chk','$pick','$random','$time','$clear','window.xpath','window.ie',
        
'window.ie6','window.ie7','window.khtml','window.webkit'
        
);
        
$this->Add($force$deps$test'Core');
    }
    
    function 
MT_Class($force false) {
        
$deps = array('Core');
        
$test = array('Class','Class.empty');
        
$this->Add($force$deps$test'Class');
    }
    
    function 
MT_ClassExtras($force false) {
        
$deps = array('Class');
        
$test = array('new Chain','new Events','new Options');
        
$this->Add($force$deps$test'Class.Extras');
    }
    
    function 
MT_Array($force false) {
        
$deps = array('Core');
        
$test = array('filter(','map(','every(','some(','indexOf(','copy(','remove(','contains(','associate(','extend(','merge(','include(','getRandom(','getLast(');
        
$this->Add($force$deps$test'Array');
    }
    
    function 
MT_String($force false) {
        
$deps = array('Core');
        
$test = array('.test(','.toInt(','toFloat(','.camelCase()','.hyphenate()','.capitalize()','.trim()','.clean()',
        
'.contains(','.escapeRegExp()','.rgbToHex(','.rgbToHex(','.rgbToHex('
        
);
        
$this->Add($force$deps$test'String');
    }
    
    function 
MT_Function($force false) {
        
$deps = array('Core');
        
$test = array('.bind(','.bindAsEventListener(','.delay(','.periodical(','.attempt(','.pass(','.create(');
        
$this->Add($force$deps$test'Function');
    }
    
    function 
MT_Number($force false) {
        
$deps = array('Core');
        
$test = array('toInt(','toFloat(','.limit(','.times(');
        
$this->Add($force$deps$test'Number');
    }
    
    function 
MT_Element($force false) {
        
$deps = array('Array''String''Function''Number''Class');
        
$test = array('$(','new Element(');
        
$this->Add($force$deps$test'Element');
    }
    
    function 
MT_ElementEvent($force false) {
        
$deps = array('Element');
        
$test = array('new Event(','.bindWithEvent(');
        
$this->Add($force$deps$test'Element.Event');
    }
    
    function 
MT_ElementFilters($force false) {
        
$deps = array('Element');
        
$test = array('.filterBy');
        
$this->Add($force$deps$test'Element.Filters');
    }
    
    function 
MT_ElementSelectors($force false) {
        
$deps = array('ElementFilters');
        
$test = array('$E(','$ES(','$$','.getElements(','.getElementsBySelector(','.getElementsByClassName(');
        
$this->Add($force$deps$test'Element.Selectors');
    }
    
    function 
MT_ElementForm($force false) {
        
$deps = array('Element');
        
$test = array('.toQueryString()','.getValue()','.getFormElements()');
        
$this->Add($force$deps$test'Element.Form');
    }
    
    function 
MT_ElementDimensions($force false) {
        
$deps = array('Element');
        
$test = array('.getSize()','.getPosition(','.getTop(','.getLeft(','.getCoordinates(');
        
$this->Add($force$deps$test'Element.Dimensions');
    }
    
    function 
MT_WindowDomReady($force false) {
        
$deps = array('ElementEvent');
        
$test = array("window.addEvent('domready'",'.onDomReady(');
        
$this->Add($force$deps$test'Window.DomReady');
    }
    
    function 
MT_WindowSize($force false) {
        
$deps = array('Element');
        
$test = array('window.getWidth','window.getHeight','window.getScrollWidth',
        
'window.getScrollHeight','window.getScrollLeft','window.getScrollTop','window.getSize');
        
$this->Add($force$deps$test'Window.Size');
    }
    
    function 
MT_FxBase($force false) {
        
$deps = array('ClassExtras','Element');
        
$test = array('Fx.Base');
        
$this->Add($force$deps$test'Fx.Base');
    }
    
    function 
MT_FxCSS($force false) {
        
$deps = array('FxBase');
        
$test = array('Fx.CSS');
        
$this->Add($force$deps$test'Fx.CSS');
    }
    
    function 
MT_FxStyle($force false) {
        
$deps = array('FxCSS');
        
$test = array('new Fx.Style(','.effect(');
        
$this->Add($force$deps$test'Fx.Style');
    }
    
    function 
MT_FxStyles($force false) {
        
$deps = array('FxCSS');
        
$test = array('new Fx.Styles(','.effects(');
        
$this->Add($force$deps$test'Fx.Styles');
    }
    
    function 
MT_FxElements($force false) {
        
$deps = array('FxCSS');
        
$test = array('new Fx.Elements(');
        
$this->Add($force$deps$test'Fx.Elements');
    }
    
    function 
MT_FxScroll($force false) {
        
$deps = array('FxBase''ElementEvent''ElementDimensions''WindowSize');
        
$test = array('new Fx.Scroll(');
        
$this->Add($force$deps$test'Fx.Scroll');
    }
    
    function 
MT_FxSlide($force false) {
        
$deps = array('FxBase');
        
$test = array('new Fx.Slide(');
        
$this->Add($force$deps$test'Fx.Slide');
    }
    
    function 
MT_FxTransitions($force false) {
        
$deps = array('FxBase');
        
$test = array('Fx.Transition');
        
$this->Add($force$deps$test'Fx.Transitions');
    }
    
    function 
MT_DragBase($force false) {
        
$deps = array('ClassExtras''ElementEvent');
        
$test = array('new Drag.Base(','.makeResizable(');
        
$this->Add($force$deps$test'Drag.Base');
    }
    
    function 
MT_DragMove($force false) {
        
$deps = array('DragBase''ElementDimensions');
        
$test = array('new Drag.Move','.makeDraggable(');
        
$this->Add($force$deps$test'Drag.Move');
    }
    
    function 
MT_XHR($force false) {
        
$deps = array('ClassExtras''Element');
        
$test = array('new XHR(');
        
$this->Add($force$deps$test'XHR');
    }
    
    function 
MT_Ajax($force false) {
        
$deps = array('XHR''ElementForm');
        
$test = array('new Ajax(','.send()');
        
$this->Add($force$deps$test'Ajax');
    }
    
    function 
MT_Cookie($force false) {
        
$deps = array('Core''Array''String''Function''Number');
        
$test = array('Cookie.set(','Cookie.get(','Cookie.remove(');
        
$this->Add($force$deps$test'Cookie');
    }
    
    function 
MT_Json($force false) {
        
$deps = array('Core''Array''String''Function''Number');
        
$test = array('Json.toString','Json.evaluate');
        
$this->Add($force$deps$test'Json');
    }
    
    function 
MT_JsonRemote($force false) {
        
$deps = array('XHR''Json');
        
$test = array('new Json.Remote(');
        
$this->Add($force$deps$test'Json.Remote');
    }
    
    function 
MT_Assets($force false) {
        
$deps = array('ElementEvent');
        
$test = array('new Asset');
        
$this->Add($force$deps$test'Assets');
    }
    
    function 
MT_Hash($force false) {
        
$deps = array('Element');
        
$test = array('new Hash(','$H');
        
$this->Add($force$deps$test'Hash');
    }
    
    function 
MT_HashCookie($force false) {
        
$deps = array('Hash''Cookie');
        
$test = array('new Hash.Cookie(');
        
$this->Add($force$deps$test'Hash.Cookie');
    }
    
    function 
MT_Color($force false) {
        
$deps = array('Element');
        
$test = array('new Color(','$RGB','$HSB','rgbToHsb(','hsbToRgb(');
        
$this->Add($force$deps$test'Color');
    }
    
    function 
MT_Scroller($force false) {
        
$deps = array('ClassExtras''ElementEvent','ElementDimensions');
        
$test = array('new Scroller(');
        
$this->Add($force$deps$test'Scroller');
    }
    
    function 
MT_Slider($force false) {
        
$deps = array('DragBase''ElementDimensions');
        
$test = array('new Slider(');
        
$this->Add($force$deps$test'Slider');
    }
    
    function 
MT_SmoothScroll($force false) {
        
$deps = array('FxScroll');
        
$test = array('new SmoothScroll(');
        
$this->Add($force$deps$test'SmoothScroll');
    }
    
    function 
MT_Sortables($force false) {
        
$deps = array('ClassExtras''ElementEvent','ElementDimensions');
        
$test = array('new Sortables(');
        
$this->Add($force$deps$test'Sortables');
    }
    
    function 
MT_Tips($force false) {
        
$deps = array('ClassExtras''ElementEvent','WindowSize');
        
$test = array('new Tips(');
        
$this->Add($force$deps$test'Tips');
    }
    
    function 
MT_Group($force false) {
        
$deps = array('ClassExtras''Element');
        
$test = array('new Group(');
        
$this->Add($force$deps$test'Group');
    }
    
    function 
MT_Accordion($force false) {
        
$deps = array('FxElements''ElementEvent');
        
$test = array('new Accordion(');
        
$this->Add($force$deps$test'Accordion');
    }
    
}

?>