
///////////////////////////////////////////////////////////////////
//
//	ophelis 2011 custom js functions
//	Design and Code by BASICS09 (www.basics09.de)
//
///////////////////////////////////////////////////////////////////
ophelis();
function ophelis(){
	var scrollBottomLoop;
	var headerDefaultHeight;
	var slideshowLoop;
	var slidesAmount = 0;
	var slideID = -1;
	var lastSearchValue = "";
	var isTouchScreen = false;
	var myPopupWindow = '';
	var searchRequest = undefined;
	var currentBigImageLoaded = false;
	var imageLoadingLoop;
	
	var ua = navigator.userAgent;
	
	$(document).ready(initScript);
	function initScript(){
		
		if(ua.indexOf('iPhone') != -1 || ua.indexOf('iPad') != -1){
			isTouchScreen = true;
		}
		
		header();
		footer();
		downloads();
		loginForm();
		
		if($('.linkGridItem').length > 0){
			gridLayout();
			gridEffects();
			gridFitting();
		}
		
		imageLinks();
		
		preventDefaults();
		slideshow();
		searchInput();
		socialLinks();
		tooltips();
		preloadImages();
	}
	function preloadImages() {
		var imgs = ['arrow-prev.gif', 'arrow-next.gif', 'slides-gradient-braun.png', 'breadcrumb-arrow-small.jpg', 'search_magnifier.gif', 'corner-f7f7f4.png', 'ophelis-logo.jpg', 'slides-gradient-braun.png', 'header-bottom.png'];

		function iterate (i) {
			if (imgs.length > i) {
				var img = new Image();
				img.src = stylesheetDirectory + '/images/' + imgs[i];
				//console.log("loading: " + img.src);
				$(img).one('load', function () {
					iterate(i + 1);
				});
			};
		};
		iterate(0);
	};
	function imageLinks(){
		$('a.gridItem').click(function(e){
			e.preventDefault();
			window.location.href = $(this).attr('href');
		})
	}
	function disableLinks(){
		$('a').attr('href', '#');
		$('a').click(function(e){
			e.preventDefault();
		})
	}
	function preventDefaults(){
		$('.gallery a:not(.use-this-link)').attr('href', '#');
		$('#access a').removeAttr('title');
		$('img').removeAttr('title');
		$('a, img').mouseenter(function(e){
			e.preventDefault();
		})
		$('a, img').mousedown(function(e){
			e.preventDefault();
		})
	}
	///////////////////////////////////////////////////////////////////////////
	// Dynamic Fitting
	//
	function fit(){
		
	}
	///////////////////////////////////////////////////////////////////////////
	// Slideshow functions 
	//
	function slideshow(){
		
		if($('#slideshow .gallery .gallery-item').length > 1){
			lightbox();
			if(adminView){
				
			} else {
				
			}
			
			$('.slideshowSingle .gallery-icon img').one('load', function(e){
				var left = $(this).parents('a').width() / 2 - $(this).width() / 2;
				$(this).css('left', left + 'px');
				if($(this).width() > 10 && $(this).width() < 500){
					$(this).parents('a').css('border-bottom', '1px solid #EFEFE7');
				} else if($(this).width() > 640){
					$(this).width(642);
				}
			}).each(function(){
				if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {
					$(this).trigger('load');
				}
			});
			
			
			$('.slideshowNav').css('display', 'block');
			$('.slideshowFooter').css('display', 'block');
			$('#slideshow .gallery').fadeIn(500);
			slidesAmount = $('#slideshow .gallery-item').length;
			var allSlidesWidth = 0;
			$('#slideshow .gallery-item').each(function(index){
				allSlidesWidth += $(this).width();
				$(this).data('id', index);
			});
			$('#slideshow .gallery').css('width', (allSlidesWidth) + 'px');
			
			
			// Bei Klick auf das Bild das nächste Sliden
			$('#slideshow .gallery-icon a:not(.use-this-link)').click(function(e){
				e.preventDefault();
				nextSlide();
				stopSlideshowLoop();
			});
			$('#nextSlide').click(function(e){
				e.preventDefault();
				nextSlide();
				stopSlideshowLoop();
			});
			$('#prevSlide').click(function(e){
				e.preventDefault();
				prevSlide();
				stopSlideshowLoop();
			});
			
			// Die Punkte generieren
			$('#slideshow .gallery .gallery-item').each(function(index){
				$('#slideshow .slideIndex').append('<a href="#" class="dot dot'+index+'"></a>');
			});
			$('#slideshow .slideIndex').width($('#slideshow .slideIndex .dot:first').width() * slidesAmount);
			$('#slideshow .slideIndex .dot').each(function(index){
				$(this).data('id', index);
			})
			$('#slideshow .slideIndex .dot').click(function(e){
				e.preventDefault();
				slideID = $(this).data('id');
				moveToSlideByID(slideID);
				stopSlideshowLoop();
			});
			//
			nextSlide();
			slideshowLoop = setInterval(nextSlide, 7000);
		}
	}
	function nextSlide(){
		slideID ++;
		slideID >= slidesAmount ? slideID = 0 : 0;
		moveToSlideByID(slideID);
	}
	function prevSlide(){
		slideID --;
		slideID < 0 ? slideID = slidesAmount-1 : 0;
		moveToSlideByID(slideID);
	}
	function moveToSlideByID(_id){
		if(_id != $('.currentItem').data('id')){
			if(_id > $('.currentItem').data('id')){
				outPos = -500;
				inPos = 500;
			} else if(_id < $('.currentItem').data('id')){
				outPos = 500;
				inPos = -500;
			} else {
				outPos = 30;
				inPos = 30;
			}
			
			$('#slideshow .gallery-item').removeClass('currentItem').css('visibility', 'visible');
			$('#slideshow .gallery-item-' + _id ).addClass('currentItem');
			
			//IE8 Pixel Bugfix
			var nX = $('.currentItem').position().left;
            nX = ((nX % 2) == 0) ?  nX : nX+1;
             
			$('#slideshow .gallery').stop(true).animate({
				left: -nX + 'px'
			}, 600, 'easeInOutQuint', function(){
				$('#slideshow .gallery-item:not(.currentItem)').css('visibility', 'hidden');
			});

			adjustDots();

			var outPos;
			var inPos;

			$('.slideshowFooter #image-download-link').attr('href', $('.currentItem .attachment-url').attr('id'));


			$('.slideshowFooterText').text('');
			$('.slideshowFooterText').text($('.currentItem').find('.description').text());

			$('#slideshowCaptionContent').animate({
				left: outPos + 'px'
			}, 300, 'easeInQuint', function(){
				$(this).find('h2').text($('.currentItem').find('.captionHead').text());
				$(this).find('p:first').html($('.currentItem').find('.description').text());
				$(this).css('visibility', 'visible');
				$(this).css('left', inPos+'px');
				$(this).animate({
					left: '30px'
				}, 300, 'easeOutQuint');
			});
			
			var galleryLink = $(".gallery .currentItem a.use-this-link");
			$(".use-this-link").mouseenter(function(){
				//$("#slideshowCaptionContent h2").css("text-decoration", "underline");
			}).mouseleave(function(){
				//$("#slideshowCaptionContent h2").css("text-decoration", "none");
			})
			if(galleryLink.length > 0){
				$('#slideshowCaptionContent').css({
					"cursor": "pointer"
				}).click(function(){
					window.location.href = galleryLink.attr("href");
				}).mouseenter(function(){
					//$(this).find("h2").css("text-decoration", "underline");
				}).mouseleave(function(){
					//$(this).find("h2").css("text-decoration", "none");
				})
			} else {
				$('#slideshowCaptionContent').css("cursor","default").unbind();
			}
		}
	}
	function adjustDots(){
		$('#slideshow .slideIndex .dot').removeClass('currentDot');
		$('#slideshow .slideIndex .dot').eq(slideID).addClass('currentDot');
	}
	function stopSlideshowLoop(){
		clearInterval(slideshowLoop);
	}
	///////////////////////////////////////////////////////////////////////////
	// Lightbox functions 
	//
	function lightbox(){
		$('body').prepend("<div id='lightbox'><div id='bg'></div><a id='lightboxClose' href='#'>x</a><a id='prevImg' class='navLink' href='#'><span class='arrow'>prev</span></a><a id='nextImg' class='navLink' href='#'><span class='arrow'>next</span></a><div id='lightboxContent'><div id='imgHolder'></div><p id='lightboxCaption'>Title</p></div></div>");
		$('#lightbox, #lightboxCaption').hide();
		$('#open-lightbox-link').click(function(e){
			e.preventDefault();
			openLightbox();
		});
		$('#lightbox #lightboxClose, #lightbox #bg').click(function(e){
			e.preventDefault();
			closeLightbox();
		});
		$('#lightbox #prevImg').click(function(e){
			e.preventDefault();
			if(currentBigImageLoaded){
				prevSlide();
				loadCurrentBigImage();
			}
		});
		$('#lightbox #nextImg, #lightbox #imgHolder').click(function(e){
			e.preventDefault();
			if(currentBigImageLoaded){
				nextSlide();
				loadCurrentBigImage();
			}
		});
	}
	function openLightbox(){
		$(window).resize(function(){
			fitLightbox();
		});
		$(document).scroll(function(){
			fitLightbox();
		});
		$('#lightboxCaption').show().css('opacity', '0');
		$('#lightbox').show().css('opacity', '1');
		
		$('#lightbox #bg').css('opacity', '0');
		$('#lightbox #bg').animate({
			opacity: .8
		}, 200, function(){
			loadCurrentBigImage();
		});
		fitLightbox();
		$('body').keydown(function(e){
			if(e.keyCode == 39){
				if(currentBigImageLoaded){
					nextSlide();
					loadCurrentBigImage();
				}
			} else if(e.keyCode == 37){
				if(currentBigImageLoaded){
					prevSlide();
					loadCurrentBigImage();
				}
			} else if(e.keyCode == 27){
				closeLightbox();
			}
		})
	}
	function closeLightbox(){
		$('#lightbox').animate({
			opacity: 0
		}, 200, function(){
			$('#lightbox, #lightboxCaption').hide();
			$('#lightbox img').remove();
		});
		
	}
	function removeLastBigImages(){
		var lastImages = $('#lightbox img');
		lastImages.animate({
			opacity: 0
		}, 200, function(){
			lastImages.remove();
		})
	}
	function loadCurrentBigImage(){
		removeLastBigImages();
		stopSlideshowLoop();
		$('#lightbox img').removeClass('currentBigImage');
		
		currentBigImageLoaded = false;
		var img = new Image();
		$(img).attr({
			alt: '',
			src: $('#slideshow .currentItem .attachment-url').attr('id')
		}).one('load', function(){
			
			$('#lightbox #imgHolder').append(this);
			
			var realWidth = this.width;
			var realHeight = this.height;
			
			$(this).data('width', realWidth);
			$(this).data('height', realHeight);
			
			$(this).addClass('currentBigImage');
			
			$(this).css('opacity', '0');
			
			imageLoadingLoop = setInterval(checkImageDimensions, 1);
			preventDefaults();
			
		}).each(function(){
			if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {
				$(this).trigger('load');
			}
		});
	}
	function checkImageDimensions(){
		if($('.currentBigImage').width() > 10 && $('.currentBigImage').height() > 10){
			showBigImage();
			clearInterval(imageLoadingLoop);
		}
	}
	function showBigImage(){
		$('#lightbox #lightboxCaption').text($('h1.page-title').text() + ' ' + ($('.currentDot').data('id')+1) + '/' + $('.slideIndex .dot').length);
		$('#lightboxCaption').css('opacity', '1');
		fitLightbox();
		currentBigImageLoaded = true;
		$('.currentBigImage, #lightbox #lightboxContent').animate({
			opacity: 1
		}, 200);
		
	}
	function fitLightbox(){
		$('#lightbox').css('top', $(document).scrollTop() + 'px');
		if($('#lightbox img').length > 0){
			fitCurrentImage();
		} else {
			$('#lightbox #lightboxContent').css('left', ($('#lightbox').width() / 2 - $('#lightbox #lightboxContent').width() / 2) + 'px');
			$('#lightbox #lightboxContent').css('top', ($('#lightbox').height() / 2 - $('#lightbox #lightboxContent').height() / 2) + 'px');
		}
		
	}
	function fitCurrentImage(){
		var image = $('.currentBigImage');
		var container = $(window);
		
		var crop = false;
		var margin = 80;
		var containerWidth = container.width() - margin * 3;
		var containerHeight = container.height() - margin;
		containerRatio = containerWidth / containerHeight;
		imageRatio = image.data('width') / image.data('height');
		
		var firstRatio;
		var secondRatio;

		if(crop == "false"){
			firstRatio = containerRatio;
			secondRatio = imageRatio;
		} else {
			firstRatio = imageRatio;
			secondRatio = containerRatio;
		}
		//
		if (firstRatio > secondRatio) {
			image.width(containerWidth);
			image.height('auto');
		} else {
			image.height(containerHeight);
			image.width('auto');
		}
		
		if(image.width() > image.data('width')){
			image.width(image.data('width'));
			image.height(image.data('height'));
		}
		
		$('#lightbox #imgHolder').width($('.currentBigImage').width());
		$('#lightbox #imgHolder').height($('.currentBigImage').height());
		$('#lightbox #lightboxContent').css('left', (container.width() / 2 - $('#lightbox #lightboxContent').width() / 2) + 'px');
		$('#lightbox #lightboxContent').css('top', (container.height() / 2 - $('#lightbox #lightboxContent').height() / 2) + 'px');
	}
	///////////////////////////////////////////////////////////////////////////
	// Grid functions 
	//

	function gridEffects(){
		var speed1 = 100;
		var speed2 = 200;
		
		/*$('.linkGridItem:not(img)').click(function(e){
			var targetName = e.currentTarget.localName;
			if(targetName == undefined || targetName != 'a' && targetName != 'img'){
				e.preventDefault();
				window.location.href = $(this).find('a:first').attr('href');
			}
		})*/
		
		$('.linkGridItem').mouseenter(function(e){
			e.preventDefault();
			showGridItemText($(this));
		});
		$('.linkGridItem').mousemove(function(e){
			$(this).unbind('mousemove');
			showGridItemText($(this));
		});
		function showGridItemText(_item){
			var theExcerpt = _item.find('.gridItemExcerpt');
			theExcerpt.stop(true).animate({
				height: theExcerpt.find('p:first').height()
			}, speed1);
		}
		$('.linkGridItem').mouseleave(function(e){
			e.preventDefault();
			
			/*$(this).find('img').stop(true).animate({
				opacity: .8
			}, speed2);*/
			
			var theContent = $(this).find('.gridItemExcerpt');
			theContent.stop(true).animate({
				height: 0
			}, speed2);
		});

		$('.linkGridItem .gridItemExcerpt p a').each(function(index){
			var maxChars = 520;
			var t = $(this).text();
			if(t.length > maxChars){
				t = t.substr(0, maxChars);
				t = t.substr(0, t.lastIndexOf(' '));
				$(this).text(t + ' ...');
			}
		});
	}
	function gridLayout(){
		/*var highestColumnID = getHighestColumnID();
		var lastItemInHighestColumn = $('.gridColumn').eq(highestColumnID).find('.gridItem').eq(-1);
		var secondLastItemInHighestColumn = $('.gridColumn').eq(highestColumnID).find('.gridItem').eq(-2);
		//secondLastItemInHighestColumn.css('border', '1px solid green');
		$('.gridColumn').each(function(index){
			if(index != highestColumnID){
				if(getBottomOf($(this).find('.linkGridItem:last')) < getBottomOf(secondLastItemInHighestColumn)){
					//$(this).find('.gridItem:last').css('border', '1px solid red');
					$(this).append(lastItemInHighestColumn);
				};
			}
		});*/
	}
	function getBottomOf(element){
		return element.position().top + element.height();
	}
	function getHighestColumnID(){
		var highestColumnID = 0;
		$('.gridColumn').each(function(index){
			if($(this).height() > $('.gridColumn').eq(highestColumnID).height()){
				highestColumnID = index;
			};
		});
		return highestColumnID;
	}
	function gridFitting(){
		$('.linkGridItem img').one('load', function(e){
			var left = $(this).parents('.imgHolder').width() / 2 - $(this).width() / 2;
			if($(this).width() > 0 && $(this).width() < 100){
				$(this).css('margin-left', left + 'px');
			}
		}).each(function(){
			if(this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {
				$(this).trigger('load');
			}
		});
	}
	///////////////////////////////////////////////////////////////////////////
	// Header functions 
	//
	function header(){
		$('#contentOverlay').css('opacity', '0');
		headerDefaultHeight = $('#masthead').height();
		$('.children').fadeOut(1);
		$('.children').css('visibility', 'visible');
		$('#masthead ul li a').click(function(e){
			if($(this).siblings('.children').length > 0 && isTouchScreen == true){
				e.preventDefault();
				showSubMenu($(this).parents('li:first'));
			};
		});
		$('#masthead ul li').mouseenter(function(e){
			e.preventDefault();
			if($(this).parents('.children').length == 0){
				showSubMenu($(this));
			};
		});
		function showSubMenu(_li){
			var targetHeight = 25 + _li.find('ul').outerHeight();
			if(_li.find('.children').length > 0){
				adjustHeaderHeight(targetHeight);
				fadeOverlayIn();
				_li.siblings().find('.children').fadeOut(1);
				_li.find('.children').fadeIn(100);
			} else if(_li.attr('id') != 'menu-item-home'){
				hideHeader();
			}
		}
		$('.current-cat, .current-cat-parent').parents('li').addClass('current-cat-parent');
		$('#header li li:not(.current-cat, .current-cat-parent) a').mouseenter(function(e){
			$(this).stop(true).animate({
				'background-position': '3px center',
				'padding-left': '12px'
			},50);
		})
		$('#header li li:not(.current-cat, .current-cat-parent) a').mouseleave(function(e){
			$(this).stop(true).animate({
				'background-position': '-10px center',
				'padding-left': '5px'
			},3<00);
		})
		$('#header').mouseleave(function(){
			hideHeader();
		})
		$('#masthead .children a').click(function(e){
			hideHeader();
		})
	}
	function hideHeader(){
		$('.children').fadeOut(200);
		adjustHeaderHeight(25);
		fadeOverlayOut();
	}
	function adjustHeaderHeight(targetHeight){
		$('#access').stop(true).animate({
			height: targetHeight + 'px'
		}, 200);
	}
	function fadeOverlayOut(){
		$('#contentOverlay').stop(true).animate({
			opacity: 0
		}, 200, function(){
			$(this).css('display', 'none');
		});
	}
	function fadeOverlayIn(){
		$('#contentOverlay').css('display', 'block');
		var overlayHeight = $('body').height();
		if($('body').height() < $(window).height()){
			overlayHeight = $(window).height();
		}
		$('#contentOverlay').css('height', overlayHeight + 'px');
		$('#contentOverlay').stop(true).animate({
			opacity: .8
		}, 200);
	}
	///////////////////////////////////////////////////////////////////////////
	// Footer functions 
	//
	function footer(){
		addShortNav();
	}
	function addShortNav(){
		$('#footer .footerColumn-1 a.cat-title-link').click(function(e){
			e.preventDefault();
			$('.footer-cat').removeClass('current-footer-cat');
			$(this).parents('.footer-cat').addClass('current-footer-cat');
			$('.footer-cat').each(function(){
				if($(this).hasClass('current-footer-cat')){
					$(this).find('.cat-list-wrapper').animate({
						height: $(this).find('ul').height() + 'px'
					}, 400, 'easeInOutQuint');
				} else {
					$(this).find('.cat-list-wrapper').animate({

						height: '0px'
					}, 400, 'easeInOutQuint');
				}
				
			})
		})
	}
	function toggleSitemap(){
		if($('#footer').height() > 40){
			$('#footer').animate({
				height: '33px'
			}, 200);
		} else {
			scrollBottomLoop = setInterval(scrollBottom, 1);
			$('#footer').animate({
				height: ($('#sitemap').height() + 33) + 'px'
			}, 200, function(){
				clearInterval(scrollBottomLoop);
			});
		}
	}
	function scrollBottom(){
		$('body').scrollTo('#footer', 0);
	}
	///////////////////////////////////////////////////////////////////////////
	// Searchbar functions 
	//
	function searchInput(){
		$('.dynamicSearch input#s').focus(function(){
			hideHeader();
			//$(this).css('border', '1px solid #ECEAEA');
			$(this).stop(true).animate({
				width: '120px'
			}, 200);
		});
		$('.dynamicSearch input#s').blur(function(){
			$(this).stop(true).animate({
				width: '60px'
			}, 200);
			closeSearch();
		});
		$.ajaxSetup({cache:false});
		$('#ajaxLoader1').clone().appendTo('.dynamicSearch');
		$('.dynamicSearch .ajaxLoader').hide();
		
		$('#s').keyup(function(e){
			e.preventDefault();
			ajaxSearch();
		})
		function ajaxSearch(){
			searchValue = $('#s').val();
			if(searchValue.length > 2 && searchValue != lastSearchValue){
				$('.dynamicSearch .ajaxLoader').show();
				var target = $('#ajaxSearchContainer #theContent');
				if(isSearch){
					target = $('#container');
				}
				if(searchRequest != undefined){
					searchRequest.abort();
				}
				searchRequest = $.ajax({
					url: rootURL + "/?s=" + searchValue + "&type=ajax",
					success: function(data) {
						if(data){
							target.html(data);
							gridEffects();
							$('.dynamicSearch .ajaxLoader').hide();
							$('#ajaxSearchContainer').stop(true).animate({
								height: $('#ajaxSearchContainer #searchContent').height()
							}, 400);
						}
					}
				});
				
			} else if(searchValue.length == 0){
				closeSearch();
			}
			lastSearchValue = searchValue;
		}
		function closeSearch(){
			$('#ajaxSearchContainer').stop(true).animate({
				height: 0
			}, function(){
				$(this).find('#searchContent').remove();
			});
			$('.dynamicSearch input#s').val(null);
		}
	}
	///////////////////////////////////////////////////////////////////////////
	// Social Links
	//
	function socialLinks(){
		$('.shareWrapper a').click(function(e){
			e.preventDefault();
			var shareLink = $(this).attr('href');
			var w = 600;
			var h = 400;
			if(shareLink.indexOf('xing') != -1){
				w = 1024;
				h = 430;
			}
			openPopup(shareLink, 'Share', w, h);
		})
	}
	function openPopup(url, name, width, height) {
		!width ? width = 500 : 0;
		!height ? height = 400 : 0;

		// Errechnet Koordinaten, um das Popup zentriert zu platzieren
		var posLeft = (screen.availWidth/2)-(width/2);
		var posTop = (screen.height/2)-(height/2);
		
		//Remove special characters from name
		name = name.replace(/\/|\-|\./gi, "");

		//Remove whitespaces from name
		var whitespace = new RegExp("\\s","g");
		name = name.replace(whitespace,"");
		
		//If it is already open
		if (!myPopupWindow.closed && myPopupWindow.location) {
			myPopupWindow.location.href = url;
		} else {
			myPopupWindow= window.open(url, name, "location=no, scrollbars=yes, resizable=yes, toolbar=no, menubar=no, width=" + width + ", height=" + height + ", top=" + posTop + ", left=" + posLeft);
			if (!myPopupWindow.opener) myPopupWindow.opener = self;
		}

		//If my main window has focus - set it to the popup
		if (window.focus) {myPopupWindow.focus()}
		
	}
	function downloads(){
		$('.download-password-form').css('height', '0px');
		$('a.password-protected').click(function(e){
			e.preventDefault();
			pwForm = $(this).parents('li').next('.download-password-form');
			var form = pwForm.find('form');
			var action = form.attr('action');
			action = action.substr(0, action.lastIndexOf('.php')+4) + '?att_id=' + $(this).attr('rel');
			form.attr('action', action);
			pwForm.height(0);
			$('.current-pw-form').stop(true).animate({
				'height': '0px'
			}, 200);
			$('.current-pw-form').removeClass('current-pw-form');
			pwForm.addClass('current-pw-form');
			pwForm.stop(true).show().animate({
				'height': form.outerHeight() + 'px'
			}, 200);
			/*$('.current-pw-form input:first').css('background', 'red');
			$('.current-pw-form input:first').focus();*/
		});
		$('.download-password-form .password-submit').click(function(e){
			$(this).after($('#ajaxLoader1').clone());
			e.preventDefault();
			var form = $(this).parents('form');
			var action = form.attr('action') + '&ajax=1';
			$.post(action, form.serialize(), function(data) {
				$('.current-pw-form .ajaxLoader').remove();
				if(data == 'incorrect'){
					$('.current-pw-form .post_password').removeAttr('value');
					$('.current-pw-form form').css({
						'backgroundColor': 'red'
					}).stop(true).animate({
						'backgroundColor': '#3B372E'
					}, 500)
				} else if(data.indexOf('http://') != -1) {
					window.location.href = data;
				}
			});
		})
	}
	
	function loginForm(){
		$('.artikelTextContent #password-submit').click(function(e){
			e.preventDefault();
			$(this).after($('#ajaxLoader1').clone());
			var form = $(this).parents('form');
			var action = form.attr('action') + '&ajax=1';

			$.post(action, form.serialize(), function(data) {
				$('.artikelTextContent .ajaxLoader').remove();
				if(data == 'incorrect'){
					$('.artikelTextContent .post_password').removeAttr('value');
					$('.artikelTextContent').css({
						'backgroundColor': 'red'
					}).stop(true).animate({
						'backgroundColor': '#ffffff'
					}, 500)
				} else if(data.indexOf('http://') != -1) {
					window.location.href = data;
				}
			});
		})
	}
	
	function tooltips(){
		$('body').prepend("<div id='tooltip'><span id='tooltip-text'>text</span><span id='tooltip-flag'></span></div>");
		$('#tooltip').css({
			'opacity': '0',
			'display': 'block',
			'visibility': 'hidden'
		});
		$('#slideshowOptions a').each(function(){
			$(this).data('text', $(this).attr('title'));
			$(this).removeAttr('title');
			$(this).mouseenter(function(){
				showToolTip($(this));
			})
			$(this).mouseleave(function(){
				hideToolTip($(this));
			})
		});
	}
	function showToolTip(anchor){
		$('#tooltip #tooltip-text').text(anchor.data('text'));
		$('#tooltip').css('top', (anchor.offset().top - 34) + 'px');
		$('#tooltip').css('left', (anchor.offset().left + 4 - $('#tooltip').width()) + 'px');
		$('#tooltip').css('visibility', 'visible');
		$('#tooltip').stop().animate({
			opacity: 1
		}, 200);
	}
	function hideToolTip(){
		$('#tooltip').stop().animate({
			opacity: 0
		}, 200)
	}
}

function alternateFontLoad(){
    WebFont.load({
        monotype: {
            projectId: 'dcb45eb4-9a9f-42f4-a2c2-c5e2f79ff032'
        }
    }); 
}
