var sUsrAgt = navigator.userAgent;
var sSearch = '?1.mp3';
var sNameLC = sSearch.toLowerCase().substring(1);
var nameLen = sNameLC.length;
var sType   = 'unknown';
if (sNameLC.lastIndexOf('.au') >nameLen-6) sType="audio/basic";
if (sNameLC.lastIndexOf('.ra') >nameLen-6) sType="audio/x-pn-realaudio";
if (sNameLC.lastIndexOf('.rm') >nameLen-6) sType="audio/x-pn-realaudio";
if (sNameLC.lastIndexOf('.mid')>nameLen-6) sType="audio/midi";
if (sNameLC.lastIndexOf('.mp3')>nameLen-6) sType="audio/mpeg";
if (sNameLC.lastIndexOf('.wav')>nameLen-6) sType="audio/wav";
if (sSearch.length<3) document.bgColor="white";

else if (sNameLC=='stop' ) document.writeln('Audio stopped.');
else if (sType=='unknown') document.writeln('Unknown audio file type.');
else

{

  if (sUsrAgt.indexOf('Opera')!=-1||sUsrAgt.indexOf('MSIE')!=-1)
  	document.writeln('<bgsound id="sonido" style="visibility:hidden" volume=-1000 LOOP=1 src="">');
  else
  	document.writeln('<object id="sonido"  style="visibility:hidden" width=194 height=16 data="" type="'+sType+'"></object>');

}

function PlayAudio(){
    setCookie("audio_on", "yes", 365);
	if (sUsrAgt.indexOf('Opera')!=-1||sUsrAgt.indexOf('MSIE')!=-1)
		$("#sonido").attr("src", encodeURI(sSearch.substring(1,99)))
	else
		$("#sonido").attr("data", encodeURI(sSearch.substring(1,99)))
}
function StopAudio(){
    setCookie("audio_on", "no", 365);
	if (sUsrAgt.indexOf('Opera')!=-1||sUsrAgt.indexOf('MSIE')!=-1)
		$("#sonido").attr("src", "")
	else
		$("#sonido").attr("data", "")
}

$(document).ready(function(){
    var audio_on = getCookie("audio_on");
    if (audio_on != null && audio_on != "") {
        if (audio_on != "no") {
            PlayAudio();
        }
        else{
            show("imagen1",'hidden');
            show("imagen2",'visible');
        }
    }
    else
        PlayAudio();
});



    function getCookie(c_name) {
        var i, x, y, ARRcookies = document.cookie.split(";");
        for (i = 0; i < ARRcookies.length; i++) {
            x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
            y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
            x = x.replace(/^\s+|\s+$/g, "");
            if (x == c_name) {
                return unescape(y);
            }
        }
    }

    function setCookie(c_name, value, exdays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
        document.cookie = c_name + "=" + c_value;
    }
