var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};


function disableIt() {
  Cookies.erase("ella_blog_autoplay");
  messageDisabled();
}

function enableIt() {
  Cookies.create("ella_blog_autoplay", "true", 20000);
  messageEnabled();
}

function messageEnabled() {
  var blah = document.getElementById("blog-blah");
  if (blah)
  {
    blah.style.display = 'none'
  }
  var div = document.getElementById("player");
  if (div)
  {
  div.innerHTML  = '\
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="100" id="musicplayer" align="middle"> \
    <param name="movie" value="/player/flashmp3player.swf"/> \
    <param name="quality" value="high" /> \
    <param name="flashvars" value="content_path=mp3&color_path=/player/default.xml&script_path=/player/flashmp3player.php" /> \
    <!--[if !IE]>--> \
    <object type="application/x-shockwave-flash" data="/player/flashmp3player.swf" width="300" height="100"> \
        <param name="movie" value="/player/flashmp3player.swf"/> \
        <param name="quality" value="high" /> \
        <param name="flashvars" value="content_path=mp3&color_path=/player/default.xml&script_path=/player/flashmp3player.php" /> \
    <!--<![endif]--> \
        <a href="http://www.adobe.com/go/getflash"> \
            <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> \
        </a> \
    <!--[if !IE]>--> \
    </object> \
    <!--<![endif]--> \
</object><a class="showbtn" href="javascript:disableIt()">不想听音乐</a>';
  }
}

function messageDisabled() {
  var blah = document.getElementById("blog-blah");
  if (blah)
  {
    blah.style.display = 'block'
  }
  var div = document.getElementById("player");
  if (div)
  {
    div.innerHTML = '<a class="showbtn" href="javascript:enableIt()">我爱听音乐</a>';
  }
}

function player_init() {
  Cookies.init();
  if (Cookies["ella_blog_autoplay"] == null)
  {    
    messageDisabled();
  }
  else
  {
    messageEnabled();
  }
}

player_init();
