/*
* HDKF
* standard.js
*
* Author: Holger M. Stangl
* Date: May 2011
*/
function openPopUp( thisUrl, width, height ) {
	
	$.fancybox({
		'titleShow' : false,
		'zoomOpacity' : true,
		'overlayShow' : true,
		//'overlayColor' : '#9dbd03',
		'overlayColor' : '#333',
		'overlayOpacity' : 0.7,
		'padding' : 0,
		'zoomSpeedIn' : 500,
		'zoomSpeedOut' : 500,
		'transitionIn' : 'fade',
		'transitionOut'	: 'fade',
		'type' : 'iframe',
		'width' : width,
		'height' : height,
		'href' : thisUrl
		}
	);
}



function CreateBookmarkLink() {
	
	var ua=navigator.userAgent.toLowerCase();
					
    title = document.title;
    url = location.href;

    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if ( window.external ) { // IE Favorite
        window.external.AddFavorite( url, title); 
    } else if ( ua.indexOf('webkit')!=-1 ) {
    	var message = 'Bitte dr�cken Sie die Taste Command/Cmd + D um f�r diese Seite ein Lesezeichen zu erstellen.'
    	alert(message);
	}
}


$(document).ready(function(){



	// JS enable
	$("html").removeClass("no-js").addClass("js");


	// ScrollTo Top
	$('a.top').click(function(){
		$.scrollTo( 'body', 800 );
		return false;
	});

	var slideShowBox=null;


	// Self-maximize Textaraes
	$('textarea').elastic();



	// Search Field Hover
	$('#search input').focus( 
		function() { if ( $(this).attr('value') === 'Suchbegriff' ) { $(this).attr('value',''); } }
	);
	
	$('#search input').blur(
		function() { if ( $(this).attr('value') === '' ) { $(this).attr('value','Suchbegriff'); } }
	);
	
	
	// Search Field Hover
	$('#networkSearch input').focus( 
		function() { if ( $(this).attr('value') === 'PLZ' ) { $(this).attr('value',''); } }
	);
	
	$('#networkSearch input').blur(
		function() { if ( $(this).attr('value') === '' ) { $(this).attr('value','PLZ'); } }
	);





	$('.radioItem label').click(
		function(){
			var $radioGroup = $(this).prev().attr('name');
			$('input[name="'+$radioGroup+'"]').next().removeClass('checked').addClass('unchecked');
			$(this).removeClass('unchecked').addClass('checked');
		}
	);
	$('.radioItem input[checked]:radio').parent().find('label').addClass('checked');
	
	
	
	$('.checkboxItem label').click(
		function(){
			if ( $(this).hasClass('checked') ){
				$(this).removeClass('checked').addClass('unchecked');
			} else {
				$(this).removeClass('unchecked').addClass('checked');
			}
		}
	);
	$('.checkboxItem input[checked]:checkbox').parent().find('label').addClass('checked');

	
	
	
	$('.close').click(function(){	
	
		$(this).parent().removeClass('teamBoxXL').addClass('teamBoxL');
	
	});
	
	$('.teamBoxL .mediaBox').click(function(){
	
		$('.teamBoxXL').removeClass('teamBoxXL').addClass('teamBoxL');
		$(this).parent().removeClass('teamBoxL').addClass('teamBoxXL');
	
	});
	
	$('.teamBoxL h2').click(function(){
	
		$('.teamBoxXL').removeClass('teamBoxXL').addClass('teamBoxL');
		$(this).parent().parent().removeClass('teamBoxL').addClass('teamBoxXL');
	
	});
	
	
	
	
	// SelectBox
	$('.selectBox').hoverIntent({
			sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			interval: 100, // number = milliseconds for onMouseOver polling interval    
			over: nothing, // function = onMouseOver callback (REQUIRED)    
			timeout: 300, // number = milliseconds delay before onMouseOut    
			out: closeQuickBox // function = onMouseOut callback (REQUIRED)    
		}).click(function(){
			$(this).toggleClass('selectBoxActive');
		}).find('.option span').click( function() {
			var $thisClicked = $(this);
			var $thisSelectBox = $(this).parent().parent().parent();
			$thisSelectBox.find('.selectedBox span').text( $thisClicked.text() );
			$thisSelectBox.find('input').attr('value', $(this).attr('class') );
		});
	function closeQuickBox(){
		$(this).removeClass('selectBoxActive');
	}
	function nothing(){ return true;}
	
	
	
	// Slideshow
	$('.containerSlideshowTeaser .slideshowBox').cycle({
        fx: 'fade',
        pause: false, // wichtig
        speed: 1500,
        timeout: 8000,
        pager: '.navigationSlider',
        requeueOnImageNotLoaded: true,
        pagerAnchorBuilder: function(i, el){
            var h1 = $('img', el).attr('alt');
            var $element = $('<li><a href="#" title="'+h1+'">'+(i+1)+'<\/a><\/li>');
            return $element;
        }
        
    });
    
    
    
    $('.containerSlideshowHome .slideshowBox').cycle({
        fx: 'fade',
        pause: true,
        speed: 1500,
        timeout: 8000,
        pager: '.navigationSlider',
        requeueOnImageNotLoaded: true,
        pagerAnchorBuilder: function(i, el){
            var h1 = $('h5', el).text();
            var $element = $('<td><a href="#" title="'+h1+'">'+h1+'<\/a><\/td>');
            return $element;
        }
    });
	
	
	
	
	// initialisiere die player mit <video> tag

	$('.containerSlideshowTeaser video').each(function(){
		jwplayer(this).setup({
			flashplayer: "http://www.haus-der-kleinen-forscher.de/fileadmin/templates/js/jwplayer/player.swf",
			file: $(this).attr('src'),
			image: $(this).attr('poster'),
			height: $(this).attr('height'),
			width: $(this).attr('width'),
			events: {
			 onPlay: function(event) {
				$('.containerSlideshowTeaser .slideshowBox').cycle('pause',true);
			 },
			 onComplete: function(event) {
				$('.containerSlideshowTeaser .slideshowBox').cycle('resume',true);
			 }
			}
			//,skin: "/fileadmin/templates/js/jwplayer/skins/ijf/skin.zip"
			//,wmode: "transparent"
		});
		
	});
	
	
	
	$('.containerDetail video').each(function(){
		jwplayer(this).setup({
			flashplayer: "http://www.haus-der-kleinen-forscher.de/fileadmin/templates/js/jwplayer/player.swf",
			file: $(this).attr('src'),
			image: $(this).attr('poster'),
			height: $(this).attr('height'),
			width: $(this).attr('width')
			//,skin: "/fileadmin/templates/js/jwplayer/skins/ijf/skin.zip"
			//,wmode: "transparent"
		});
		
	});
	
	
	
	$('.containerRelated').each(function(){				
		
		if ( $(".teaserCol", this).length > 1 ) {
			
			var scrollable = $(".selectionBox", this).scrollable({ 
				easing: 'easeOutQuart',
				speed: 900,
				items:'.wrap',
				prev:'.prev',
				next:'.next'/*,
				size: 1,
				loop: true
				circular: true*/
			});
			var scrollableAPI = $(".thumbImages", this).scrollable({api: true});
		
		} else {
		
			$(".prev", this).hide();
			$(".next", this).hide();
			
		}
		
	});
	
	
	$('.containerRelated2').each(function(){				
		
		if ( $(".teaserBox", this).length > 1 ) {
			
			var scrollable = $(".selectionBox", this).scrollable({ 
				//easing: 'easeOutQuart',
				//speed: 900,
				items:'.wrap',
				prev:'.prev',
				next:'.next',
				size: 2,
				loop: true
			});
			var scrollableAPI = $(".thumbImages", this).scrollable({api: true});
		
		} else {
		
			$(".prev", this).hide();
			$(".next", this).hide();
			
		}
		
	});
	
	


	$(".containerAccordeon").tabs(".containerAccordeon .textBox", {
		tabs: 'h3',
		effect: 'slide'
	});
	
	

	$('.netEventBox h4')
	.bind(
		"accordeonDown",
		function(){
			$(this).parent().parent().parent().find('h4').removeClass('open');
			$(this).parent().parent().parent().find('.boxInner').slideUp(50);
			$(this).addClass('open').next().slideDown(200);
		}
	)
	.bind(
		"accordeonUp",
		function(){
			$(this).removeClass('open').next().slideUp(50);
		}
	)
	.bind(
		"accordeonToggle",
		function(){
			if( $(this).hasClass('open') ){
				$(this).trigger("accordeonUp");
			} else {
				$(this).trigger("accordeonDown");
			}
		})
	.click(
		function(){
			/*
			if( $('#map') ){
				console.log("Hallo");
				var id = parseInt($(this).attr('id').replace('link',''));
				google.maps.event.trigger(markers[id], 'openBox');
			}
			*/ 
			$(this).trigger("accordeonToggle");
		}
	);
	


	$('.expAdditionalBox h2')
	.bind(
		"accordeonDown",
		function(){
			$(this).parent().parent().find('h2').removeClass('open');
			$(this).parent().parent().find('.contentBox').slideUp(50);
			$(this).addClass('open').next().slideDown(200);
		}
	)
	.bind(
		"accordeonUp",
		function(){
			$(this).removeClass('open').next().slideUp(50);
		}
	)
	.click(
		function(){
			if( $(this).hasClass('open') ){
				$(this).trigger("accordeonUp");
			} else {
				$(this).trigger("accordeonDown");
			}
		}
	);
	
	
	
	$('#comment-write').click(
		function(){
			$('#comment-form').slideDown(200);
			$.scrollTo( $(this).parent(), 600 );
			$(this).hide();
		}
	);
	
	$('#comment-reset').click(
		function(){
			$('#comment-form').slideUp(200);
			$.scrollTo( $('#comment-form').parent(), 600 );
			$('#comment-write').show();
		}
	);

	$('#comment-link').click(
		function(){
			$('#comment-form').slideUp(200);
			$.scrollTo( $('#comment-form').parent(), 600 );
			$('#comment-write').show();
		}
	);




	// Main Navigation
	$('#navigation li.level1').hoverIntent({
		sensitivity: 3,
		interval: 30,
		over: function(){
			$(this).addClass('hover');
		},
		timeout: 150,
		out: function(){
			$(this).removeClass('hover');
		}
	});




	// Login FlyOut
	$('#login').hoverIntent({
		sensitivity: 3,
		interval: 30,
		over: function(){
			$(this).addClass('hover');
			//$(this).next().show();
		},
		timeout: 150,
		out: function(){
			$(this).removeClass('hover');
			//$(this).next().hide();
		}
	});

	
	
	$("a.modularbox").click( function(){
		openPopUp( $(this).attr('href'), 800, 500 );
		return false;
	});



	// Body Height
	$('#content .wrapper').eq(0).css('min-height', $('body').height()-650-217-142 );
	
	

});
