// JavaScript Document

// SUCHEN und ERSETZEN
	function SUE(QuellText, SuchText, ErsatzText){   // Erstellt von Ralf Pfeifer
            // Fehlerpruefung
            if ((QuellText == null) || (SuchText == null)) { return null; }
            if ((QuellText.length == 0) || (SuchText.length == 0)) { return QuellText; }

            // Kein ErsatzText ?
            if ((ErsatzText == null) || (ErsatzText.length == 0)) { ErsatzText = ""; }

            var LaengeSuchText = SuchText.length;
            var LaengeErsatzText = ErsatzText.length;
            var Pos = QuellText.indexOf(SuchText, 0);

            while (Pos >= 0){
                QuellText = QuellText.substring(0, Pos) + ErsatzText + QuellText.substring(Pos + LaengeSuchText);
                Pos = QuellText.indexOf(SuchText, Pos + LaengeErsatzText);
            }
            return QuellText;
	}


$(document).ready(function(){
		
		/*$('#navi ul li:eq('+Aktiv+') a img').attr('src',SUE($('#navi ul li:eq('+Aktiv+') a img').attr('src'), '.', '_h.')).addClass('aktiv');
		
		// Menü Hover Zustände
		$('#navi ul li > a img').hover(function(){
			if($(this).hasClass('aktiv')) return false;
			Yet = $(this).attr('src');
			Hover = SUE(Yet, '.', '_h.');
			$(this).attr('src',Hover);
		},function(){
			if($(this).hasClass('aktiv')) return false;
			$(this).attr('src',Yet);
		})*/;
		
		// ITEM Hover Zustände
		$('span.item').hover(function(){
			$(this).css({'background-color':'#ebebeb'});
		},function(){
			$(this).css({'background-color':'#fff'});
		});
		
		// PAGINIERUNG
		$('#content').find('.item').parent('p').hide();
		var ITEM = $('#content').find('.item').size();
		var Start=0,Ende=5,Num=5;
		paginiere(Start,Num);
		function paginiere(Start,Ende){
			for(var i=Start;i<Ende;i++){
				$('#content').find('.item:eq('+i+')').parent('p').fadeIn(400);
				if(Ende>=ITEM) $('a#next').parent('p').hide();
			};
		}
		$('#next').click(function(){
			Start = Ende;
			Ende = Ende+Num;
			paginiere(Start,Ende);
		});
		
		
		$('span.wrapper_showreel').css({'display':'none'});
		$('span.wrapper_gallery').css({'display':'none'});
		
		// iPhone ABFRAGE
		if(navigator.userAgent.toLowerCase().indexOf('iphone') > -1){
			$('div#claim p').css('font-size','14px');
		}
		
		$('span.item').click(function(){
		
			if($(this).hasClass('active')){
				$('.vid').html('');
				$(this).next('span.wrapper_showreel').slideUp(400);
				$(this).next('span.wrapper_showreel').find('span.wrapper_gallery').fadeOut(200,function(){ $(this).css({'margin-left':0}); });
				$('span.nav_left').remove();
				$('span.nav_right').remove();
				$(this).find('span.picnum').css({'background-color':'#b8b8b8'});
				$(this).removeClass('active');
				return;
			};
			$('span.item').each(function(){
				$('.vid').html('');
				$(this).next('span.wrapper_showreel').slideUp(400);
				$(this).next('span.wrapper_showreel').find('span.wrapper_gallery').fadeOut(200,function(){ $(this).css({'margin-left':0}); });
				$('span.nav_left').remove();
				$('span.nav_right').remove();
				$(this).find('span.picnum').css({'background-color':'#b8b8b8'});
				$(this).removeClass('active');
				return;
			});
			var IMG = $(this).next('span').find('span.wrapper_gallery').find('img').size();
			$(this).next('span.wrapper_showreel').slideDown(400);
			$(this).next('span.wrapper_showreel').find('span.wrapper_gallery').css({'width':IMG*700+'px'});
			$(this).next('span.wrapper_showreel').find('span.wrapper_gallery').delay(200).fadeIn(400,function(){
				
			
				//VIDEO EINBINDUNG
				if($(this).hasClass('vid')) {
					var VID = $(this).attr('name');
					if(swfobject.hasFlashPlayerVersion("9")){
						$(this).attr('id',VID);
						$(this).append('<span id="'+VID+'"></span>');
						swfobject.embedSWF("video.swf?"+Math.round(Math.random()*10000) , VID, "690", "388", "9.0.0",false,{pfad:"video/"+VID+".flv",autoplay:"true"},{allowfullscreen:"true"},{});
					} else {
						$(this).append('<object codebase=http://www.apple.com/qtactivex/qtplugin.cab height=388 width=690 classid=clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B><param name="cache" value="true"><param name="src" value="video/'+VID+'.mp4"><param name="autoplay" value="true"><param name="controller" value="false"><embed height="388" pluginspage="http://www.apple.com/quicktime/download/" src="video/'+VID+'.mp4" type="video/quicktime" width="690" controller="false" autoplay="true" cache="true"></embed></object>');
					}
					//$(this).before('span.active').find('span.picnum').css({'background-color':'#696969'});
				}
						
				
				/*if(navigator.userAgent.toLowerCase().indexOf('iphone') > -1){
					$(document).scrollTo( this, 0, {offset:-100} );
				} else {
					$(document).scrollTo( this, 400, {offset:-100} );
				}*/
				
				//$(this).parent('span.wrapper_showreel').corner('5px');
				
				function checkBrowserName(name){  
					var agent = navigator.userAgent.toLowerCase();  
					if (agent.indexOf(name.toLowerCase())>-1) {  
			     		return true;  
			    	}  
						return false;  
				}
				if(checkBrowserName('MSIE')){} else $(this).parent('span.wrapper_showreel').corner('5px');  
				
				var Pic = IMG-1;
				$(this).parent('span').prev('span.item').find('span.picnum:eq('+Pic+')').css({'background-color':'#696969'});
				
				var NAV_GAL_l = '<span class="nav_left" style="float:left; position:absolute; width:25%; height:388px; background:url(img/left.png) 25% center no-repeat;"></span>';
				var NAV_GAL_r = '<span class="nav_right" style="float:left; position:absolute; width:75%; margin-left:25%; height:388px; background:url(img/right.png) 93% center no-repeat;"></span>';
				
				var count = IMG;
				
				if(count!=0) $(this).parent('span.wrapper_showreel').prepend(NAV_GAL_l+NAV_GAL_r);
								
				$('span.nav_left').css('width',0).css({'opacity':0}).hover(function(){ 
					$(this).fadeTo(200,0.8); 
					$(this).click(function(){
						if($(this).hasClass('stop')) return;
						count++;
						Pic++;
						$(this).parent('span').prev('span.item').find('span.picnum').css({'background-color':'#b8b8b8'});
						$(this).parent('span').prev('span.item').find('span.picnum:eq('+Pic+')').css({'background-color':'#696969'});
						if(count>=IMG) $(this).css('width',0); else $('span.nav_right').css('width',75+'%');
						if(count>IMG) {count=IMG; return;}  else $('span.nav_right').css('width',75+'%');
						$(this).addClass('stop');
						var Pos  = $(this).parent('span').find('span.wrapper_gallery').css('margin-left');
						$(this).parent('span').find('span.wrapper_gallery').animate({'margin-left':parseInt(Pos)+700},400,function(){ $('span.nav_left').removeClass('stop'); });
						return;
					});
					return; 
				},function(){ 
					$(this).fadeTo(200,0); return; 
				});
				$('span.nav_right').css({'opacity':0}).hover(function(){ 
					$(this).fadeTo(200,0.8); 
					$(this).click(function(){
						if($(this).hasClass('stop')) return;
						count--;
						Pic--;
						$(this).parent('span').prev('span.item').find('span.picnum').css({'background-color':'#b8b8b8'});
						$(this).parent('span').prev('span.item').find('span.picnum:eq('+Pic+')').css({'background-color':'#696969'});
						if(count<=1) $(this).css('width',0); else $('span.nav_left').css('width',25+'%');
						if(count<=0) {count=1; return;} else $('span.nav_left').css('width',25+'%');
						$(this).addClass('stop');
						var Pos  = $(this).parent('span').find('span.wrapper_gallery').css('margin-left');
						$(this).parent('span').find('span.wrapper_gallery').animate({'margin-left':parseInt(Pos)-700},400,function(){ $('span.nav_right').removeClass('stop'); });
						return;
					});
					return; 
				},function(){ 
					$(this).fadeTo(200,0);  return; 
				});
				
				// iPhone ABFRAGE		
				if(navigator.userAgent.toLowerCase().indexOf('iphone') > -1){
					$(this).parent('span.wrapper_showreel').prepend(NAV_GAL_l+NAV_GAL_r).find('.nav_left').delay(2000).fadeTo(200,0).next('.nav_right').delay(2000).fadeTo(200,0);
				}

				});
						
			$(this).addClass('active');
		});
	
		// IMPRESSUM
		$('a#impressum_btn').click(function(){ $('#impressum').slideToggle(400).find('ul').animate({ opacity:'toggle'},300); });
		$('#impressum').click(function(){ $('a#impressum_btn').trigger('click'); });
		
	});		
				
