// @format (hex|rgb|null) : Format to return, default is integer
function random_color(format)
{
 var rint = Math.round(0xffffff * Math.random());
 switch(format)
 {
  case 'hex':
   return ('#0' + rint.toString(16)).replace(/^#0([0-9a-f]{6})$/i, '#$1');
  break;
  
  case 'rgb':
   return 'rgb(' + (rint >> 16) + ',' + (rint >> 8 & 255) + ',' + (rint & 255) + ')';
  break;
  
  default:
   return rint;
  break;
 }
}

function nova(){
	var color =  random_color('rgb');
	$(document.body).animate({ backgroundColor:color }, 3000);
	// https://developer.mozilla.org/en/DOM/window.setTimeout
	// vs. http://api.jquery.com/delay/
	// window.setTimeout("nova()",10000);	
};

$.uicornerfix('10px');

$(function() {
// do something on document ready

	
		/* Allgemeine funktionen */
		
		$("a").focus(function () {
			$(this).blur();
		});

		
		/*
		BG SIZER
		*/

		//$('body').append('')		
		var image = $('#current-picture');
		var box = $('#picture-box');

		
		function bg_sizer () {
			var percent = $(window).width() / image.width();
			if ((image.height() * percent) < $(window).height())  percent = $(window).height() / image.height();

			var nLeft	= parseInt(image.attr('width') * percent * 0.5 *-1);
			var nTop	= parseInt(image.attr('height') * percent * 0.5 *-1);
			var nWidth	= parseInt(image.attr('width') * percent);
			var nHeight	= parseInt(image.attr('height') * percent);
			
			image.attr({
			        width		: nWidth,
			        height		: nHeight
			});			
			image.css({
			        marginLeft	: nLeft+'px',
			        marginTop	: nTop+'px'
			});
		};



		$(window).resize(function () {
			bg_sizer();
		});
	
		image.css({visibility:'visible'});
		
		// http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
		setInterval ( "nova()", 10000 );
		
		bg_sizer();
		
		/*
		THICKBOX
		http://jquery.com/demo/thickbox/
		*/
		
		// tb_show('', './tpl/aktuelles.tpl?KeepThis=true&TB_iframe=true&height=600&width=1000', null);
		
		
		/*
		Hovereffekte einzelner DIV layers
		*/
		
		$('.boxL').mouseenter(function() {
			$(this).fadeTo('fast' , 1.0)
		}).mouseleave(function(){
			$(this).fadeTo('fast' , 0.8)
		});
		
		$('.boxR').mouseenter(function() {
			$(this).fadeTo('fast' , 1.0)
		}).mouseleave(function(){
			$(this).fadeTo('fast' , 0.8)
		});	


		
		/*
		 JQUERY SWFOBJECT PLUGIN
		http://code.google.com/p/swfobject/wiki/documentation
		swfobject.embedSWF (swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes)
		http://plugins.jquery.com/project/swfobject
		*/

		var video = $.flash.create({
			swf: 'http://plugins.raum-der-stille.net/mediaplayer-viral/player-viral.swf',
			width: 451,
			height: 430,
			hasVersion: 8,
			expressInstaller: 'http://plugins.raum-der-stille.net/expressInstall.swf',
			
			params: {
				
				allowfullscreen:'true',
				allowscriptaccess:'always',
				allownetworking:'all',
				wmode:'opaque',
				
				flashvars: {
					playlistfile:'http://gdata.youtube.com/feeds/api/playlists/F1900900E4F1B833',
					playlist:'bottom',
					playlistsize:'200',
					autostart:'false',
					item:'0',
					plugins:'yousearch-1'
				}
			}
		});			
		

		var mp3 = $.flash.create({
			swf: 'http://plugins.raum-der-stille.net/mediaplayer-viral/player-viral.swf',
			width: 451,
			height: 430,
			hasVersion: 8,
			expressInstaller: 'http://plugins.raum-der-stille.net/expressInstall.swf',
			
			params: {
				
				allowfullscreen:'false',
				allowscriptaccess:'always',
				allownetworking:'all',
				wmode:'opaque',
				
				flashvars: {
					playlistfile:'http://raum-der-stille.net/xml/audio.xml',
					playlist:'bottom',
					playlistsize:'200',
					autostart:'false',
					plugins:'revolt-1',
					item:'0'
				}
			}
		});	
		

					
		/*
		CLICK EVENTS
		*/

				
		$('a#contact').click(function() {
			$('#scr1').empty();
			$('#scr1').css("display", "none");
			$("#scr1").load("tpl/kontakt.tpl");
			$("#scr1").fadeIn(1000);
			$('#titel_3').html("<h1>IMPRESSUM</h2>")
		});

		$('a#tedeum').click(function() {
			$('#scr1').empty();
			$('#scr1').css("display", "none");
			$("#scr1").load("include/laach-policy.php");
			$("#scr1").fadeIn(1000);
			$('#titel_3').html("<h1>LITURGIA - Morgen- und Abendlob</h2>")
		});


		$('a#video').click(function() {
			$('#mediaplayer').empty().html(video).fadeIn('slow');
		});
		
		$('a#audio').click(function() {
			$('#mediaplayer').empty().html(mp3).fadeIn('slow');
		});
		
		$('a#biblio').click(function() {
			$('#scr1').empty();
			$('#scr1').fileTree({ root: '/media/', script: 'include/jqueryFileTree.php' }, function(file) {
				// tb_show('', 'http://raum-der-stille.net/include/jqueryFileTree.php?file='+file+'&KeepThis=true&TB_iframe=true&height=600&width=1000', null);
				window.open(file);
				return false;
			});
			$('#titel_3').html("<h1>BIBLIOTHEK - SHARING</h2>");
		});		
	
	
	
		//START LOADING
		// $('#mediaplayer').html(mp3);
		$('a#tedeum').click();
									
});
