// create flash control
function CreateFlash(flashid, srcpath, width, height, cssclass) {
  var proto = location.protocol;
  var flash_tag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+proto+'//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+width+'" height="'+height+'" id="'+flashid+'" align="middle">'+
  '<param name="allowScriptAccess" value="sameDomain" />' +
  '<param name="movie" value="'+srcpath+'" />' +
  '<param name="quality" value="high" />' +
  '<param name="bgcolor" value="#ffffff" />' +
  '<embed src="'+srcpath+'" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+flashid+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="'+proto+'//www.macromedia.com/go/getflashplayer" />'+
  '</object>';
  
  document.write('<div class="'+cssclass+'">' + flash_tag + '</div>');
}


function gologin() {
  location.href='https://sems.shoeisha.com/users/login/moneyzine?ref='+escape(location.href)
}

function goregist() {
  location.href='/user/regist/?ref='+escape(location.href);
}


function menu_open(id,active){
  var isMSIE = navigator.appVersion.indexOf('MSIE')>=0;
  for(var i = 1 ; i <= 8 ; i++){
    if(!document.getElementById('menu-0' + i)){
      continue;
    }
    document.getElementById('menu-0' + i).className = (id != i ? "" : "active");
    if (active != i){
      if(isMSIE){
        document.getElementById('menu-0' + i).attachEvent("onmouseout",function(){ 
          if(event.srcElement.parentNode){
            event.srcElement.parentNode.className = "";
          }
        });
      }else{
        document.getElementById('menu-0' + i).addEventListener( "mouseout",function(){ 
            this.className = "";
              } ,false);
      }
    }
  }
  document.getElementById('menu-0' + active).className = "active";
}


// ---- SiteCatalyt Click Events ----//

// <a href="#" 
//    ref="sc" 
//    scCategory="AreaTest" 
//    scVars="14" 
//    scVals="Data" 
//    scEvents="5"  
//    scProducts="%TITLE%" 
//    scLabel="test">Test</a>
// 
//    
//    If you'd like to omit value of attributes 
//    in scProducts,scLabel,scCategory and scVals , 
//    you can set the following value to the attributes.
//    
//    %TITLE% = this anchor text
//    %LOC% = location.href(page url)
//    %HREF% = this anchor href
//    

$(function(){
  $("a").click(function () {
    var ref = $(this).attr("ref");
    if (typeof(ref) == 'undefined' || ref != 'sc') return;
    
    // event
    var events = $(this).attr("scEvents");
    if(typeof(events) == 'undefined'){
        events = '';
    } else {
      events = events.split(',');
    }

    // category
    var category = $(this).attr("scCategory");
    if(typeof(category) == 'undefined'){
        category = '';
    } 
    category = rep_val(category, $(this));
    
    // products
    var products = $(this).attr("scProducts");
    if(typeof(products) == 'undefined'){
        products = $(this).text();
    }
    products = rep_val(products, $(this));

    // eVar
    var eVars = $(this).attr("scVars");
    if(typeof(eVars) == 'undefined'){
        eVars = '';
    } else {
      eVars = eVars.split(',');
    }
    
    // eVal
    var eVals = $(this).attr("scVals");
    if(typeof(eVals) == 'undefined'){
        eVals = '';
    } else {
      eVals = eVals.split(',');
    }
    
    // LABEL
    var linkname = $(this).attr("scLabel");
    if(typeof(linkname) == 'undefined'){
        linkname = $(this).text();
    }
    linkname = rep_val(linkname, $(this));
    
    var s=s_gi(s_account);

    // Set linkTrackVars
    var linkTrackVars = '';
    for ( var i=0; i < eVars.length  ; i++  ){
      linkTrackVars +=  "eVar" + eVars[i];
      if (i != eVars.length -1 ){
         linkTrackVars += ",";
      }
    }
    if (products){
       if (linkTrackVars){
          linkTrackVars += ",products";
       } else {
          linkTrackVars += "products";
       }
    }
    if (events.length > 0){
       if (linkTrackVars){
          linkTrackVars += ",events";
       } else {
          linkTrackVars += "events";
       }
    }
    s.linkTrackVars = linkTrackVars  ;
    
    // Set linkTrackEvents
    var linkTrackEvents = '';
    for ( var i=0; i < events.length  ; i++  ){
      linkTrackEvents +=  "event" + events[i];
      if (i != eVars.length -1 ){
         linkTrackVars += ",";
      }
    }
    s.linkTrackEvents = linkTrackEvents;
    // Set events
    s.events = linkTrackEvents;
    // Set products
    s.products = category + ";" + products;
    
    // Set eVar99
    if ( eVars && eVals ){
       for ( var i=0; i < eVars.length  ; i++  ){
            eVals[i] = rep_val(eVals[i], $(this));
            eval( "s.eVar" + eVars[i] + "='" + eVals[i] + "'");
       }
       
    }
    
    s.tl(this,'o',linkname);
  });
  
  function rep_val(val, elem) {
    if (val) {
      val = val.replace('%TITLE%', elem.text(), 'g');
      val = val.replace('%HREF%', elem.attr('href'), 'g');
      val = val.replace('%LOC%', location.href, 'g');
    }
    return val;
  }
});

// show random menubanner 
function show_menubanner() {
  // menubannerlist is defined in fxtop.js
  var rand = Math.floor( Math.random() * menubannerlist.length );
  var item = menubannerlist[rand];
  document.getElementById("menu_banner").innerHTML = item.html;
}
