$(document).ready(function(){
  function setCookie(theKey, theValue, limitDays) {
    var theDate = new Date();
    theDate.setTime(theDate.getTime()+limitDays*24*60*60*1000);
    document.cookie = theKey + "=" + escape(theValue) + ";expires=" + theDate.toGMTString();
  }
  
  function getCookie(key) {
    var cookieRaw = document.cookie;
    var cookies = cookieRaw.split('; ');
    for(var i = 0 ; i < cookies.length ; i++) {
        var theCookie = cookies[i].split('=');
        if (theCookie[0] == key) {
            return unescape(theCookie[1]);
        }
    }
    return false;
  }

  $('#product_detail #product_txt').each(function(){
    var itemSwfs = new Array(
      '/base/z_swf/act1.swf',
      '/base/z_swf/act2.swf',
      '/base/z_swf/act3.swf',
      '/base/z_swf/act4.swf',
      '/base/z_swf/act5.swf'
    );
    var itemSwf = itemSwfs[Math.floor(Math.random() * itemSwfs.length)];
    $('<div id="swf_box"></div>').insertBefore('#product_txt .product_name').css({
      'float': 'right'
    });
    var so = new SWFObject(itemSwf, 'item_swf', '96', '180', '8', '#ffffff');
    so.addParam('quality', 'high');
    so.write('swf_box');

    $('#product_txt .detail_inner').css({
      'clear': 'both'
    });
  });


  if (location.pathname == '/') {
    var theDate = new Date();
    if (getCookie('date') != '' + theDate.getYear() + theDate.getMonth() + theDate.getDate()) {
      setCookie('date', '' + theDate.getYear() + theDate.getMonth() + theDate.getDate(), 1);
  
      var barSwfs = new Array(
        '/base/z_swf/bar1.swf',
        '/base/z_swf/bar2.swf',
        '/base/z_swf/bar3.swf'
      );
      $('<div id="swf_bar"></div>').insertBefore('div#alpha').css({
        'width': '980px',
        'height': '40px',
        'position': 'relative'
      });
  
      for (var n = 0; n < 6; n++) {(function(){
        var i = n;
        setTimeout(function(){
          $('<div id="swf_bar_' + i + '"></div>').appendTo('div#swf_bar').css({
            'position': 'absolute',
            'top': '0',
            'left': '0'
          });
          var barSwf = barSwfs[Math.floor(Math.random() * barSwfs.length)];
          var so = new SWFObject(barSwf, 'bar_swf_' + i, '980', '40', '8', '');
          so.addParam('quality', 'high');
          so.addParam('wmode', 'transparent');
          so.write('swf_bar_' + i);
        }, i * 2000 +  Math.floor(Math.random() * 500));
      })()}
    }
  }
});

