// North Group JavaScript

window.onload = function() {
	sfListen();
	//placeDiv();
}

/* -- checker function - checks to see if variables in each function exist -- */

function checkVars(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;

	for(i=0; i<x.length; i++) {
		
		if(!eval(x[i])) {
		pass = false; 
		checkerInvalid[checkerInvalid.length] = x[i];
		}
		
	}
	
	return pass;

}


/* get element by class function */

function getElementsByClass(cname,tel) {
	var elementsByClass = new Array();	
	if(tel) {
		var target = tel;
	}
	else {
		var target = document;
	}
	
	if(target.className == cname) {
		elementsByClass[0] = target;
	}
	var children = target.childNodes;
	for(var i=0;i<children.length;i++) {
		elementsByClass = elementsByClass.concat(getElementsByClass(cname,children[i]));
	}
	return elementsByClass;
}

function playerOpen(soundfilepath,soundfilename,soundfiletitle) {
	
	var unique_id = 314 // Make each link open in a new window

	var window_pos = 160 // Position of first pop-up

	var player_window = window.open('',unique_id,'width=320,height=250,top=' + window_pos +',left=160,resizable=0,scrollbars=0,titlebar=0,toolbar=0,menubar=0,status=0,directories=0,personalbar=0');
	
	player_window.focus();

	var win_content = "<html><head><title>" + soundfilename + "</title>";
	win_content += "<link rel='stylesheet' type='text/css' href='css/pop.css'></head><body>";
	win_content += "<h1>Straight<em>Forward</em>&trade;</h1>"
    win_content += "<p><strong>" + soundfilename + "</strong></p>";
	win_content += "<p>" + soundfiletitle + "</p>";
	win_content += "<object width='300' height='350'>";
    win_content += "<param name='src' value='" + soundfilepath + "'>";
    win_content += "<param name='autoplay' value='true'>";
    win_content += "<param name='controller' value='true'>";
    win_content += "<param name='bgcolor' value='#f5f4f0'>";
    win_content += "<embed src='" + soundfilepath + "' autostart='true' loop='false' width='300' height='42' controller='true'></embed>";
    win_content += "</object>";
    win_content += "</body></html>";
	player_window.document.write(win_content);
	player_window.document.close(); // "Finalizes" new window
	unique_id = unique_id + 1 // window_pos = window_pos + 20 // subsequent pop-ups will be this many pixels lower

}

function sfListen() {
	
	if(!checkVars('getElementsByClass("audio-file")')) {
		return;
	}
				
	var listen_btn = getElementsByClass("audio-file");
		
	for(i=0; i<listen_btn.length; i++) {
				
		listen_btn[i].onclick = function() {
			playerOpen(this.href,this.getAttribute("name"),this.getAttribute("title"));
			return false;
		} 
	
	}
	
	
}



