﻿$(function(){
  /* register category menu click */
  $("#expenable-tree > li > a").click(function(){
    var current = $(this);
    var ul = current.next();
    if(ul.length){
      if(ul.is(":visible")){
        ul.hide();
      }else{
        ul.show();
      }
    }
  });
  
  $("#expenable-tree > li ul").hide();
  
  $('li.active').parents('ul').show();
  
  /* end register category menu click */
  
  /* register code hightlight */
  $('code').addClass('prettyprint');
  prettyPrint();
  
  /* end register code hightlight */
  
  
  /*register template script */
  
  $('#upload-template-btn').colorbox({inline:true,href:'#upload-form-div'});
  $('#filter-div select').change(function(){
    var item = $(this).find('option:selected');
    document.location.href = item.attr('redirectUrl');
  });
  $('div.template ul a').click(function(){
    var handle = $(this),
        parentLi = handle.parent(),
        updateFormDiv = parentLi.find('div.update-count-form'),
        form = $('<form/>').html(updateFormDiv.html())
        .attr({ method:'post',action: updateFormDiv.attr('action')});
    
    var counter = form.find('[name="Count"]');
    counter.val( parseInt(counter.val()) + 1 );
    
    form.ajaxSubmit();
    //window.open($(this).attr('href'));
    //return false;
  });
  
  /*end register template script */
  
  
});

