var button_on = 'sound_on.png'; // ссылка на иконку включеной кнопки
var button_off = 'sound_off.png'; 

function button_init(){

 var file = 'song.mp3'; // где лежит mp3 файл
 
 var autostart = 'true';
 var button_img = button_on;

 if(ReadCookie('playsong') == 'no'){
    autostart = 'false';
    button_img = 'sound_off.png';
 }

 
 document.getElementById('container').innerHTML = '<embed width="328" height="20" flashvars="file='+file+'&amp;controlbar=none&amp;autostart='+autostart+'&amp;repeat=always&amp;allowfullscreen=false" allowscriptaccess="always" name="ply" id="ply" src="player.swf" type="application/x-shockwave-flash">';

 document.getElementById('sound_button').innerHTML = '<img id="button_img" src="'+button_img+'">';
}

function sound_toggle(){
 if(ReadCookie('playsong') != 'no'){
    document.getElementById('ply').sendEvent('STOP');
    document.getElementById('button_img').src = button_off;
    SetCookie('playsong', 'no');
 }else{
    document.getElementById('ply').sendEvent('PLAY');
    SetCookie('playsong', 'yes');
    document.getElementById('button_img').src = button_on;
 }
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue) {
 var today = new Date();
 var expire = new Date();

 expire.setTime(today.getTime() + 3600000*24*14);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

