var demo_options = {
  'demo-act':
  {
    act:[
    ['i', function(i){$(i).css('color','yellow'); }],
      ['p', function(elem,options){
        $(elem).css({backgroundColor:'green'}).after('每'+options.speed+' ms 一個字');
      }],
      ['hr', function(elem,options,pages){$(elem).before('<p>總頁數：'+pages.length+'</p>');}],
      ['hr ~ span.highlight:eq(2)', function(i){$(i).css('backgroundColor','purple');}]
    ],
    forward: 'auto'
  },
  'demo-act-option':
  {
    act:[
      ['i', null, 'pause'],
      ['big', function(i){$(i).fadeIn(2000);}, 'queue'],
      ['img', function(i){$(i).fadeIn(2000);}],
      ['table', null, 'pause']
    ],
    forward: 'auto'
  },
  'demo-pagination':
  {
    pageExpr: 'div',
    forward: 'auto',
    back: 'auto'
  },
  'demo-pagination-2':
  {
    pageExpr: 'p',
    forward: "not-found",
    back: '#ex-btn-back',
    next: '#ex-btn-next'
  },
  'demo-elemSpeed':
  {
    elemSpeed: 300,
    forward: 'auto'
  },
  'demo-misc':
  {
    dump: 'none',
    removeUnused: false,
    trimText: false,
    keepInvisible: false,
    pageExpr: 'div',
    forward: '#ex-btn-forward2',
    back: '#ex-btn-back2',
    next: '#ex-btn-next2'
  },
  'demo-callback':
  {
    onPageStart: function(){ $('#demo-list').append("<li class='red'>onPageStart</li>"); },
    onPageDump: function(){$('#demo-list').append('<li class="green">onPageDump</li>'); },
    onForward: function(){$('#demo-list').append('<li>onForward</li>'); },
    pageExpr: 'div',
    forward: '#ex-btn-forward3',
    back: '#ex-btn-back3',
    next: '#ex-btn-next3',
    removeUnused: false
  },
  'demo-alt_content':
  {
    pageExpr: 'div',
    forward: '#ex-btn-forward4',
    back: '#ex-btn-back4',
    next: '#ex-btn-next4',
    act: [
      ['img.face',function(i){$(i).fadeIn('slow');}],
      ['br.fire',function(){$('#demo-ac-body img.face:first').attr('src','image/demo100_alt.jpg');}]
    ]
  }
};


//jQuery.noConflict();
jQuery(document).ready( function($){
  $('#toggle-tab').toggle(
    function() {
      $('hr').hide();
      $('.tab').slice(1).hide();
      $('#navigation li').click( function(e) {
        $('.tab').hide();
        $( '#' + ($(this).children('a').attr('href').substr(1)) ).show();
      }).children('a').click(function(e){setTimeout(function(){scroll(0,0);},13);scroll(0,0);});
      $('.link-to-option').click(function(e){ 
        $('.tab').hide();
        $('#option').show();
        setTimeout(function(){scroll(0,0);},13);
        scroll(0,0);
      });
    },
    function() {
      $('hr').show();
      $('.tab').show();
      $('#navigation li').unbind().children('a').unbind();
      $('.link-to-option').unbind();
    }
  );
  
  $('.demo-header a').toggle(
    function() {  // 開始
      var demo = $(this).parents('.demo-wrapper:first');
      demo.children('.demo').show().find('div.demo-body:first').html( demo.children('.dom').html() ).msgPlay(demo_options[this.id]);
      demo.children('.dom').hide();
      $(this).attr('title','顯示 DEMO 元素內容').text('還原');
    },
    function() {  // 還原
      var demo = $(this).parents('.demo-wrapper:first');
      demo.children('.demo').hide().find('div.demo-body:first').html('');
      demo.children('.dom').show();
      $(this).attr('title','開始 DEMO').text('開始');
    }
  );
});


function demo_ac(obj) {
  if( jQuery(obj).parents('#demo-ac-body').length ) {
    jQuery(obj).attr('disabled','disabled');
    var ans = (obj.value=='好') ? '#ac-yes' : '#ac-no';
    jQuery('#demo-ac-body').load( 'demo_body.html ' + ans, function(){$(this).children(':first').msgPlay(demo_options['demo-alt_content']);} );
  }
};

