﻿/* ------------------------------------------------------------ */
/*                                                              */
/*                         global param                         */
/*                                                              */
/* ------------------------------------------------------------ */

var _loc      = location.pathname;
var _pathName = _loc.substring(0,_loc.lastIndexOf('/')+1);
var _fileName = _loc.substring(_loc.lastIndexOf('/')+1);
var _swfAry   = new Array();

function _(p,q) {q=new Image;q.src=p;p=q.src;q.src='#';return p}
var _absPath  = (_(document.getElementsByTagName('script')[0].src.split('_global')[0]));

var $j = jQuery.noConflict();





/* ------------------------------------------------------------ */
/*                                                              */
/*                       import libraries                       */
/*                                                              */
/* ------------------------------------------------------------ */

document.write('<script type="text/javascript" src="'+_absPath+'_global/js/core/swfobject.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.superfish.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.cookie.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.imghover.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.innerfade2.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.tablesorter.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.socialbutton.js"></script>');
// document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/jquery.newsticker.js"></script>');
// document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/iepngfix/iepngfix_tilebg.js"></script>');
document.write('<script type="text/javascript" src="'+_absPath+'_global/js/lib/thickbox/thickbox.js"></script>');
document.write('<link rel="stylesheet" type="text/css" href="'+_absPath+'_global/js/lib/thickbox/thickbox.css" media="screen" />');





/* ------------------------------------------------------------ */
/*                                                              */
/*                           IEPNGFix                           */
/*                                                              */
/* ------------------------------------------------------------ */

// document.write('<style type="text/css">.transparent { behavior:url('+_absPath+'_global/js/lib/iepngfix/iepngfix.htc) }</style>');





/* ------------------------------------------------------------ */
/*                                                              */
/*                          initialize                          */
/*                                                              */
/* ------------------------------------------------------------ */

try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}  // ie6 background-image reload issue

$j(function($){

  // Pulldown Menu -------------------------------------------
  $('#nav-main ul').superfish();

  // fontsize switcher ------------------------------------------------------------
  $.fn.setFontsize(($.cookie('fsize')) ? $.cookie('fsize'):'fs-small');
  $('#fontsize a').click(function(){$.fn.setFontsize(this.id)});
  
  // _blank window -----------------------------------------------------
  $('a.blank, area.blank').click(function(){ window.open(this.href, '_blank'); return false; });

  // img hover -------------------------------------------
  $('.imghover').imghover();

  // table sorter -------------------------------------------
  $('.tablesorter').tablesorter( {_sortList: [[0,1]], widgets: ['zebra']} );

  // odd-even -------------------------------------------
  $('li:first-child').addClass('first');
  $('li:last-child').addClass('last');
  $('#contentarea ul,#contentarea ol').each(function(j) {
    $(this).children('li:even').addClass('even');
    $(this).children('li:odd').addClass('odd');
  });
  $('.stripe').each(function(j) {
    $('li:even,tr:even',this).addClass('even');
    $('li:odd,tr:odd',this).addClass('odd');
  });

  // Search Text Label -------------------------------------------
  swapValues = [];
  $('.swap_value').each(function(i){
    swapValues[i] = $(this).val();
    $(this).focus(function(){
      if ($(this).val() == swapValues[i]) $(this).val("");
    }).blur(function(){
      if ($.trim($(this).val()) == "") $(this).val(swapValues[i]);
    });
  });

  // current menu -------------------------------------------
  $('div#nav-main li#nm-' + _pathName.split('/')[1]+' a').addClass('active');

  // centered ------------------------------------------------------------
  $('.centered').each(function(j){
    var marginL = ($(this).parent().width() - $(this).width())/2;
    $(this).css({'margin-left':marginL+'px'});
  });

  // dl-column ------------------------------------------------------------
  $('dl.dt-left,dl.dt-right').each(function(j) {
    $(this).each(function() {
      var maxW = 0;
      $('dt',this).each(function(i) {
        maxW = ($(this).width() > maxW) ? $(this).width() : maxW;
      });
      maxW+=10;
      if($(this).attr('class').indexOf('dt-left')>-1) $('dd',this).css({'margin-left':maxW+'px'});
      if($(this).attr('class').indexOf('dt-right')>-1) $('dd',this).css({'margin-right':maxW+'px'});
    });
  });

  // socialbutton ------------------------------------------------------------
  if($('#social_facebook').size()) {
    var targetURL = document.URL;
    targetURL = targetURL.replace(/[0-9](\/)?$/,'/');
    $('#social_facebook').socialbutton('facebook_like', {button: 'button_count', url:targetURL});
    $('#social_twitter').socialbutton('twitter', {button: 'horizontal', url:targetURL});
    $('#social_google').socialbutton('google_plusone', {size: 'medium', url:targetURL});
  }

});





/* ------------------------------------------------------------ */
/*                                                              */
/*                     fontsize switcher                        */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    setFontsize: function(fsize) {
      $('#fontsize a').removeClass('active');
      switch (fsize) {
        case 'fs-large' : fsize_val='104%'; $('#fontsize a#fs-large').addClass('active'); break;
        case 'fs-medium': fsize_val='90%';  $('#fontsize a#fs-medium').addClass('active'); break;
        default         : fsize_val='78%';  $('#fontsize a#fs-small').addClass('active');
      }
      $('body').css('font-size',fsize_val);
      $.cookie('fsize',fsize,{expires:30,path:'/'});
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                 doShuffle : ( randomize [li] )               */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    doShuffle: function() {
      var shuffled = this.find('li').get().sort(function(){
        return Math.round(Math.random())-0.5; //just a random number between -0.5 and 0.5
      });
      $(shuffled).appendTo(this);
      return this;
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*         delay  : ( delay a jQuery animation or func.)        */
/*                                                              */
/* ------------------------------------------------------------ */
(function($){
  $.fn.extend({
    delay: function(time, callback){
      // Empty function:
      jQuery.fx.step.delay = function(){};
      // Return meaningless animation, (will be added to queue)
      return this.animate({delay:1}, time, callback);
    }
  });
})(jQuery);





/* ------------------------------------------------------------ */
/*                                                              */
/*                           Utility                            */
/*                                                              */
/* ------------------------------------------------------------ */
Array.prototype.max = function(){
    return Math.max.apply(null,this);
}
Array.prototype.min = function(){
    return Math.min.apply(null,this);
}
Array.prototype.shuffle = function(){
    var i   = this.length;
    var ary = this.concat();
    var ret = [];
    while(i) ret.push(ary.splice(Math.floor(Math.random()*i--),1));
    return ret
}





/* ------------------------------------------------------------ */
/*                                                              */
/*                      Flash  -  SWFObject                     */
/*                                                              */
/* ------------------------------------------------------------ */
// <div id="swf1Holder"></div>
// <script type="text/javascript">_swf({type:'promo'});</script>
// <script type="text/javascript">_swf({w:'940',h:'210',id:'swf2',swf:_absPath+'_global/swf/feature.swf',param:'_v=Fp&flag=1',bgcolor:'#990000'});</script>

function _swf(obj) {
  if (typeof obj == 'undefined') return null;
  if (_swfAry.toString().indexOf(obj.type)>-1) return null;

  var expressInstall = _absPath+'_global/swf/expressInstall.swf';
  var flvars = {};
  var params = {};
  var attrib = {};

  switch (obj.type) {
    case 'flvplayer':
      prm    = {w:575,h:332,id:'flvPlayer',swf:_absPath+'_global/swf/fp.swf'};
      params = {wmode:'transparent'};
      break;
    case 'feature':
      prm    = {w:570,h:100,id:'swf1',swf:_absPath+'_global/swf/feature.swf'};
      flvars = {_a:_absPath,_f:_fileName};
      params = {bgcolor:'#009900'};
      break;
    default:
      prm    = obj;
      if (prm.param) { var pAry=prm.param.split('&'); for (var i=0;i<pAry.length;i++) {var a=pAry[i].split('='); flvars[a[0]] = a[1];} };
      params = {bgcolor:obj.bgcolor,scale:obj.scale,salign:obj.salign};
  }
  if (typeof prm == 'undefined') return null;

  /* --- [4] swf version --- */
  prm.v = (obj.v) ? obj.v : '9.0.28';

  /* --- [6] flvars --- */
  flvars._p = _pathName;
  if (location.search) { var sAry=location.search.substr(1).split('&'); for (var i=0;i<sAry.length;i++) {var a=sAry[i].split('='); flvars[a[0]] = a[1];} };

  /* --- [7] params --- */
  params.bgcolor = (params.bgcolor) ? params.bgcolor : '#ffffff';
  params.scale   = (params.scale)   ? params.scale :   'noScale';
  params.salign  = (params.salign)  ? params.salign :  'TL';

  /* --- [8] attrib --- */
  attrib.id = prm.id;

  swfobject.embedSWF(prm.swf, prm.id+'Holder', prm.w, prm.h, prm.v, expressInstall, flvars, params, attrib);
}

