  
  /**
   * snapShot.js
   * ----------------------------------------------------------------------------------
   * Copyright 2009 , Freesale .Inc, Japan http://www.freesale.co.jp
   *                  Founded at 2001, Located In Shibuya, Tokyo.
   * 
   * @File Informations -
   * @LastModified : 2009/3/30
   * @Version      : 1.0
   * @License      : http://www.opensource.org/licenses/mit-license.php The MIT License
   *                 Redistributions of files must retain the above copyright notice.
   * ----------------------------------------------------------------------------------
   */
  
  var loading      = 'images/loading.gif';
  var margin       = 10;
  
  $(function(){
    var loader     = new Image();
        loader.src = loading;
    
    $('a.snap').click(function(){
      var title = $(this).attr('title');
      var href  = $(this).attr('href');
      snapShot(href, title);
      return false;
    });
  });
  
  function snapShot(h,t) {
    $('body, html').css({height: '100%', width: '100%'});
    $('body').append('<div id="snap_bg"></div><div id="snap_window"></div>');
    $('#snap_bg').css({ width:      $(document).width(),
                        height:     $(document).height(),
                        background: '#000000',
                        opacity:    0.8,
                        position:   'absolute',
                        top:        0,
                        left:       0,
                        zIndex:     100,
                        cursor:     'pointer' });
    $('#snap_bg').click(snap_close);
    
    $('#snap_window').css({
                        width:  120,
                        height: 90,
                        background: '#ffffff url('+loading+') no-repeat center center',
                        position:   'fixed',
                        top:        '50%',
                        left:       '50%',
                        marginTop:  -60,
                        marginLeft: -45,
                        padding:    0,
                        zIndex:     101 });
    
    if ( typeof document.body.style.maxHeight === 'undefined' ) {
      $('html').css({ overflow: 'hidden' });
      var sTop = $('body').scrollTop();
      if( !sTop )
        sTop = $('html').scrollTop();
      $('#snap_window').css({ marginTop: sTop,
                              position: 'absolute' });
      
      $('html').scroll(function(){
        var sTop = $('body').scrollTop();
        if( !sTop )
          sTop = $('html').scrollTop();
         $('#snap_window').css({ marginTop: sTop-windowHeight/2 });
      });
    }
    
    if ( h.match(/(.*?\.swf)/) ) {
      var sx   = 400;
      var sy   = 300;
      if ( h.match(/width=(\d+)/) )     sx = RegExp.$1 - 0;
      if ( h.match(/height=(\d+)/) )    sy = RegExp.$1 - 0;
      snapShot_show( sx, sy, { type: 'swf', src: h, title: t } );
    }
    else if( h.match(/\.jpg|\.png|\.gif|\.bmp/) ){
      var loader        = new Image();
          loader.onload = function(){ snapShot_show( loader.width, loader.height, { type: 'image', src: h, title: t } ); };
          loader.src    = h;
    }
    else if( h.match(/iframe/) ){
      
    }
    else if( h.match(/inline/) ){
      
    }
    
  }
  
  function snapShot_show( w, h, obj ) {
    var subx = ( w - $('#snap_window').width() ) / 2;
    var suby = ( h - $('#snap_window').height() ) / 2;
    $('#snap_window').css({ background: '#ffffff' })
                     .animate({ width: w+margin*2, marginLeft: '-='+subx })
                     .animate({ height: h+margin*2, marginTop: '-='+suby },
                     function(){
                       if( obj.type == 'image' ) {
                         $(this).append('<img src="'+obj.src+'" />');
                         $(this).children('img').hide()
                                                .css({ display: 'block', marginTop: margin, marginLeft: margin, marginBottom: margin, cursor: 'pointer' })
                                                .fadeIn(1000, function(){ if( obj.title ){ snapShowTitle (obj.title); } })
                                                .click(snap_close);
                       } else if ( obj.type == 'swf' ) {
                         var param = {
                                       bgcolor: '#ffffff',
                                       salign: 'TL',
                                       quality: 'high',
                                       allowScriptAccess: 'sameDomain'
                                     };
                         var params = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'"><param name="movie" value="'+obj.src+'" />';
                         var embed  = '<embed src="'+obj.src+'" width="'+w+'" height="'+h+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"';
                         for( var prop in param ) {
                           params += '<param name="'+prop+'" value="'+param[prop]+'" />';
                           embed  += ' '+prop+'="'+param[prop]+'"';
                         }
                         params += embed+' /></object>';
                         $(this).append(params);
                         $(this).children('object').hide()
                                                   .css({ display: 'block', marginTop: margin, marginLeft: margin, marginBottom: margin })
                                                   .fadeIn(1000, function(){ if( obj.title ){ snapShowTitle(obj.title); } });
                       }
                     });
  }
  
  function snapShowTitle (t) {
    var w = $('#snap_window').width();
    var h = $('#snap_window').height();
    $('#snap_window').append('<div id="snap_title"><span id="close_bt"><img src="images/close_bt.gif" /></span><span id="title">'+t+'</span></div>');
    $('#snap_title').hide().css({ position: 'absolute', top: h, left: 0, width: w, height: 30, background: '#ffffff' });
    $('#snap_title span').css({ paddingLeft: margin, paddingRight: margin });
    $('#snap_title #close_bt').css({ float: 'right', cursor: 'pointer' })
                              .click(function(){ snap_close(); return false; });
    $('#snap_title #close_bt img').css({ border: 0 });
    $('#snap_title').slideDown();
  }
  
  function snap_close() {
    $('#snap_bg').remove();
    $('#snap_window').remove();
    $('html').css({ overflow: 'auto' });
  }
  
  
  /**
   *  End Of File
   */