YAHOO.namespace("mycontainer");

function addBookmark(title,url) {	
	if (window.sidebar) { // Mozilla Firefox Bookmark
		alert("Press CTRL + D to bookmark this page");
	} 
	else if( window.external ) { // IE Favorite
		window.external.AddFavorite(url, title); 
	}
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

function setExitPage() {	
	var pageURL = null;
	var pattern = new RegExp("http://[\\w-\\.]+(/[\\w-\\./]*)([#\\?]?.*)");
	var relativeURL = pattern.exec(document.URL);
	if (relativeURL!=null) {
		pageURL = relativeURL[1];
//		document.title = document.title + "[" + pageURL + "]";
	}
	if (pageURL == "/join.html") {
		window.onunload=myExit;
//		document.title = document.title + "{MATCH!}";
	}
	return true;
}

function loadDownloadReminders() {
	var downloadLinks = YAHOO.util.Dom.getElementsByClassName('downloadLink');
	if (downloadLinks) {
		new YAHOO.widget.Tooltip("reminder",  { context:downloadLinks,  text:" Click right and select 'save target as ...'" } ); 
	}
}

function decorateThumbnails() {
	var tnDIV = document.getElementById('thumbnails');
	if (tnDIV) {
		var tnAs = tnDIV.getElementsByTagName('a');
		for(i=0;i<tnAs.length;i++) {
			var tnIMGs=tnAs[i].getElementsByTagName('img');
			if (tnIMGs) {
				YAHOO.util.Event.addListener(tnAs[i], "mouseover" , enlargeSample, tnAs[i],true); 
			}
		}
		YAHOO.util.Event.addListener(tnDIV,   "mouseout"  , reduceSample,  tnDIV,true); 
		YAHOO.mycontainer.SampleBox = document.getElementById('sampleBox').getElementsByTagName('img')[0];

		YAHOO.mycontainer.SampleBoxOverlay = new YAHOO.widget.Panel("sampleBox", {  visible:false, constraintoviewport:true } ); 
/*
		YAHOO.mycontainer.SampleBoxOverlay = new YAHOO.widget.Overlay('sampleBox', { visible:false, fixedcenter:true , context:["thumbnails","tr","tl"]
			, effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}]
		} ); 
*/
		YAHOO.mycontainer.SampleBoxOverlay.render(); 
	}
}
/*
<div id="sampleBox"> 
    <div class="hd">sample photo</div> 
    <div class="bd"><img src="/img/screen-empty.gif" /></div> 
</div> 
*/
function enlargeSample(event,thumbnail) {
	YAHOO.mycontainer.SampleBox.src = thumbnail.href;
	if (! YAHOO.mycontainer.SampleBoxOverlay.visible) {
//		alert("show");
		YAHOO.mycontainer.SampleBoxOverlay.show();
	}
}
function reduceSample(event,thumbnail) {
//			alert("hide");
	YAHOO.mycontainer.SampleBoxOverlay.hide();
}



var times=0;
var newSlideNr;
/*
function showError() {
	alert ("times="+times+" newSlideNr="+newSlideNr+"  ( "+allscenesTNs[newSlideNr].src+" =?= "+filmstripTNs[i].src+" )");
}
window.onerror=showError;
*/
function startSlideshow() {
	YAHOO.mycontainer.slideshowSize=29;
	YAHOO.mycontainer.slideshowBuffer=new Array(18);
	YAHOO.mycontainer.silverscreen=document.getElementById('silverscreen');
	for(i=0;i<YAHOO.mycontainer.slideshowBuffer.length;i++) {
			YAHOO.mycontainer.slideshowBuffer[i]=i+1;
	}
	for(i=0;i<YAHOO.mycontainer.slideshowBuffer.length;i++) {
			addRandomSlideAtPosition(i);
	}
	nextSlide();
}
function addRandomSlideAtPosition(pos) {
  if (pos>=0 && pos<YAHOO.mycontainer.slideshowBuffer.length) {
	do {
		newSlideNr=1+Math.floor(Math.random()*(YAHOO.mycontainer.slideshowSize));
		var i=0;
		do {
			//alert ("newSlideNr="+newSlideNr+"  ( "+allscenesTNs[newSlideNr].src+" =?= "+filmstripTNs[i].src+" )");
			if (newSlideNr == YAHOO.mycontainer.slideshowBuffer[i]) {
				newSlideNr=-1;
			}
			i++;
		} while(i<YAHOO.mycontainer.slideshowBuffer.length && newSlideNr>=0);
	} while (newSlideNr<0);
	YAHOO.mycontainer.slideshowBuffer[pos]=newSlideNr;
  }
}
function nextSlide(){
	//pos=Math.round(Math.random()*(filmstripLength-1));
	//showRandomSlideAtPosition(pos);
	for(i=0;i<YAHOO.mycontainer.slideshowBuffer.length-1;i++) {
		YAHOO.mycontainer.slideshowBuffer[i] = YAHOO.mycontainer.slideshowBuffer[i+1];
	}
	addRandomSlideAtPosition(YAHOO.mycontainer.slideshowBuffer.length-1);

	var zeros = "";
	if (YAHOO.mycontainer.slideshowBuffer[0]<=9) { zeros = "00"; }
	else if (YAHOO.mycontainer.slideshowBuffer[0]<=99) { zeros = "0"; }
	YAHOO.mycontainer.silverscreen.src = "/cinema/screens/cinemascreen"+zeros+new String(YAHOO.mycontainer.slideshowBuffer[0])+".jpg"
//	alert(YAHOO.mycontainer.slideshowBuffer[0]);

	delay=7+Math.floor(Math.random()*(7));
	times++;
	//if (times<10) 
	setTimeout("nextSlide()",delay*1000);
}



function onLoad() {
	if ( document.getElementById('dvdscenes') || document.getElementById('cinemascenes') ) { loadDownloadReminders(); }

//	if (document.getElementById('thumbnails')) { decorateThumbnails(); }
	if (document.getElementById('silverscreen')) { startSlideshow(); }
	return true;
}

function myExit() {
//	alert ("... und tschüss baba und foi' ned'!");
	return true;
}

function onUnload() {
	return true;
}
