$starten = 1;
$gelinkt = 0;
$('document').ready(function(){
	$starten = 0;
	los();
	window.setInterval(pruefen, 2000)
});
function pruefen(){
	if($starten==1){
		$starten = 0;
		los();
	}
}
function los(){
	adresse = window.location.href.substring(window.location.href.lastIndexOf('/')+1,window.location.href.lastIndexOf('.'));
	referrer = document.referrer.substring(document.referrer.lastIndexOf('/')+1,document.referrer.lastIndexOf('.'));
	$zusammen = new Array();
	$zusammen[0] = new Array('index', 'services', 'services_images', 'services_interactive', 'services_event');
	$zusammen[1] = new Array('work', 'work_player');
	$grpact = -1;
	$grpref = -1;
	for($z=0;$z<$zusammen.length;$z++){
		if(jQuery.inArray(adresse, $zusammen[$z])>-1)
			$grpact = $z;
		if(jQuery.inArray(referrer, $zusammen[$z])>-1)
			$grpref = $z;
	}
	$('#hintergrund').css({left: '853px', opacity: 0});
	$('#playerbg').css({opacity: 0});
	$('#works').css({opacity: 0});
	$('#teaser').css({opacity: 0});
	$('#playbuttons').css({opacity: 0});
	$('#hintergrund').animate({left: '-147px', opacity: 1}, 700);
	$('#playerbg').animate({opacity: 1}, 1000);
	$('#works').animate({opacity: 1}, 1000);
	$('#teaser').animate({opacity: 1}, 1000);
	$('#playbuttons').animate({opacity: 1}, 1000);
	if($grpref>-1 && $grpref==$grpact){
		$('#subnav').css({opacity: 1});
		$('#text').css({opacity: 1});
		$('#text').children().css({opacity: 0});
		$('#text').children().animate({opacity: 1}, 1000);
	}else{
		$('#subnav').css({opacity: 0});
		$('#text').css({opacity: 0});
		$('#text').children().css({opacity: 1});
		$('#subnav').animate({opacity: 1}, 900);
		$('#text').animate({opacity: 1}, 1000);
	}
	if($gelinkt==0){
		$link = new Array();
		$('a').each(function(index){
			$link[index] = $(this).attr('href');
			if($link[index]!=undefined && $link[index]!=""){
				link = $link[index].substring($link[index].lastIndexOf('/')+1,$link[index].lastIndexOf('.'));
				$grplnk = -1;
				for($z=0;$z<$zusammen.length;$z++){
					if(jQuery.inArray(link, $zusammen[$z])>-1)
						$grplnk = $z;
				}
				$(this).removeAttr('href');
				if($grplnk>-1 && $grplnk==$grpact){
					$(this).click(function(){
						$('#player, #playerbg, #works, #teaser, #playbuttons').animate({opacity: 0}, 700, function(){
							$starten = 1;
						});
						$('#text').children().animate({opacity: 0}, 700, function(){
							$starten = 1;
							//$(this).delay(5000).css({opacity: 1});
						});
						$('#hintergrund').animate({left: '-1147px', opacity: 0}, 700, function(){
							window.location.href = $link[index];
							$starten = 1;
							//$(this).delay(5000).css({left: '-147px', opacity: 1});
						});
					});
				}else{
					$(this).click(function(){
						$('#player, #playerbg, #works, #subnav, #teaser, #playbuttons, #text').animate({opacity: 0}, 700, function(){
							$starten = 1;
							//$(this).delay(5000).css({opacity: 1});
						});
						$('#hintergrund').animate({left: '-1147px', opacity: 0}, 700, function(){
							window.location.href = $link[index];
							$starten = 1;
							//$(this).delay(5000).css({left: '-147px', opacity: 1});
						});
					});
				}
			}
		});
		$gelinkt = 1;
	}
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
function mute_unmute(){
	if($muted==0){
		if(getMethods($('video')[0]).indexOf("|play|")!=-1)
			$('video').prop('muted', true);
		else
			thisMovie('fplayer').fmute();
		$('#mute_unmute').removeClass('mute');
		$('#mute_unmute').addClass('unmute');
		$muted = 1;
	}else{
		if(getMethods($('video')[0]).indexOf("|play|")!=-1)
			$('video').prop('muted', false);
		else
			thisMovie('fplayer').funmute();
		$('#mute_unmute').removeClass('unmute');
		$('#mute_unmute').addClass('mute');
		$muted = 0;
	}
}
function play_pause(){
	if($playing==1){
		if(getMethods($('video')[0]).indexOf("|pause|")!=-1)
			$('video')[0].pause();
		else
			thisMovie('fplayer').fstop();
		$('#play_pause').removeClass('pause');
		$('#play_pause').addClass('play');
		$playing = 0;
	}else{
		if(getMethods($('video')[0]).indexOf("|play|")!=-1)
			$('video')[0].play();
		else
			thisMovie('fplayer').fplay();
		$('#play_pause').removeClass('play');
		$('#play_pause').addClass('pause');
		$playing = 1;
	}
}
function getMethods(obj) {
  var result = [];
  result.push("!");
  for (var id in obj) {
    try {
      if (typeof(obj[id]) == "function") {
        result.push(id);
      }
    } catch (err) {
    }
  }
  result.push("!");
  return result.join("|");
}

