/* Date:        03/01/2006
   Author:      Dwayne Black
   Description: To play audio at a particular time depending on if mouseover or page load event
*/

var expDays = .042;
var expTime = .002;

//Check the value in the cookie to varify data integrity 
function getCookieValue (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
	endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

//Read saved cookie to see if it's time to play audio
function GetSavedCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
	var j = i + alen;    
	if (document.cookie.substring(i, j) == arg)      
	return getCookieValue (j);    
	i = document.cookie.indexOf(" ", i) + 1;    
	if (i == 0) break;   
}  
	return null;
}

//Save info to cookie and set expiration of cookie
function SaveCookie (name, value, expd) {  
var exp = new Date(); 
exp.setTime(exp.getTime() + (expd*24*60*60*1000));

var argv = SaveCookie.arguments;  
var argc = SaveCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + exp)) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

//If you want to manually expire the cookie for testing, call function and pass cookie name, eg. DeleteCookie('loadaudio');
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetSavedCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//Play audio when mouse over an object with particular link
function PlayOver() {
var replay = GetSavedCookie('replay');
	if (replay == null) {
		SaveCookie('replay', 1, expTime);
		document.all.sound.src = "http://www.goodaccountants.com/images/need_to_speak.mp3";
	}
}

function SoundLoader(cook,spath) {
    //Check if brower support Cookie and display a message if not
    if (navigator.cookieEnabled == 0) {
      //alert("You need to enable cookies for this site to load properly!");
    }
    else {
        //document.write('<EMBED SRC="http://www.goodaccountants.com/images/intro.mp3" autostart="false" hidden="true" width="1" height="1">')
        document.write('<bgsound id="sound">')
        var loadaudio = GetSavedCookie(cook);
        if (loadaudio == null) {
	        SaveCookie(cook, 1, expDays);
	        document.all.sound.src = spath//"http://www.goodaccountants.com/images/intro.mp3";
        }
    }
}