//  radioPromotions.js

// Javascript file for www.radiopromotions.info 

// Author: Russel Mulock



//	["", ""],





function MM_findObj(n, d) { //v4.01

	var p,i,x;  

	if(!d) 

		d = document; 

	if((p = n.indexOf("?"))>0 && parent.frames.length) {

		d = parent.frames[n.substring(p+1)].document; 

		n = n.substring(0,p);

	}

	if(!(x = d[n])&&d.all) 

		x = d.all[n]; 

	for (i=0; !x && i<d.forms.length; i++) 

		x = d.forms[i][n];

	for(i=0; !x && d.layers && i<d.layers.length; i++) 

		x=MM_findObj(n, d.layers[i].document);

	if(!x && d.getElementById) 

		x = d.getElementById(n); 

	return x;

}

function MM_swapImage() { //v3.0

	var i, j=0, x, a=MM_swapImage.arguments; 

	document.MM_sr = new Array; 

	for(i=0; i<(a.length-2); i+=3)

	if ((x = MM_findObj(a[i])) != null){

		document.MM_sr[j++] = x; 

		if(!x.oSrc) 

			x.oSrc = x.src; 

		x.src = a[i+2];

	}

}

function MM_swapImgRestore() { //v3.0

	var i, x, a=document.MM_sr; 

	for(i=0; a && i<a.length && (x=a[i]) && x.oSrc; i++) 

		x.src = x.oSrc;

}



function MM_preloadImages() { //v3.0

	var d=document; 

	if(d.images){ 

		if(!d.MM_p) 

			d.MM_p = new Array();

   		var i, j = d.MM_p.length, a = MM_preloadImages.arguments; 

   		for(i=0; i<a.length; i++)

   			if (a[i].indexOf("#") != 0){ 

   				d.MM_p[j] = new Image; 

   				d.MM_p[j++].src = a[i];

   			}

   	}

}

function pagePreloads( pageName )  {
	MM_preloadImages('graphics/nav_books_over.gif', 'graphics/nav_dvds_over.gif', 'graphics/nav_games_over.gif', 'graphics/nav_kids_over.gif', 

					 'graphics/nav_music_over.gif',	'graphics/nav_tweens_over.gif', 'graphics/nav_software_over.gif', 'graphics/nav_contactus_over.gif', 

					 'graphics/nav_online_over.gif');

   	//_runTrans();		//Added by Rym -- onLoad event for rotation of audio link images

	if (pageName == "home") {
   		setupSpotShow();		//Added by Rym -- onLoad event for rotation of audio link images
	}

	if (pageName == "home") {
		setupTextCrossFades( pageName );		//Added by Rym -- onLoad event for rotation of text strings
	}
	if (pageName == "online") {
		setupTextCrossFades( pageName );		//Added by Rym -- onLoad event for rotation of text strings
	}
}



var DHTML = (document.getElementById || document.all || document.layers);

function getObjById(idName)

{

	var nodeObj

	if (document.getElementById)  {

		nodeObj = document.getElementById(idName);

	}

	else if (document.all)  {

		nodeObj = document.all[idName];

	}

	else if (document.layers)  {

		nodeObj = document.layers[idName];

	}

	return nodeObj

}



function openWindowRym() {	

	window.alert("spotIdx = " + spotIdx + "\n" +

				"spotList[name] = " + spotList[spotIdx][0] + "\n" +

				"spotList[img] = " + spotList[spotIdx][1] + "\n" 

				); 

	return false;

}



function openWindow() {	//this constructs the popup window out of the two line entries of the audio link array spotList

	//onClick="window.open('/cgi-local/popup.cgi?t=Grateful+Dead+Scrapbook&f=music_GratefulDeadScrapbook','popup','height=384,width=512,resize=0,toolbars=0,status=0');return false">





	//alert( "window.open == " + "'/cgi-local/popup-rym.cgi?t=' + spotList[windowIdx][0] + '&f=' + spotList[windowIdx][1],'popup','height=384,width=512,resize=0,toolbars=0,status=0'");

	//window.open ("http://www.javascript-coder.com","mywindow");

	//window.open('/cgi-local/popup-rym.cgi?t=' + spotList[windowIdx][0] + '&f=' + spotList[windowIdx][1],'popup','height=384','width=512','resize=0','toolbars=0','status=0');

	//window.open('/cgi-local/popup-rym.cgi?t=' + spotList[windowIdx][0] + '&f=' + spotList[windowIdx][1], 'popup', "height=384, width=512, resizable=0, toolbar=0, status=0");

	window.open('/cgi-local/popup.cgi?t=' + spotList[windowIdx][0] + '&f=' + spotList[windowIdx][1], 'popup', "height=384, width=512, resizable=0, toolbar=0, status=0");

	return false;

}



var fadeTimer1;
var fadeTimer2;
var fadeTimer3;

function xfadeStop( pageName ) {

	//alert( "In xfadeStop" );
	if (pageName == "home") {
		clearTimeout(fadeTimer1);
		clearTimeout(fadeTimer2);
	}
	
	if (pageName == "online") {
		clearTimeout(fadeTimer3);	
	}
}



function setOpacity( obj ) {		

	if(obj.xOpacity > .99) {

		obj.xOpacity = .99;

	}

	obj.style.opacity = obj.xOpacity;

	//Opacity in IE only works on elements with attribute of display:block 

	obj.style.zoom = 1;

	obj.style.filter = "alpha(opacity=" + (obj.xOpacity * 100) + ")"; 

} 



var textIdx = -1;

var rotationTextSpan;
var rotationRefSpan;
var rotationTextDiv;
var fadeUp = false;
var textClone;

function setupTextCrossFades( pageName )  {

	if (pageName == "home") {
		rotationFade = getObjById( "textFade" );
		rotationTextSpan = getObjById( "audioStats" );
		rotationRefSpan = getObjById( "audioRefs" );
	}
	if (pageName == "online") {
		rotationFade = getObjById( "textFade" );
	}

	rotationFade.xOpacity = .99;
	setOpacity( rotationFade );		// update the opacity
	if (pageName == "home") {
		fadeTimer2 = setTimeout( runTextRotation_home, 7000 );				// wait 7 seconds and start new fade
	}
	if (pageName == "online") {
		fadeTimer3 = setTimeout( runTextRotation_online, 7000 );				// wait 7 seconds and start new fade
	}

}

function runTextRotation_home()  {

	setOpacity( rotationFade );		// update the opacity

	if (fadeUp == false) { //we are fading down
		rotationFade.xOpacity -= .025;	// descrement the opacity
		if(rotationFade.xOpacity <= 0) {		// when the current opacity reaches zero,
			fadeUp = true;  // change fade direction
			textIdx = audioStatsList2[textIdx+1] ? textIdx+1 : 0;	// get array location of next text string
			rotationTextSpan.innerHTML = audioStatsList2[textIdx][0];	//Set the text into the span
			rotationRefSpan.innerHTML = audioStatsList2[textIdx][1];	//Set the text into the span
			rotationFade.xOpacity = 0;	// 
		}
		fadeTimer2 = setTimeout( runTextRotation_home, 50 );		// wait a tenth of a second and then continue fade

	} else { //we are fading up
		rotationFade.xOpacity += .025;	// descrement the opacity
		if(rotationFade.xOpacity >= .99 ) {		// when the current opacity reaches max,
			rotationFade.xOpacity =.99;	// for older firefox issue if set to 1
			setOpacity( rotationFade );		// update the opacity
			fadeUp = false;  // change fade direction	
			fadeTimer2 = setTimeout( runTextRotation_home, 7000 );				// wait 4 seconds and start new fade
		} else {
			fadeTimer2 = setTimeout( runTextRotation_home, 50 );		// wait a tenth of a second and then continue fade-in
		}
	}
}

function runTextRotation_online()  {

	setOpacity( rotationFade );		// update the opacity

	if (fadeUp == false) { //we are fading down
		rotationFade.xOpacity -= .025;	// descrement the opacity
		if(rotationFade.xOpacity <= 0) {		// when the current opacity reaches zero,
			fadeUp = true;  // change fade direction
			textIdx = audioStatsList3[textIdx+1] ? textIdx+1 : 0;	// get array location of next text string
		///	alert("textIdx == " + textIdx + "  audioStatsList3[textIdx] == " + audioStatsList3[textIdx]);
			rotationFade.innerHTML = audioStatsList3[textIdx];	//Set the text into the span
			rotationFade.xOpacity = 0;	// 
		}
		fadeTimer2 = setTimeout( runTextRotation_online, 50 );		// wait a tenth of a second and then continue fade

	} else { //we are fading up
		rotationFade.xOpacity += .025;	// descrement the opacity
		if(rotationFade.xOpacity >= .99 ) {		// when the current opacity reaches max,
			rotationFade.xOpacity =.99;	// for older firefox issue if set to 1
			setOpacity( rotationFade );		// update the opacity
			fadeUp = false;  // change fade direction	
			fadeTimer3 = setTimeout( runTextRotation_online, 7000 );				// wait 4 seconds and start new fade
		} else {
			fadeTimer3 = setTimeout( runTextRotation_online, 50 );		// wait a tenth of a second and then continue fade-in
		}
	}
}


function runTextRotation()  {

	setOpacity( rotationTextSpan );		// update the opacity

	if (fadeUp == false) { //we are fading down

		rotationTextSpan.xOpacity -= .025;	// descrement the opacity

		if(rotationTextSpan.xOpacity <= 0) {		// when the current opacity reaches zero,

			fadeUp = true;  // change fade direction

			textIdx = audioStatsList[textIdx+1] ? textIdx+1 : 0;	// get array location of next text string

			rotationTextSpan.innerHTML = audioStatsList[textIdx];	//Set the text into the span

			//textClone.innerHTML = audioStatsList[textIdx] ;	// Make the clone match its original

			rotationTextSpan.xOpacity = 0;	// 

		}

		//clearTimeout(fadeTimer2);

		fadeTimer2 = setTimeout( runTextRotation, 50 );		// wait a tenth of a second and then continue fade

	} else { //we are fading up

		rotationTextSpan.xOpacity += .025;	// descrement the opacity

		if(rotationTextSpan.xOpacity >= .99 ) {		// when the current opacity reaches max,

			rotationTextSpan.xOpacity =.99;	// for older firefox issue if set to 1

			setOpacity( rotationTextSpan );		// update the opacity

			fadeUp = false;  // change fade direction	

			//rotationTextSpan.style.filter = ''; 

//			rotationTextSpan.style.backgroundColor = '#525e8c'; 

			//rotationTextSpan.parentNode.replaceChild(textClone, rotationTextSpan) // IE fix -- restores ClearType text

			//clearTimeout(fadeTimer2);

			fadeTimer2 = setTimeout( runTextRotation, 7000 );				// wait 4 seconds and start new fade

		} else {

			//clearTimeout(fadeTimer2);

			fadeTimer2 = setTimeout( runTextRotation, 50 );		// wait a tenth of a second and then continue fade-in

		}

	}

	

			

//	function setOpacity( obj ) {		

////		if(obj.xOpacity > .99) {

////			obj.xOpacity = .99;

////		}

//		obj.style.opacity = obj.xOpacity;

//		obj.style.MozOpacity = obj.xOpacity;

//		obj.style.filter = "alpha(opacity=" + (obj.xOpacity * 100) + ")";

//	} 

}











var spotIdx = 0, windowIdx = 0;

var spotRotaImg, spotRotaAnchor;



function setupSpotShow( )  {

	//alert("Entering setupSpotShow.");

	spotRotaImg = getObjById( "spotRotationImg" );

	//alert( "spotRotaImg.id = " + spotRotaImg.id )

	spotRotaAnchor = getObjById( "spotRotationAnchor" );

	//alert( "spotRotaAnchor.id = " + spotRotaAnchor.id )

	spotRotaAnchor.onclick = openWindow ;

	

	spotRotaImg.src = "images/" + spotList[spotIdx][1] + ".jpg" ;	//Set the first image to be display when page loads

	//alert( "spotRotaImg.src = " + spotRotaImg.src )

	spotRotaAnchor.style.backgroundImage="url("+spotRotaImg.src+")";

	//alert( "spotRotaAnchor.style.backgroundImage = " + spotRotaAnchor.style.backgroundImage );

	

	spotRotaImg.xOpacity = 1;

	//spotRotaImg.xOpacity = 0;

	//	spotRotaImg.style.opacity = spotRotaImg.xOpacity;

	//	spotRotaImg.style.MozOpacity = spotRotaImg.xOpacity;

	//	spotRotaImg.style.filter = "alpha(opacity=" + (spotRotaImg.xOpacity * 100) + ")";

	

	//spotIdx = spotList[spotIdx+1][1] ? spotIdx+1 : 0;	// get array location of next image

	

	//fadeTimer1 = setTimeout( runSpotShow, 4000 );

	//alert("First run of runSpotShow().");

	runSpotShow();

}



function runSpotShow2()  {

	alert( "spotList[2][1] = " + spotList[2] );

	alert( "spotList[3][1] = " + spotList[3] );

	alert( "spotList[4][1] = " + spotList[4] );

	spotIdx = spotList[spotIdx+1] ? spotIdx+1 : 0;	// get array location of next image

	openWindowRym();

	runSpotShow2();

}









function runSpotShow()  {

	spotRotaImg.xOpacity += .025;	// increment the opacity

	//alert( "spotRotaImg.xOpacity = " + spotRotaImg.xOpacity )

	setOpacity( spotRotaImg );		// update the opacity

	//alert("Opacity set");

	if(spotRotaImg.xOpacity >= .99) {		// when the current opacity reaches max,

		//alert("Opacity at max");

		spotRotaAnchor.style.backgroundImage="url("+spotRotaImg.src+")";	// copy the image to the anchor

		//alert( "spotRotaAnchor.style.backgroundImage = " + spotRotaAnchor.style.backgroundImage );

		spotRotaImg.xOpacity = 0;	// make image tag invisible

		setOpacity( spotRotaImg );	// update the opacity

		windowIdx = spotIdx;

		//alert("windowIdx = " + windowIdx );

		spotIdx = spotList[spotIdx+1] ? spotIdx+1 : 0;	// get array location of next image

		spotRotaImg.src = "images/" + spotList[spotIdx][1] + ".jpg" ;	//Set the picture into the image tag

		

		fadeTimer1 = setTimeout( runSpotShow, 4000 );				// wait 4 seconds and start new fade

	} else {										// if current opacity is not yet max

		fadeTimer1 = setTimeout( runSpotShow, 50 );		// wait a tenth of a second and then continue fade-in

	}

	

}






