var win=null;
var proj_shown=null;

/* -- Quicktime detection -- */

var quicktime = new Object();
quicktime.installed=false;
quicktime.version='0.0';
quicktime.version1='';

if (navigator.plugins && navigator.plugins.length) {
	for (i=0; i<navigator.plugins.length; i++) {
		if (navigator.plugins[i].name.indexOf('QuickTime') >= 0) {
			quicktime.installed = true;
			var splitter ='QuickTime Plug-in ';
			quicktime.version = navigator.plugins[i].name.substr( splitter.length );
			break;
		}
	}
}else if (window.ActiveXObject) {
	try	{
		QTime = new ActiveXObject('QuickTimeCheckObject.QuickTimeCheck.1');
		if (QTime) {
			quicktime.installed = QTime.IsQuickTimeAvailable(0);
			quicktime.version = parseInt(QTime.QuickTimeVersion.toString(16).substring(0,3))/100;
		}
	}catch(e) {}
}
quicktime.ver4 = (quicktime.installed && parseInt(quicktime.version) >= 4);
quicktime.ver6 = (quicktime.installed && parseInt(quicktime.version) >= 6);
quicktime.ver8 = (quicktime.installed && parseInt(quicktime.version) >= 8);
quicktime.ver9 = (quicktime.installed && parseInt(quicktime.version) >= 9);


/* -- Diverse Functions -- */

function openWin( url, name, xsize, ysize ) {
	if (win!=null) win.close();
	var features = '';
	if (arguments.length>2) features = 'resizable=no,hotkeys=no,menubar=no,locationbar=no,status=yes,width='+xsize+',height='+ysize;
	win = window.open(url ,name , features);
	win.focus();
}

function highlight(el) {
	if (el.className.indexOf('project_sel') < 0)
	{
		el.className = el.className.replace(/project/g, "");
		el.className += ' project_sel';
		//var i = el.className.indexOf('project');
		//el.className = substr(0, i) + substr(i + ('project').length);
		//el.className.split("project");
	}
}
function unhighlight(el) {
	if (el.className.indexOf('project_sel') >= 0)
	{
		el.className = el.className.replace(/project_sel/g, "");
		el.className += ' project';
	}
}

function getWinWidth() {
	if (window.innerWidth) return window.innerWidth;
	else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
	else return 1024;
}

function myOnResize() {
	var winWidth = getWinWidth();
	if (winWidth<1100) {
		document.getElementById("global").className = "globalSmall";
		document.getElementById("head_mfo").className = (proj_shown==null)? "head_mfo_small" : "head_mfo_small2";
	}else{
		document.getElementById("global").className = "globalLarge";
		document.getElementById("head_mfo").className = (proj_shown==null)? "head_mfo_large" : "head_mfo_large2";
	}
}

/* -- Project anzeigen  -- */

var recent_movie_id=null;
function showProject(id, movie_id, qt_src, qt_width, qt_height, yt_src, yt_width, yt_height ) {
	proj_shown = id;
	document.getElementById(id).style.display = "block";
	myOnResize();
	document.getElementById("head_mfo").onclick = hideProject;
	document.getElementById("blog").display = "none";
	if (arguments.length>1) {
		recent_movie_id = movie_id;
		if (quicktime.ver6) showQuicktime( movie_id, qt_src, qt_width, qt_height );
		else if (arguments.length>5) showYouTube(movie_id, yt_src, yt_width, yt_height);
	}
	// history
	unFocus.History.addHistory(1);
}
function hideProject() {
	if (proj_shown!=null) document.getElementById(proj_shown).style.display = "none";
	proj_shown = null;
	myOnResize();
	document.getElementById("blog").display = "block";
	stopMovie( recent_movie_id );
}

/* -- History Manager -- */

historyListener = function(historyHash) {
	if (historyHash==0) hideProject();
}
unFocus.History.addEventListener('historyChange', historyListener);

/* -- Filme anzeigen (Quicktime, YouTube, ..)  -- */

function showQuicktime(id, src, width, height) {
	var el=document.getElementById(id)
	el.style.height = height+"px";
	el.innerHTML='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+width+'" height="'+height+'" SCALE="toFit">'
				+'  <param name="src" value="'+src+'" />'
				+'  <param name="controller" value="true" />'
				+'  <param name="scale" value="toFit" />'
				+'  <object type="video/quicktime" data="'+src+'" width="'+width+'" height="'+height+'" class="mov" scale="toFit">'
				+'    <param name="scale" value="toFit" />'
				+'  </object>'
				+'</object>' ;
}

function showYouTube(id, src, width, height) {
	var el=document.getElementById(id);
	el.style.width = width+"px";
	el.style.height = height+"px";
	el.innerHTML= '<div class="movie_info">'
				+ ((lang=='de')? ' Das Quicktime Plug-In ist nicht installiert ... um den Film zu sehen bitte dem YouTube Link auf der rechten Seite folgen!' :
								 ' The Quicktime plug-in is not installed ... follow the YouTube link on the right to watch the film! <br/> ' )
				+ '</div>';
/*	el.innerHTML='<object width="'+width+'" height="'+height+'">'
				+'	<param name="movie" value="'+src+'" />'
				+'  <param name="bgcolor" value="#EFEFEF" />'
				+'	<embed src="'+src+'" type="application/x-shockwave-flash" '
				+'		width="'+width+'" height="'+height+'" '
				+'		bgcolor="#000000">'
				+'	</embed>'
				+'</object>';
*/
}

function stopMovie(id) {
	if (id==null) return;
	var el=document.getElementById(id);
	el.innerHTML='';
}

/* -- Post-Loading Functions -- */

function registerPostImg(src, id ) {
	if (arguments.length>2) the_link = arguments[2];
	else the_link = null;
	if (typeof(postLoad)=="undefined") postLoad = new Array(0);
	var i = postLoad.length;
	postLoad[i] = new Array( src , id , the_link);
}

function startPostLoading(callAfter) {
	window.setTimeout("doPostLoading()", 2000);
	if (callAfter!="") window.setTimeout("doAnotherPostLoading("+callAfter+")", 4000);
}

function doPostLoading() {
	if (postLoad.length==0) return false;
	for (i in postLoad) {
		var el = document.getElementById(postLoad[i][1]);
		if (!el) continue;
		if (postLoad[i][2])		
	  	el.innerHTML += '<a href="'+postLoad[i][2]+'" target="_blank" class="noArrow" onfocus="this.blur();"><img src='+postLoad[i][0]+' /></a>';
	  else
			el.innerHTML += '<img src='+postLoad[i][0]+' />';
	}
}

function doAnotherPostLoading(callAfter) {
	if (callAfter == 1)
			showProject('aviorama', 'aviorama_movie', 'projects/aviorama/mfo__aviorama.mov', '800', '338', 'http://www.youtube.com/v/ENhCjRyqk5I', '800', '467');
}