/*-------------------------------------------------------------
 ready!!
 *require[jquery.js]
-------------------------------------------------------------*/
$(function(){
  ieFix();
  headerReplace();
  uriReplace();
});

/*-------------------------------------------------------------
 IE CHECK
-------------------------------------------------------------*/
var isIE = /*@cc_on!@*/false;

/*-------------------------------------------------------------
 PROTOCOL CHECK
-------------------------------------------------------------*/
var isHTTPS = (location.protocol == "https:") ? true : false;

/*-------------------------------------------------------------
 GET UNIQUE
-------------------------------------------------------------*/
var uniqueID = new Date().getTime();

/*-------------------------------------------------------------
 GET HASH
-------------------------------------------------------------*/
var hash = location.hash.split("?"); 
hash = hash[0].split("#/");
hash = hash[1];

/*-------------------------------------------------------------
 GET URI
-------------------------------------------------------------*/
var uri = location.href;


/*-------------------------------------------------------------
 URI replace
 *require[jquery.js]
-------------------------------------------------------------*/
function uriReplace(){
  if(uri.indexOf('kensetsutown_test') != -1){
    $('#footer>dl.sub-nav li>a[href^="https://"]').each(function(){
       var testURI = $(this).attr('href').replace("kensetsutown","kensetsutown_test");
       $(this).attr('href',testURI);
    });
    if($('body').attr('id') == 'sitemap'){
      $('#site-tree li>a[href^="https://"]').each(function(){
        var testURI = $(this).attr('href').replace("kensetsutown","kensetsutown_test");
        $(this).attr('href',testURI);
      });
    }
  }
}

/*-------------------------------------------------------------
 header replace
 *require[jquery.js]
-------------------------------------------------------------*/
function headerReplace(){
  $('#header').css('background-image','none');
  var current = $('body').attr('id');
  var hierarchy = $('body').attr('class').replace('level','');
  var pathTo = '';
  var _P = (isHTTPS) ? '&https=true' : '';
  var _U = '&here='+uri;
  if(hierarchy == 1){
    pathTo = "./";
  } else {
    var i = 1;
    while(i < hierarchy){
      pathTo += "../";
      i++;
    }
  }
  $('#header').html('<object data="' + pathTo + 'common/swf/header.swf" width="950" height="151" type="application/x-shockwave-flash"><param name="movie" value="' + pathTo + 'common/swf/header.swf" /><param name="wmode" value="transparent" /><param name="flashvars" value="pathTo=' + pathTo + '&current=' + current + '&unique=' + uniqueID + '&hierarchy=' + hierarchy + _P + _U + '" /></object>');
}

/*-------------------------------------------------------------
 ie fix
 *require[jquery.js]
-------------------------------------------------------------*/
function ieFix(){
  if(isIE && jQuery.browser.version <= 6) {
    $('#header-bg').remove();
  }
}

/*-------------------------------------------------------------
 Flash contents
 *require[AC_RunActiveContent.js]
-------------------------------------------------------------*/
function setContent(contentName, contentHeight, arg){
  var _H = (contentHeight) ? contentHeight : "100%";
  var _A = (arg) ? arg : 'arg=none';
  var _U = '&unique=' + uniqueID;
  var _C = (hash) ? '&hash='+hash : '';
  var _D = '&dir=' + uri;
  AC_FL_RunContent(
    'src','./swf/'+contentName,
    'movie','./swf/'+contentName,
    'width','900',
    'height', _H,
    'FlashVars', _A + _U + _C + _D,
    'quality','best',
    'salign','TL',
    'scale','noscale',
    'play','true',
    'base','.',
    'bgcolor','#ffffff',
    'wmode','transparent',
    'allowScriptAccess','always',
    'pluginspage','http://www.macromedia.com/go/getflashplayer',
    'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'
  );
}


