$(document).ready(function() {		
/*#######---------------Bildergalerie im Header -------###########*/
/*#################################################################*/		
	//loading information
	var $loadingIndicator = $('<img/>')
	.attr({
		'src': 'http://2wgmbh.webseiten.cc/uploads/tf/bildergalerie/pics/ajax-loader.gif'
	})
	.addClass('wait')
	.appendTo('#header')
	.ajaxStart(function(){
		$(this).show();
		}).ajaxStop(function(){
			$(this).remove();
			});
	
	
	//get url for data 
	var myurl = document.URL;
	var address = myurl.replace("2wgmbh.de/","2wgmbh.de/json/");
	//load data	
	$.getJSON(address, function(data) {		
		var $header = $('#header');
		$header.empty();

		//Video
		if(data.video){
			//change height
			$header.css({height: data.height});
			
			 //HTML for Player
		      var htmlVideo = '<div id="jp_container_1" class="jp-video ">';
				  htmlVideo += '<div class="jp-type-single">';
				  htmlVideo += '<div id="jquery_jplayer_1" class="jp-jplayer"></div>';
				  htmlVideo += '<div class="jp-gui">';
				  htmlVideo += '<div class="jp-video-play">';
				  htmlVideo += '<a href="javascript:;" class="jp-video-play-icon" tabindex="1">play</a>';
				  htmlVideo += '</div>';
				  
				  htmlVideo += '</div>';
				  htmlVideo += '<div class="jp-no-solution">';
				  htmlVideo += '<span>Update Required</span>';
				  htmlVideo += 'To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.';
				  htmlVideo += '</div>';
				  htmlVideo += '</div>';
				  htmlVideo += '</div>';
			      htmlVideo += '<div class="playPause playerPause">&nbsp;</div>';
			      $header.append(htmlVideo);
			   
			    //Player 
			    var clicked = 0;
				$("#jquery_jplayer_1").jPlayer({
			        ready: function () {
			          $(this).jPlayer("setMedia", {
			           m4v: data.video
			          }).jPlayer("play");
			        },
			       
			        swfPath: "http://2wgmbh.webseiten.cc/js/Jplayer.swf",
			        solution:"flash, html",
			        supplied: "m4v",
			        backgroundColor:"#ffffff",
			        size: {
						width: data.width,
						height: data.height,
						cssClass: "jp-video-270p"
					},
					loop: true
			      });
			     //change width
				//$(".jp-video-270p").css({width: data.width});
				$("#jquery_jplayer_1").mouseenter(
					function(){
						$('.playPause').fadeIn(800);
					}).mouseout(function(){
						$('.playPause').fadeOut(800);
						});
				
				$('.playPause').click(function(){
					clicked++;
					if((clicked*1) %2== 0){
						$("#jquery_jplayer_1").jPlayer("play");
						$('.playPause').removeClass('playerPlay');
						$('.playPause').addClass('playerPause');
					}else{
						$("#jquery_jplayer_1").jPlayer("pause");
						$('.playPause').removeClass('playerPause');
						$('.playPause').addClass('playerPlay');
					}
					
				});
			}else{
		//Bilder	
		//add HTML
			var htmlBilder = '<div id="bildergalerie">';	
			$.each(data, function(entryIndex, entry) {
				htmlBilder += '<div class="bild">';
				if(entry['link']){
					htmlBilder += '<a href="'+entry['link']+'">';
					}
				htmlBilder += '<img src="'+ entry['path'] + entry['image'] +'" />';
				if(entry['link']){
					htmlBilder += '</a>';
					}
				htmlBilder += '</div>';
			});
			htmlBilder += '</div>';	
			$header.append(htmlBilder);
			
			var $container = $('#bildergalerie');					 			
			//after everything has finished loading
			$container.ajaxStop(function(){
				//more than one images
				if($("#bildergalerie > div").size() > 1){
					//bring elements into right order			
					for(var i = $container.children().length, y = 0; i > 0; i--, y++) { 					
						$container.children().eq(y).css('zIndex', i + 99999);
					}									
					//fade images in and out
					setInterval(function() {
						$container.children(':first').animate({'opacity' : 0}, 2000, function() {	
							$container
							   .children(':first')
							   .css('opacity', 1) // Return opacity back to 1 for next time.
							   .css('zIndex', $container.children(':last').css('zIndex') - 1) // Reduces zIndex by 1 so that it's no longer on top.					
							   .appendTo($container); // move it to the end of the line.
						})
					}, 8000);
				}
				$container.delay(1000).fadeIn(2000);
			});	
		}		
	});	
				
	
/*#######---------------Textfading Startseite -------###########*/
/*#################################################################*/	

$('.tx-startpage2w-pi1 .mehrlink').click(function(){
	var $this = $(this);
	$this
		.hide() //hide mehrlink
		.next('.text2')
		.show()
		.parent()
		.css('color' , '#686868') //change color of parent
		.parent() 
		.siblings() //find siblings of parents parent
		.find('.text') 
		.css('color' , '#999999') //change color of text
		.find('.mehrlink') //show mehrlink
		.show()
		.next('.text2')
		.hide()
		;
	
	return false;
	});

$('.tx-topofarticles2w-pi1 .mehrlink').click(function(){
	var $this = $(this);
	$this
		.hide() //hide mehrlink
		.next('.text2')
		.show()
		.parent()
		.css('color' , '#686868') //change color of parent
		.parent() 
		.siblings() //find siblings of parents parent
		.find('.text') 
		.css('color' , '#999999') //change color of text
		.find('.mehrlink') //show mehrlink
		.show()
		.next('.text2')
		.hide()
		;
	
	return false;
	});
		
		
});
