/**
 * @author bao.nguyen
 */
var fontSizes = new Array();
fontSizes[0] = ".8";
fontSizes[1] = "1";
fontSizes[2] = "1.2";
fontSizes[3] = "1.4";
fontSizes[4] = "1.6";
fontSizes[4] = "1.8";

var fontSelectedIndex;

if($.cookie('selectedFontIndex')){
  fontSelectedIndex = $.cookie('selectedFontIndex');
}
else{
  fontSelectedIndex = 1; 
}
var options = { path: '/', expires: 10 };

function increaseFontSize()
{  
  if (fontSelectedIndex < fontSizes.length-1){
    fontSelectedIndex++;    
    $.cookie('selectedFontIndex',fontSelectedIndex, options);  
    setFontSize();
  }  
}

function decreaseFontSize()
{  
  if (fontSelectedIndex > 0){
    fontSelectedIndex--;
    $.cookie('selectedFontIndex',fontSelectedIndex, options);
    setFontSize();
  }  
}

function setFontSize()
{
  $('#contentPrimary,#contentSecondary').css('font-size', fontSizes[fontSelectedIndex] + 'em');
}

$(document).ready(function(){
 // Reset Font Size

 // Increase Font Size
 $(".increaseFont").click(function(){
   increaseFontSize();  
  return false;
 });
 $(".decreaseFont").click(function(){
    decreaseFontSize();  
    return false;
   }); 
 setFontSize();
 formatTables();
 formatMainNav();
});

function formatTables()
{  
  $('p:has(table)').css({
      'font-size':'1em',
      'padding-left' : 0,
      'padding-right': 0
      });
  $('table').width( jQuery.trim($('#contentPrimary').css('width').replace('px',''))-50);  
  //$('table').width( '100%');
  
  $('table').css('border','none');
  
//  var currentTableRows;
//  var currentMaxCells = 0;
//  var curretTableCells = 0;
//  var cellValue;
//  for(i=0;i<$('table').length;i++){
//    currentTableRows = $('tr',$('table')[i]);
//    for(j=0;j<currentTableRows.length;j++){
//      curretTableCells = $('td',currentTableRows[j]);
//      if(curretTableCells.length > currentMaxCells){
//        currentMaxCells = curretTableCells.length;
//      }
//    }
//    // set td width in percent
//    cellValue = Math.floor(100/currentMaxCells);
//    curretTableCells.css('width', cellValue + '%');
//    //reset values
//    currentMaxCells = 0;
//    curretTableCells = 0;
//    cellValue = 0;
//  }
  
//  for(var i in $('table')){
//    alert(i);
//  }
  //alert($('tr',$('table')).length);
  
  
  $('table').show();
  
}

function formatMainNav()
{
  $('#mainNav li:has(ul)').addClass('dir');
  $('#mainNav li:has(ul)').hover(function(){$(this).addClass('dirHover');}, function(){$(this).removeClass('dirHover');});
}
