// JavaScript Document

var on = 0;
var color = 0;
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
var strSoundFile = '';
var strTracks = new Array();
var strSpans = new Array();
var strTimes = new Array();
intArray = 0;
var intCheck = 0;

function getIndexTracks(){
  strSpans = new Array(1);
 
  strTracks[0] = '/txtsounds/Home1DialHouseChester.mp3';

  intCheck = 1;
}

function get1000CustTracks(){
  strSpans = new Array(3);
 
  strTracks[0] = '/txtsounds/1000thCustomer1.mp3';
  strTracks[1] = '/txtsounds/1000thCustomer2.mp3';
  strTracks[2] = '/txtsounds/1000thCustomer3.mp3';

  intCheck = 1;
}

function getATracks(){
  strSpans = new Array(1);
 
  strTracks[0] = '/txtsounds/A.mp3';

  intCheck = 1;
}


function getAdviceTracks(){
  strTracks = new Array(3);

  strTracks[0] = '/txtsounds/AdviceAndInformation1.mp3';
  strTracks[1] = '/txtsounds/AdviceAndInformation2.mp3';  
  strTracks[2] = '/txtsounds/AdviceAndInformation3.mp3';

  intCheck = 1;
}

function getAimsTracks(){
  strTracks = new Array(2);

  strTracks[0] = '/txtsounds/AimsAndObjectivesPage1.mp3';
  strTracks[1] = '/txtsounds/AimsAndObjectivesPage2.mp3';  

  intCheck = 1;
}

function getCafeTracks(){
  strTracks = new Array(3);

  strTracks[0] = '/txtsounds/CafePage1.mp3';
  strTracks[1] = '/txtsounds/CafePage2.mp3';  
  strTracks[2] = '/txtsounds/CafePage3.mp3';

  intCheck = 1;
}

function getClientFaciTracks(){
  strTracks = new Array(3);

  strTracks[0] = '/txtsounds/ClientFacilitiesPage1.mp3';
  strTracks[1] = '/txtsounds/ClientFacilitiesPage2.mp3';  
  strTracks[2] = '/txtsounds/ClientFacilitiesPage3.mp3';

  intCheck = 1;
}

function getContactTracks(){
  strTracks = new Array(2);

  strTracks[0] = '/txtsounds/Contact1.mp3';
  strTracks[1] = '/txtsounds/Contact2.mp3';  

  intCheck = 1;
}

function getFundTracks(){
  strTracks = new Array(1);

  strTracks[0] = '/txtsounds/Fundraising.mp3';

  intCheck = 1;
}

function getHistoryTracks(){
  strTracks = new Array(3);

  strTracks[0] = '/txtsounds/HistoryPage1.mp3';
  strTracks[1] = '/txtsounds/HistoryPage2.mp3';  
  strTracks[2] = '/txtsounds/HistoryPage3.mp3';

  intCheck = 1;
}

function getNewsTracks(){
  strTracks = new Array(2);

  strTracks[0] = '/txtsounds/news1.mp3';
  strTracks[1] = '/txtsounds/news2.mp3';

  intCheck = 1;
}

function getServicesTracks(){
  strTracks = new Array(1);

  strTracks[0] = '/txtsounds/ServicesPage.mp3';

  intCheck = 1;
}

function getShopMobilityTracks(){
  strTracks = new Array(1);

  strTracks[0] = '/txtsounds/shopmobility.mp3';

  intCheck = 1;
}

function getCommTracks(){
  strTracks = new Array(4);

  strTracks[0] = '/txtsounds/SpecialCommendation1.mp3';
  strTracks[1] = '/txtsounds/SpecialCommendation2.mp3';  
  strTracks[2] = '/txtsounds/SpecialCommendation3.mp3';
  strTracks[3] = '/txtsounds/SpecialCommendation4.mp3'; 

  intCheck = 1;
}

function getVancanciesTracks(){
  strTracks = new Array(2);

  strTracks[0] = '/txtsounds/vacancies1.mp3';
  strTracks[1] = '/txtsounds/vacancies2.mp3';  

  intCheck = 1;
}

function getVolunteeringTracks(){
  strTracks = new Array(2);

  strTracks[0] = '/txtsounds/Volunteering1.mp3';
  strTracks[1] = '/txtsounds/Volunteering2.mp3';  

  intCheck = 1;
}

function loadArrays(){
	
	if (intCheck == 0){
		var sPath = window.location.pathname;
    	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
    	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	sPage = sPage.toLowerCase(); 
	switch(sPage){
 	  case '':
	    getIndexTracks();
	    break;
 	  case 'Index.aspx':
	    getIndexTracks();
	    break;
	  case '1000th-customer.aspx':
	    get1000CustTracks();
	    break;
	  //case '':
	    //getATracks();
	   // break;
	  case 'adviceandinformation.aspx':
	    getAdviceTracks();
	    break;
	  case 'aimsandobjectives.aspx':
	    getAimsTracks();
	    break;
	  case 'cafe.aspx':
	    getCafeTracks();
	    break;
	  case 'clientfacilities.aspx':
	    getClientFaciTracks();
	    break;
	  case 'contact.aspx':
	    getContactTracks();
	    break;
	  case 'fundraising.aspx':
	    getFundTracks();
	    break;
	  case 'history.aspx':
	    getHistoryTracks();
	    break;
	  case 'news.aspx':
	    getNewsTracks();
	    break;
	  case 'services.aspx':
	    getServicesTracks();
	    break;
	  case 'shopmobility.aspx':
	    getShopMobilityTracks();
	    break;
	  case 'special-commendation.aspx':
	    getCommTracks();
	    break;
	  case 'vacancies.aspx':
	    getVancanciesTracks();
	    break;
	  case 'volunteering.aspx':
	    getVolunteeringTracks();
		break;
	}

	}
}

function audioControl(whSound,play) {
  var text = '';
  if (play=='true') {
    if (browser == 'Microsoft Internet Explorer') {
	  document.getElementById('ieplayer').src = whSound;
	}
	else {
	  text = "<OBJECT WIDTH=\"1\" HEIGHT=\"1\" type='audio/midi' data='" + whSound + "'></OBJECT>";
	}
  }
  else {
    if (browser == 'Microsoft Internet Explorer') {
	  document.getElementById('ieplayer').src = 'jsilence.mid';
	}
  }

  document.getElementById('player').innerHTML = text;
}

//Different Audio Playes for different sites

/* Audio Play from below for likes of Grapevine
function audioPlay(){
  loadArrays();
  strSoundFile = strTracks[intArray];
  if (on == 0){
    on = 1;
    playSound(strSoundFile);
  }
  else {
    on = 0;
    stopSound(strSoundFile);  }
}*/

//Dial House
function audioPlay(intPlay){
  stopSound(strSoundFile);
  loadArrays();
  //alert(strTracks[0]);
  strSoundFile = strTracks[intPlay - 1];
  playSound(strSoundFile);
  /*if (on == 0){
    on = 1;
    playSound(strSoundFile);
  }
  else {
    on = 0;
    stopSound(strSoundFile);  }*/
}

function nextSound(){
  stopSound(strTracks[intArray]);
  loadArrays();
  if (intArray < strTracks.length - 1){
	  intArray = intArray + 1;
  }
  else {
	  intArray = 0;
  }
  //alert(intArray);
  strSoundFile = strTracks[intArray];
  on = 0;
  playSound(strSoundFile);
}


function prevSound(){
  stopSound(strTracks[intArray]);
  loadArrays();

  if (intArray == 0){
	  intArray = strTracks.length - 1;
  }
  else {
	  intArray = intArray - 1;
  }

  strSoundFile = strTracks[intArray];
  on = 0;
  playSound(strSoundFile);

}

function playSound(whSound) {
  audioControl(whSound,'true');
  //changeBackground();
}

function stopSound(whSound) {
	if (whSound != '') {
    	audioControl(whSound,'false');
    	//resetBackground();
	}
}

function changeBackground(){
	var intStart = 0;
	var intEnd = 0
	var doc = document.getElementsByTagName('p');

	intStart = strSpans[intArray];
	
	if (intArray  == strSpans.length - 1){
		intEnd = doc.length;
	}
	else {
		intEnd = strSpans[intArray + 1];
	}

	for (var i = 0; i < doc.length; i++){

		if (i >= intStart && i < intEnd){		
   			doc[i].style.fontSize = '16px';
		}
	}

	self.setTimeout('resetBackground();', strTimes[intArray]);

}

function resetBackground(){
	var intStart = 0;
	var intEnd = 0
	var doc = document.getElementsByTagName('p');

	intStart = strSpans[intArray];
	
	if (intArray  == strSpans.length - 1){
		intEnd = doc.length;
	}
	else {
		intEnd = strSpans[intArray + 1];
	}

	for (var i = 0; i < doc.length; i++){

		//if (i >= 0 && i < intEnd){		
   			doc[i].style.fontSize = '12px';
		//}
	}
}