var moo = false;
var playing = 0;
var pausethis = 0;
var whatbrowser = 0;


function makeMooga( vimeoID, mooID, vwidth, vheight, vautoplay){

	if (vautoplay==0){
		var flashvars = {
		clip_id: vimeoID,
		show_portrait: 0,
		show_byline: 0,
		show_title: 0,
		hd_off: 1,
		js_api: 1, 							// required in order to use the Javascript API
		js_onLoad: 'vimeo_player_loaded', // moogaloop will call this JS function when it's done loading (optional)
		js_swf_id: mooID // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
		};
	}
	else {
		var flashvars = {
		clip_id: vimeoID,
		show_portrait: 0,
		show_byline: 0,
		show_title: 0,
		hd_off: 1,
		js_api: 1, 								// required in order to use the Javascript API
		js_onLoad: 'vimeo_player_loaded_play', // moogaloop will call this JS function when it's done loading (optional)
		js_swf_id: mooID // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
		};
		}
	var params = {
		allowscriptaccess: 'always',
		allowfullscreen: 'true'
		};
	var attributes = {};
	// For more SWFObject documentation visit: http://code.google.com/p/swfobject/wiki/documentation
	swfobject.embedSWF("http://vimeo.com/moogaloop.swf", mooID, vwidth, vheight, "9.0.0","expressInstall.swf", flashvars, params, attributes);
}
	



/*function checkbrowser(){
	if (navigator.userAgent.indexOf("Firefox")!=-1){
		whatbrowser = 1;}
	if (navigator.userAgent.indexOf("MSIE")!=-1){
		whatbrowser = 2;}
	document.getElementById('state').innerHTML = 'browser: '+whatbrowser;
}
*/
function vimeo_player_loaded(swf_id) {
	moo = document.getElementById(swf_id);
	moo.api_addEventListener('onPlay', 'vimeo_on_play');
	moo.api_addEventListener('onPause', 'vimeo_on_pause');
}


function vimeo_player_loaded_play(swf_id) {
	moo = document.getElementById(swf_id);
	moo.api_addEventListener('onPlay', 'vimeo_on_play');
	moo.api_addEventListener('onPause', 'vimeo_on_pause');
	vplay(swf_id);
	
}

function vimeo_on_play(swf_id) {
	vpause(pausethis);
	playing = swf_id;
	pausethis = playing;
	grayOut(1);
	
//	document.getElementById('state').innerHTML = 'Playing '+swf_id;
}


function vimeo_on_pause(swf_id) {
//	document.getElementById('state').innerHTML = 'Paused '+swf_id;
	playing = 0;
	grayOut(0);
}


function vplay(id){
	pausethis = playing;
	eval(id+".api_play();");
}

function vpause(id){
	if (playing != 0){
		eval(id+".api_pause();");
	}
}
	
function grayOut(vis) {
   var zindex =  3;
   var opacity = 70;
  var opaque = 0.7;
  var bgcolor =  '#000000';
var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
		 tnode.style.cursor='pointer';
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
		
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
	dark.onclick=grayOff;
	dark.style.zIndex=zindex;
	//document.getElementById('v10').style.zIndex=200;
	}
 
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';  
	//andere inhalte anpassen
	document.getElementById('darken').style.backgroundColor='#111'; //hintergrund div ändern (dunkelgrau)
	//$('p').addClass('txtinvert');
	$('h1').toggleClass("txtinvert", true);
	$('p').toggleClass("txtinvert", true);
	$('h2').toggleClass("txtinvert", true);
	//$('h1 a:hover').toggleClass("txtinvert", true);

	
	
	
	
  } else {
     dark.style.display='none';
	 document.getElementById('darken').style.backgroundColor='#FFF';
	$('p').toggleClass("txtinvert", false);
	$('h1').toggleClass("txtinvert", false);
	$('h2').toggleClass("txtinvert", false);
	//$('h1 a:hover').toggleClass("txtinvert", false);
  }
}
	
function grayOff(){
	grayOut(0);
	}
	
	

