var timer_01 = null;
var timer_02 = null;
var timerRunning = false;

function stopclock() {
	if(timerRunning) {
		clearInterval(timer_01);
		clearTimeout(timer_02);
		timerRunning = false;
	}
}

function startshow(movidx,msgIntvl,onoff,movplayURL,resized) {
// Make sure the clock is stopped
stopclock();
var intvl = msgIntvl;
timer_01 = setInterval("runshow("+ movidx +","+ intvl +","+ onoff +",'"+ movplayURL +"',"+ resized +")",intvl);
timerRunning = true;
}


function StopIt(idx){
	if(document["movie"+idx]) {
		document["movie"+idx].width = 1;
		document["movie"+idx].height = 1;
		document["movie"+idx].Stop();
		var movSize = (Math.round(document["movie" + idx].GetMovieSize()/(1024*102.4))/10) + ' MB';
		document.getElementById("A_status"+idx).innerHTML = '&nbsp;';
		document.getElementById("B_status"+idx).innerHTML = '(' + movSize + ')';
	}
	stopclock();	
}
	
function attSlideShow(bigimg,divThumbs,imgW,imgH) {
		
	 var picLink = "slideshow.php?divThumbs=" + divThumbs + "&bigimg=" + bigimg + "&imgW=" + imgW + "&imgH=" + imgH;
	//alert(picLink);
     	slideshow = window.open(picLink, 'slideshow', 'menubar=yes,personalbar=no,scrollbars=yes,dependent,directories=no,resizable=yes,width='+ (imgW+200) +',height=' + (imgH+200));
		slideshow.focus();
}
	

		
function runshow(movidx,msgIntvl,onoff,movplayURL,resized) {
		var resizedDone = resized;
		myExp2 = new RegExp(movplayURL.toString());
		var str = document["movie" + movidx].GetURL();
		if(myExp2.test(str)) {
			if((resizedDone == 0) && (document["movie" + movidx].GetPluginStatus() == "Playable" || document["movie" + movidx].GetPluginStatus() == "Complete")) {
				resizedDone = 1;
				resized = 1;
				document["movie" + movidx].SetMatrix('1,0,0.0 0.0,1,0.0 0.0,0.0,1');
				var rect = document["movie" + movidx].GetRectangle();
				sizeArray = rect.split(',')
				document["movie" + movidx].SetRectangle('0,0,'+ sizeArray[2] + ',' + sizeArray[3] + '');
				var w = Math.abs(Number(sizeArray[2]));
				var h = Math.abs(Number(sizeArray[3]));
				if(h < 60){w = 360;}
				//if(w < 120 ){w = 120;}
				document["movie" + movidx].width = w;
				document["movie" + movidx].height = h+15;
				document["movie" + movidx].focus();						
			
				if((document["movie" + movidx].GetPluginStatus() == "Playable" || document["movie" + movidx].GetPluginStatus() == "Complete")) {
				document.getElementById("A_status"+movidx).innerHTML = '<a href="javascript:StopIt(' + movidx + ');" >Close</a>\n';
				document.getElementById("A_status"+movidx).style.font['size'] = '8pt';
				document.getElementById("A_status"+movidx).style.border = 1;
				intvl = 100;
				movStatus(movidx);
				
					if(document["movie" + movidx].GetPluginStatus() == "Complete"){ //
					onoff = 0;		
					clearTimeout(timer_01);
					timerRunning = false;
					document["movie" + movidx].focus();
					}
				}
			}
		} else {
			document.getElementById("B_status"+movidx).innerHTML = 'Movie is being loaded. Please be patient...<br />';
			intvl = msgIntvl;
		}
}
	
	
function movStatus(movstatidx) {
	var movSize = (Math.round(document["movie" + movstatidx].GetMovieSize()/(1024*102.4))/10) + ' MB';
	var movStatusMsg = document["movie" + movstatidx].GetPluginStatus();
	var movBytesLd = (Math.round(document["movie" + movstatidx].GetMaxBytesLoaded()/(1024*102.4))/10);
	document.getElementById("B_status" + movstatidx).firstChild.nodeValue = '(' + movStatusMsg + ' ' + movBytesLd + ' of ' + movSize + ')';
}
	
function show(divID, idx, playURL) {
	for (i=0; i <= 1000; i++) {
		if(document["movie"+i]) {
			document["movie"+i].Stop();
		}
	}
	var movplayURL = playURL;
	myExp = new RegExp(playURL.toString());
	var str = document["movie" + idx].GetURL();
	if (!myExp.test(str)) {
		document.getElementById("B_status" + idx).innerHTML = 'Movie is being loaded. Please be patient...<br />';
		document["movie" + idx].SetURL(playURL);
		startshow(idx, 1000, 1, movplayURL,0);
		
	} else {
		
		document.getElementById("A_status"+idx).innerHTML = '<a href="javascript:StopIt(' + idx + ');" >Close</a>\n';
		document["movie" + idx].SetMatrix('1,0,0.0 0.0,1,0.0 0.0,0.0,1');
		var rect = document["movie" + idx].GetRectangle();
		//alert(rect + ' | ' + rect.length);
		sizeArray = rect.split(',')
		document["movie" + idx].SetRectangle('0,0,'+ sizeArray[2] + ',' + sizeArray[3] + '');
		var w = Math.abs(Number(sizeArray[2]));
		var h = Math.abs(Number(sizeArray[3]));
		if(h < 60){w = 360;}
		document["movie" + idx].width = w;
		document["movie" + idx].height = h+15;
		document["movie" + idx].focus();
		document["movie" + idx].Play();
	}
}	
	
