$(function(){
	$("#menu a").characterJustify();
	
	
	
	// Mouseover Effect für Bilder mit Hyperlinks
	$('a img').not('#logo-small a img, #sn-link a img').mouseover(function() {
		$(this).stop(true, true).fadeTo(350, 0.6); 
	}).mouseout(function(){
		$(this).stop(true, true).fadeTo(100, 1); 
	});
	
	/*
	$("#sn-link a").mouseover(function() {
		$('img', this).stop().animate({
			//bottom: '3px',
			height: '15px'
		});
	}).mouseout(function(){
		$('img', this).stop().animate({
			//bottom: '0px',
			height: '20px'
		});
	});
	*/
	
	if($.browser.version < 9 && $.browser.msie){
	}else{
		$("#logo-big").hide();
		$("#logo-big").fadeTo(1500,1);
	}
	
	$("#space, #socialnetwork, #navi").hide();
	$("#navi").fadeTo(2500,1);
	$("#space, #socialnetwork").fadeTo(2000,0.8);
	
	$('#menu a').click(function() {
		$("#logo-award").css('visibility', 'hidden');
		$("#logo-big-faded").css('visibility', 'visible');
		$('#menu a').removeClass('active');
		$(this).addClass('active');
		
		if($.browser.version < 9 && $.browser.msie){
			$("#logo-big").css('visibility', 'hidden');
		}else{
			$("#logo-big").hide();
			$("#logo-big").fadeTo(350,0);
		}
		
		if($(this).attr('id') == 'contact'){
			$("#logo-big").css('visibility', 'visible');
			if($.browser.version < 9 && $.browser.msie){
				$("#logo-big").css('visibility', 'visible');
			}else{
				$("#logo-big").hide();
				$("#logo-big").fadeTo(350,1);
			}
		}
		$("#content").show();
		data = $("." + $(this).attr('id')).html();
		if ($("#content-box").is(":hidden")) {
			$('#content-box:hidden').slideDown(350, function() {
				$("#content").empty().html(data);
				startAnimation();
				startFunction();
			});
		}else{
			$("#content").html(data);
			startAnimation();
			startFunction();
		}
		return false;
	});
	
	
	$('img.body-bg').maxImage({
		isBackground: true,
		resizeMsg: {show: false, location: 'after', message: 'Hands Solo'},
		overflow:('hidden'),
		verticalOffset: 0,
		horizontalAlign: 'top',
		verticalAlign: 'left',
		maxFollows:('both')
	});
		
});

function startAnimation(){
	
	/* AGENDA *****************************************************************************************/
	if($('#content .agenda-item').length > 0){		
		$("#content .agenda-item").not("#content .agenda-item2").css('right', '-300px');
		//$("#content .agenda-item").hide();
		var dur = 600;
		$("#content .agenda-item").not("#content .agenda-item2").each(function() {
			dur = dur - 100;
			$(this).animate( { right: "0px" }, { queue: true, duration: dur });
			//$(this).slideDown(1000);
		});
		
		
		
		
		
		$("#content .agenda-item2").css('right', '-1000px');
		//$("#content .agenda-item").hide();
		var dur = 600;
		$("#content .agenda-item2").each(function() {
			dur = dur - 100;
			$(this).animate( { right: "0px" }, { queue: true, duration: dur });
			//$(this).slideDown(1000);
		});
	}
	/* AGENDA *****************************************************************************************/
	
	
	/* Media *****************************************************************************************/
	
	if($('#content .media-item').length > 0){
		$("#content a.media-item").css('top', '-200px');
		var dur = 600;
		$("#content a.media-item").each(function() {
			dur = dur - 100;
			$(this).animate( { top: "0px" }, { queue: true, duration: dur });
		});
        $("#content .media-item-special-link").characterJustify();
        $("#content .media-item-special-link li a").characterJustify();
	}

	/* Media *****************************************************************************************/
	
	
	/* Contact *****************************************************************************************/
	
	if($('#content .contact-item').length > 0){
		$("#content .contact-item").hide();
		$("#content .contact-item").each(function() {
			$(this).slideDown(600);
        	$("#content .contact-item p").characterJustify();
		});
	}

	/* Contact *****************************************************************************************/
}

function startFunction(){
	if($('#content #scrollbar1').length > 0){
		$('#scrollbar1').tinyscrollbar({ sizethumb: 60 });
	}
	
	
	
	// Mouseover Effect für Bilder mit Hyperlinks
	$('a img').not('#logo-small a img').mouseover(function() {
		$(this).stop(true, true).fadeTo(350, 0.6); 
	}).mouseout(function(){
		$(this).stop(true, true).fadeTo(100, 1); 
	});
	
	
	
	if($('#content .agenda-item').length > 0){
		$('#content .agenda-item ').not('#content .no-tipsy, #content .agenda-item2').tipsy({
			delayIn: 0,      // delay before showing tooltip (ms)
			delayOut: 0,     // delay before hiding tooltip (ms)
			fade: false,     // fade tooltips in/out?
			fallback: 'Hands Solo',    // fallback text to use when no tooltip text
			gravity: 'w',    // gravity
			html: true,     // is tooltip content HTML?
			live: false,     // use live event support?
			offset: 0,       // pixel offset of tooltip from element
			opacity: 0.8,    // opacity of tooltip
			title: function(){
					return $('.info-tooltip', this).html();
				},  // attribute/callback containing tooltip text
			trigger: 'hover' // how tooltip is triggered - hover | focus | manual
		});
		
		$('#content .agenda-item2 ').not('#content .no-tipsy').tipsy({
			delayIn: 0,      // delay before showing tooltip (ms)
			delayOut: 0,     // delay before hiding tooltip (ms)
			fade: false,     // fade tooltips in/out?
			fallback: 'Hands Solo',    // fallback text to use when no tooltip text
			gravity: 'e',    // gravity
			html: true,     // is tooltip content HTML?
			live: false,     // use live event support?
			offset: 0,       // pixel offset of tooltip from element
			opacity: 0.8,    // opacity of tooltip
			title: function(){
					return $('.info-tooltip', this).html();
				},  // attribute/callback containing tooltip text
			trigger: 'hover' // how tooltip is triggered - hover | focus | manual
		});
		/*
		$('#content .agenda-item .img a').imgPreview({
			containerID: 'imgPreviewWithStyles',
			//srcAttr: 'rel',
			// Change srcAttr to rel:
			//srcAttr: 'rel',
			imgCSS: {
				// Limit preview size:
				height: 200
			},
			// When container is shown:
			onShow: function(link){
				//$('<span>' + link.href + '</span>').appendTo(this);
			},
			// When container hides: 
			onHide: function(link){
				//$('span', this).remove();
			}
		});
		*/
	}
	
	if($('#content .fb').length > 0){
		$("#content a.fb").fancybox({
			'titlePosition'		: 'inside',
			'overlayColor'		: '#000',
			'overlayOpacity'	: 0.6,
			'onStart'		: function() {
        		$("#content .media-soundcloud").css('visibility', 'hidden');
			},
			'onClosed'		: function() {
        		$("#content .media-soundcloud").css('visibility', 'visible');
			}
		});
		
	}
	
	
	
	$('.media-video').click(function(){
		alert(564654);
	});
	$('.media-video').mouseenter(function(){
		alert(564654);
		$('.media-video').click(function(){
		alert(564654);
	});
	});
	
	$(".media-video-item").fancybox({
		'width'				: '75%',
		'height'			: '75%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	/* Projekt Detail Video *************************************************************/
	if($('.projekt-detail-video').length > 0){
		var videoId 	= '';
		var videoUrl 	= '';
		$('.projekt-detail-video video').each(function() {
			videoId 	= $(this).attr('tabindex');
			videoUrl 	= $(this).attr('src');
			fbVideo('a.fb-video' + videoId, 'projekt-detail-video' + videoId, 'projekt-detail-video-item' + videoId, videoUrl);
		})
	}
	/* Projekt Detail Video *************************************************************/
}


function fbVideo(clickElement, vElementOuter, vElement, vFile){
	playVideo(vElement, vFile);
	
	$(clickElement).fancybox({
		'titlePosition'		: 'inside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.6, 
		'onClosed'		: function() {
			$('#'+vElementOuter).html('<video id="'+vElement+'"></video>');
			playVideo(vElement, vFile);
		}
	});
}
function playVideo(element, file){
	if($("#"+element).length > 0){
		jwplayer(element).setup({
			'flashplayer': '_js/mediaplayer/player.swf',
			'file': file,
			'autostart': 'true',
			'width': 720,
			'height': 393
		});
	}
}
