/* ========================================================================
 * @license The MIT License
 *    http://www.opensource.org/licenses/mit-license.php
 * @author  Yoshiaki Sugimoto <neo.yoshiaki.sugimoto@gmail.com>
 * @copyright Neo,Inc <http://neo-navi.net/>
 * @version    ,v 0.6.1
 * ========================================================================
 */


var Flint = {
    __initialTime : new Date().getTime(),
    __systemTime : 0, __loadTime : 0, __domTime : 0,
    config : {
      //current Flint version Code
      version : '0.6.0',

      //chenge your site url of document root
      site_url : 'http://www.skinfood.co.jp/',
      //site_url : 'http://localhost/skinfood/',

      // if access use port 443 of 'https://', use this site_url
      ssl_site_url : 'https://www.skinfood.co.jp/',
      //ssl_site_url : 'https://192.168.0.10/skinfood/',
      //ssl_site_url : 'https://neo-navi.net/sugimoto/skinfood/',

      //setting of this script file path from site_url
      script_path : 'js/',

      //if use google map API, change state to 'true';
      //true : use google map API
      //false : unuse google map API
      useGmap : false,

      //if use googlemap API, insert your API key.
      GmapAPIkey : 'API Key',

      //define google map API path.
      GmapAPI_path : 'http://maps.google.com/maps?file=api&amp;v=2&amp;key=',

      //initialize set center point
      Gmap_initPoint : 'google map center address',

      //debug mode
      // if this value is true, some methods returns alert with message when methods throw Error.
      // true : debug mode ON
      // false : debug mode OFF
      debugMode : false,

      //use output profiler
      // use profiling system data. execution times and current DOM tree visible
      // true : profiling ON
      // false : profiling OFF
      useProfiler : false,

      // use zIndexer
      // auto calculate heighest z-index value in all element.
      zIndexer : false,

      //autoload library
      // preload library names this array value.
      autoload_Library : [],

      //autoload helper
      // preload helper names set this array value.
      autoload_Helper : [],

      //autoload models
      // preload model names set this array value.
      autoload_Models : [],

      //use extended builtin Classes
      // if these paremer set true, extends Builtin Class.
      useExtendedClass : {
        'string' : false,
        'array' : false,
        'math' : false,
        'function' : false
      },

      //IE fix
      //positionFix : element style 'position:fixed' enables in IE6.
      //floatFix    : element style margin bug fix for 'float' in IE6.
      //pngFix      : image or backgroundImage in 'png' extentions fix in IE6.
      IEFix : {
        positionFix : false,
        floatFix  : false,
        pngFix    : false
      },

      //routing mode
      //load Controller and execute method decide from this mode.
      // 'none'  : default controller is none, when, make only 'FL' variable on global in script.
      // 'default' : load Controller from attribute 'src' in <script>. execute method from attirbute 'id' in <script>.
      // 'query'   : query base approache. load Controller from 'load=' of parameter. execute method from 'method=' of parameter.
      //         if you use this mode, other parameters supply method arguments.
      // 'segment' : segment base approache. load Controller from first segment after site_url. execute method from second segment after site_url.
      //         if you use this mode,other parameters supply method arguments.
      //         if you use "CodeIgniter" of PHP FrameWork, please set this mode is 'segment'.
      routingMode : 'segment',

      //default controller
      // if routingMode is 'segment', and undefined controller(URI like http://example.com/), use this parameter to controller name
      defaultController : 'top',

      //cookie config
      //cookie prefix
      cookieName    : 'flCookie',
      cookieDomain  : document.domain,
      cookiePath    : '/',
      cookieMaxAge  : 7,
      cookieDelimiter : '&',
      cookieSeparator : ':',

      //session config
      //session prefix
      sessionName   : 'flSession'
    },
    // some initial parameters
    _doc : document, _win : window, onLoadFunc : [], registedFunc : [], DOMFuncs : [], controller : '', controllerName : '', exec : null, methodArguments : {}, loadedApp : {},loadedCss : {},
    attachCount : 0, loaded : false, DOMReady : false, registedElm : {}, currentIndex : 1, layer : null, loadedImage : [],
    readyFunc : function(funcName, type){
     if  (!Flint.loaded){
    	 Flint.onLoadFunc.unshift([funcName, false, (type || 0)]);
     }
     else {
    	 var tmpf = new funcName();
    	 if (tmpf.__construct)tmpf.__construct.call(tmpf);
     }
    },
    __evElmClean : function()
    {
      //delete all EventListener
      Flint.event.deleteAllEvent();
      //delete all createdElements
      for (var i = 0, len = Flint.registedElm.length; i < len; i++)Flint.registedElm[i] = null;
      DOM.layer = null;
    },
    profiler : {
      values : [], load : 0, dom : 0, box : null, btn : null, close : null, domtree : null, loading : null, treeShowFlag : false, tree : null, layer : null, showFlag : false, defaultTop : 30,//for IE6
      noEndTag : {'input' : 1, 'img' : 1, 'link' : 1, 'meta' : 1, 'br' : 1, 'hr' : 1, 'param' : 1, 'area' : 1, 'embed' : 1, 'isindex' : 1, 'frame' : 1, 'bgsound' : 1},
      set : function()
      {
        var FL = getInstance();
        FL.load.css('flint_profiler');
        var showBtn = DOM.create('a', {'class' : 'fl_profiler_show_button'});
        showBtn.inText('profile');
        showBtn.event('click', Flint.profiler.execute);
        showBtn.add();
        if (FL.ua.IE6)
        {
          var sc = FL.utility.getScrollPosition();
          showBtn.addStyle('top', sc.y + 20 + 'px');
          var scrollListener = function(ev)
          {
            var sc = FL.utility.getScrollPosition();
            showBtn.addStyle('top', showBtn.readStyle('bottom', true) + sc.y + 'px');
          }
          FL.event.set(window, 'scroll', scrollListener)
        }
        Flint.profiler.btn = showBtn;
        var d = DOM.create('div', {'id' : 'fl_profiler_box'});
        d.add();
        Flint.profiler.box = d;
      },
      execute : function()
      {
        var FL = getInstance();
        var vals = Flint.profiler.values;
        var table = DOM.create('table', {'id' : 'fl_profiler_lists'});
        var tbody = DOM.create('tbody');
        var head = DOM.create('tr', {'class' : 'head'});
        var tdh1 = DOM.create('td', {'class' : 'cell1'});
        tdh1.inText('variable name');
        var tdh2 = DOM.create('td', {'class' : 'cell2'});
        tdh2.inText('variable type');
        var tdh3 = DOM.create('td', {'class' : 'cell3'});
        tdh3.inText('value')
        tdh1.add(head);
        tdh2.add(head);
        tdh3.add(head);
        head.add(tbody);
        for (var i = 0, len = vals.length; i < len; i++)
        {
          var tr = (i % 2 === 0) ? DOM.create('tr', {'class' : 'even'}) : DOM.create('tr', {'class' : 'odd'});
          var td1 = DOM.create('td');
          td1.inText(vals[i][0]);
          var td2 = DOM.create('td');
          td2.inText(vals[i][1]);
          var td3 = DOM.create('td', {'class' : 'values'});
          td3.inText(vals[i][2]);
          td1.add(tr);
          td2.add(tr);
          td3.add(tr);
          tr.add(tbody);
        }
        var emptr = DOM.create('tr');
        emptr.attr('height', '10px');
        var emptd = DOM.create('td', {'colSpan' : 3});
        emptd.add(emptr);
        emptr.add(tbody);
        var trsys = DOM.create('tr');
        var tdsys = DOM.create('td');
        tdsys.inText('system execution time');
        var tdsysv = DOM.create('td', {'colSpan' : 2});
        tdsysv.inText((Flint.__systemTime - Flint.__initialTime) + '(ms)');
        tdsys.add(trsys);
        tdsysv.add(trsys);
        trsys.add(tbody);

        var trsys2 = DOM.create('tr');
        var tdsys2 = DOM.create('td');
        tdsys2.inText('execution time untill "DOM_READY"');
        var tdsysv2 = DOM.create('td', {'colSpan' : 2});
        tdsysv2.inText(Flint.profiler.dom + '(ms)');
        tdsys2.add(trsys2);
        tdsysv2.add(trsys2);
        trsys2.add(tbody);

        var trsys3 = DOM.create('tr');
        var tdsys3 = DOM.create('td');
        tdsys3.inText('execution time untill "WINDOW_ONLOAD"');
        var tdsysv3 = DOM.create('td', {'colSpan' : 2});
        tdsysv3.inText(Flint.profiler.load + '(ms)');
        tdsys3.add(trsys3);
        tdsysv3.add(trsys3);
        trsys3.add(tbody);

        tbody.add(table);
        table.add(Flint.profiler.box);
        Flint.profiler.treeTable = table;
        var close = DOM.create('input', {'class' : 'fl_profiler_close'});
        close.attr({'type': 'button','value': 'CLOSE'});
        close.add(Flint.profiler.box);
        var treeShow = DOM.create('a', {'class' : 'fl_profiler_tree_show'});
        treeShow.attr('href', 'javascript:void(0)');
        treeShow.inText('open DOMTree');
        var wrap = DOM.create('p');
        treeShow.add(wrap);
        wrap.add(Flint.profiler.box);
        treeShow.event('click', Flint.profiler.__domTreeShow);
        //create DOM tree
        var treeSpace = DOM.create('div', {'id' : 'fl_profiler_dom_tree_block'});
        Flint.profiler.domTree = treeSpace;
        Flint.profiler.treeShowBtn = treeShow;
        var loading = DOM.create('img', {'src' : Flint.config.site_url + Flint.config.script_path + 'fl_images/loader.gif', 'class' : 'fl_loading'});
        loading.add(treeSpace);
        Flint.profiler.loading = loading;
        treeSpace.add(Flint.profiler.box);
        Flint.profiler.close = close;
        Flint.profiler.show();
        if (FL.ua.IE6)FL.event.set(window, 'scroll', Flint.profiler.__boxScrollListener)
      },
      __domTreeShow  : function()
      {
        var tr = Flint.profiler.domTree, loading = Flint.profiler.loading;
        if (Flint.profiler.treeShowFlag == true)
        {
          this.inText('open DOMTree');
          tr.addStyle('display', 'none');
          if (Flint.profiler.tree != null) {
            Flint.profiler.tree.remove();
            Flint.profiler.tree.unevent('click', Flint.profiler.__domTreeToggleEventListner);
          }
          Flint.profiler.tree = null;
          Flint.profiler.treeShowFlag = false;
          return;
        }
        this.inText('close DOMTree')
        tr.addStyle('display', 'block');
        loading.addStyle('display', 'block');
        var doc = Flint._doc.getElementsByTagName('html')[0];
        var res = Flint.profiler.__nowDocParse(doc);
        var ul = DOM.create('ul', {'id' : 'fl_profiler_dom_tree'});
        loading.addStyle('display', 'none');
        ul.getNative().appendChild(res);
        ul.event('click', Flint.profiler.__domTreeToggleEventListner);
        Flint.profiler.tree = ul;
        ul.add(tr);
        Flint.profiler.treeShowFlag = true;
      },
      __domTreeToggleEventListner : function(ev)
      {
        var elm = Flint.utility.getEventElement(ev);
        Flint.event.capture(ev);
        if (elm.tagName.toLowerCase() != 'li' || elm.className == '')return;
        var flag = false;
        for (var i = 0, len = elm.childNodes.length; i < len; i++)
        {
          if (elm.childNodes[i].nodeType == 1 && elm.childNodes[i].tagName.toLowerCase() == 'ul')
          {
            if (elm.childNodes[i].style.display == 'block')
            {
              elm.childNodes[i].style.display = 'none';
              elm.className = 'attr_inner';
              if (!flag)
              {
                if (elm.parentNode != null)(elm.parentNode.lastChild == elm) ? elm.parentNode.removeChild(elm.parentNode.lastChild) : elm.parentNode.removeChild(elm.nextSibling);
                flag = true;
              }
              continue;
            }
            else
            {
              elm.childNodes[i].style.display = 'block';
              elm.className = 'attr_inner_close';
              if (!flag)
              {
                var txt = elm.firstChild.nodeValue;
                var end = document.createElement('li');
                end.appendChild(document.createTextNode(txt.replace(/^<([a-z]*?)\s?>??$/, '</$1>').replace(/\s(.*?)$/, '>')));
                (elm.parentNode.lastChild == elm) ? elm.parentNode.appendChild(end) : elm.parentNode.insertBefore(end, elm.nextSibling);
                flag = true;
              }
              continue;
            }
          }
        }
      },
      __nowDocParse : function(obj)
      {
        var res = document.createElement('li'), cacheTag = {}, att = obj.attributes, at = [];
        if (att != null && att.length != 0) {
          for (var a = 0, lenA = att.length; a < lenA; a++)
            at.push(att[a].nodeName.toLowerCase() + '="' + att[a].nodeValue + '"');
        }
        for (var i = 0, len = obj.childNodes.length; i < len; i++)
        {
          var ch = obj.childNodes[i];
          if (ch.nodeType == 3)
          {
            if (ch.nodeValue.replace(/[\s|\t|\n]/g, '') == '' || ch.nodeValue == null)continue;
            else ('text' in cacheTag) ? cacheTag['text'].push(ch.nodeValue) : cacheTag['text'] = [ch.nodeValue];
          }
          else if (ch.nodeType == 1)(ch.tagName.toLowerCase() in cacheTag) ? cacheTag[ch.tagName.toLowerCase()].push(arguments.callee(ch)) : cacheTag[ch.tagName.toLowerCase()] = [arguments.callee(ch)];
        }
        if (at.length == 0) var txt = (obj.tagName.toLowerCase() in Flint.profiler.noEndTag) ? '<' + obj.tagName.toLowerCase() +  ' />' : '<' + obj.tagName.toLowerCase() +  '>'
        else var txt = (obj.tagName.toLowerCase() in Flint.profiler.noEndTag) ? '<' + obj.tagName.toLowerCase() + ' ' + at.join(' ') + ' />' : '<' + obj.tagName.toLowerCase() + ' ' + at.join(' ') + '>';
        res.appendChild(document.createTextNode(txt));
        for (var p in cacheTag)
        {
          if (p == 'text')
          {
            var chn = document.createElement('ul');
            chn.style.display = 'none';
            var l = document.createElement('li');
            var inText = cacheTag['text'].join('').split(/\n/);
            for (var t = 0, lenT = inText.length; t < lenT; t++)
            {
              if(inText[t].replace(/[\t|\s]/g, '') == '')continue;
              (/script|style/.test(obj.tagName.toLowerCase())) ? l.appendChild(document.createTextNode(inText[t].replace(/[\t]/g, '　'))) : l.appendChild(document.createTextNode(inText[t].replace(/[\t]/g, '')));
              l.appendChild(document.createElement('br'));
            }
            chn.appendChild(l);
          }
          else
          {
            if (cacheTag[p].constructor == Array)
            {
              var chn = document.createElement('ul');
              chn.style.display = 'none';
              for (var li = 0, lenL = cacheTag[p].length; li < lenL; li++)chn.appendChild(cacheTag[p][li]);
            }
          }
          res.appendChild(chn);
          if (res.childNodes.length > 0)res.className = 'attr_inner';
        }
        return res;
      },
      __quicks : function(val)
      {
        var type = typeof val;
        alert('type : ' + type + '\n' + 'value : ' + val);
      },
      __boxScrollListener : function()
      {
        var sc = Flint.utility.getScrollPosition();
        Flint.profiler.box.addStyle('top', Flint.profiler.defaultTop + sc.y + 'px');
      },
      show : function(ev)
      {
        if (Flint.profiler.box == null)return;
        var FL = getInstance();
        Flint.profiler.layer = (Flint.profiler.layer === null) ? new DOM.layer() : Flint.profiler.layer;
        var page = FL.utility.getPageSize();
        Flint.profiler.box.addStyle({
          width : page.width * 2 / 3 + 'px',
          maxHeight : page.height * 2 / 3 + 'px',
          marginLeft  : -(page.width * 2 / 3 / 2) + 'px',
          overflow : 'auto'
        });
        if (FL.ua.IE) {
          Flint.profiler.box.addStyle('height', page.height * 2 / 3 + 'px');
        }
        var showFunc = function(){
         if (Flint.profiler.showFlag) {
           Flint.profiler.box.show();
         }
         else {
           Flint.profiler.box.show();
           Flint.profiler.showFlag = true;
         }
        }
        Flint.profiler.layer.show(showFunc, false);
        FL.event.set(Flint.profiler.close, 'click', Flint.profiler.hide);
        FL.event.remove(Flint.profiler.btn, 'click');
      },
      hide : function(ev)
      {
        if (Flint.profiler.box == null)return;
        var FL = getInstance();
        if (Flint.profiler.showFlag) {
          Flint.profiler.box.remove();
          Flint.profiler.showFlag = false;
        }
        else {
          Flint.profiler.box.hide();
        }

        FL.event.remove(Flint.profiler.close, 'click', arguments.callee);
        if (FL.ua.IE6)FL.event.remove(window, 'scroll', Flint.profiler.__boxScrollListener);
        FL.event.set(Flint.profiler.btn, 'click', Flint.profiler.show);
        Flint.profiler.treeShowFlag = false;
        Flint.profiler.layer.hide();
      }
    },
    __ua : function(){
      var res = {};
      var ua = navigator.userAgent.toLowerCase();
      res.IE = (ua.indexOf('msie') > 0 && !window.opera) ? true : false;
      res.IE7 =( !window.opera && ua.indexOf('msie 7.0') > 0) ? true : false;
      res.IE8 = (!window.opera && ua.indexOf('msie 8.0') > 0 && ua.indexOf('trident') > 0) ? true : false;
      res.IE9 = (!window.opera && ua.indexOf('msie 9.0') > 0 && ua.indexOf('trident') > 0) ? true : false;
      res.IE10 = (!window.opera && ua.indexOf('msie 10') > 0 && ua.indexOf('trident') > 0) ? true : false;
      res.IE6 = (!window.opera && ua.indexOf('msie 6.0') > 0) ? true : false;
      res.IE8S = (res.IE8 && typeof Flint._doc.documentMode != 'undefined' && Flint._doc.documentMode === 8) ? true : false;
      res.Firefox = (ua.indexOf('gecko') > 0 && ua.indexOf('khtml') === -1) ? true : false;
      res.Safari = (ua.indexOf('safari') > 0 && ua.indexOf('applewebkit') > 0 && ua.indexOf('chrome') == -1) ? true : false;
      res.Opera = (ua.indexOf('opera') !== -1 && window.opera) ? true : false;
      res.GoogleChrome = (ua.indexOf('chrome') !== -1) ? true : false;
      res.Lunascape = (ua.indexOf('lunascape') !== -1) ? true : false;
      res.Sleipnir = (ua.indexOf('sleipnir') !== -1) ? true : false;
      res.Win = (ua.indexOf('windows') !== -1) ? true : false;
      res.Mac = (ua.indexOf('mac') !== -1) ? true : false;
      res.Linux = (ua.indexOf('linux') !== -1) ? true : false;
      // check Browser version
      res.IEV = (!res.IE) ? null : parseFloat(ua.replace(/(.*?)msie\s([0-9\.]);(.*?)/, '$2'));
      res.FirefoxV = (!res.Firefox) ? null : parseFloat(ua.replace(/(.*?)firefox\/([0-9])\.([0-9])(.*?)/, '$2.$3'));
      res.OperaV = (!res.Opera) ? null : ua.replace(/(.*?)opera[\/|\s]([0-9\.])(.*?)/, '$2');
      res.GoogleChromeV = (!res.GoogleChrome) ? null : parseFloat(ua.replace(/(.*?)chrome\/([0-9])\.([0-9])(.*?)/, '$2.$3'));
      var sfV = (!res.Safari) ? null : ua.replace(/applewebkit\/([0-9])\.(.*?)/, '$2').substring(0, 2);
      if (sfV == null) res.SafariV = null;
      else {
        switch (true) {
          case (sfV == '52'):res.SafariV = ua.replace(/(.*?)version\/([0-9])\.([0-9])(.*?)/, '$2.$3');break;
          case (sfV == '41'):res.SafariV = '2.0';break;
          case (sfV == '31'):res.SafariV = '1.3';break;
          case (sfV == '12'):res.SafariV = '1.2';break;
          case (sfV == '10'):res.SafariV = '1.1';break;
          case (sfV == '85'):res.SafariV = '1.0';break;
          default:res.SafariV = 'unrecognized version of Safari';break;
        }
      }
      // game machine user agent
      res.Wii = (ua.indexOf('nintendo wii') !== -1) ? true : false;
      res.GameBoy = (ua.indexOf('gameboy') !== -1) ? true : false;
      res.NintentdoDS = (ua.indexOf('nitro') !== -1) ? true : false;
      res.PSP = (ua.indexOf('psp') !== -1) ? true : false;
      res.PlayStation2 = (ua.indexOf('ps2') !== -1 && ua.indexOf('bb navigator') !== -1) ? true : false;
      res.PlayStation3 = (ua.indexOf('playstation 3') !== -1) ? true : false;
      // PDA user agent
      res.iPod = (ua.indexOf('ipod') !== -1) ? true : false;
      res.iPnone = (ua.indexOf('iphone') !== -1) ? true : false;
      res.iPhone3G = (res.iPhone === true && ua.indexOf('applewebkit/525') !== -1) ? true : false;
      // rendaring mode (standard or quirks)
      res.compatMode = (Flint._doc.compatMode == 'CSS1Compat') ? 'standard' : 'quirks';
      return res;
    },
    __zIndexer : function(){
      (function(){
        var zIndexValue;
        DOM.search('tag', '*', Flint._doc.body).foreach(function(){
          if (this.nodeType !== 1)return; // guard IE
           zInexValue = this.readStyle('z-index');
          if ((zIndexValue == 'auto' || zIndexValue == 'inherit') && zIndexValue <= Flint.currentIndex)Flint.currentIndex = zIndexValue;
        });
      })();
      var thisClass = function()
      {
        this.getCurrentIndex = function()
        {
          return Flint.currentIndex;
        }
        this.getNextHigherIndex = function()
        {
          return ++(Flint.currentIndex);
        }
        this.setHighestIndex = function(elm)
        {
          elm.style.zIndex = ++Flint.currentIndex;
        }
      }
      Flint.__controller.prototype.zIndexer = Flint.zIndexer = new thisClass();
    },
    sharedParams: {},
    parameter : {
      set : function(name, value) {
        Flint.sharedParams[name] = value;
      },
      get : function(name) {
        return (Flint.sharedParams.hasOwnProperty(name)) ? Flint.sharedParams[name] : null;
      }
    },
    utility : {
      pageWidth : document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth,
      pageHeight : document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight,
      absPos : function(target){
        if (target.getBoundingClientRect)
        {
          var p = target.getBoundingClientRect();
          var sc = Flint.utility.getScrollPosition();
          return { x : p.left - sc.x, y : p.top - sc.y};
        }
        var position = {x : 0, y : 0};
        var getStyle = function(elm, propertyCameled, property){
          var elm = elm;
          if (elm.currentStyle) {
            switch (elm.currentStyle[propertyCameled])
            {
              case 'thin': return 0; break;
              case 'medium': return 0; break;
              case 'thick': return 0; break;
              default: return elm.currentStyle[propertyCameled]; break;
            }
          }
          else
            if (Flint._win.getComputedStyle || Flint._doc.defaultView.getComputedStyle) {
              var gCS = Flint._win.getComputedStyle || Flint._doc.defaultView.getComputedStyle;
              var nowStyle = gCS(elm, '');
              return nowStyle.getPropertyValue(property);
            }
        }
        while (target) {
          position.x += target.offsetLeft;
          position.y += target.offsetTop;
          target = target.offsetParent;
          if ((target) && Flint.ua.IE) {
            position.x += (parseInt(getStyle(target, 'borderLeftWidth', 'border-left-width') || 0));
            position.y += (parseInt(getStyle(target, 'borderTopWidth', 'border-top-width')) || 0);
          }
        }
        if (Flint.ua.Firefox) {
          var body = Flint._doc.body;
          position.x += 2 * (parseInt(getStyle(body, 'borderLeftWidth', 'border-left-width')) || 0);
          position.y += 2 * (parseInt(getStyle(body, 'borderTopWidth', 'border-top-width')) || 0);
        }
        return position;
      },
      getScrollPosition : function(){
        var scroll = {
          y : Flint._doc.body.scrollTop || Flint._doc.documentElement.scrollTop,
          x : Flint._doc.body.scrollLeft || Flint._doc.documentElement.scrollLeft
        }
        return scroll;
      },
      getMousePosition : function(eObj){
        var eObj = eObj, sc = Flint.utility.getScrollPosition();
        return (Flint.ua.IE) ? {x : eObj.clientX + sc.x, y : eObj.clientY + sc.y} : {x : eObj.pageX, y : eObj.pageY};
      },
      getBodyHeight : function(){
        return (Flint.loaded) ? Math.max(Flint._doc.body.clientHeight, Flint._doc.body.scrollHeight, Flint._doc.documentElement.scrollHeight, Flint._doc.documentElement.clientHeight, 0) : null;
      },
      getEventElement : function(eObj){
        var eObj = eObj;
        return eObj.srcElement || eObj.target;
      },
      getEventObject : function(eObj){
        return eObj || window.event;
      },
      getPageSize : function(){
        var size = {
          width: Flint._doc.documentElement.clientWidth || Flint._doc.body.clientWidth || Flint._doc.body.scrollWidth,
          height: Flint._doc.documentElement.clientHeight || Flint._doc.body.clientHeight || Flint._doc.body.scrollHeight
        }
        return size;
      },
      getWindowSize : function() {
        return {width : screen.width, height : screen.height};
      },
      getObjectCount : function(json) {
        var cn = 0;
        for (var i in json)cn++;
        return cn;
      }
    },
    event : {
      set : function(target, eventType, listener, bind)
      {
        var target = (target.extended) ? target.element : target, listener = listener;
        var event = (Flint.ua.IE && !target.addEventListener) ? 'on' + eventType : eventType;
        var bind = (bind) ? bind : false;
        if (eventType == 'domReady') {
          Flint.DOMFuncs.push([Flint._doc, listener, bind]);
        }
        else if (eventType == 'load' && target == window) {
            Flint.onLoadFunc.push([listener, bind, 0]);
        }
        else
        {
          if (target.addEventListener)
          {
            var wrapped = function(ev) {(!bind) ? listener.call(Flint.controller, ev) : listener.call(DOM.ex(target) , ev);}
            target.addEventListener(event, wrapped, false);
            wrapped.__listenerId = listener.__listenerId = 'lis_' + ++Flint.attachCount;
          }
          else if (target.attachEvent)
          {
            var wrapped = function(ev){
              var eObj = Flint.event.__margeDOM2Event(window.event);
              (!bind) ? listener.call(Flint.controller, eObj) : listener.call(DOM.ex(target), eObj);
            }
            target.attachEvent(event, wrapped);
            wrapped.__listenerId = listener.__listenerId = 'lis_' + ++Flint.attachCount;
          }
          else target['on' + eventType] = listener(ev);
          Flint.registedFunc.push([target, eventType, wrapped, listener]);
        }
      },
      remove : function(target, eventType, listener)
      {
        var event = (target.removeEventListener) ? eventType : 'on' +  eventType;
        var fn = Flint.registedFunc;
        if (!listener)
        {
          for (var i = (fn.length - 1); i == 0; i--)
          {
            if (fn[i][0] == target && fn[i][1] == eventType)
            {
              if (window.removeEventListener) fn[i][0].removeEventListener(event, fn[i][2], false);
              else if (window.detachEvent) target.detachEvent(event, fn[i][2]);
              else target['on' + eventType] = null;
              fn.splice(i, 1);
            }
          }
        }
        else
        {
          for (var i = fn.length - 1; i > 0; i--) {
            if (fn[i][0] == target && fn[i][1] == eventType && fn[i][3] == listener) {
              if (window.removeEventListener) {
                target.removeEventListener(event, fn[i][2], false);
              }
              else
                if (window.detachEvent) {
                  target.detachEvent(event, fn[i][2]);
                }
                else {
                  target['on' + eventType] = null;
                }
              fn.splice(i, 1);
              break;
            }
          }
        }
      },
      deleteAllEvent : function()
      {
        var fn = Flint.registedFunc;
        if (fn.length  === 0)return;
        for (var i = 0, len = fn.length; i < len; i++) {
          (Flint.ua.IE) ?  fn[i][0].detachEvent('on' + fn[i][1], fn[i][2]) : fn[i][0].removeEventListener(fn[i][1], fn[i][2], false);
        }
      },
      cancelDefault : function(ev)
      {
        (Flint.ua.IE) ? ev.returnValue = false : ev.preventDefault();
      },
      capture : function(ev)
      {
        (Flint.ua.IE) ? ev.cancelBubble = true : ev.stopPropagation();
      },
      dragCancel : function(ev)
      {
        (Flint.ua.IE) ? ev.srcElement.ondrag = function(){return false;} : ev.preventDefault();
      },
      __margeDOM2Event : function(ev) //IE only
      {
        ev.preventDefault = function(){
          ev.returnValue = false;
        }
        ev.stopPropagation = function(){
          ev.cancelBubble = true;
        }
        return ev;
      },
      __setDOMEvent : function(target, listener, bind, opt)
      {
        if(!Flint.DOMReady) Flint.DOMFuncs.push([target, listener, bind]);
      },
      __execDOM : function()
      {
        Flint.DOMReady = true;
        //if (Flint.ua.IE6)Flint.__fixIE.apply();
        //autoload
        if (Flint.config.autoload_Helper.length !== 0)
        {
          var help = Flint.config.autoload_Helper;
          for (var h = 0, len = help.length; h < len; h++)Flint.load.helper(help[h]);
        }

        var listeners = Flint.DOMFuncs;
        for (var k = 0; k < listeners.length; k++) (listeners[k][2] === true) ? listeners[k][1].call(thisClass) : listeners[k][1].call(listeners[0]);
        Flint.__domTime = new Date().getTime();
        Flint.profiler.dom = (Flint.__domTime - Flint.__initialTime);
      },
      __execLoad : function()
      {
        var listeners = Flint.onLoadFunc;
        for (var l = 0, len = listeners.length; l < len; l++)
        {
          if (listeners[l][2] === 1)
          {
            var f = new listeners[l][0];
            if (f.__construct || f.hasOwnProperty('__construct')){
            	f.__construct.call(f);
            }
          }
          else new listeners[l][0];
        }
        Flint.__loadTime = new Date().getTime();
        Flint.profiler.load = (Flint.__loadTime - Flint.__initialTime);
        if (typeof Flint.controller['__destruct'] == 'function')Flint.controller['__destruct'].call();
      },
      __DOM2Event : function(ev, target) {
    	  this.extended = true;
    	  this.ev = ev || window.event;
    	  this.target = (Flint.ua.IE) ? ev.srcElement : ev.target;
    	  this.currentTarget = (Flint.ua.IE) ? target : ev.currentTraget;
      }
    },
    load :{
      config : function(loadFunc){
        if (typeof loadFunc == 'object') {
          for (var k = 0, len = loadFunc.length; k < len; k++)
            arguments.callee(loadFunc[k]);
        }
        else
          if (typeof loadFunc == 'string') {
            if (loadFunc in Flint.loadedApp)return;
            var __loadpath = 'config/' + loadFunc;
            if (!Flint.DOMReady) {
              var s = '<script type="text\/javascript" src="' + __loadpath + '.js"><\/script>';
              Flint._doc.write(s);
            }
            else {
              var s = Flint._doc.createElement('script');
              s.src = __loadpath + '.js';
              s.type = 'text/javascript';
              Flint._doc.getElementsByTagName('head')[0].appendChild(s);
            }
            Flint.loadedApp[loadFunc] = loadFunc;
          }
      },
      helper : function(loadFunc){
        if (typeof loadFunc == 'object') {
          for (var k = 0, len = loadFunc.length; k < len; k++)
            arguments.callee(loadFunc[k]);
        }
        else
          if (typeof loadFunc == 'string') {
            if (loadFunc in Flint.loadedApp)return;
            if (Flint.hasOwnProperty(loadFunc))
            {
              if (typeof window.Helper == 'undefined')window.Helper = {};
              Flint[loadFunc]();
            }
            else if (Flint.hasOwnProperty(loadFunc + 'Helper'))
            {
              if (typeof window.Helper == 'undefined')window.Helper = {};
              Flint[loadFunc + 'Helper']();
            }
            else {
              var __loadpath = (Flint.config.routingMode == 'segment') ? Flint.config.site_url + Flint.config.script_path  + 'helpers/' + loadFunc : Flint.config.script_path  + 'helpers/' + loadFunc;
              if (!Flint.DOMReady) {
                var s = '<script type="text\/javascript" src="' + __loadpath + '.js"><\/script>';
                Flint._doc.write(s);
              }
              else {
                var s = Flint._doc.createElement('script');
                s.src = __loadpath + '.js';
                s.type = 'text/javascript';
                Flint._doc.getElementsByTagName('head')[0].appendChild(s);
              }

            }
            Flint.loadedApp[loadFunc] = loadFunc;
          }
      },
      library : function(loadFunc, bindName){
        if (typeof loadFunc == 'object') {
          for (var k = 0, len = loadFunc.length; k < len; k++)
            arguments.callee(loadFunc[k]);
        }
        else
          if (typeof loadFunc == 'string') {
            if (loadFunc in Flint.loadedApp)return;
              var __loadpath = Flint.config.site_url + Flint.config.script_path  + 'libraries/' + loadFunc;
            if (!Flint.DOMReady) {
              var s = '<script type="text\/javascript" src="' + __loadpath + '.js' + ((bindName) ? '?bind=' + bindName : '') + '"><\/script>';
              Flint._doc.write(s);
            }
            else {
              var s = Flint._doc.createElement('script');
              s.src = __loadpath + '.js' + ((bindName) ? '?bind=' + bindName : '');
              s.type = 'text/javascript';
              Flint._doc.getElementsByTagName('head')[0].appendChild(s);
            }
            Flint.loadedApp[loadFunc] = loadFunc;
          }
      },
      model : function(loadFunc, bindName)
      {
        if (typeof loadFunc == 'object') {
          for (var k = 0, len = loadFunc.length; k < len; k++)
            arguments.callee(loadFunc[k]);
        }
        else
          if (typeof loadFunc == 'string') {
            if (loadFunc in Flint.loadedApp)return;
              var __loadpath = Flint.config.site_url + Flint.config.script_path + 'models/' + loadFunc;
            if (!Flint.DOMReady) {
              var s = '<script type="text\/javascript" src="' + __loadpath + '.js' + ((bindName) ? '?bind=' + bindName : '') + '"><\/script>';
              Flint._doc.write(s);
            }
            else {
              var s = Flint._doc.createElement('script');
              s.src = __loadpath + '.js' + ((bindName) ? '?bind=' + bindName : '');
              s.type = 'text/javascript';
              Flint._doc.getElementsByTagName('head')[0].appendChild(s);
            }
            Flint.loadedApp[loadFunc] = loadFunc;
          }
      },
      css : function(loadCss, media)
      {
        if (loadCss in Flint.loadedCss)return;
        var media = (media) ? media : '';
        var __loadpath = (Flint.config.routingMode == 'segment') ? Flint.config.site_url + Flint.config.script_path + 'fl_css/' + loadCss : Flint.config.script_path  + 'fl_css/' + loadCss;
        if (!Flint.loaded && !Flint.DOMReady) {
          var l = '<link rel="stylesheet" type="text\/css" href="' + __loadpath + '.css" ';
          if (media != '') l += 'media="' + media + '"';
          l += ' \/>';
          Flint._doc.write(l);
        }
        else
        {
          var l = Flint._doc.createElement('link');
          l.type = 'text/css';
          l.href = __loadpath + '.css';
          if (media != '') l.setAttribute('media');
          l.rel = 'stylesheet';
          var target = Flint._doc.getElementsByTagName('head')[0];
          target.appendChild(l);
        }
        Flint.loadedCss[loadCss] = loadCss;
      },
      view : function(url, target)
      {
        var res;
        if (!('ajax' in Flint.loadedAp))Flint.load.ajax(Flint);
        var url = Flint.config.site_url + url;
        Flint.ajax.get(url, function(obj){
          res = obj.responsteText;
        });
        (target) ? target.innerHTML = res : Flint._doc.write(s);
      },
      ajax : function(obj){
        if (obj) {
          obj.ajax = new Flint.__ajax();
        }
        else {
          Flint.__controller.prototype['ajax'] = new Flint.__ajax();
        }
      },
      gmap : function(){
        if (Flint.config.useGmap === false)
        {
          alert('if you use google map, please set "useGmap" is "true" and set API key.');
          return;
        }
        if ('gmap' in Flint.loadedApp)return;
        Flint.gmapSet();
        Flint.__controller.prototype['gmap'] = Flint.Gmap;
        Flint.loadedApp['gmap'] = 'gmap';
      }
    },
    parser : {
      XML : function(ajax)
      {
        if (ajax.responseXML != null)var xmlDoc = ajax.responseXML;
        else {
            if (window.ActiveXObject) {
              var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
              xmlDoc.async = false;
              xmlDoc.loadXML(ajax.responseText);
            }
            else if (window.DOMParser) var xmlDoc =  (new DOMParser()).parseFromString(ajax.responseText, "application/xml");
            else return;
        }
        var xml = xmlDoc.documentElement;
        var loopParse = function(obj)
        {
          var res = {}, cacheTag = {};
          var ob = {}, att = obj.attributes;
          if (att != null && att.length != 0) {
            for (var a = 0, lenA = att.length; a < lenA; a++) {
              ob[att[a].nodeName.toLowerCase()] = att[a].nodeValue;
            }
            res['_attr'] = ob;
          }

          for (var i = 0, len = obj.childNodes.length; i < len; i++)
          {
            var ch = obj.childNodes[i];
            if (ch.nodeType == 3)
            {
              if (ch.nodeValue.replace(/[\s|\t|\n]/g, '') == '' || ch.nodeValue == null)continue;
              else return ch.nodeValue;
            }
            else if (ch.nodeType == 1)
            {
              (ch.tagName in cacheTag) ? cacheTag[ch.tagName].push(arguments.callee(ch)) : cacheTag[ch.tagName] = [arguments.callee(ch)];
            }
          }
          for (var p in cacheTag)(cacheTag[p].constructor == Array && cacheTag[p].length == 1) ? res[p] = cacheTag[p][0] : res[p] = cacheTag[p];
          return res;
        }
        return loopParse(xmlDoc);
      },
      XHTML : function(ajax)
      {
        if (ajax.responseXML != null)var xmlDoc = ajax.responseXML;
        else {
            if (window.ActiveXObject) {
              var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
              xmlDoc.async = false;
              xmlDoc.loadXML(ajax.responseText);
            }
            else if (window.DOMParser) var xmlDoc =  (new DOMParser()).parseFromString(ajax.responseText, "application/xhtml+xml");
            else return;
        }
        var xhtml = xmlDoc.documentElement;
        var loopParse = function(obj)
        {
          var res = {}, cacheTag = {};
          var ob = {}, att = obj.attributes;
          if (att != null && att.length != 0) {
            for (var a = 0, lenA = att.length; a < lenA; a++) {
              ob[att[a].nodeName.toLowerCase()] = att[a].nodeValue;
            }
            res['_attr'] = ob;
          }
          for (var i = 0, len = obj.childNodes.length; i < len; i++)
          {
            var ch = obj.childNodes[i];
            if (ch.nodeType == 3)
            {
              if (ch.nodeValue.replace(/[\s|\t|\n]/g, '') == '' || ch.nodeValue == null)continue;
              else {
                ('text' in cacheTag) ? cacheTag['text'].push(ch.nodeValue.replace(/[\t|\n]/g, '')) : cacheTag['text'] = [ch.nodeValue.replace(/[\t|\n]/g, '')];
              }
            }
            else if (ch.nodeType == 1)
            {
              (ch.tagName.toLowerCase() in cacheTag) ? cacheTag[ch.tagName.toLowerCase()].push(arguments.callee(ch)) : cacheTag[ch.tagName.toLowerCase()] = [arguments.callee(ch)];
            }
          }
          for (var p in cacheTag)(cacheTag[p].constructor == Array && cacheTag[p].length == 1) ? res[p] = cacheTag[p][0] : res[p] = cacheTag[p];
          return res;
        }
        return loopParse(xhtml);
      },
      CSV : function(ajax, first, delimiter, escapable, nl)
      {
        if (!ajax || !ajax.responseText || ajax.responseText == null)return;
        var delimiter = (delimiter) ? delimiter : ',';
        var escapable = (escapable) ? escapable : '"';
        var nl = (nl) ? new RegExp(nl) : /\n/;
        var first = (first) ? first : false;
        var csv = ajax.responseText.split(nl), res = [];
        csv.pop();
        for (var i = 0, len = csv.length; i < len; i++)
        {
          if (first)
          {
            if (i == 0)continue;
          }
          var esc = csv[i].replace(escapable, '');
          esc = esc.replace(/\r\n$/, '');
          esc = esc.replace(/\n$/, '');
          esc = esc.replace(/\r$/, '');
          var sp = esc.split(delimiter);
          res.push(sp);
        }
        return res;
      }
    },
    image : {
    	preLoad : function(path) {
	    	if (typeof path == 'string') {
	    		var img = new Image();
	    		img.src = path;
	    		Flint.loadedImage.push(img);
	    	}
	    	else if (typeof path == 'object') {
	    		for (var i = 0; i < path.length; i++) {
	    			arguments.callee(path[i]);
	    		}
	    	}
    },
/*      preLoad : function(path, retElm) {
        if (typeof path == 'string') {
          var toElm = (retElm) ? true : false;
          var img = (!toElm) ? new Image() : DOM.create('image');
          img.onerror = function() {throw Error('image was\'t loaded' + path)};
          img.src = path;
          if (toElm)return img;
        }
        else if (typeof path == 'object' && path.constructor == Array) {
          var res = [];
          var toElm = (retElm) ? true : false;
          for (var i = 0; i < path.length; i++)
          {
            if (toElm)res.push(Flint.image.preLoad(path[i], toElm));
            else Flint.image.preLoad(path[i], toElm);
          }
          if (toElm)return res;
        }
      },
 */     getDefaultSize : function(img) {
        if (img.naturalWidth) {
          return { width : img.naturalWidth, height : img.naturalHeight };
        }
        else if (img.runtimeStyle){
          var oldW = img.runtimeStyle.width, oldH = img.runtimeStyle.height;
          img.runtimeStyle.width ='auto';
          img.runtimeStyle.height = 'auto';
          var def = {width : img.width, height : img.height};
          img.runtimeStyle.width = oldW;
          img.runtimeStyle.height = oldH;
          return def;
        }
        else {
        	return { width : img.width, height : img.height};
        }
      }
    },
    ui : {
      __draggingStack : {},
      drag: function(target, mode, opt){
        DOM.draggable(target, mode, opt);
        Flint.ui.__draggingStack[target.__eid] = target;
        return target;

      },
      inArea : function(mouse, target)
      {
        if (!mouse || !target)return false;
        var elm = (target.extended) ? target : DOM.__setExtends(target);
        var dimension = elm.absDimension();
        var scl = Flint.utility.getScrollPosition();
        var position = Flint.utility.absPos(elm);
        if (mouse.x + scl.x >= position.x && mouse.x + scl.x <= position.x + dimension.width
          && mouse.y + scl.y >= position.y && mouse.y + scl.y <= position.y + dimension.height)
        {
          return true;
        }
        else return false;
      },
      inAbsoluteArea : function(mouse, dimensition)
      {
        if (!dimension)return false;
        var dim = dimension;
        var scl = Flint.utility.getScrollPosition();
        if (mouse.x + scl.x >= dim.left && mouse.x + scl.x <= dim.left + dim.width
          && mouse.y + scl.y >= dim.top && mouse.y + scl.y <= dim.top + dim.height)
        {
          return true;
        }
        else return false;
      },
      inRect : function(obj1, obj2, opt) {
        var offset = {
          top : (opt && opt.top) ? opt.top : 0,
          left : (opt && opt.left) ? opt.left : 0,
          right : (opt && opt.right) ? opt.right : 0,
          bottom : (opt && opt.bottom) ? opt.bottom : 0
        }
        var dim1 = obj1.absDimension(), dim2 = obj2.absDimension();
        var pos1 = Flint.utility.absPos(obj1), pos2 = Flint.utility.absPos(obj2);
        if (pos1.x + dim1.width < pos2.x + offset.left|| pos1.x > pos2.x + dim2.width - offset.right || pos1.y + dim1.height < pos2.y + offset.top || pos1.y > pos2.y + dim2.height - offset.bottom)return false;
        else return true;
      }
    },
    init : function()
    {
      //recognize <canvas> for IE
      if (this.ua.IE)Flint._doc.createElement('canvas');
      var path;
      if(Flint.config.useGmap == true){
        var gmapapi = Flint.config.GmapAPI_path + Flint.config.GmapAPIkey;
        Flint._doc.write('<script type="text\/javascript" src="' + gmapapi + '"><\/script>');
      }
      if (Flint.config.useProfiler == true)
      {
        window.debug = function(name, variable)
        {
          if (!variable)return;
          var FL = getInstance(), name = (name) ? name : '', type = typeof variable, value = '';
          switch (type)
          {
            case 'string': value = 'String(' + variable.length + ') : ' + Flint.__htmlspecialchars(variable); break;
            case 'number': value = 'Number : ' + variable; break;
            case 'function': value = 'constructor : ' + variable; break;
            case 'object':
              //array object
              if (variable.constructor == Array)
              {
                type = 'Array';
                if (variable.toSource) value = variable.toSource();
                else {
                  value = [];
                  for (var a = 0, len = variable.length; a < len; a++) value.push(a + ' => ' + valiable[a] + "\n");
                  value = value.join('');
                }
              }
              //element object
              else if (variable.nodeType)
              {
                switch (variable.nodeType)
                {
                  case 1: type = 'ELEMENT_NODE'; value = ['tagName : ' + variable.tagName + "\n"]; value = value.join('');break;
                  case 2: type = 'ATTRIBUTE_NODE'; value = ''; break;
                  case 3: type = 'TEXT_NODE'; value = variable.nodeValue; break;
                  case 4: type = 'CDATA_SECTION_NODE'; value = ''; break;
                  case 5: type = 'ENTITY_REFERENCE_NODE'; value = ''; break;
                  case 6: type = 'ENTITY_NODE'; value = ''; break;
                  case 7: type = 'PROCESSING_INSTRUCTION_NODE'; value = ''; break;
                  case 8: type = 'COMMENT_NODE'; value = ''; break;
                  case 9: type = 'DOCUMENT_NODE'; value = ''; break;
                  case 10: type = 'DOCUMENT_TYPE_NODE'; value = ''; break;
                  case 11: type = 'DOCUMENT_FRAGMENT_NODE'; value = ''; break;
                  case 12: type = 'NOTATION_NODE'; value = ''; break;
                  default: type = 'undefined'; value = 'undefined'; break;
                }
              }
              //object object
              else{
                if (variable == window)
                {
                  type = 'Window object';
                  value = '';
                }
                else if (variable == document.documentElement)
                {
                  type = 'document.documentElement object';
                  value = '';
                }
                else
                {
                  type = 'object object';
                  if (variable.toSource) value = variable.toSource();
                  else
                  {
                    value = [];
                    for (var p in variable) value.push(p + ' : ' + variable[p] + '\n');
                    value = value.join('');
                  }
                }
              }
            break;
          }
          Flint.profiler.values.push([name, type, value]);
        }
        window.quickDebug = function(val){Flint.profiler.__quicks(val);};
      }
      else
      {
        window.debug = function(name, value){return;};
        window.quickDebug = function(val){return;};
      }
      if (Flint.config.autoload_Library.length != 0)
      {
        var lib = Flint.config.autoload_Library;
        for (var l = 0, len = lib.length; l < len; l++)
        {
          var s = '<script type="text\/javascript" src="' + Flint.config.site_url + Flint.config.script_path + 'libraries/' + lib[l] + '.js"><\/script>';
          document.write(s);
        }
      }

      if (Flint.config.autoload_Models.length != 0)
      {
        var mod = Flin.config.autoload_Models;
        for (var m = 0, len = mod.length; m < len; m++)
        {
          var s = '<script type="text\/javascript" src="' + Flint.config.site_url + Flint.config.script_path + 'libraries/' + mod[m] + '.js"><\/script>';
          document.write(s);
        }
      }
      //routing mode
      switch (Flint.config.routingMode) {
        case 'none' :
          window.FL = new Flint.__controller();
          FL.ajax = new Flint.__ajax();
          FL.createClass = function(bool){
            var flag = (bool) ? bool : false;
            var newClass = function(){
              if (flag)
              {
                this.load = Flint.load;
                this.event = Flint.event;
                this.ua = Flint.ua;
                this.utility = Flint.utility;
                this.ajax = FL.ajax;
              }
              this.__construct.apply(this, arguments);
            };
            return newClass;
          }
          break;
        case 'default':
          var load = Flint._doc.getElementsByTagName('script');
          for (var i = 0; i < load.length; i++) {
            if (/flint\.js/.test(load[i].src)) {
              Flint.exec = load[i].id;
              var sliced = load[i].src.split('flint.js?load=');
              path = sliced[0];
              var lib = sliced[1];
              Flint.controllerName = sliced[1];
              Flint._doc.write('<script type="text\/javascript" src="' + path + 'controllers/' + lib + '.js"><\/script>');
            }
            else continue;

          }
          break;
        case 'query':
          var parameters = location.search.substring(1);
          var load = parameters.split('&');
          for (var p = 0; p < load.length; p++)
          {
            var splitPoint = load[p].indexOf('=');
            if (splitPoint > 0)
            {
              var splited = load[p].split('=');
              switch (splited[0])
              {
                case 'load':
                Flint._doc.write('<script type="text\/javascript" src="' + Flint.config.site_url + Flint.config.script_path + 'controllers/' + splited[1] + '.js"><\/script>');
                Flint.controllerName = splited[1];
                break;
                case 'method':
                Flint.exec = splited[1];
                break;
                default :
                Flint.methodArguments[splited[0]] = Flint.__htmlspecialchars(decodeURIComponent(splited[1]), 'ENT_QUOTES');
                break;
              }
            }
            else
            {
              if (Flint.config.debugMode)return alert('undefined load controller.');
            }
          }
          break;
        case 'segment':
          var load = location.href.replace(Flint.config.site_url, '');
          if (load == '') {
            var params = [Flint.config.defaultController, ''];
            Flint.controllerName = params[0];
          }
          else {
            var params = load.split('/');
            Flint.controllerName = params[0];
          }
          Flint._doc.write('<script type="text\/javascript" src="' + Flint.config.site_url + Flint.config.script_path + 'controllers/' + params[0] + '.js"><\/script>');
          Flint.exec = (params[1] && params[1] != '') ? params[1] : '';
          var paramCount = 2;
          while (params[paramCount])
          {
            Flint.methodArguments[paramCount - 2] = params[paramCount];
            paramCount++;
          }
          break;
      }
      (Flint.ua.IE) ? window.attachEvent('onunload', Flint.__evElmClean) : window.addEventListener('unload', Flint.__evElmClean, false);
      var loadfunc = function()
      {
        Flint.loaded = true;
        if(Flint.config.useProfiler)Flint.profiler.set();
      }
      Flint.onLoadFunc.push([loadfunc, false, 0]);
      if (window.addEventListener)
      {
        window.addEventListener('load', Flint.event.__execLoad, false);
      }
      else if (window.attachEvent)
      {
        window.attachEvent('onload', Flint.event.__execLoad);
      }
      else
      {
        window.onload = Flint.event.__execLoad;
      }
      //DOMReadyEvent set
      if (Flint.DOMReady === true)
      {
        Flint.__systemTime = new Date().getTime();
        return;
      }
      if (Flint.ua.Safari || Flint.ua.IE)
      {
        if (window.attachEvent) {
          Flint._doc.attachEvent('onreadystatechange', function(){
            Flint.event.__execDOM();
            Flint._doc.detachEvent('onreadystatechange', this);
          })
        }
        else {
          var timer = setInterval(function(){
            if (Flint._doc.readyState.match(/loaded|complete/)) {
              Flint.event.__execDOM();
              clearInterval(timer);
            }
          }, 5);
        }
      }
      else
      {
        (Flint.ua.Firefox || Flint.ua.Opera || Flint.ua.GoogleChrome) ? Flint._doc.addEventListener("DOMContentLoaded", Flint.event.__execDOM, false) : Flint.event.set(window, 'load', Flint.event.__execDOM, true);
      }
      Flint.__systemTime = new Date().getTime();
    },
    //controller base class
    __controller : function(){
        this.config = Flint.config;
        this.parameter = Flint.parameter;
    },
    //extend class
    __extend : function(extArr)
    {
      var func = function(){
        this.config = Flint.config;
        this.parameter = Flint.parameter;
          for (var i = 0, len = extArr.length; i < len; i++) {
          if (extArr[i] == 'ajax') {
            this['ajax'] = new Flint.__ajax();
          }
          else
            this[extArr[i]] = Flint[extArr[i]];
        }
      }
      return func;
    },
    // get attach name for library or models
    getExecuteName : function(func, fromQuery)
    {
      var execName, targetScript;
      var name = Flint.__getRealName(func);
      if (fromQuery && fromQuery === true)
      {
        var scripts = Flint._doc.getElementsByTagName('script');
        for (var i = scripts.length - 1; i >= 0; i--) {
          if (!scripts[i].src)continue;
          if (scripts[i].src.indexOf(name) > 0) {
            targetScript = scripts[i].src;
            break;
          }
        }
        if (!targetScript || targetScript.indexOf('?') === -1 || targetScript.indexOf('bind') === -1)return name;
        execName = targetScript.replace(/(.*?)\?bind=([a-zA-Z$_][a-zA-Z0-9$_]+)/, '$2');
        return execName;
       }
       return name;
    },
    // get real function name
    __getRealName : function(func)
    {
      if (func.name) {
        return func.name;
      }
      else {
        var name = func.toString();
        return name.substring(9, name.indexOf('('));
      }
    },
    //uri module
    uri : {
      segment : function(segmentNum, defaultValue)
      {
        if (Flint.config.routingMode != 'segment') return alert('routing mode is not "segment". please change routingMode = "segment" in "Flint.config.routingMode".');
        var segments = location.href.split(Flint.config.site_url).join('');
        var parsedSegments = segments.split('/');
        return (!parsedSegments[segmentNum]) ? defautValue : parsedSegments[segmentNum];
      }
    },
    //htmlspecilachars function of PHP function.
    __htmlspecialchars : function(str, quote_mode)
    {
      if (typeof str == 'object')
      {
        var quote_mode = (quote_mode) ? quote_mode : 'ENT_QUOTES';
        for (var i in str)
        {
          str[i] = arguments.callee(str[i], quote_mode);
        }
        return str;
      }
      str = str.replace(/<script>(.*?)<\/script>/ig, '[removedtag]$1[removedtag]');
      str = str.replace(/&/g, '&amp;');
      str = str.replace(/</g, '&lt;');
      str = str.replace(/>/g, '&gt;');
      //remove 'javascript' string
      str = str.replace(/javascript:/ig, '[removedprotocol]');
      if (quote_mode && quote_mode != 'ENT_NOQUOTES')str = str.replace(/"/g, '&quot;');
      if (!quote_mode || quote_mode == 'ENT_QUOTES') str = str.replace(/\'/g, '&#039;');
      return str;
    },
    __ajax : function()
    {
      var thisClass = this;
      this.xhr = '';
      this.state = {request : '', code : '', text : 'UNINITIALIZED', httpResponse : 'NOT LOADED'}
      this.startListener = null;
      this.startlistener = null;
      this.stopListener = null;
      this.successListener = null;
      this.errorListener = null;
      this.timeout = 200;
      this.tmpJSONPTimeStamp = '';
      function getAjax()
      {
        var ajax;
        if (window.XMLHttpRequest) {
          try {ajax = new XMLHttpRequest();}
          catch (e) {ajax = false;}
        }
        else
          if (window.ActiveXObject) {
            try {ajax = new ActiveXObject("Msxml2.XMLHTTP");}
            catch (e) {
              try {ajax = new ActiveXObject("Microsoft.XMLHTTP");}
              catch (e) {ajax = false;}
          }
        }
        return ajax;
      }
      var __loadedFunc = function(ajax, listener, Opt, ifModify)
      {
        var ajax = ajax, listener = listener, Opt = Opt;
        if (Opt.ansyncronous == true) {
            var timer = setTimeout(function(){thisClass.stop();}, thisClass.timeout);
            ajax.onreadystatechange = function(){
                this.state.code = ajax.readyState;
                switch (ajax.readyState)
                {
                  case 3: thisClass.state.text = 'INTERACTIVE'; break;
                  case 4: thisClass.state.text = 'COMPLETED';
                    thisClass.state.httpCode = ajax.status;
                    switch (ajax.status)
                    {
                      case 403:
                        thisClass.state.httpResponse = 'permition error';
                        if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                        {
                          thisClass.errorListener.call(Flint);
                        }
                      break;
                      case 404:
                        thisClass.state.httpResponse = 'file not found';
                        if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                        {
                          thisClass.errorListener.call(Flint);
                        }
                      break;
                      case 500:
                        thisClass.state.httpResponse = 'server error';
                        if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                        {
                          thisClass.errorListener.call(Flint);
                        }
                      break;
                      case 503:
                        thisClass.state.httpResponse = 'internal server error';
                        if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                        {
                          thisClass.errorListener.call(Flint);
                        }
                      break;
                      case 200:
                        thisClass.state.httpResponse = 'loaded';
                        if (ifModify) {
                          var mod = ajax.getResponseHeader('Last')
                        }
                        else {
                          if (listener)

                            listener.call(Flint.controller, getWrappedResponse(ajax));
                          else {
                            if (thisClass.successListener != null && typeof thisClass.successListener == 'function') {
                              thisClass.successListener.call(Flint, getWrappedResponse(ajax));
                            }
                          }
                        }

                      break;
                    }
                  break;
                  default : break;
                }
                clearTimeout(timer);
              }
          }
          else
          {
            switch (ajax.status)
            {
              case 403:
                thisClass.state.httpResponse = 'permition error';
                if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                {
                  thisClass.errorListener.call(Flint);
                }
              break;
              case 404:
                thisClass.state.httpResponse = 'file not found';
                if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                {
                  thisClass.errorListener.call(Flint);
                }
              break;
              case 500:
                thisClass.state.httpResponse = 'server error';
                if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                {
                  thisClass.errorListener.call(Flint);
                }
              break;
              case 503:
                thisClass.state.httpResponse = 'internal server error';
                if (thisClass.errorListener != null && typeof thisClass.errorListener == 'function')
                {
                  thisClass.errorListener.call(Flint);
                }
              break;
              case 200:
                thisClass.state.httpResponse = 'loaded';
                if (listener) listener.call(Flint.controller, getWrappedResponse(ajax));
                else
                {
                  if (thisClass.successListener != null && typeof thisClass.successListener == 'function')
                  {
                    thisClass.successListener.call(Flint, getWrappedResponse(ajax));
                  }
                }
              break;
            }
          }
      };

      function getWrappedResponse(xhr)
      {
        var res = {
            responseText : xhr.responseText,
            responseXML : xhr.responseXML,
            responseJSON : eval('(' + xhr.responseText + ')'),
            getAllResponseHeaders : (function ()
                        {
                          var headers = xhr.getAllResponseHeaders().split('\n'), head = {};
                          for (var i = 0; i < headers.length; i++)
                          {
                            if (headers[i].length === 0)continue;
                            var pos = headers[i].indexOf(':');
                            var name = headers[i].substring(0, pos).replace(/^\s/, '').replace(/\s$/, '');
                            var value = headers[i].substring(pos + 1).replace(/^\s/, '').replace(/\s$/, '');
                            head[name] = value;
                          }
                          return head;
                        })()
          };
        return res;
      }
      this.get = function(url, listener, params, opt)
      {
        var ajax = getAjax();
        if (ajax === false)return alert('Ajax Object can\'t create.');
        this.xhr = ajax;
        this.state.request = 'GET';
        var url = (/^http/.test(url)) ? url : Flint.config.site_url + Flint.config.script_path + url, Opt = {}, params = params || {};
        if(opt)
        {
          Opt = opt;
          Opt.ansyncronous = (opt.ansyncronous) ? opt.ansyncronous : false;
        }
        else Opt.ansyncronous = false;
        var tmp = [];
        if (Flint.config.routingMode != 'segment'){
            for (var i in params)
            {
                tmp.push(encodeURIComponent(i)+ '=' + encodeURIComponent(params[i]));
            }
            var parameter = (tmp.length == 0) ? null :tmp.join('&');
            url = (/\?/.test(url)) ? url + '&' + parameter : url + '?' + parameter;
         }else {
        	 for (var i in params)
             {
                 tmp.push(encodeURIComponent(i)+ '/' + encodeURIComponent(params[i]));
             }
              var parametar = (tmp.length == 0) ? null : tmp.join('/');
              if (parametar !== null) {
            	  url = (/\/$/.test(url)) ? url + parametar : url + '/' + parametar;
              }
         }


        ajax.open('GET', url, Opt.ansyncronous);
        if (this.startListener != null && typeof this.startListener == 'function')this.startlistener.call(Flint);
        this.state.text = 'LOADING';
        if (Opt.header)
        {
          for (var i in Opt.header)
          {
            ajax.setRequestHeader(i, Opt.header[i]);
          }
        }
        if (!Opt.cache || Opt.cache === false) {
          ajax.setRequestHeader('If-Modified-Since', "01 Jan 1970 00:00:00 GMT");
          ajax.setRequestHeader('Cache-Control', 'no-store, no-chache, must-revalidate, post-check=0, pre-check=0');
          ajax.setRequestHeader('Pragma', 'no-cache');
          ajax.setRequestHeader('Expires', 'Mon, 26, Jul, 1997, 05:00:00 GMT');
        }
        ajax.send(null);
        __loadedFunc(ajax, listener, Opt)
      }
      this.post = function(url, listener, form, opt)
      {
        var ajax = getAjax();
        if (ajax === false)return alert('Ajax Object can\'t create.');
        this.xhr = ajax;
        this.state.request = 'POST';
        var url = (/^http/.test(url)) ? url : Flint.config.site_url + url;
        var Opt = {};
        //create some options
        if(opt)
        {
          Opt.ansyncronous = (opt.ansyncronous) ? opt.ansyncronous : true;
          Opt.escape = (opt.escape) ? opt.escape : false;
          Opt.disable = (opt.disable) ? opt.disable : {};
        }
        else
        {
          Opt.ansyncronous = true;
          Opt.escape = false;
          Opt.disable = {};
        }
        if (!form || form == '') var parameter = null;
        else if (!form.nodeType) // native object
        {
          var params = [];
          for (var i in form)
          {
            (Opt.escape) ? params.push(Flint.__htmlspecialchars(i, 'ENT_QUOTES') + '=' + Flint.__htmlspecialchars(form[i], 'ENT_QUOTES')) : params.push( i + '=' + form[i]);
          }
          var parameter = (params.length == 0) ? null : params.join('&');
        }
        else {
          var parameter = null;
          var form = (typeof form == 'object') ? form : (Flint._doc[form] || DOM.search('id', form));
          var elms = form.Elements;
          if (!elms || elms.length == 0) parameter = null;
          else {
            for (var i = 0; i < elms.length; i++) {
              var elmName = elms[i].getAttribute('name');
              if ( elmName in Opt.disable && Opt.disable[elmName] == true)continue;
              if (i == elm.length - 1) {
                (Opt.escape) ? parameter += Flint.__htmlspecialchars(elms[i].name, 'ENT_QUOTES') + '=' + Flint.__htmlspecialchars(elms[i].value, 'ENT_QUOTES') : parameter += elms[i].name + '=' + elms[i].value;
              }
              else {
                (Opt.escape) ? parameter += Flint.__htmlspecialchars(elms[i].name, 'ENT_QUOTES') + '=' + Flint.__htmlspecialchars(elms[i].value, 'ENT_QUOTES') + '&' : parameter += elms[i].name + '=' + elms[i].value + '&';
              }
            }
          }
        }
        ajax.open('post', url, Opt.ansyncronous);
        if (this.startListener != null && typeof this.startListener == 'function')this.startlistener.call(Flint);
        this.state.text = 'LOADING';
        if (Opt.header)
        {
          for (var i in Opt.header)
          {
            ajax.setRequestHeader(i, Opt.header[i]);
          }
        }
        if (!Opt.cache || Opt.cache === false) {
          ajax.setRequestHeader('If-Modified-Since', "01 Jan 1970 00:00:00 GMT");
          ajax.setRequestHeader('Cache-Control', 'no-store, no-chache, must-revalidate, post-check=0, pre-check=0');
          ajax.setRequestHeader('Pragma', 'no-cache');
          ajax.setRequestHeader('Expires', 'Mon, 26, Jul, 1997, 05:00:00 GMT');
        }
        ajax.send(parameter);

        __loadedFunc(ajax, listener, Opt);
      };
      this.getIfModified = function(url, listener, params, opt)
      {
        var ajax = getAjax();
        if (ajax === false)return alert('Ajax Object can\'t create.');
        this.xhr = ajax;
        ajax.state.request = 'GET';
        var url = (/^http/.test(url)) ? url : Flint.config.site_url + url, Opt = {}, params = params || {};
        if(opt)
        {
          Opt = opt;
          Opt.ansyncronous = (opt.ansyncronous) ? opt.ansyncronous : false;
        }
        else Opt.ansyncronous = true;
        var tmp = [];
        for (var i in params)
        {
          (Opt.escape) ? tmp.push(Flint.__htmlspecialchars(i, 'ENT_QUOTES') + '=' + Flint.__htmlspecialchars(form[i], 'ENT_QUOTES')) : tmp.push( i + '=' + form[i]);
        }
        var parameter = (tmp.length == 0) ? null : tmp.join('&');
        url = (/\?/.test(url)) ? url + '&' + parameter : url + '?' + parameter;

        ajax.open('GET', url, Opt.ansyncronous);
        if (this.startListener != null && typeof this.startListener == 'function')this.startlistener.call(Flint);
        this.state.text = 'LOADING';
        if (Opt.header)
        {
          for (var i in Opt.header)
          {
            ajax.setRequestHeader(i, Opt.header[i]);
          }
        }
        ajax.send(null);
      }
      this.jsonp = function(url, callback)
      {
        if (!url || !callback)return;
        Flint.tmpSetJSONPTimeStamp = new Date().getTime();
        var url = (/^http/.test('url')) ? url : Flint.config.site_url + url;
        var fn = function(obj)
        {
          callback(obj);
          try {
            delete window['flintjsoncallback' + Flint.tmpSetJSONPTimeStamp];
          }
          catch(e){window['flintjsoncallback' + Flint.tmpSetJSONPTimeStamp] = undefined};
          Flint._doc.getElementsByTagName('head')[0].removeChild(Flint._doc.getElementById('flintjsonpelm'));
        };
        window['flintjsoncallback' + Flint.tmpSetJSONPTimeStamp] = fn;
        if (Flint.loaded || Flint.DOMReady)
        {
          var s = Flint._doc.createElement('script');
          s.type = 'text/javascript';
          s.src = url + '?callback=flintjsoncallback' + Flint.tmpSetJSONPTimeStamp.toString();
          s.id = 'flintjsonpelm';
          Flint._doc.getElementsByTagName('head')[0].appendChild(s);
        }
        else
        {
          Flint._doc.write('<script type="text/javascript" id="flintjsonpelm" src="' + url + '?callback=flintjsoncallback' + Flint.tmpSetJSONPTimeStamp.toString() + '"></script>');
        }
      };
      this.stop = function()
      {
        if (this.xhr === '')return;
        this.xhr.abort();
        if (this.stopListener != null && typeof this.stopListener == 'function')this.stopListener.call(Flint);
      }
      return thisClass;
    },
    Gmap : {},
    gmapSet : function()
    {
      Flint.Gmap.initPoint = Flint.config.Gmap_initPoint;
      Flint.Gmap.mapobj = '';
      Flint.Gmap.target = '';
      Flint.Gmap.point = '';
      Flint.Gmap.infoHTML = '';
      Flint.Gmap.opt = {
        mapWidth : 400,
        mapHeight : 300,
        LargeMapControl: true,
        MapTypeControl: true,
        withMarker: true,
        markerDraggable: true,
        showMarkerInfo : true
      }
      Flint.Gmap.callback = function(response){
        if (!response || response.Status.code != 200)return alert('住所が見つかりません');
        var res = response.Placemark[0];
        center = new GLatLng(res.Point.coordinates[1], res.Point.coordinates[0]);
        Flint.Gmap.mapobj = new GMap2(Flint.Gmap.target);
        if (Flint.Gmap.opt.LargeMapControl == true) {
          Flint.Gmap.mapobj.addControl(new GLargeMapControl());
        }
        if (Flint.Gmap.opt.MapTypeControl == true) {
          Flint.Gmap.mapobj.addControl(new GMapTypeControl());
        }
        Flint.Gmap.mapobj.setCenter(center, 17);
        if (Flint.Gmap.opt.withMarker == true) {
          var marker = new GMarker(center, {
            draggable: Flint.Gmap.opt.markerDraggable
          });
          Flint.Gmap.mapobj.addOverlay(marker);
          if (Flint.Gmap.opt.showMarkerInfo)
          {
            GEvent.addListener(marker, 'click', function(draw, pointObj){
              Flint.Gmap.mapobj.openInfoWindowHtml(marker.getLatLng(), Flint.Gmap.infoHTML);
            });
          }
        }
      }
      Flint.Gmap.mapCallBack = function(response)
      {
        if( !response || response.Status.code != 200)return alert('unknown address.');
        var res = response.Placemark[0];
        point = new GLatLng( res.Point.coordinates[1], res.Point.coordinates[0]);
        var marker = new GMarker(point);
        Flint.Gmap.mapobj.addOverlay(marker);
      }
      Flint.Gmap.setMarker = function(address)
      {
        if(Flint.Gmap.mapobj == '')return alert('target mapObject id undefined.');
        var geocoder = new GClientGeocoder();
        geocoder.getLocations(address, Flint.Gmap.mapCallBack);
      }

      Flint.Gmap.setOption = function(obj)
      {
        if(typeof obj != 'object')return;
        for(var m in obj)Flint.Gmap.opt[m] = obj[m];
      }

      Flint.Gmap.generate = function(target, obj)
      {
        if (typeof target == 'object')
        {
          if (typeof target.extended == 'undefined')Flint.Gmap.target = DOM.__setExtends(target);
        }
        if (typeof target == 'string')Flint.Gmap.target = DOM.search('id', target);
        if (Flint.Gmap.target == null)return;
        if (obj) {
          for (var i in obj) {
            Gmap.opt[i] = obj[i];
          }
        }
        Flint.Gmap.target.style.width = Flint.Gmap.opt.mapWidth + 'px';
        Flint.Gmap.target.style.height = Flint.Gmap.opt.mapHeight + 'px';

        var geocoder = new GClientGeocoder();
        geocoder.getLocations(Flint.Gmap.initPoint, Flint.Gmap.callback);
      }
    },
    // alias funtion
    alias : function(name, data, obj, isOverWrite)
    {
      var aliasTo = obj || Flint._win;
      if (aliasTo[name]) {
        aliasTo[name] = (isOverWrite && isOverWrite === true) ? data : aliasTo[name];
      }
      else aliasTo[name] = data;

    },
    //some helper functions

    //url helper
    urlHelper : function()
    {
      var FL = Flint;
      Helper.base_url = function(){return FL.config.site_url;}
      Helper.anchor = function(path, text, attributes, returnFlag)
      {
        var resFlag = (returnFlag) ? returnFlag : false;
        if (!resFlag)
        {
          var a = DOM.create('a');
          a.attr('href', FL.config.site_url + path);
          if (attributes && typeof attirbutes == 'object') {
            for (var i in attributes) a.attr(i, attributes[i]);
          }
          a.inText(text);
          return a;
        }
        else
        {
          var a = '<a href="' + FL.config.site_url + path + '"';
          if (attributes && typeof attributes == 'object')
          {
            for (var i in attributes)a += i + '="' + attributes[i] + '" ';
          }
          else
          {
            a += ' ';
          }
          a += '>' + text + '</a>';
          return a;

        }
      }
      Helper.redirect = function(path){location.href = FL.config.site_url + path;}
      Helper.absRedirect = function(abspath){location.href = abspath;}
    },
    //string helper
    stringHelper : function()
    {
      Helper.clean = function(str){ return Flint.__htmlspecialchars(str, 'ENT_QUOTES');}
      Helper.randomString = function(type, length)
      {
        var type = (type) ? type : 'alnum';
        var length = (length) ? length : 8;
        switch (type)
        {
          case 'alnum' : var strArr = ['0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ']; break;
          case 'alpha' : var strArr = ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ']; break;
          case 'numeric' : var strArr = ['0123456789']; break;
          case 'nonzero' : var strArr = ['123456789']; break;
        }
        var res = [];
        for (var i = 0; i< length; i++) res[res.length] = strArr[Math.random() * strArr.length];
        return res.join();
      }
    },
    //date helper
    dateHelper : function()
    {
      var FL = Flint, d = new Date();
      var monthList = [['Jan', 'January', 31], ['Feb', 'February', 28], ['Mar', 'March', 31], ['Apr', 'Aplil', 30], ['May', 'May', 31], ['Jun', 'June', 30], ['Jul', 'July', 31], ['Aug', 'August', 31], ['Sep', 'September', 30], ['Oct', 'October', 31], ['Nov', 'November', 30], ['Dec', 'December', 31]];
      var dayList = [['Mon', 'Monday'], ['Tue', 'Tuesday'], ['Wed', 'Wednesday'], ['Thu', 'Thursday'], ['Fri', 'Friday'], ['Sat', 'Saturday'], ['Sun', 'Sunday']];
      Helper.time = function(){ return d.getTime();}
      Helper.checkDate = function(month, day, year, yearRange)
      {
        if (!yearRange)var yearRange = 1900;
        if (year < yearRange)return false;
        var dayList = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        if((year % 4 ) == 0 && (year % 100) != 0 || (year % 400) == 0)dayList[1] = 29;
        if (month <= 0 || month > 12)return false;
        if (day <= 0 || day > dayList[month])return false;
        return true;
      }
      Helper.date = function(format, timeStamp)
      {
        var time = (timeStamp) ? timeStamp :Helper. time();
        d.setTime(time);
        var y = d.getFullYear();
        if ((y % 4) == 0 && (y % 100) != 0 || (y % 400) == 0)monthList[1][2] = 29;
        var dateFormat = {
          'Y' : d.getFullYear(),
          'y' : d.getYear(),
          'F' : monthList[d.getMonth()][1],
          'm' : ((d.getMonth() + 1).toString().length == 1) ? '0' + (d.getMonth() + 1) : d.getMonth() + 1,
          'M' : monthList[d.getMonth()][0],
          'n' : d.getMonth(),
          't' : monthList[d.getMonth()][2],
          'd' : ((d.getDate() + '').length == 1) ? '0' + d.getDate() : d.getDate(),
          'D' : dayList[d.getDay()][0],
          'j' : d.getDate(),
          'l' : dayList[d.getDay()][1],
          'N' : d.getDay(),
          'w' : (d.getDay() - 1),
          'z' : (function(){
            var count;
            for (var m = 0; m < (d.getMonth() + 1); m++)count += monthList[m][2];
            return count + d.getDate();
          }),
          'a' : (d.getHours() < 12) ? 'am' : 'pm',
          'A' : (d.getHours() < 12) ? 'AM' : 'PM',
          'g' : (d.getHours() > 12) ? d.getHours() - 12 : d.getHours(),
          'G' : d.getHours(),
          'h' : (d.getHours() > 12) ? (((d.getHours() - 12).toString().length == 1) ? '0' + (d.getHours() - 12) : (d.getHours() - 12)) : ((d.getHours() + '').length == 1) ? ('0' + d.getHours()) : d.getHours(),
          'H' : ((d.getHours()+ '').length == 1) ? '0' + d.getHours() : d.getHours(),
          'i' : d.getMinutes(),
          's' : ((d.getSeconds() + '').length == 1) ? '0' + d.getSeconds() : d.getSeconds(),
          'u' : d.getMilliseconds()
        }
        for (var p in dateFormat)
        {
          var pattern = new RegExp(p.toString());
          if (!pattern.test(format))continue;
          format = format.replace(pattern, dateFormat[p]);
        }
        return format;
      }
    },
    //cookie helper
    cookieHelper : function()
    {
      var FL = Flint, cookieEnabledCache, cookieCahe = {};
      var cookieEnable = function()
      {
        if (navigator.cookieEnabled != undefined)return navigator.cookieEnabled;
        if (cookieEnabledCache != undefined)return cookieEnabledCache;
        //cookie_test
        document.cookie = 'FL_cookie_check=checkValue; max-age=65535';
        var cookie = document.cookie;
        if (cookie.indexOf('FL_cookie_check') == -1) {
          cookieEnabledCache = false;
          return;
        }
        else {
          document.cookie = 'FL_cookie_check=checkValue; max-age=0';
          cookieEnabledCache = true;
          return;
        }
      }
      Helper.setCookie = function(obj)
      {
        if (typeof obj != 'object')return;
        //set parameter
        var cookieValue = [];
        if ('path' in obj) {
          var path = obj.path;
          delete obj.path;
        }
        else var path = FL.config.cookiePath;
        if ('domain' in obj) {
          var domain = obj.domain;
          delete obj.domain;
        }
        else var domain = FL.config.cookieDomain;
        if ('secure' in obj)
        {
          var secure = obj.secure;
          delete obj.secure;
        }
        else var secure = false;
        if (!('lifetime' in obj))
        {
          if (FL.ua.IE || FL.ua.Safari) {
            var d = new Date();
            d.setTime(d.getTime() + FL.config.cookieMaxAge * 1000 * 60 * 60 * 24);
            var maxAge = d.toGMTString();
          }
          else var maxAge = FL.config.cookieMaxAge * 60 * 60 * 24;
        }
        else
        {
          if (FL.ua.IE || FL.ua.Safari) {
            var d = new Date();
            d.setTime(d.getTime() + (obj.lifetime * 1000 * 60 * 60 * 24));
            var maxAge = d.toGMTString();
          }
          else var maxAge = obj.lifetime * 60 * 60 * 24;
          delete obj.lifetime;
        }

        for (var p in obj)
        {
          cookieValue.push(FL.config.cookieName + '_' + p + '=' + encodeURIComponent(obj[p]));
          cookieValue.push('d' + FL.config.cookieSeparator + domain);
          cookieValue.push('p' + FL.config.cookieSeparator + path);
          var cookie = [cookieValue.join(FL.config.cookieDelimiter)];
          if (path != '')cookie.push('path=' + path);
          cookie.push((FL.ua.IE || FL.ua.Safari) ? 'expires=' + maxAge : 'domain=' + domain + ';max-age=' + maxAge);
          document.cookie = cookie.join('; ');
          cookieValue = [];
        }
        return (document.cookie) ? true : false;
      }
      Helper.getCookie = function(name)
      {
        var cookie = document.cookie;
        if (!cookie || !name)return false;
        var cookieValues = cookie.split(';'), cookieValue = null;
        for (var c = 0; c < cookieValues.length; c++)
        {
          if (cookieValues[c].indexOf(FL.config.cookieName + '_' + name) != -1) {
            cookieValue = cookieValues[c].replace(new RegExp(FL.config.cookieName + '_' + name + '='), '');
            break;
          }
        }
        if (cookieValue == null)return false;
        var value = cookieValue.split(FL.config.cookieDelimiter)[0];
        return decodeURIComponent(value);
      }
      Helper.deleteCookie = function(name)
      {
        var cookie = document.cookie;
        if (!cookie || !name)return false;
        var cookieValues = cookie.split(';'), domain = '', path = '';
        var cookieValue = null, cookieDomain = null, cookiePath = null, cookieMaxAge = null;
        for (var c = 0; c < cookieValues.length; c++)
        {
          if (cookieValues[c].indexOf(FL.config.cookieName + '_' + name) != -1) {
            cookieValue = cookieValues[c];
            break;
          }
        }
        if (cookieValue == null)return false;
        var cName = cookieValue.split('=');
        var value = cName[1].split(FL.config.cookieDelimiter);
        for (var i = 0, len = value.length; i < len; i++)
        {
          var del = value[i].split(FL.config.cookieSeparator);
          if (del[0] == 'd')domain = del[1];
          else if (del[0] == 'p')path = del[1];
          else var tmp = del[0];
        }
        if (FL.ua.IE || FL.ua.Safari)
        {
          var newCookie = [cName[0] + '=' + tmp];
          //if (domain != '')newCookie.push('domain=' + domain);
          if (path != '')newCookie.push('path=' + path);
          var exp = new Date();
          exp.setTime(exp.getTime() - (10 * 1000 * 24 *60 * 60))
          newCookie.push('expires=' + exp.toGMTString());
          document.cookie = newCookie.join(';');
        }
        else
        {
          var newCookie = [cName[0] + '=', 'domain=' + domain, 'path=' + path, 'max-age=0'];
          document.cookie = newCookie.join(';');
        }
        return true;
    //    FL.ua.IE || FL.ua.Safari) ? cName[0] + "=;domain=" + value[1].split(FL.config.cookieSeparator)[1] + ";path=" + value[2].split(FL.config.cookieSeparator)[1] + ";max-age=0" : cName[0] + "=;domain=" + value[1].split(FL.config.cookieSeparator)[1] + ";path=" + value[2].split(FL.config.cookieSeparator)[1] + ";max-age=0";
      }
    },
    //boolian helper
    booleanHelper : function()
    {
      Helper.isNumber = function(num){ return (typeof num == 'number') ? true : false;}
      Helper.isString = function(str){ return (typeof str == 'string') ? true : false;}
      Helper.isFunction = function(f){ return (typeof f == 'function') ? true : false;}
      Helper.isArray = function(arr){ return (typeof arr == 'object' && arr.constructor == Array) ? true : false;}
      Helper.isObject = function(obj){ return (typeof obj == 'object' && obj.constructor == Object) ? true : false;}
      Helper.isReg = function(obj){ return (typeof obj == 'object' && obj.constructor == RegExp) ? true : false;}
      Helper.inMethod = function(method, func){ return (func.hasOwnProperty(method)) ? true : false;}
      Helper.inArray = function(value, arr)
      {
        for (var i = 0, len = arr.length; i < len; i++)
        {
          if (arr[i] === value)return true;
        }
        return false;
      }
      Helper.inKey = function(key, obj){ return (key in obj) ? true : false;}
    },
    //some IE6 CSSBugFix function
    __fixIE : function()
    {
      var posfixE = [];
      //positionFix function
      var posFix = function(ev)
      {
        var nowScValue = Flint.utility.getScrollPosition();
        for (var pos = 0; pos < posfixE.length; pos++)
        {
          posfixE[pos].elm.addStyle({
            top : posfixE[pos].top + nowScValue.y + 'px',
            left : posfixE[pos].left + nowScValue.x + 'px'
          })
        }
      }
      var all = DOM.search('tag', '*', document.body);
      if (all.length == 0)return;
      //positionfix
      if (Flint.config.IEFix.positionFix === true)
      {
        for (var e = 0; e < all.length; e++) {

          if (all[e].readStyle('position') == 'fixed') {
            all[e].addStyle('position', 'absolute');
            var p = Flint.utility.absPos(all[e]);
            var state = {
              elm: all[e],
              top: p.y,
              left: p.x
            }
            posfixE.push(state);
          }
        }
        Flint.event.set(window, 'scroll', posFix);


      }
      //floafFix
      if (Flint.config.IEFix.floatFix === true)
      {
        for (var e = 0; e < all.length; e++) {
          if (all[e].readStyle('styleFloat') == 'left' || all[e].readStyle('styleFloat') == 'right')
            all[e].addStyle('display', 'inline');
        }
      }
      //pngFix
      if (Flint.config.IEFix.pngFix === true)
      {
        for (var e = 0; e < all.length; e++)
        {
          if (all[e].tagName.toLowerCase() == 'img')
          {
            if (/\.png$/.test(all[e].src))
            {
              var path = all[e].src;
              var replace = DOM.create('div');
              replace.addStyle({
                display : 'inline',
                width : all[e].width + 'px',
                height : all[e].height + 'px',
                zoom : 1
              });
              replace.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="' + path + '")';
              replace.add(all[e], 'before');
              all[e].addStyle('display', 'none');
            }
          }
          else
          {
            if (/\.png$/.test(all[e].readStyle('background-image')))
            {
              var path = all[e].readStyle('background-image');
              all[e].addStyle('background', 'none');
              all[e].addStyle('zoom', 1);
              all[e].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="scale", src="' + path + '")';
              var inEl = all[e].getElementsByTagName('*');
              if (inEl.length != 0)
              {
                for (var l = 0; l < inEl.length ; l++)
                {
                  switch (inEl[l].tagName.toLowerCase())
                  {
                    case 'a': inEl[l].style.style.cursor = 'pointer'; inEl[l].style.position = 'relative'; break;
                    case 'input': inEl[l].style.position = 'relative'; break;
                    case 'select': inEl[l].style.position = 'relative'; break;
                    case 'textarea': inEl[l].style.position = 'relative'; break;
                  }
                }
              }
            }
          }
        }
      }
    },
    //builtinClass extends
    __stringExtends : function()
    {
      if (typeof String.prototype.trim == 'undefined') String.prototype.trim = function() { return this.replace(/^\s*(.*?)\s*$/, '$1');}
      if (typeof String.prototype.ltrim == 'undefined') String.prototype.ltrim = function(){ return this.replace(/^\s*/, '');}
      if (typeof String.prototype.rtrim == 'undefined') String.prototype.rtrim = function(){ return this.replace(/\s*$/, '');}
      if (typeof String.prototype.toCamelCase == 'undefined') String.prototype.toCamelCase = function(){return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();}
      if (typeof String.prototype.clean == 'undefined')
      {
        String.prototype.clean = function(quote_mode)
        {
          this.replace(/<script>(.*?)<\/script>/ig, '[removedtag]$1[removedtag]');
          this.replace(/&/g, '&amp;');
          this.replace(/</g, '&lt;');
          this.replace(/>/g, '&gt;');
          //remove 'javascript' string
          this.replace(/javascript:/ig, '[removedprotocol]');
          if (quote_mode && quote_mode != 'ENT_NOQUOTES')return this.replace(/"/g, '&quot;');
          if (!quote_mode || quote_mode == 'ENT_QUOTES') return this.replace(/\'/g, '&#039;');
          return;
        }
      }
      if (typeof String.prototype.truncate == 'undefined')
      {
        String.prototype.truncate = function(length, etc)
        {
          if (!length ||length == 0)return;
          var etc = (etc) ? etc : '...';
          this.replace(/\[removedtag\](.*?)\[removedtag\]/ig, '<script>$1</script>');
          this.replace(/&amp;/g, '&');
          this.replace(/&lt;/g, '<');
          this.replace(/&gt;/g, '>');
          //remove 'javascript' string
          this.replace(/javascript:/ig, '[removedprotocol]');
          this.replace(/"/g, '&quot;');
          this.replace(/\'/g, '&#039;');
          this.substr(0, length) + etc;
          return (typeof String.prototype.clean == 'function') ? this.clean() : Flint.__htmlspecialchars(this, 'ENT_QUOTES');
        }
      }

      if (typeof String.prototype.numberFormat == 'undefined')
      {
        String.prototype.numberFormat = function()
        {
          this.replace(/,/g, "");
          while(this != (this.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
          return ;
        }
      }
      if (typeof String.prototype.nl2br == 'undefined')
      {
        String.prototype.nl2br = function()
        {
          this.replace(/\r\n/g, '<br />');
          return this.replace(/[\r|\n]/g, '<br />');
        }
      }
    },
    __arrayExtends : function()
    {
      if (typeof Array.prototype.forEach == 'undefined')
      {
        Array.prototype.forEach = function(fn){
          for (var i = 0, len = this.length; i < len; i++)fn(this[i]);
        }
      }
      if (typeof Array.prototype.map == 'undefined')
      {
        Array.prototype.map = function(fn)
        {
          var res = [];
          for (var i = 0, len = this.length; i < len; i++) res[i] = fn(this[i]);
          return res;
        }
      }
      if (typeof Array.prototype.indexOf == 'undefined')
      {
        Array.prototype.indexOf = function(search, offset)
        {
          var res, offset = (offset) ? offset : 0;
          for (var i = offset, len = this.length; i < len; i++)
          {
            if (this[i] === search)
            return i;
          }
          return -1;
        }
      }
      if (typeof Array.prototype.walk == 'undefined')
      {
        Array.prototype.walk = function(arr, callback, prefix)
        {
          for (var i = 0, len = this.length; i < len; i++)
          {
            (prefix) ?  callback(i, this[i], prefix) : callback(i, this[i]);
          }
        }
      }
    },
    __mathExtends : function()
    {
      if (typeof Math.allMax == 'undefined')
      {
        Math.allMax = function(arr)
        {
          var res = 0;
          for (var i = 0, len = arr.length; i < len; i++)
          {
            if (isNaN(parseFloat(arr[i] + 0)))continue;
            res = (res < (arr[i] + 0)) ? arr[i] + 0 : res;
          }
          return res;
        }
      }
      if (typeof Math.allMin == 'undefined')
      {
        Math.allMin = function(arr)
        {
          var res = 0;
          for (var i = 0, len = arr.length; i < len; i++)
          {
            if (isNaN(parseFloat(arr[i] + 0)))continue;
            res = (res > (arr[i] + 0)) ? arr[i] + 0 : res;
          }
          return res;
        }
      }
      if (typeof Math.nRandom == 'undefined')
      {
    	  Math.nRandom = function(min, max){return Math.round(Math.random() * (max - min)) + min;};
      }
    },
    __functionExtends : function()
    {
      if (typeof Function.name == 'undefiend')
      {
        Function.prototype.name = function(){
          var name = this.toString();
          if (/^function\s\(/.text(name)) {
            return '';
          }
          else {
            return name.substring(9, name.indexOf('('));
          }
        }
      }
    }
  }

// prototype of Flint.__DOM2Event (not impl)
Flint.event.__DOM2Event.prototype = {
	preventDefault : function() {
		if (this.ev.preventDefault) this.ev.preventDefault();
		else {
			try{
				this.ev.returnValue = false;
			}
			catch (e) {};
		}
	},
	stopPropagation : function() {
		if (this.ev.stopPropagation) this.ev.stopPropagation();
		else {
			try{
				this.ev.cancelBubble = true;
			}
			catch(e){};
		}
	}
}

//check server port and replace site_url.
//if (location.protocol === 'https:')Flint.config.site_url = Flint.config.site_url.replace(/^http/, 'https');
if (location.protocol === 'https:')Flint.config.site_url = Flint.config.ssl_site_url;
//config load
Flint.config.load = function(conf) {
	Flint.load.config(conf);
}
Flint.config.item = function(prop){
	return Flint.config[prop];
}
Flint.config.base_url = Flint.config.site_url + Flint.config.script_path;


Flint.ua = new Flint.__ua();
if (Flint.config.zIndexer) Flint.DOMFuncs.push([Flint, Flint.__zIndexer, false]);
//use method of Controller　prototype
Flint.__controller.prototype.ua = Flint.ua;
Flint.__controller.prototype.utility = Flint.utility;
Flint.__controller.prototype.load = Flint.load;
Flint.__controller.prototype.event = Flint.event;
Flint.__controller.prototype.parser = Flint.parser;
Flint.__controller.prototype.ui = Flint.ui;
Flint.__controller.prototype.image = Flint.image;
Flint.__controller.prototype.alias = Flint.alias;

function ClassExtend(bindFrom, func, onload)
{
  if (typeof bindFrom === undefined)return alert('Extendclass is undefined or protectred.');
  else if (typeof bindFrom !== 'string')return alert('Extend Classname must be string.');
  else if (/flint/i.test(bindFrom))return alert('Coreclass can\'t extend.');
  var extend = bindFrom.toLowerCase();
  switch(extend)
  {
    case 'config':
      if (typeof func === 'object') {
        for (var p in func) { if (!(p in Flint.config))Flint.config[p] = func[p];}
      }
      return;
    break;
    case 'model': var arr = ['ua', 'utility', 'event', 'ajax'];break;
    case 'library': var arr = ['ua', 'utility', 'event'];break;
    case 'helper': var arr = ['ua', 'utility', 'event'];break;
    default : break;
  }
  if (extend !== 'controller') {
    var prfunc = Flint.__extend(arr);
    func.prototype = new prfunc();
    if (extend == 'helper') return Flint.readyFunc(func, 1);
    var tmp = new func();
    if (tmp.hasOwnProperty('__construct'))tmp.__construct();
      var name = Flint.getExecuteName(func, true);
      (Flint.config.routingMode != 'none') ? Flint.__controller.prototype[name] = tmp : window.FL[name] = tmp;
    return;
  }
  if (Flint.controller !== '')return alert('Controler Class has already extended!');
  func.prototype = new Flint.__controller();
  Flint.controller = new func();

  if (Flint.controller.hasOwnProperty('__construct'))Flint.controller.__construct();
  if (onload === true) {
    if (!Flint.DOMReady) {
      var domFunc = function() {
        if (Flint.exec == '' || Flint.exec == 'init') {
          if (Flint.controller.hasOwnProperty('init')) Flint.controller.init(Flint.methodArguments);
        }
        else {
          if (Flint.controller.hasOwnProperty(Flint.exec) && !(/^[_]/.test(Flint.exec))) {
            Flint.controller[Flint.exec](Flint.methodArguments);
          }
          else {
            if (Flint.config.debugMode) return alert(Flint.exec + ' is undefined or private.');
          }
        }
      };
      Flint.DOMFuncs.push([Flint.controller, domFunc, false]);
    }
    else {
      if (Flint.exec == '') Flint.controller.init(Flint.methodArguments);
      else {
        if (Flint.controller.hasOwnProperty(Flint.exec) && !Flint.exec.match(/^[_]/)) {
          Flint.controller[Flint.exec](Flint.methodArguments);
        }
        else {
          if (Flint.config.debugMode) {
            alert(Flint.exec + ' is undefined or private.');
          }
          return;
        }
      }
    }
  }
  else {
    if (Flint.exec == '') Flint.controller.init(Flint.methodArguments);
    else
    {
      if (Flint.controller.hasOwnProperty(Flint.exec)) {
        Flint.controller[Flint.exec](Flint.methodArguments);
      }
      else {
        if (Flint.config.debugMode)alert(Flint.exec + ' is undefined or private.');
        return;
      }
    }
  }
}

function getInstance(){
  // var a = Flint.__extend(['ua', 'event', 'utility', 'load']);
  //return new a();
  return new Flint.__controller();
}

 var DOM = {
  cid : 0, did : 0, queryCache : {},
  //タグのdisplayマップ。何かに使う　・・・かもしれない
  tagMap : {
        'a' : 'inline', 'span' : 'inline', 'b' : 'inline', 'br' : 'inline', 'em' : 'inline', 'i' : 'inline', 'big' : 'inline', 'basefont' : 'inline',
        'button' : 'inline', 'cite' : 'inline', 'code' : 'inline', 'font' : 'inline', 'iframe' : 'inline', 'img' : 'inline', 'input' : 'inline',
        'label' : 'inline', 'map' : 'inline', 'q' : 'inline', 's' : 'inline', 'select' : 'inline', 'small' : 'inline', 'strike' : 'inline', 'strong' : 'inline',
        'sub' : 'inline', 'sup' : 'inline', 'textarea' : 'inline', 'tt' : 'inline', 'u' : 'inline'  ,
        'address' : 'block', 'blockquote' : 'block', 'center' : 'block', 'div' : 'block', 'dl' : 'block', 'fieldset' : 'block',
        'form' : 'block', 'h1' : 'block', 'h2' : 'block', 'h3' : 'block', 'h4' : 'block', 'h5' : 'block', 'h6' : 'block', 'hr' : 'block', 'noframes' : 'block',
        'ol' : 'block', 'ul' : 'block', 'p' : 'block', 'pre' : 'block', 'li' : 'block', 'dt' : 'block', 'dd' : 'block',
        'table' : 'block', 'thead' : 'block', 'tbody' : 'block', 'tr' : 'block', 'td' : 'block', 'th' : 'block'
  },
  search : function(mode, value, root, toObj, bool)
  {
    if(!root)var root = Flint._doc;
    else if(typeof root == 'string') var root = Flint._doc.getElementById(root);
    else var root = root;
    var bool = (bool) ? bool : true;
    switch (mode)
    {
      case 'id':
        if(typeof value != 'string')return null;
        var node = Flint._doc.getElementById(value);
        return (node) ? (bool) ? DOM.__setExtends(node) : node : null;
      break;
      case 'class':
        if (Flint._doc.getElementsByClassName)
        {
          var nodeList = root.getElementsByClassName(value);
          if (nodeList.length == 0) return [];
          return DOM.__setExtendsArray(nodeList);
        }
        var nodeList = root.getElementsByTagName('*');
        if (nodeList.length == 0) return [];
        var res = [];
        for (var i = 0; i < nodeList.length; i++) {
          if (nodeList[i].nodeType !== 1)continue; //guard IE for '*'
          if (DOM.__isClass(nodeList[i], value)) {
            res.push(nodeList[i]);
          }
        }
        return DOM.__setExtendsArray(res);
      break;
      case 'tag':
        var res = [];
        var nodeList = root.getElementsByTagName(value);
        if (nodeList.length == 0) return [];
        if (value == '*' && Flint.ua.IE6)
        {
          for (var i = 0; i < nodeList.length; i++)
          {
            if (nodeList[i].nodeType !== 1)continue;
            res.push(nodeList[i]);
          }
          return DOM.__setExtendsArray(res);
        }
       return DOM.__setExtendsArray(Array.prototype.slice.call(nodeList));
      break;
      case 'name':
        var res = [];
        var nodeList = Flint._doc.getElementsByName(value);
        if (nodeList.length == 0) return [];
        return DOM.__setExtendsArray(nodeList);
      break;
      case 'attribute':
        if (typeof value != 'object' || value.constructor== Array)return [];
        var nodeList = root.getElementsByTagName('*');
        if (nodeList.length == 0) return [];
        var res = [];
        for (var i = 0; i < nodeList.length; i++) {
          if (nodeList[i].nodeType !== 1)continue; //guard IE for '*';
          if (DOM.__isAttr(nodeList[i], value[name], value[val])) {
            res.push(nodeList[i]);
          }
        }
        return DOM.__setExtendsArray(res);
      break;
      case 'css':
        var res = DOM.__getElementsBySelector(value);
        return DOM.__setExtendsArray(res);
      break;
     }
   },
 //private function
  __is_Attr : function(node, att, val)
  {
    var at = node.getAttribute(att);
    if(!at) return false;
    if(at == val) return true;
  },
//private function
  __isClass : function(elm, classname)
  {
    var cn = elm.className;
    if(!cn) return false;
    if(cn == classname) return true;
    var wh = /\s+/;
    if(!wh.test(cn))return false;
    var clArr = cn.split(wh);
    for(var i=0;i<clArr.length;i++){if(clArr[i] == classname)return true;}
    return false;
  },

  create : function(tagName, attr)
  {
    var element = Flint._doc.createElement(tagName);
    if (tagName.toLowerCase() == 'script' || tagName.toLowerCase() == 'link')  return element;
    element = DOM.__setExtends(element);
    if (!attr || typeof attr != 'object') return element;
    for (var i in attr)element.attr(i, attr[i]);
    return element;
  },
  ex : function(element)
  {
	 if (element.extended)return element;
	 else return DOM.__setExtends(element);
  },
  __setExtends : function(element)
  {
    if (element.__cid) {
    	var __cid = element.__cid;
    } else {
    	var __cid = ++DOM.cid;
    	element.__cid = __cid;
    }
    if (('elm' + __cid) in Flint.registedElm)return Flint.registedElm['elm' + __cid];
    Flint.registedElm['elm' + __cid] = new DOM.__wrappedExtendElement(element);
    return Flint.registedElm['elm' + __cid];
  },
  __wrappedExtendElement : function(elm)
  {
    this.extended = true;
    this.element = elm;
    this.tag = elm.tagName.toLowerCase();
    this.nodeType = elm.nodeType;
    this.FL = Flint;
  },
  __setExtendsArray : function(nodeList)
  {
    return new DOM.__wrappedExtendNodeList(nodeList);
  },
  __wrappedExtendNodeList : function(list)
  {
    this.list = list;
    this.length = list.length;
  },
  union : function(suTo, suBase, unable)
  {
    var unable = (unable) ? unable : '';
    // faster
    if (unable == '') {
      for (var t in suTo)suBase[t] = suTo[t];
      return suBase;
    }
    // unable is defined
    for (var t in suTo) {
      var p = suTo[t];
      switch (true) {
        case /Object/i.test(unable):
          if (typeof p == 'object' && p.constructor == Object) continue;
        break;
        case /function/i.test(unable):
          if (typeof p == 'function')continue;
        break;
        case /Array/i.test(unable):
          if (typeof p == 'object' && p.constructor === Array)continue;
        break;
        case /number/i.test(unable):
          if (typeof p == 'number')continue;
        break;
        case /string/i.test(unable):
          if (typeof p == 'string')continue;
        break;
        default:
          if (unable.indexOf(t) !== -1) continue;
        break;
      }
      suBase[t] = suTo[i];
    }
    return suBase;
  }
 }
DOM.__wrappedExtendElement.prototype = {
      attr :  function(attribute, value){
      if (typeof attribute == 'object')
      {
        for (var i in attribute)arguments.callee.apply(this, [i, attribute[i]]);
      }
      else
      {
        if (attribute == 'class') {
          this.element.className = value;
        }
        else if (attribute == 'for') {
          this.element.htmlFor = value;
        }
        else
          if (attribute == 'style') {
            (this.FL.ua.IE) ? this.element.style.cssText = this.element.style.cssText + value : this.element.setAttribute('style', value);
          }
          else {
            if (attribute == 'colspan')
              attribute = 'colSpan';
            if (attribute == 'rowSpan')
              attribute = 'rowSpan';
            this.element.setAttribute(attribute, value);
          }
      }
      return this;
    },
    addClass : function(cl)
    {
      if (!cl)return this;
      if (this.readAttr('class') == '')
      {
        this.attr('class', cl);
      }
      else
      {
        this.attr('class', this.readAttr('class') + ' ' + cl);
      }
      return this;
    },
    removeClass : function(cl)
    {
      if (!cl) return this;
      var nowCL = this.readAttr('class');
      if (!(/\s/.test(nowCL)))
      {
        this.removeAttr('class');
      }
      else
      {
        var ar = nowCL.split(' ');
        for (var i = 0; i < ar.length; i++)
        {
          if (ar[i] == cl)
          {
            ar.splice(i, 1);
          }
        }
        this.attr('class', ar.join(' '));
      }
      return this;
    },
    hasClass : function(cl) {
    	var c = this.element.className.split(/\s/);
    	for (var i = 0; i < c.length; i++) {
    		if (c[i] == cl)return true;
    	}
    	return false;
    },
    readAttr : function(attribute)
    {
      if (attribute == 'class') {
        return this.element.className;
      }
      else if (attribute == 'style')
      {
        if(this.FL.ua.IE) return this.element.style.cssText;
        else return this.element.getAttribute('style');
      }
      else {
        if (attribute == 'colspan')
          attribute = 'colSpan';
        if (attribute == 'rowSpan')
          attribute = 'rowSpan';
        return this.element.getAttribute(attribute);
      }
    },
    removeAttr : function(attribute)
    {
      if (typeof attribute == 'string')
      {
        switch (attribute)
        {
          case 'class' : attribute = 'className'; break;
          case 'colspan' : attribute = 'colSpan'; break;
          case 'rowSpan' : attribute = 'rowSpan'; break;
        }
        if(attribute == 'style') (this.FL.ua.IE) ? this.element.style.cssText == '' : this.element.removeAttribute(attribute);
      }
      else if (attribute.constructor == Array)
      {
        for (var i = 0, len = attribute.length; i < len; i++)arguments.callee(attribute[i]);

      }
    },
    event : function(eventType, listener){
      this.FL.event.set(this.element, eventType, listener, true);
      return this;
    },
    FLevent : function(eventType, listener){
      this.FL.event.set(this.element, eventType, listener, false);
      return this;
    },
    unevent : function(eventType, listener)
    {
      (listener) ? this.FL.event.remove(eventType, listener) : this.FL.event.remove(eventType);
      return this;
    },
    inText : function(text){
      for (var e = 0; e < this.element.childNodes.length; e++)
      {
        this.element.removeChild(this.element.childNodes[e]);
      }
      if (/\n/.test(text)) {
        var tmp = text.split(/\n/);
        for (var t = 0, len = tmp.length; t < len; t++)
        {
          this.element.appendChild(this.FL._doc.createTextNode(tmp[t]));
          this.element.appendChild(this.FL._doc.createElement('br'));
        }
      }
      else {
        this.element.appendChild(this.FL._doc.createTextNode(text));
      }
      return this;
    },
    html : function(html){
      this.element.innerHTML = html;
      return this;
    },
    getHTML : function(){
      return this.element.innerHTML.toString();
    },
    add : function(target, mode)
    {
      var mode = (mode) ? mode : '';
      var target = (target) ? (target.extended) ? target.getNative() : target : this.FL._doc.getElementsByTagName('body')[0];
      switch (mode) {
        case 'before': target.parentNode.insertBefore(this.element, target); break;
        case 'after':
          var parent = target.parentNode;
          (parent.lastChild == target) ? parent.appendChild(this.element) : parent.insertBefore(this.element, target.nextSibling);
        break;
        default : target.appendChild(this.element);break;
      }
      return this;
    },
    copy : function(flag)
    {
      var flag = (flag) ? flag : false;
      var cp = this.element.cloneNode(flag);
      return DOM.__setExtends(cp);
    },
    remove : function(target)
    {
      (target) ? target.removeChild(this.element) : this.element.parentNode.removeChild(this.element);
    },
    addStyle : function(name, value)
    {
      if (typeof name == 'string') {
        var p = name;
        var pattern_bg = /^[url]/g;
        if (p.indexOf('-') > 0) {
          var spl = p.split('-'), i = 1;
          p = spl[0];
          while (spl[i]) {
            p += spl[i].charAt(0).toUpperCase() + spl[i].substring(1).toLowerCase();
            i++;
          }
        }
        if (p == 'float')
        {
          (this.FL.ua.IE) ? this.element.style.styleFloat = value : this.element.style.cssFloat = value;
        }
        else if (p == 'opacity') {
          if (this.FL.ua.IE) {

            if (this.readStyle('hasLayout') == 1) {
              this.element.style.zoom = 1;
            }
            this.element.style.filter = 'alpha(opacity=' + value * 100 + ')';
          }
          else {
            this.element.style.opacity = value;
          }
        }
        else {
          if (p == 'backgroundImage') value = (pattern_bg.test(value)) ? value : 'url(' + value + ')';
          this.element.style[p] = value;
        }
      }
      else if (typeof name == 'object')
      {
        var obj = name;
        for (var p in obj)
        {
          var pattern_bg = /^[url]/;
          if (p.indexOf('-') > 0) {
            var spl = p.split('-');
            p = spl[0];
            var i = 1;
            while (spl[i]) {
              p += spl[i].charAt(0).toUpperCase() + spl[i].substring(1).toLowerCase();
              i++;
            }
          }
          if (p == 'float')
          {
            (this.FL.ua.IE) ? this.element.style.styleFloat = obj[p] : this.element.style.cssFloat = obj[p];
          }
          else if (p == 'opacity') {
            if (this.FL.ua.IE) {

              if (this.readStyle('hasLayout') == 1) {
                this.element.style.zoom = 1;
              }
              this.element.style.filter = 'alpha(opacity=' + obj[p] * 100 + ')';
            }
            else {
              this.element.style.opacity = obj[p];
            }
          }
          else {
            if (p == 'backgroundImage') obj[p] = (pattern_bg.test(obj[p])) ? obj[p] : (obj[p] != 'none') ? 'url(' + value + ')' : 'none';
            else this.element.style[p] = obj[p];
          }
        }
      }
      else
      {
        throw Error('invalid parametars');
      }
      return this;
    },
    readStyle : function(name, parsed){
      var name = name;
      if (name.indexOf('-') > 0) {
        var spl = name.split('-'), subname = spl[0], i = 1;
        while (spl[i]) {
          subname += spl[i].charAt(0).toUpperCase() + spl[i].substring(1).toLowerCase();
          i++;
        }
      }
      else {
        var subname = name;
      }
      if (subname == 'opacity')
      {
        if (this.FL.ua.IE)
        {
          if (this.element.style.filter)
          {
            value = this.element.style.filter.replace(/alpha\(opacity=(.*?)\)/g, '$1');
            return parseFloat(value / 100);
          }
          else
          {
            return 1.0;
          }
        }
        else
        {
          value = this.element.style.opacity;
          return (value) ? value : 1.0;
        }
      }
      if (subname == 'float')subname = (FL.ua.IE) ? 'styleFloat' : 'cssFloat';
      if (this.element.style[subname]) {
        if (isNaN(parseInt(this.element.style[subname]))) {
          return (subname == 'backgroundImage') ? this.element.style[subname].replace(/url\((.*?)\)/g, '$1').replace(/['"]/g, '') : this.element.style[subname];n
        }
        else
        {
          return (parsed) ? parseInt(this.element.style[subname]) : this.element.style[subname];
        }
      }
      else {
        if (this.element.currentStyle) {
          if (isNaN(parseInt(this.element.currentStyle[subname]))) {
            return (subname == 'backgroundImage') ? this.element.currentStyle[subname].replace(/url\((.*?)\)/g, '$1').replace(/['"]/g, '') : this.element.currentStyle[subname];
          }
          else {
            return (parsed) ? parseInt(this.element.currentStyle[subname]) : this.element.currentStyle[subname];
          }
        }
        else {
          if (Flint._win.getComputedStyle || (Flint._doc.defaultView && Flint._doc.defaultView.getComputedStyle)) {
            var gCS = Flint._win.getComputedStyle || Flint._doc.defaultView.getComputedStyle;
            var nowStyle = gCS(this.element, '');
            if (isNaN(parseInt(nowStyle.getPropertyValue(name)))) {
              return (name == 'background-image') ? nowStyle.getPropertyValue(name).replace(/url\((.*?)\)/g, '$1').replace(/'"/g, '') : nowStyle.getPropertyValue(name);
            }
            else
            {
              return (parsed) ? parseInt(nowStyle.getPropertyValue(name)) : nowStyle.getPropertyValue(name);
            }
          }
        }
      }
    },
    removeStyle : function(stylename)
    {
      var st = (this.FL.ua.IE) ? this.element.style.cssText : this.element.getAttribute('style');
      if (st == '')return false;
      reg = new RegExp(((this.FL.ua.IE) ? stylename.toUpperCase() : stylename) + '(.*?);');
      newSt = st.replace(reg, '');
      (this.FL.ua.IE) ? this.element.style.cssText = newSt : this.element.setAttribute('style', newSt);
      return this;
    },
    removeAllStyle : function()
    {
      (this.FL.ua.IE) ? this.element.style.cssText = '' : this.element.removeAttribute('style');
      return this;
    },
    absDimension : function()
    {
      if (this.element.getBoundingClientRect) {
        var rect = this.element.getBoundingClientRect();
       // var sc = this.FL.utility.absPos(this.element);
        var sc = this.FL.utility.getScrollPosition();
         var res = {
          width: (rect.right - rect.left),
          height: (rect.bottom - rect.top),
          top : rect.top + sc.y,
          left : rect.left + sc.x,
          right : rect.right + sc.x,
          bottom : rect.bottom + sc.y
        };
      }
      else {
        var res = {
          width: (element.readStyle('width', true) === 0 || element.readStyle('width', true) == 'auto') ? element.offsetWidth : element.readStyle('width', true),
          height: (element.readStyle('height', true) === 0 || element.readStyle('height', true) == 'auto') ? element.offsetHeight : element.readStyle('height', true)
        }
        var pos = this.FL.utlity.absPos();
        res.top = pos.y;
        res.left = pos.x;
        res.right = pos.x + res.width;
        res.bottom = pos.y + res.height
      }
      return res;
    },
    show : function(mode)
    {
      var flag = (mode) ? mode : false;
      this.addStyle('display', (flag === false) ? DOM.tagMap[this.element.tagName.toLowerCase()] : 'block');
      return this;
    },
    hide : function()
    {
      this.addStyle('display', 'none');
      return this;
    },
    toggleShow : function(mode)
    {
      var flag = (mode) ? mode : false;
      if (mode)
      {
        this.addStyle('display', (this.readStyle('display') == this.__defaultComputedStyle) ? 'block' : this.__defaultComputedStyle);
      }
      else this.addStyle('display', (this.readStyle('display') == this.__defaultComputedStyle) ? DOM.tagMap[this.element.tagName.toLowerCase()] : element.__defaultComputedStyle);
    },
    animate : function(effect, opt)
    {
      if (!Animation.hasOwnProperty(effect))
      {
        throw new Error(effect + ' animation is undefined.');
        return false;
      }
      else Animation[effect](this, opt);
    },
    drag : function (mode, opt)
    {
      DOM.draggable(this.element, mode, opt);
    },
    prop : function(prop, value)
    {
      // if supplied second argument, works setter.
      if (value) {
    	  try{
          this.element[prop] = value;
        }
        catch(e) {
          throw Error(this.element + ' don\'t have ' + prop);
          return;
        }
        return this;
      }
      // if supplied first argument only, works getter.
      else
      {
        if (prop in this.element) {
          return this.element[prop];
        }
        else {
          throw Error(this.element + ' don\'t have ' + prop);
          return;
        }
      }
    },
    getNative : function(){return this.element},
    parent : function(bool) {
    	return (bool && bool === true) ? DOM.__setExtends(this.element.parentNode) : this.element.parentNode;
    },
    childs : function(num, bool) {
    	var l = this.element.childNodes, ar = [];
    	for (var i = 0; i < l.length; i++)  if (l[i].nodeType === 1)ar.push(l[i]);
    	if (ar[num]) return (bool && bool === true) ? DOM.__setExtends(ar[num]) : ar[num];
    	return undefined;
    },
    first : function(bool) {
    	var f = this.element.firstChild;
    	while (f != null)  {
    		if (f.nodeType == 1)break;
    		else f = f.nextSibling;
    	}
    	if (f == null)return alert('not found');
    	return (bool && bool === true) ? DOM.__setExtends(f) : f;
    },
    last : function(bool) {
    	var l = this.element.lastChild;
    	while (l.nodeType !== 1) l = l.previousSibling;
    	return (bool && bool === true) ? DOM.__setExtends(l) : l;
    },
    next : function(bool) {
    	var n = this.element.nextSibling;
    	if (!n)return;
    	if (n.nodeType === 1) return (bool && bool === true) ? DOM.__setExtends(n) : n;
    	else return n;
    },
    prev : function(bool) {
    	var p = this.element.previousSibling;
    	if (!p)return;
    	if (p.nodeType === 1) return (bool && bool === true) ? DOM.__setExtends(p) : p;
    	else return p;
    },
    parentForm : function(bool) {
    	var e = this.element;
    	while (e) {
    		if (e === Flint._doc.body) break;
    		if (e.tagName.toLowerCase() == 'form') {
    			return (bool && bool === true) ? DOM.__setExends(e) : e;
    			break;
    		}
    		e = e.parentNode;
    	}
    	return null;
    },
    find : function(val /* val = CSS selector*/) {
    	var list = DOM.__getElementsBySelector(val, this.elment);
    	if (list == null)return null;
    	return  new DOM.__wrappedExtendNodeList(list);
    }
}

DOM.__wrappedExtendNodeList.prototype = {
  foreach : function(func) {
    for (var i = 0; i < this.length; i++) {
      func.apply(DOM.__setExtends(this.list[i]), [i]);
    }
  },
  forEach : function(func) {
	   for (var i = 0; i < this.length; i++) {
		      func.apply(DOM.__setExtends(this.list[i]), [i]);
		}
  },
  get : function(num) {
    return DOM.__setExtends(this.list[num]);
  }
}
DOM.__getElementsBySelector = function(value, root){
        var _doc = (root) ? root : document;
        _doc.__cid = ++DOM.cid;
        var cache = {};
        var trim = function(str){
          if (typeof str == 'string') {
            return str.replace(/^\s*(.*)\s*$/, '$1');
          }
          return str;
        }
        var value = trim(value);
        //if document.querySelectorAll is suppoted, use this API.
        if (_doc.querySelectorAll)
        {
          if (Flint.ua.IE8) //IE8 is not supports 'nth-child' , 'last-child' token.
          {
            if (/[\(|\)]|only\-child|last\-child|!/.test(value) === false) {
              var res = document.querySelectorAll(value);
              var ret = [];
              for (var i = 0, len = res.length; i < len; i++)
              {
                ret.push(res[i]);
              }
              return ret;
            }
          }
          else //else Browser is not supports '!', ':contains' token.
          {
            if (/!/.test(value) === false && value.indexOf(':contains') === -1)
            {
              return Array.prototype.slice.call(_doc.querySelectorAll(value));
            }
          }
        }
        //else : document.querySelectorAll is not supported or unsupoort token.
        //quick parse
        var quickParse = function(value)
        {
          cache = {};
          var spl = value.split(/\s/);
          var root = [_doc];
          for (var i = 0, len = spl.length; i < len; i++) {
            var res = [], tag = trim(spl[i]);
            for (var j = 0, len2 = root.length; j < len2; j++) {
              var tmp = root[j].getElementsByTagName(tag);
              for (var e = 0, m = tmp.length; e < m; e++) {
                tmp[e].__cid = (tmp[e].__cid) ? tmp[e].__cid : ++DOM.cid;
                if (tmp[e].__cid in cache)
                  continue;
                else {
                  res.push(tmp[e]);
                  cache[tmp[e].__cid] = tmp[e];
                }

              }
            }
            root = res;
          }
          return root;
        }
        if ((/[a-zA-Z0-9]\s{1}[a-zA-Z0-9]$/.test(value) || /[a-zA-Z0-9]\s{1}[a-zA-Z0-9]\s{1}[a-zA-Z0-9]$/.test) && (/[>\+~\[\],#\.:\|\-]/.test(value) === false))
        {
          return quickParse(value);
        }
        //quick parse with conma
        if ((/[a-zA-Z0-9]\s?,\s?[a-zA-Z0-9]$/.test(value) || /[a-zA-Z0-9]\s?,\s?[a-zA-Z0-9]\s?,\s?[a-zA-Z0-9]$/.test) && (/[>\+~\[\]#\.:\|\-]/.test(value) === false))
        {
          cache = {};
          var spl = value.split(',');
          var root = _doc, res = [];
          for (var i = 0, len = spl.length; i < len; i++)
          {
            if (/[a-zA-Z0-9]\s[a-zA-Z0-9]/.test(trim(spl[i])))
            {
              var tmp = quickParse(trim(spl[i]));
              for (var k = 0, lenk = tmp.length; k < lenk; k++)
              {
                res.push(tmp[k]);
              }
            }
            else
            {
              var tmp = root.getElementsByTagName(trim(spl[i]));
              for (var e = 0, m = tmp.length; e < m; e++)
              {
                tmp[e].__cid = (tmp[e].__cid) ? tmp[e].__cid : ++DOM.cid;
                if (tmp[e].__cid in cache)
                  continue;
                else {
                  res.push(tmp[e]);
                  cache[tmp[e].__cid] = tmp[e];
                }
              }
            }
          }
          return res;
        }

        var SelectorCSSExp = {
          //universal selector
          universal: /^[\*]/,
          //Attribute selector
          AttributeSelector: /\[.+\]/g,
          //Structural pseudo-classes
          root: /^\w+[:]root$/,
          nthChild: /^\w+[:]nth-child\(.+\)$/,
          nthLastChild: /^\w+[:]nth-last-child\(.+\)$/,
          nthOfType: /^\w+[:]nth-of-type\(.+\)$/,
          nthLastOfType: /^\w+[:]nth-last-of-type\(.+\)$/,
          firstChild: /^\w+[:]first-child$/,
          lastChild: /^\w+[:]last-child$/,
          firstOfType: /^\w+[:]first-of-type$/,
          lastOfType: /^\w+[:]last-of-type$/,
          onlyChild: /^\w+[:]only-child$/,
          onlyOfType: /^\w+[:]only-of-type$/,
          contains : /^\w+[:]contains\(.+\)$/,
          empty: /^[a-z]+[:]empty$/,
      /*    link: /^[a-z]+[:]link$/,
          visited: /^[a-z]+[:]visited$/,
          active: /^[a-z]+[:]active$/,
          hover: /^[a-z]+[:]hover$/,
          focus: /^[a-z]+[:]focus$/,
          target: /^[a-z]+[:]target$/,
          enabled: /^[a-z]+[:]enabled$/,
          disabled: /^[a-z]+[:]disabled$/,
          checked: /^[a-z]+[:]checked$/,
          firstLine: /^[a-z]+[:]first-line$/,
          firstLetter: /^[a-z]+[:]first-letter$/,
          selection: /^[a-z]+[:]selection$/,
          before: /^[a-z]+[:]before$/,
          after: /^[a-z]+[:]after$/,
      */    //class selector
          classSelector : /^\w*\.[\w\-_]+$/,
          //ID selector
          idSelector : /^\w*\#[\w\-_]+$/
        }
        var getNextElNode = function (node)
        {
          if (!node || !node.nextSibling)
          {
            return;
          }
          if (node.nextSibling.nodeType != 1)
          {
            return getNextElNode(node.nextSibling);
          }
          return node.nextSibling;
        }
        var getPreviousElNode = function(node)
        {
          if (!node || !node.previousSibling)return;
          if (node.previousSibling.nodeType !=1)
          {
            return getPreviousElNode(node.previousSibling);
          }
          return node.previousSibling;
        }
        var getParseRule = function(text)
        {
          var matched;
          for (var pattern in SelectorCSSExp)
          {
            if (SelectorCSSExp[pattern].test(text))
            {
              return pattern;
              break;
            }
          }
          if (matched == null)return false;
        }

        var separateLoop = function(arr)
        {
          if (typeof arr == 'string')var arr = [arr];
          var tmpElm = null;
          var rootElm = [((root) ? root : document)];

          var mode;
          var last = false;

          for (var i = 0; i < arr.length; i++)
          {
            if (/^[>+~]/.test(trim(arr[i])))
            {
              continue;
            }
            var t = trim(arr[i]);
            var next = (arr[i+1] != 'undefined') ? trim(arr[i+1]) : null;
            var res = getParseRule(t);
              switch(res)
              {
                case 'root':
                  tmpElm = [document.getElementsByTagName('html')[0]];
                break;
                case 'nthChild':
                  var rule = t.replace(/^[a-z]+[:]nth-child\((.*?)\).*$/, '$1');
                  var tag = t.split(":")[0], done = ++DOM.did;
                  var tmp = [];
                  if (tag == '')
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  cache = {};
                  switch (true)
                  {
                    case (rule == 'odd'):
                      var first = 2;
                      var offset = 1;
                      break;
                    case (rule == 'even'):
                      var first = 2;
                      var offset = 0;
                      break;
                    case (/[0-9]*[\\n][\+\-][0-9]*$/.test(rule)):
                    //case (rule.indexOf('n+') !== -1 || rule.indexOf('n-') !== -1):
                      var sp = rule.split('n');
                      var first = sp[0];
                      var offset = sp[1].substring(1);
                      break;
                    break;
                    case (rule.indexOf('n') != -1):
                      var first = (rule.indexOf('n') !== 0) ? rule.substring(0, rule.indexOf('n')) : 1;
                      var offset = 0;
                    break;
                    default :
                      if (isNaN(parseInt(rule)))
                      {
                        throw new Error('syntan error!');
                        return null;
                      }
                      else
                      {
                        var first = 0;
                        var offset = parseInt(rule);
                      }

                    break;
                  }
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var childs = [], cacheParent = {};
                    var tmps = rootElm[k].getElementsByTagName(tag);

                    for (var c = 0, len = tmps.length; c < len; c++) {
                      var e = tmps[c], parent = tmps[c].parentNode;
                      if (parent && (!parent.__done || parent.__done !== done)) {
                        var cnt = 0;
                        for (var n = parent.firstChild; n; n = n.nextSibling) {
                          if (n.nodeType === 1) {
                            n.__cid = ++cnt;
                          }
                        }
                        parent.__done = done;
                      }
                      //var offset = (e.__cid - ruleNum[1]);
                      if (first === 0) {
                        if ((e.__cid - offset) === 0)
                          tmp.push(e);
                      }
                      else {
                        if (((e.__cid - offset) % first === 0) && ((e.__cid - offset) / first >= 0)) {
                          tmp.push(e);
                        }
                      }
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'nthLastChild':
                  var rule = t.replace(/^[a-z]+[:]nth-last-child\((.*?)\).*$/, '$1');
                  var tag = t.split(':')[0];
                  var tmp = [];
                  if (tag == '')
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                    if (rootElm[k].__cid in DOM.queryCache) {
                      if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                      var childs = DOM.queryCache[rootElm[k].__cid][1];
                      }
                      else {
                        var childs = rootElm[k].getElementsByTagName(tag);
                        DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                      }
                    }
                    else {
                      var childs = rootElm[k].getElementsByTagName(tag);
                      DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                    }
                    if (childs.length == 0)continue;
                    if (isNaN(parseInt(rule))){
                      throw new Error('syntax error for "nth-child"');
                      return null;
                    }
                    else{
                      var num = parseInt(rule);
                      if (num == 0)num = 1;
                      childs.reverse();
                    }
                    tmp.push(childs[num - 1]);
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'nthOfType':
                  var rule = t.replace(SelectorCSSExp.nthOfType, '$1');
                  var tag = t.split(/[:]/)[0];
                  var tmp = [], r = parseInt(rule);
                  if (tag == '' || isNaN(r))
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  done = ++DOM.did;
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var e = rootElm[k], p = e.parentNode;
                    if (p && (!p.__done || p.__done || p.__done != done)) {
                     var cnt = 0;
                     for (var i = p.firstChild; i; i = i.nextSibling) {
                       if (i.nodeType === 1 && i.tagName.toLowercase() == tag) {
                         ++cnt;
                         if (cnt == r)tmp.push(e);
                       }
                     }
                     p.__done = done;
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'nthLastOfType':
                  var rule = t.replace(SelectorCSSExp.nthLastOfType, '$1');
                  var tag = t.split(/[:]/)[0];
                  var tmp = [], r = parseInt(rule);
                  if (tag == '' || isNaN(r))
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  done = ++DOM.did;
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var e = rootElm[k], p = e.parentNode;
                    if (p && (!p.__done || p.__done || p.__done != done)) {
                     var cnt = 0;
                     for (var i = p.lastChild; i; i = i.previousSibling) {
                       if (i.nodeType === 1 && i.tagName.toLowerCase() == tag) {
                         ++cnt;
                         if (cnt == r)tmp.push(e);
                       }
                     }
                     p.__done = done;
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'firstChild':
                  var tag = t.split(":")[0];
                  var tmp = [], done = ++DOM.did;
                  if (tag == '') {
                    throw new Error('syntax error');
                    return null;
                  }
                  cache = {};
                  for (var k = 0; k < rootElm.length; k++) {
                    rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                    if (rootElm[k].__cid in DOM.queryCache) {
                      if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                      var childs = DOM.queryCache[rootElm[k].__cid][1];
                      }
                      else {
                        var childs = rootElm[k].getElementsByTagName(tag);
                        DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                      }
                    }
                    else {
                      var childs = rootElm[k].getElementsByTagName(tag);
                      DOM.DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                    }
                    if (childs.length == 0)continue;
                      for (var c = 0; c < childs.length; c++) {
                        var p = childs[c].parentNode, e = childs[c];
                        if (p)
                        {
                          if (!p.__done || p.__done !== done)
                          {
                            for (var n = p.firstChild; n; n = n.nextSibling) {
                              if (n.nodeType === 1) {
                                if (n === e)
                                  tmp.push(e);
                                p.__done = done;
                                break;
                              }
                            }
                          }
                        }
                      }

                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'lastChild':
                  var tag = t.split(/[:]/)[0];
                  var tmp = [], done = ++DOM.did;
                  if (tag == '') {
                    throw new Error('syntax error');
                    return null;
                  }
                  cache = {};
                  for (var k = 0; k < rootElm.length; k++) {
                    rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                    if (rootElm[k].__cid in DOM.queryCache) {
                      if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                      var childs = DOM.queryCache[rootElm[k].__cid][1];
                      }
                      else {
                        var childs = rootElm[k].getElementsByTagName(tag);
                        DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                      }
                    }
                    else {
                      var childs = rootElm[k].getElementsByTagName(tag);
                      DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                    }
                    if (childs.length == 0)continue;
                    for (var c = 0; c < childs.length; c++) {
                      var p = childs[c].parentNode, e = childs[c];
                      if (p) {
                          for (var n = p.lastChild; n; n = n.previousSibling) {
                            if (n.nodeType === 1) {
                              if (n === e)
                                tmp.push(e);
                              p.__done = done;
                              break;
                            }
                          }
                      }
//                      p.__cid = (p.__cid) ? p.__cid : ++DOM.cid;
                      //if (p.__cid in cache)continue;

//                      var e = p.lastChild;
//                      while (e.nodeType != 1)
//                      {
//                        if (!e) {
//                          cache[p.__cid] = p;
//                          break;
//                        }
//                        e = e.previousSibling;
//                      }
//                      if (e == childs[c]) {
//                        tmp.push(e);
//                        cache[p.__cid] = p;
//                      }
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'onlyChild':
                  var tag = t.split(/[:]/)[0];
                  var tmp = [];
                  cache = {};
                  if (tag == '') {
                    throw new Error('syntax error');
                    return null;
                  }
                  for (var k = 0; k < rootElm.length; k++) {
                    rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                    if (rootElm[k].__cid in DOM.queryCache) {
                      if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                      var childs = DOM.queryCache[rootElm[k].__cid][1];
                      }
                      else {
                        var childs = rootElm[k].getElementsByTagName(tag);
                        DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                      }
                    }
                    else {
                      var childs = rootElm[k].getElementsByTagName(tag);
                      DOM.queryCache[rootElm[k].__cid] = [tag, childs];
                    }
                    if (childs.length == 0)continue;
                    for (var c = 0; c < childs.length; c++) {
                      var p = childs[c].parentNode;
                      var ef = p.firstChild;
                      var el = p.lastChild;
                      while (ef.nodeType != 1) {
                          if (!ef) {
                            cache[p.__cid] = p;
                            break;
                          }
                          ef = ef.nextSibling;
                        }
                      while (el.nodeType != 1)
                      {
                        if (!el){
                          cache[p.__cid] = p;
                          break;
                        }
                        el = el.previousSibling;
                      }
                      if (ef == childs[c] && el == childs[c]) {
                          tmp.push(e);
                          cache[p.__cid] = p;
                        }
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'firstOfType':
                  var rule = t.replace(SelectorCSSExp.firstOfType, '$1');
                  var tag = t.split(/[:]/)[0];
                  var tmp = [];
                  if (tag == '')
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  done = ++DOM.did;
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var e = rootElm[k], p = e.parentNode;
                    if (p && (!p.__done || p.__done || p.__done != done)) {
                     for (var i = p.firstChild; i; i = i.nextSibling) {
                       if (i.nodeType === 1 && i.tagName.toLowerCase() == tag) {
                         tmp.push(e);
                         break;
                       }
                     }
                     p.__done = done;
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'lastOfType':
                  var rule = t.replace(SelectorCSSExp.lastOfType, '$1');
                  var tag = t.split(/[:]/)[0];
                  var tmp = [];
                  if (tag == '')
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  done = ++DOM.did;
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var e = rootElm[k], p = e.parentNode;
                    if (p && (!p.__done || p.__done || p.__done != done)) {
                     for (var i = p.lastChild; i; i = i.previousSibling) {
                       if (i.nodeType === 1 && i.tagName.toLowerCase() == tag) {
                         tmp.push(e);
                         break;
                       }
                     }
                     p.__done = done;
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'onlyOfType':
                  var rule = t.replace(SelectorCSSExp.OnlyOfType, '$1');
                  var tag = t.split(/[:]/)[0];
                  var tmp = [];
                  if (tag == '')
                  {
                    throw new Error('syntax error');
                    return null;
                  }
                  done = ++DOM.did;
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var e = rootElm[k], p = e.parentNode;
                    if (p && (!p.__done || p.__done || p.__done != done)) {
                     var cnt = 0;
                     for (var i = p.firstChild; i; i = i.nextSibling) {
                       if (i.nodeType === 1 && i.tagName.toLowerCase() == tag) {
                         ++cnt;
                       }
                     }
                     if (cnt == 1)tmp.push(e);
                     p.__done = done;
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'empty':
                  var tag = t.split(':')[0], tmp = [], cache = {};
                  if (tag == '') {
                    throw Error('systax error');
                    return null;
                  }
                  for (var k = 0; k < rootElm.length; k++) {
                    var e = rootElm[k];
                    var list = e.getElementsByTagName(tag);
                    for (var i = 0; i < list.length; i++) {
                      var p = list[i];
                      if (p.firstChild == null && p.childNodes.length == 0 && (!p.__cid || !(p.__cid in cache))) {
                        tmp.push(p);
                        p.__cid = ++DOM.cid;
                        cache[p.__cid] = p;
                      }
                    }
                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'contains':
                  //not supported.
                  return null;
                  var tag = t.split(':')[0];
                  var txt = t.replace(/^\w+:contains\((.*?)\)$/, '$1').replace(/['"]/g, '');
                  var tmp = [];
                  if (tag == '') {
                    throw new Error('syntax error');
                    return null;
                  }
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                    if (rootElm[k].__cid in DOM.queryCache) {
                      if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                      var e = DOM.queryCache[rootElm[k].__cid][1];
                      }
                      else {
                        var e = rootElm[k].getElementsByTagName(tag);
                        DOM.queryCache[rootElm[k].__cid] = [tag, e];
                      }
                    }
                    else {
                      var e = rootElm[k].getElementsByTagName(tag);
                      DOM.queryCache[rootElm[k].__cid] = [tag, e];
                    }
                    if (e.length == 0)continue;
                    for (var m = 0; m < e.length; m++)
                    {
                      var p = e[m].firstChild;
                      while (!p)
                      {
                        if (p.nodeType == 3)
                        {
                          if (p.nodeValue.indexOf(txt) != -1)
                            tmp.push()
                        }
                      }
                    }
                  }
                case 'AttributeSelector':
                  var tag = t.split(/\[/)[0];
                  if (tag == '')tag = '*';


                  var getAtts = function(t, cacheObj){
                    cache = (cacheObj) ? cacheObj : {};
                    if (t.indexOf("=") != -1) {
                      var att = t.split(/[=]/);
                    }
                    else {
                      var att = [t, ''];
                    }
                    var tmp = [];
                    if (/[\^~\$\*\|!]$/.test(att[0])) {
                      //条件指定属性取得　if

                      if (/[\^]/.test(att[0])) {
                        att[0] = att[0].replace(/[\^]/, '');
                        for (var k = 0; k < rootElm.length; k++) {
                          rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                          if (rootElm[k].__cid in DOM.queryCache) {
                            if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                            var e = DOM.queryCache[rootElm[k].__cid][1];
                            }
                            else {
                              var e = rootElm[k].getElementsByTagName(tag);
                              DOM.queryCache[rootElm[k].__cid] = [tag, e];
                            }
                          }
                          else {
                            var e = rootElm[k].getElementsByTagName(tag);
                            DOM.queryCache[rootElm[k].__cid] = [tag, e];
                          }
                          if (e.length == 0)
                            continue;
                          for (a = 0; a < e.length; a++) {
                            if (att[0] == 'class')
                            {
                              if (new RegExp("^" + att[1]).test(e[a].className)) {
                                e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                if (e[a].__cid in cache)continue;
                                tmp.push(e[a]);
                                cache[e[a].__cid] = e[a];
                              }
                            }
                            else
                            {
                              if (new RegExp("^" + att[1]).test(e[a].getAttribute(att[0]))) {
                                e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                if (e[a].__cid in cache)continue;
                                tmp.push(e[a]);
                                cache[e[a].__cid] = e[a];
                              }
                            }

                          }
                        }
                      }
                      else
                        if (/[\$]/.test(att[0])) {

                          att[0] = att[0].replace(/[\$]/, '');
                          for (var k = 0; k < rootElm.length; k++) {
                            rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                            if (rootElm[k].__cid in DOM.queryCache) {
                              if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                              var e = DOM.queryCache[rootElm[k].__cid][1];
                              }
                              else {
                                var e = rootElm[k].getElementsByTagName(tag);
                                DOM.queryCache[rootElm[k].__cid] = [tag, e];
                              }
                            }
                            else {
                              var e = rootElm[k].getElementsByTagName(tag);
                              DOM.queryCache[rootElm[k].__cid] = [tag, e];
                            }
                            if (e.length == 0)
                              continue;
                            for (a = 0; a < e.length; a++) {
                              if (att[0] == 'class')
                              {
                                if (new RegExp(att[1] + "$").test(e[a].className)) {
                                  e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                  if (e[a].__cid in cache)continue;
                                  tmp.push(e[a]);
                                  cache[e[a].__cid] = e[a];
                                }
                              }
                              else {
                                if (new RegExp(att[1] + "$").test(e[a].getAttribute(att[0]))) {
                                  e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                  if (e[a].__cid in cache)
                                    continue;
                                  tmp.push(e[a]);
                                  cache[e[a].__cid] = e[a];
                                }
                              }
                            }
                          }
                        }
                        else
                          if (/[\*]$/.test(att[0])) {

                            att[0] = att[0].replace(/[\*]/, '');
                            cache = {};
                            for (var k = 0; k < rootElm.length; k++) {
                              rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                              if (rootElm[k].__cid in DOM.queryCache) {
                                if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                                var e = DOM.queryCache[rootElm[k].__cid][1];
                                }
                                else {
                                  var e = rootElm[k].getElementsByTagName(tag);
                                  DOM.queryCache[rootElm[k].__cid] = [tag, e];
                                }
                              }
                              else {
                                var e = rootElm[k].getElementsByTagName(tag);
                                DOM.queryCache[rootElm[k].__cid] = [tag, e];
                              }
                              if (e.length == 0)
                                continue;
                              for (a = 0; a < e.length; a++) {
                                e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                if (e[a].__cid in cache)
                                  continue;
                                if (att[0] == 'class') {
                                  if (e[a].className.indexOf(att[1]) != -1)
                                    tmp.push(e[a]);
                                    cache[e[a].__cid] = e[a];

                                }
                                else {
                                  if (e[a].getAttribute(att[0]).indexOf(att[1]) != -1) {
                                    tmp.push(e[a]);
                                    cache[e[a].__cid] = e[a];

                                  }
                                }

                              }
                            }
                          }
                          else
                            if (/[~]/.test(att[0])) {
                              att[0] = att[0].replace(/[\~]/, '');
                              for (var k = 0; k < rootElm.length; k++) {
                                rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                                if (rootElm[k].__cid in DOM.queryCache) {
                                  if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                                  var e = DOM.queryCache[rootElm[k].__cid][1];
                                  }
                                  else {
                                    var e = rootElm[k].getElementsByTagName(tag);
                                    DOM.queryCache[rootElm[k].__cid] = [tag, e];
                                  }
                                }
                                else {
                                  var e = rootElm[k].getElementsByTagName(tag);
                                  DOM.queryCache[rootElm[k].__cid] = [tag, e];
                                }
                                if (e.length == 0)
                                  continue;
                                for (var a = 0; a < e.length; a++) {
                                  e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                  if (e[a].__cid in cache)
                                    continue;
                                  if (att[0] == 'class') {
                                    if (e[a].className.indexOf(att[1]) != -1)
                                      tmp.push(e[a]);
                                      cache[e[a].__cid] = e[a];

                                  }
                                  else {
                                    if (e[a].getAttribute(att[0]) != null)
                                    {
                                      if (e[a].getAttribute(att[0]).indexOf(att[1]) != -1) {
                                        tmp.push(e[a]);
                                        cache[e[a].__cid] = e[a];
                                      }

                                    }
                                  }

                                }
                              }
                            }
                          else
                            if (/[!]/.test(att[0])) {

                              att[0] = att[0].replace(/[!]/, '');
                              for (var k = 0; k < rootElm.length; k++) {
                                rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                                if (rootElm[k].__cid in DOM.queryCache) {
                                  if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                                  var e = DOM.queryCache[rootElm[k].__cid][1];
                                  }
                                  else {
                                    var e = rootElm[k].getElementsByTagName(tag);
                                    DOM.queryCache[rootElm[k].__cid] = [tag, e];
                                  }
                                }
                                else {
                                  var e = rootElm[k].getElementsByTagName(tag);
                                  DOM.queryCache[rootElm[k].__cid] = [tag, e];
                                }
                                if (e.length == 0)
                                  continue;
                                for (var a = 0; a < e.length; a++) {
                                  e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                  if (e[a].__cid in cache)
                                    continue;
                                  if (att[0] == 'class') {
                                    if (e[a].className.indexOf(att[1]) == -1)
                                      tmp.push(e[a]);
                                      cache[e[a].__cid] = e[a];

                                  }
                                  else {
                                    if (e[a].getAttribute(att[0]) != null)
                                    {
                                      if (e[a].getAttribute(att[0]).indexOf(att[1]) == -1) {
                                        tmp.push(e[a]);
                                        cache[e[a].__cid] = e[a];
                                      }

                                    }
                                  }

                                }
                              }
                            }
                            else {
                              return null;
                            }
                    }
                    else {
                      for (var k = 0; k < rootElm.length; k++) {
                        rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                        if (rootElm[k].__cid in DOM.queryCache) {
                          if (DOM.queryCache[rootElm[k].__cid][0] == tag) {
                            var e = DOM.queryCache[rootElm[k].__cid][1];
                          }
                          else {
                            var e = rootElm[k].getElementsByTagName(tag);
                            DOM.queryCache[rootElm[k].__cid] = [tag, e];
                          }
                        }
                        else {
                          var e = rootElm[k].getElementsByTagName(tag);
                          DOM.queryCache[rootElm[k].__cid] = [tag, e];
                        }
                        if (e.length == 0)
                          continue;
                        for (var a = 0; a < e.length; a++) {
                          if (att[0] == 'class') {
                            if (att[1] == '') {
                              if (e[a].className == null || e[a].className != '') {
                                e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                if (e[a].__cid in cache)
                                  continue;
                                tmp.push(e[a]);
                                cache[e[a].__cid] = e[a];
                              }
                            }
                            else {
                              if (e[a].className == att[1]) {
                                e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                if (e[a].__cid in cache)
                                  continue;
                                tmp.push(e[a]);
                                cache[e[a].__cid] = e[a];
                              }
                            }
                          }
                          else
                          {
                            if (att[1] == '') {
                                if (e[a].getAttribute(att[0]) == null || e[a].getAttribute(att[0]) != '') {
                                  e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                  if (e[a].__cid in cache)
                                    continue;
                                  tmp.push(e[a]);
                                  cache[e[a].__cid] = e[a];
                                }
                              }
                              else {
                                att[0] = (att[0] == 'class') ? 'className' : att[0];
                                if (e[a].getAttribute(att[0]) == att[1]) {
                                  e[a].__cid = (e[a].__cid) ? e[a].__cid : ++DOM.cid;
                                  if (e[a].__cid in cache)
                                    continue;
                                  tmp.push(e[a]);
                                  cache[e[a].__cid] = e[a];
                                }
                              }
                            }
                          }
                      }
                    }
                    return [tmp, cache];
                  }
                  var tp = t.replace(/^[a-z]+\[(.*?)\]$/, '$1');
                  var attributes = tp.split('][');
                  var totalElms = [];
                  var cached = {};
                  for (var a = 0; a < attributes.length; a++) {

                    var ret = getAtts(attributes[a], cached);
                    if (ret == null)return null;
                    for (var r = 0; r < ret[0].length; r++)
                    {
                      totalElms.push(ret[0][r]);
                    }
                    cached = ret[1];
                  }
                  tmpElm = totalElms;
                break;
                case 'universal':
                  var tmp = [];
                  for (var k = 0; k < rootElm.length; k++)
                  {
                    var e = rootElm[k].getElementsByTagName('*');
                    for (var c = 0; c < e.length; c++)
                    {
                      tmp.push(e[c]);
                    }
                  }
                  tmpElm = tmp;
                break;
                case 'classSelector':
                  t = t.split(".");
                  var tmp = [];
                  if (t[0] == '')
                  {

                    for (var k = 0; k < rootElm.length; k++)
                    {
                      if (document.getElementsByClassName) {
                        var e = rootElm[k].getElementsByClassName(t[1]);
                        if (e.length == 0)
                          continue;
                        for (var i = 0; i < e.length; i++) {
                          tmp.push(e[i]);
                        }
                      }
                      else {
                        var e = rootElm[k].getElementsByTagName('*');
                        if (e.length == 0)
                          continue;
                        for (var c = 0; c < e.length; c++) {
                          if (e[c].className == t[1])
                            tmp.push(e[c]);
                        }
                      }
                    }
                  }
                  else
                  {
                    for (var k = 0; k < rootElm.length; k++) {
                      rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;

                      if (rootElm[k].__cid in DOM.queryCache) {
                          if (DOM.queryCache[rootElm[k].__cid][0] == t[0]) {
                            var e = DOM.queryCache[rootElm[k].__cid][1];
                          }
                          else {
                            var e = rootElm[k].getElementsByTagName(t[0]);
                            DOM.queryCache[rootElm[k].__cid] = [t[0], e];
                          }
                      }
                      else {
                        var e = rootElm[k].getElementsByTagName(t[0]);
                        DOM.queryCache[rootElm[k].__cid] = [t[0], e];
                      }
                      if (e.length == 0)
                        continue;
                      for (var c = 0; c < e.length; c++) {
                        if (e[c].className == t[1])
                          tmp.push(e[c]);
                      }
                    }

                  }
                  if (tmp.length == 0)return null;
                  tmpElm = tmp;
                break;
                case 'idSelector':
                  t = t.split("#");
                  var tmp = [];
                  var e = document.getElementById(t[1]);
                  if (e == null)return null;
                  if (t[0] != '')
                  {
                    if (e.tagName.toLowerCase() == t[0])tmp.push(e);
                  }
                  else
                  {
                    tmp.push(e);
                  }
                  if (tmp.length == 0)return null;

                  tmpElm = tmp;

                break;
                default :
                  switch(mode)
                  {
                    case 'adjacent':
                      if (rootElm.length == 0)
                      {
                        return null;
                        break;
                      }
                      else
                      {
                        var tmp = [];
                        for (var k = 0; k < rootElm.length; k++)
                        {
                          var e = getNextElNode(rootElm[k]);
                          if (typeof e == 'undefined')continue;
                          if (e.tagName.toLowerCase() == t)
                            tmp.push(e);
                        }
                        if (tmp.length == 0)return null;
                        tmpElm = tmp;
                      }
                    break;
                    case 'child':
                      var tmp = [];

                      for (var k = 0; k < rootElm.length; k++)
                      {
                        rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                        if (rootElm[k].__cid in DOM.queryCache) {
                          if (DOM.queryCache[rootElm[k].__cid][0] == t) {
                            var e = DOM.queryCache[rootElm[k].__cid][1];
                          }
                          else {
                            var e = rootElm[k].getElementsByTagName(t);
                            DOM.queryCache[rootElm[k].__cid] = [t, e];
                          }
                        }
                        else {
                          var e = rootElm[k].getElementsByTagName(t);
                          DOM.queryCache[rootElm[k].__cid] = [t, e];
                        }

                        if (e.length == 0)continue;
                        for (var l = 0; l < e.length; l++)
                        {
                          if (e[l].parentNode == rootElm[k])tmp.push(e[l]);
                        }
                      }
                      tmpElm = tmp;
                    break;
                    case 'general':
                      if (rootElm == null) {
                        return null;
                        break;
                      }
                      else {
                        var tmp = [], cache = {}, done = 'general' + ++DOM.did;
                        for (var k = 0; k < rootElm.length; k++) {
                          var e = rootElm[k], p = e.parentNode;
                          if (!p.__done || p.__done !== done)
                          {
                            while(e != null)
                            {
                              if (e.nodeType == 1) {
                                if (e.tagName.toLowerCase() == t) {
                                  e.__cid = (e.__cid) ? e.__cid : ++DOM.cid;
                                  if (!(e.__cid in cache)) {
                                    tmp.push(e);
                                    cache[e.__cid] = e;
                                  }
                                }

                              }
                              e = e.nextSibling;
                            }
                            p.__done = done;
                          }
                        }
                        if (tmp.length == 0)
                          return null;
                        tmpElm = tmp;
                      }
                    break;
                    default :
                      var tmp = [];
                      cache = {};
                      for (var k = 0; k < rootElm.length; k++)
                      {
                        rootElm[k].__cid = (rootElm[k].__cid) ? rootElm[k].__cid : ++DOM.cid;
                        if (rootElm[k].__cid in DOM.queryCache) {
                          if (DOM.queryCache[rootElm[k].__cid][0] == t) {
                            var e = DOM.queryCache[rootElm[k].__cid][1];
                          }
                          else {
                            var e = rootElm[k].getElementsByTagName(t);
                            DOM.queryCache[rootElm[k].__cid] = [t, e];
                          }
                        }
                        else {
                          var e = rootElm[k].getElementsByTagName(t);
                          DOM.queryCache[rootElm[k].__cid] = [t, e];
                        }
                        if (e.length == 0)continue;

                          for (var l = 0; l < e.length; l++)
                          {
                            e[l].__cid = (e[l].__cid) ? e[l].__cid : ++DOM.cid;
                            if (e[l].__cid in cache)continue;
                            tmp.push(e[l]);
                            cache[e[l].__cid] = e[l];
                          }
                      }
                      tmpElm = tmp;
                    break;
                  }
                break;
              }

            if (next == null) {
              return tmpElm;
            }
            else
              if (/^[\+]/.test(next)) {
                mode = 'adjacent';
              }
              else
                if (/^[~]/.test(next)) {
                  mode = 'general';
                }
                else
                  if (/^[>]/.test(next)){
                    mode = 'child';
                  }
            if (tmpElm != null)
            {
              rootElm = tmpElm;
            }
            else
            {
              return tmpElm;
            }
          }
        }
      var returns = [];
        var text = value.split(",");
        for (var i = 0; i < text.length; i++) {
          if (text[i] == '')continue;
          var pointer = trim(text[i]).split(/\s/);
          var ret = separateLoop(pointer);
          if (ret != null) {
            for (var m = 0; m < ret.length; m++) {
              returns.push(ret[m]);
            }
          }
        }

      return returns;

}

DOM.createTable = function(arr, obj)
  {
    if (!arr || typeof arr == 'string' || arr.constructor != Array)return;
    var tbl = DOM.create('table');
    if (obj)tbl.attr(obj);
    var tb = DOM.create('tbody');
    for (var r = 0, len = arr.length; r < len; r++)
    {
      var tr = DOM.create('tr');
      for (var c = 0, len2 = arr[r].length; c < len2; c++)
      {
        var td = DOM.create('td');
        if (typeof arr[r][c] == 'string')
        {
          td.inText(arr[r][c]);
        }
        else
        {
          if (!arr[r][c].extended) DOM.__setextends(arr[r][c]);
          arr[r][c].add(td);
        }
        td.add(tr);
      }
      tr.add(tb);
    }
    tb.add(tbl);
    return tbl;
  }

DOM.layer = function()
  {
    if (Flint.layer != null)return Flint.layer;
    var FL = getInstance(), thisClass = this;
    var dNode = DOM.create('div', {'id' : 'fl_layer_id'});
    var added = false;
    dNode.attr('class', 'fl_dom_layer');
    dNode.addStyle({
      position: (!FL.ua.IE6) ? 'fixed' : 'absolute',
      zIndex: 1000,
      top: '0px',
      left: '0px',
      margin: '0px',
      padding: '0px'
    });
    var params = {
      backgroundColor: '#000',
      opacity: 0.7,
      animate: false
    }
    this.setPrams = function(obj){
      if (!obj) return;
      for (var p in obj) {
        params[p] = obj[p];
      }
    }
    var resize = function()
    {
      var page = FL.utility.getPageSize();
      var body = FL.utility.getBodyHeight();
      dNode.addStyle({
        'width' : page.width + 'px',
        'height' : (page.height > body) ? page.height + 'px' : body + 'px'
      });
    }
    this.show = function(listener, animate){
      var animate = (animate) ? animate : params.animate;
      var pageSize = FL.utility.getPageSize();
      var bodyHeight = FL.utility.getBodyHeight();
      ///well safe
      dNode.addStyle('overflow', 'hidden');
      dNode.addStyle({
        width: pageSize.width + 'px',
        height: (pageSize.height > bodyHeight) ? pageSize.height + 'px' : bodyHeight + 'px',
        opacity: (animate == true) ? 0 : params.opacity,
        backgroundColor: params.backgroundColor
      });
      if (added === false) {
        dNode.add(Flint._doc.body);
        added = true;
      }
      else {
        dNode.show();
      }
      if (FL.ua.IE6) {
        var sl = Flint._doc.getElementsByTagName('select')
        if (sl.length != 0) {
          for (var h = 0, len = sl.length; h < len; h++) {
            sl[h].style.visibility = 'hidden';
          }
        }
      }
      (animate) ? Animation.appear(dNode, {from: 0, to: params.opacity, listener: (listener)}) : listener();
      FL.event.set(window, 'resize', resize);
    }
    this.hide = function(){
      if (FL.ua.IE6) {
        var sl = Flint._doc.getElementsByTagName('select')
        if (sl.length != 0) {
          for (var h = 0, len = sl.length; h < len; h++) sl[h].style.visibility = 'visible';
        }
      }
      dNode.hide();
      FL.event.remove(window, 'resize', resize);
    }
  }
 DOM.draggable = function(target, mode, opt)
 {
  if (!target)return;
  if (typeof target == 'string') {
    var target = DOM.search('id', target);
    if (target == null)return;
  }
  else {
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
  }

  var FL = getInstance();
  var position = FL.utility.absPos(target);
  var offset = {}, dragFlag = false;
  if (opt) {
    var listeners = {
      'start': (opt.start) ? opt.start : null,
      'dragging': (opt.dragging) ? opt.dragging : null,
      'end': (opt.end) ? opt.end : null,
      'bind': (opt.bind) ? opt.bind : arguments.callee.caller
    }
  }
  else {
    var listeners = {
      'start': null,
      'dragging': null,
      'end': null,
      'bind': arguments.callee.caller
    }
  }
  var mode = (mode) ? mode : 'XY';
  var mouseDownListener = function(ev)
  {
    (FL.ua.IE) ? Flint._doc.body.onselectstart = function(){return false;} : ev.preventDefault();
    target.addStyle({
      cursor : 'move',
      opacity : 0.8,
      position : 'absolute',
      top : position.y + 'px',
      left : position.x + 'px'
    });
    var mouse = FL.utility.getMousePosition(ev);
    offset.x = mouse.x - position.x;
    offset.y = mouse.y - position.y;
    FL.event.set(document, 'mousemove', mouseMoveListener);
    FL.event.set(document, 'mouseup', mouseUpListener);
    dragFlag = true;
    if (listeners.start != null)listeners.start.call(listeners.bind, mouse);
  }
  var mouseMoveListener = function(ev)
  {
    //well safe.
    if (!dragFlag)return;
    var mouse = FL.utility.getMousePosition(ev);
    switch (mode)
    {
      case 'X' : target.addStyle({left : mouse.x - offset.x + 'px'});break;
      case 'Y' : target.addStyle({top : mouse.y - offset.y + 'px'});break;
      default :
          target.addStyle({
            top : mouse.y - offset.y + 'px',
            left : mouse.x - offset.x + 'px'
          });
      break;
    }
    if (listeners.dragging != null)listeners.dragging.call(listeners.bind, mouse);

  }
  var mouseUpListener = function(ev)
  {
    var mouse = FL.utility.getMousePosition(ev);
    position.y = target.readStyle('top', true);
    position.x = target.readStyle('left', true);
    target.addStyle('cursor', 'default');
    FL.event.remove(document, 'mousemove', mouseMoveListener);
    FL.event.remove(document, 'mouseup', arguments.callee);
    dragFlag = false;
    if (listeners.end != null)listeners.end.call(listeners.bind, mouse);
  }
  target.event('mousedown', mouseDownListener);
  this.stop = function()
  {
    FL.event.remove(document, 'mousemove', mouseMoveListener);
    FL.event.remove(document, 'mouseup', mouseUpListener);
    dragFlag = false;
    if (listeners.end != null)listeners.end.call(listeners.bind);

  }
 }


 var Animation = {
  globaltimer: {
    af : '', bd : '', bu : '', bbd : '', bbu : '', apc : '', sf : '', mx : '', my : '', pf : '', pf_d : '',
    dO : '', s : '', ew : '', eh : ''
  },
  appear : function(target, opt)
  {
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {position: target.readStyle('position'), display : target.readStyle('display')}
    if (FL.ua.IE && target.readStyle('hasLayout') == false) target.addStyle('zoom', 1);
    if (info.position == 'static')target.addStyle('position', 'relative');
    if (opt && typeof opt == 'object') {
      var from = (opt.from) ? opt.from : (target.readStyle('opacity', true) >= 1) ? 0 : target.readStyle('opacity', true);
      var to = (opt.to) ? opt.to : 1.0;
      var speed = (opt.speed) ? opt.speed : 0.02;
      var listener = opt.listener;
    }
    else var from = (target.readStyle('opacity') >= 1) ? 0 : target.readStyle('opacity', true), to = 1.0, speed = (FL.ua.IE) ? 0.1 : 0.02;
    if (info.display == 'none')target.addStyle('display', 'block');
    from = parseFloat(from);
    var option = {
      from : from, to : to, speed : speed, info : info, listener : (listener) ? listener : null, def : def
    }
    Animation.__af(target, option, 'ap');
  },
  fade : function(target, opt)
  {
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {position: target.readStyle('position')}
    if (opt && typeof opt == 'object') {
      var from = (opt.from) ? opt.from : parseInt(target.readStyle('opacity'));
      var to = (opt.to) ? opt.to : 0;
      var speed = (opt.speed) ? opt.speed : 0.02;
      var listener = opt.listener;
    }
    else var from = target.readStyle('opacity'), to = 0, speed = 0.02;
    from = parseFloat(from);
    var option = {
      from : from, to : to, speed : speed, info : info, listener : (listener) ? listener : null
    }
    Animation.__af(target, option, 'fd');
  },
  __af : function(target, opt, mode)
  {
    var from = opt.from, to = opt.to, speed = opt.speed;
    target.__af = Flint._win.setInterval(function(){
      if (from > to)
      {
        from -= speed ;
        if (from < to) from = to;
      }
      else
      {
        from += speed;
        if (from > to)from = to;
      }
      target.addStyle('opacity', from);
      if (from == to) {
        clearInterval(target.__af);
        if (opt.info.position == 'static')target.addStyle('position', 'static');
        if (opt.listener) opt.listener.apply(target);
      }
    }, 10);
  },
  expandW : function(target)
  {
    try {
      clearInterval(target.__ew)
    }
    catch (e) {}
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    if (target.readStyle('width', true) == 0 || target.readStyle('width', true) == 'auto') {
      var width = target.offsetWidth;
      var left = (info.position == 'static') ? width / 2 : info.pos.x + width /2;
    }
    else {
      var width = target.readStyle('width', true);
      var left = (info.position == 'static') ? width / 2 : info.pos.x + width /2;
    }
    if (info.position == 'static')target.addStyle('position', 'relative');
    target.addStyle('overflow', 'hidden');
    var to = width, from = 0, speed = 4;
    target.__ew = Flint._win.setInterval(function(){
      from += speed;
      left -= speed /2;
      if (from > to)from = to;
      target.addStyle({'width' : from + 'px', 'left' : left + 'px'});
      if (from == to) {
        clearInterval(target.__ew);
        setTimeout(function(){
          target.removeAllStyle();
          if (def !== '')target.attr('style', def);
        }, 500);
      }
    }, 5);
  },
  expandH : function(target, to)
  {
    try {
      clearInterval(target.__eh);
    }
    catch (e) {}
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    if (target.readStyle('height', true) == 0 || target.readStyle('wiheightdth', true) == 'auto') {
      var height = target.offsetHeight;
      var top = (info.position == 'static') ? height / 2 : info.pos.y + height /2;
    }
    else {
      var height = target.readStyle('height', true);
      var top = (info.position == 'static') ? height / 2 : info.pos.y + height /2;
    }
    if (info.position == 'static' && target.readStyle('display') !== 'inline')target.addStyle('position', 'relative');
    if (/input|select|textarea/.test(target.tagName.toLowerCase()) === false)target.addStyle('overflow', 'hidden');
    var to = (to) ? to : height, from = target.absDimension().height, speed = 4;
//    var flag = (to > from) ? true : false;
    target.__eh = setInterval(function(){
      from += speed;
      top -= speed /2;
      if (from > to)from = to;
      target.addStyle({'height' : from + 'px','top' : top + 'px'});
      if (from == to) {
        clearInterval(target.__eh);
        //setTimeout(function(){
        //  target.removeAllStyle();
        //  if (def != '')target.attr('style', def);
        //}, 500);
      }
    }, 5);
  },
  blindDown : function(target, opt)
  {
    try {
      clearInterval(target.__bdu);
    }
    catch (e) {}
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    target.addStyle('height', 'auto');
    target.addStyle('display', 'block');
    var height = (target.readStyle('height', true) == 0 || target.readStyle('height', true) == 'auto') ? target.element.offsetHeight : target.readStyle('height', true);
    //if (info.position == 'static')target.addStyle('position', 'relative');
    if (/input|select|textarea/.test(target.tag) === false) {
      target.addStyle({
        'overflow': 'hidden',
        'height': '0px',
        'display' : 'block'
      });
    }
    if (opt && typeof opt == 'object') {
      var from = (opt.from) ? opt.from : 0;
      var to = (opt.to) ? opt.to : height;
      var speed = (opt.speed) ? opt.speed : 0.1;
      var listener = opt.listener;
    }
    else var from = 0, speed = 0.1, to = height;
    alert(to);
    var option = {
      from : from, to : to, speed : speed, listener : (listener) ? listener : null, def : def
    };
    Animation.__bdu(target, option, 'down');
/*    target.__bdu = setInterval(function(){
      from += speed * 50;
      if (from > to) from = to;
      target.addStyle('height', from + 'px');
      if (from == to) {
        clearInterval(target.__bdu);
//        setTimeout(function(){
          target.removeAllStyle();
        if (def != '')target.attr('style', def);
//        }, 1000);
        if (listener) listener.apply();
      }
    }, 5);
*/  },
  blindUp : function(target, opt)
  {
    try {
      clearInterval(target.__bdu);
    }
    catch (e) {}
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    var height = target.absDimension().height;
    //if (info.position == 'static')target.addStyle('position', 'relative');
    if (/input|select|textarea/.test(target.tag) === false)target.addStyle('overflow', 'hidden');

    if (opt && typeof opt == 'object') {
      var to = (opt.to) ? opt.to : 0;
      var from = (opt.from) ? opt.from : height;
      var speed = (opt.speed) ? opt.speed : 0.1;
      var listener = opt.listener;
    }
    else var to = 0, speed = 0.1, from = height;
    var option = {
      from : from, to : to, speed : speed, listener : (listener) ? listener : null, def : def
    };
    Animation.__bdu(target, option, 'up');
/*    target.__bdu = setInterval(function(){
      from -= speed * 50;
      if (from < to) from = to;
      target.addStyle('height', from + 'px');
      if (from == to) {
        clearInterval(target.__bdu);
      //  setTimeout(function(){
          target.removeAllStyle();
          if (def != '')target.attr('style', def);
      //  }, 1000);
      } if (listener)listener.apply();
    }, 1);
*/  },
  __bdu : function(target, opt, mode)
  {
    var from = opt.from, to = opt.to, speed = opt.speed, def = opt.def, listener = opt.listener;
    target.__bdu = setInterval(function(){
      if (mode == 'up')
      {
        from -= speed * 50;
        if (from < to) from = to;
      }
      else
      {
        from += speed * 50;
        if (from > to) from = to;
      }
      target.addStyle('height', from + 'px');
      if (from == to) {
        clearInterval(target.__bdu);
        if (/input|select|textarea/.test(target.tag) === true)target.removeStyle('overflow');

        if (listener)listener.apply();
      //  setTimeout(function(){
        //  target.removeAllStyle();
        //  if (def != '')target.attr('style', def);
      //  }, 1000);

      }
    }, 1);
  },

  boundBlindDown : function(target)
  {
    try {
      clearInterval(target.__bbd);
    }
    catch (e) {}
    var FL = getInstance();
    var def = target.readAttr('style');
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    target.addStyle('display', 'block');
    target.addStyle('height', 'auto');
    var height = (target.readStyle('height', true) == 0 || target.readStyle('height', true) == 'auto') ? target.element.offsetHeight : target.readStyle('height', true);
    target.addStyle('height', 0 + 'px');
    //if (info.position == 'static')target.addStyle('position', 'relative');
    target.addStyle('overflow', 'hidden');
    var to = height;
    var secondTo = to * 0.85;
    var from = 0, speed = 2, flag = 0;

    target.__bbd = setInterval(function(){
      if (flag == 0)
      {
        from += speed;
        if (from > to) from = to;
        target.addStyle('height', from + 'px');
        if (from == to) {speed = 2; flag = 1;}
      }
      else if (flag == 1)
      {
        from -= speed;
        if (from < secondTo) from = secondTo;
        target.addStyle('height', from + 'px');
        if (from == secondTo) {speed = 2; flag = 2;}
      }
      else
      {
        from += speed;
        if (from > to) from = to;
        target.addStyle('height', from + 'px');
        if (from == to) {
          clearInterval(target.__bbd);
//          setTimeout(function(){
//            target.removeAllStyle();
//            if (def != '')target.attr('style', def);
//          }, 1000);
        }
      }
      speed += 0.5;
    }, 1);
  },
  boundBlindUp : function(target)
  {
    try{
      clearInterval(target.__bbu);
    }
    catch(e){};
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    var height = (target.readStyle('height', true) == 0 || target.readStyle('height', true) == 'auto') ? target.offsetHeight : target.readStyle('height', true);
    //if (info.position)target.addStyle({position: 'relative'});
    target.addStyle('overflow', 'hidden');
    var from = height;
    var secondTo = from * 0.15, to = 0, speed = 0.5, flag = 0;
    target.__bbu = setInterval(function(){
      if (flag == 0)
      {
        from -= speed;
        if (from < to) from = to;
        target.addStyle('height', from + 'px');
        if (from == to) {speed = 2; flag = 1;}
      }
      else if (flag == 1)
      {
        from += speed;
        if (from > secondTo) from = secondTo;
        target.addStyle('height', from + 'px');
        if (from == secondTo) {speed = 2; flag = 2;}
      }
      else
      {
        from -= speed;
        if (from < to) from = to;
        target.addStyle('height', from + 'px');
        if (from == to) {
          clearInterval(target.__bbu);
//          setTimeout(function(){
//            target.removeAllStyle();
//            if (def != '')target.attr('style', def);
//          }, 1000);
        }
      }
      speed += 0.5;
    }, 10);
  },
/*  approache : function(target, opt)
  {
    if (!opt || typeof opt != 'object') return;
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var nowPos = FL.utility.absPos(target);
    var fromX = nowPos.x, fromY = nowPos.y;
    target.addStyle('position', 'absolute');
    if (opt.x && opt.y)var percent = opt.y / opt.x, mode = 'XY';
    else
    {
      var percent = 1;
      if (!opt.x) mode = 'Y';
      else{
        if (!opt.y) mode = 'X';
      }
    }
    var toX = (opt.x) ? (opt.x) : nowPos.x;
    var toY = (opt.y) ? (opt.y - nowPos.y) : nowPos.y;
    var absFlag = (toY - nowPos.y < 0 || toX - nowPos.x < 0) ? true : false;
    var speed = 15;
    switch (mode) {
      case 'X':
        Animation.globaltimer.apc = setInterval(function(){
          fromX = fromX + (toX - fromX) / speed;
          if (fromX > toX - 1) fromX = toX;
          target.addStyle('left', fromX + 'px');
          if (fromX == toX)clearInterval(Animation.globaltimer);
        }, 10);
        break;
      case 'Y':
        Animation.globaltimer.apc = setInterval(function(){
          if (!absFlag) {
            fromY = fromY + (toY - fromY) / speed;
            if (fromY > toY - 5) fromY = toY;
            target.addStyle('top', fromY + 'px');
            if (fromY == toY) clearInterval(timer);
          }
          else
          {
            fromY = fromY + (toY - fromY) / speed;
            if (fromY < toY - 5) fromY = toY;
            target.addStyle('top', fromY + 'px');
            if (fromY == toY) clearInterval(timer);
          }
        }, 10);
        break;
      case 'XY':
        Animation.globaltimer.apc = setInterval(function(){
          fromX = fromX + (toX - fromX) / speed;
          fromY = fromY + (toY - fromY) / speed;
          if (fromX > toX - 1 || fromY > toY - 1) {
            fromX = toX;
            fromY = toY;
          }
          target.addStyle('top', fromY + 'px');
          target.addStyle('left', fromX + 'px');
          if (fromX == toX) clearInterval(this.globaltimer);
        }, 10);
        break;
      }
  },
*/  scrollFollow : function(target, offsetY, min)
  {
    try{
      clearInterval(target.__sf);
    }
    catch(e){};
    var FL = getInstance(), min = (min) ? min : 0;
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var info = {
      pos: FL.utility.absPos(target),
      position: target.readStyle('position')
    }
    var offsetY = (offsetY) ? offsetY : 0;
    target.addStyle({'position' : 'absolute', 'top' : info.pos.y + 'px', 'left' : info.pos.x + 'px'})
     FL.event.set(window, 'scroll', function(ev){
      var scroll = FL.utility.getScrollPosition();

      try{
        clearTimeout(target.__sf);
      }
      catch(e){}
      target.__sf = setTimeout(function(){
        var page = FL.utility.getPageSize();
        var posY = target.readStyle('top', true);
        var to = page.height / 2 + scroll.y - offsetY;
        var flag = (to > posY)? true : false;
        var distance = Math.abs(to - posY);
        var toY = distance, dis = 0, nowY = posY;
        var speed = (speed) ? speed : 3;
        var timer = setInterval(function(){
          (!flag) ? nowY -= speed : nowY += speed;
          dis += speed;
          if (dis >= distance) {
            (!flag) ? nowY = posY - distance : nowY = posY + distance;
            target.addStyle('top', nowY + 'px');
            clearInterval(timer);
          }
          else
            target.addStyle('top', nowY + 'px');
        }, 1);
        clearTimeout(target.__sf);
      }, 300);
    });
  },
  moveX : function(target, distance, abs, speed)
  {
    try{
      clearInterval(target.__mx);
    }
    catch(e){}
    var absFlag = (abs && abs == 'l') ? false : true;
    var info = FL.utility.absPos(target);
    var info = FL.utility.absPos(target);
    var pos = target.readStyle('position');
    var toX = (!absFlag) ? -distance + info.x : distance + info.x;
    if(!target.__defY)target.__defX = info.x;
    var speed = (speed) ? speed : 5;
    if (pos == 'static') {
      target.addStyle({
        'position': 'relative'
      });
      //target.addStyle('top', target.readStyle('top', true) + 'px');
    }
    nowX = (target.readStyle('left', true) == 'auto') ? 0 : target.readStyle('left', true);

    target.__my = setInterval(function(){
      (!absFlag) ? nowX -= speed : nowX += speed;

        //(!absFlag) ? nowY = -(distance + Math.abs(info.y - target.__defY)) : nowY =  info.y + distance - target.__defY;
        //target.addStyle('top', nowY + 'px');
        //target.removeAllStyle();
        //if (def != '')target.attr('style', def);


      target.addStyle('left', nowX + 'px');
      if (!absFlag) {
        if (nowX <= toX)
          clearInterval(target.__my);
      }
      else {
         if (nowX >= toX)
          clearInterval(target.__my);
      }

    }, 5);
  },
/*    target.addStyle({'position' : 'absolute', 'top' : info.y + 'px', 'left' : info.x + 'px'});
    var toX = distance, dis = 0, nowX = info.x;
    var speed = (speed) ? speed : 5;
    var pod
    target.__mx = setInterval(function(){
      (!absFlag) ? nowX -= speed : nowX += speed;
      dis += speed;
      if (dis >= distance)
      {
        (!absFlag) ? nowX = info.x - distance : nowX = info.x + distance;
        target.addStyle('left', nowX + 'px');
        clearInterval(target.__mx);
      }
      else target.addStyle('left', nowX + 'px');
    }, 1);
  },
*/  moveY : function(target, distance, abs, speed, def)
  {
    try{
      clearInterval(target.__my);
    }
    catch(e){}
    if (!distance || !target)return;
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var absFlag = (abs && abs == 'o') ? false : true;
    var info = FL.utility.absPos(target);
    var pos = target.readStyle('position');
    var toY = (!absFlag) ? -distance + info.y : distance + info.y;
    if(!target.__defY)target.__defY = info.y;
    var speed = (speed) ? speed : 5;
    if (pos == 'static') {
      target.addStyle({
        'position': 'relative'
      });
      //target.addStyle('top', target.readStyle('top', true) + 'px');
    }
    nowY = target.readStyle('top', true);
    target.__my = setInterval(function(){
      (!absFlag) ? nowY -= speed : nowY += speed;

        //(!absFlag) ? nowY = -(distance + Math.abs(info.y - target.__defY)) : nowY =  info.y + distance - target.__defY;
        //target.addStyle('top', nowY + 'px');
        //target.removeAllStyle();
        //if (def != '')target.attr('style', def);


      target.addStyle('top', nowY + 'px');
      if (!absFlag) {
        if (nowY <= toY)
          clearInterval(target.__my);
      }
      else {
         if (nowY >= toY)
          clearInterval(target.__my);
      }

    }, 5);
  },
  puff : function(target)
  {
    try{
      clearInterval(target.__pf);
      clearInterval(target.__pf_d)
    }
    catch(e){}
    if (!target)return;
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var ps = FL.utility.absPos(target);
    var speed = 2;
    var info = {
      width : target.readStyle('width', true),
      height : target.readStyle('height', true),
      pos : FL.utility.absPos(target),
      op : target.readStyle('opacity'),
      position : target.readStyle('position')
    };
    target.addStyle({
      position : (info.position == 'static') ? 'relative' : info.position,
      top : info.pos.y + 'px',
      left : info.pos.x + 'px'
     });
    target.__pf = setInterval(function(){
      var w = target.readStyle('width', true) + speed;
      var h = target.readStyle('height', true) + speed;
      var op = target.readStyle('opacity') - speed / 80;
      var t = target.readStyle('top', true) - speed/4;
      var l = target.readStyle('left', true) - speed/4;
      if (op < - 0.1) {
        target.__pf_d = setTimeout(function(){
          target.removeAllStyle();
          if (def != '' && def != null) {
            target.attr('style', def);
          }
        }, 1000);
        clearInterval(target.__pf);
      }
      else {
        target.addStyle({
          width: w + 'px',
          height: h + 'px',
          top: t + 'px',
          left: l + 'px',
          opacity: op
        });
      }
    }, 2);
  },
  switchOff: function(target){
    try {
      clearInterval(target.__so);
    }
    catch (e) {
    }
    if (!target)
      return;
    var FL = getInstance(), defaultFlag = false, defaultHFlag = false;
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var ps = FL.utility.absPos(target);
    var speed = 2, cn = 0;
    var info = {
      op : target.readStyle('opacity'),
      position: target.readStyle('position')
    };
    if (target.readStyle('height', true) == 0 || target.readStyle('height', true) == 'auto') {
      var height = target.offsetHeight;
      defaultHFlag = true;
    }
    else {
      var height = target.readStyle('height', true);
    }
    switch (info.position)
    {
      case 'static':
        target.addStyle({position: 'relative'});
        info.y = FL.utility.absPos(target).y;
        defaultFlag = true;
        var t = info.y;
      break;
      default :
        if (target.readStyle('top', true) == 0 || target.readStyle('top', true) == 'auto') {
          info.y = FL.utility.absPos(target).y;
          var t = (info.position == 'relative') ? 0 :info.y;
          defaultFlag = true;
        }
        else
        {
          info.y = target.readStyle('top', true);
          var t = (info.position == 'relative') ? 0 :info.y;
        }
      break;
    }
    var h = height;
    var timer = setInterval(function(){
      if (cn == 0 || cn == 2)
        target.addStyle('opacity', info.op - 0.3);
      else if (cn == 1 || cn == 3)
        target.addStyle('opacity', info.op);
      cn++;
      if (cn == 10) {
        clearInterval(timer);
        target.__so = setInterval(function(){
          h -= speed * 2;
          t += speed;
          if (h < 0)
          {
            clearInterval(target.__so);
            target.removeAllStyle();
            if (def != '')target.attr('style', def);
          }
          else
          {
            target.addStyle({height : h + 'px', top : t + 'px'});
          }
        }, 5);
      }

    }, 50);
  },
  dropOut : function(target)
  {
    try {
      clearInterval(target.__dO);
    }
    catch (e) {
    }
    if (!target)
      return;
    var FL = getInstance(), defaultFlag = false;
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style'), speed = 1.5;
    var info = {
      op: target.readStyle('opacity'),
      position: target.readStyle('position'),
      z : target.readStyle('zIndex')
    };
    switch (info.position)
    {
      case 'static':
        target.addStyle({position: 'relative'});
        info.y = FL.utility.absPos(target).y;
        var t = 0;
      break;
      default :
        if (target.readStyle('top', true) == 0 || target.readStyle('top', true) == 'auto') {
          info.y = FL.utility.absPos(target).y;
          var t = (info.position == 'relative') ? 0 :info.y;
          defaultFlag = true;
        }
        else
        {
          info.y = target.readStyle('top', true);
          var t = (info.position == 'relative') ? 0 :info.y;
        }
      break;
    }
    target.__dO = setInterval(function(){
      t += speed;
      var op = target.readStyle('opacity') - speed / 50;
      if (op  < -0.5)
      {
        clearInterval(target.__dO);
        target.removeAllStyle();
        if (def != '')target.attr('style', def);
      }
      else
      {
        target.addStyle({top : t + 'px', opacity : op});
      }
    }, 1);
  },
  shake : function(target)
  {
    try {
      clearInterval(target.__sh);
    }
    catch (e) {
    }
    if (!target)
      return;
    var FL = getInstance();
    var target = (!target.extended) ? DOM.__setExtends(target) : target;
    var def = target.readAttr('style');
    var speed = 2, cn = 0, lrFlag = true, dis = 0;
    var info = {position: target.readStyle('position')};
    switch (info.position)
    {
      case 'static':
        target.addStyle({position: 'relative'});
        var nl = 0;
      break;
      default :
        if (target.readStyle('left', true) == 0 || target.readStyle('left', true) == 'auto') {
          info.left = FL.utility.absPos(target).x;
          var nl = info.left;
        }
        else {
          info.left = target.readStyle('left', true);
          var nl = info.left;
        }
      break;
    }
    target.__sh = setInterval(function(){
      if (cn == 0 || cn == 2)
      {
        if (lrFlag) {
          var timer = setInterval(function(){
            nl += speed * 2;
            dis += speed * 2;
            if (cn == 0) {
              if (dis > 20) {
                clearInterval(timer);
                dis = 0;
                lrFlag = true;
                cn++;
              }
              else target.addStyle('left', nl + 'px');
            }
            else {
              if (dis > 40) {
                clearInterval(timer);
                dis = 0;
                lrFlag = true;
                cn++;
              }
              else target.addStyle('left', nl + 'px');
            }
          }, 1);
          lrFlag = false;
        }
      }
      else if (cn == 1 || cn == 3)
      {
        if (lrFlag)
        {
          var timer2 = setInterval(function(){
            nl -= speed * 2;
            dis += speed * 2;
            if (dis > 40) {
              clearInterval(timer2);
              dis = 0;
              cn++;
              lrFlag = true;
            }
            else target.addStyle('left', nl + 'px');
          }, 1);
          lrFlag = false;
        }
      }
      else if (cn == 4)
      {
        if (lrFlag) {
          var timer3 = setInterval(function(){
            nl += speed * 2;
            dis += speed * 2;
            if (dis > 10) {
              clearInterval(timer3);
              clearInterval(target.__sh);
              dis = 0;
              cn++;
              target.removeAllStyle();
              if (def != '')target.attr('style', def);
            }
            else {
              target.addStyle('left', nl + 'px');
            }
          }, 1);
          lrFlag = false;
        }
      }
    }, 1);
  }
 }

 for (var ex in Flint.config.useExtendedClass)
{
  if (Flint.config.useExtendedClass[ex] === true) Flint['__' + ex + 'Extends']();
}

//Flint CoreClass Load
Flint.init();

