var startBlendedOut = false;
var navShrinked = false;
var height = null;
function loadImages() {
		for(i in aPics) {
			$("#image_"+i).attr('src', aPics[i]);
		}
}

function blendStartOut () {
	if (!startBlendedOut) {
		// safari fix
		var p = $("#logo");
		var offset = p.offset();
		$("#logo").css("top",offset.top+"px");
		$("#logo_black").css("top",offset.top+"px");
		
		$("#logo").animate({"top": "50px","opacity": 0}, { duration:2000 });
		$("#logo_black").animate({"top": "50px","opacity": 1}, { duration:2000 });
		
		$("#nav").fadeIn();
		
		//navSelect(contentToLoad, true);
		//loadImages();
		
		//$("#wrapper").fadeIn(1800,function(){$("body").addClass("white");$("#"+contentToLoad).fadeIn(1800);$("#liner").css("height","100px");$("#liner").css("width","100%");});
		$("#wrapper").fadeIn(1800,function(){$("body").addClass("white");$("#liner").css("height","100px");$("#liner").css("width","100%");});
		startBlendedOut = true;
	};
}

function navSelect (itemToSelect) { // shrinks navigation and selects item
	$("#navMenu").fadeIn();
	$("#navMenu span").html(itemToSelect);
	
	if (!navShrinked) {
		
		if (height == null) {
			height = $(".navlink").css('height');
		};
		
		/*// shrink navigation
		leftpos = parseInt($("#navMenu").css("right")) - 100;
		$("#nav").animate({  
																	"top" : "50px",
																	"right" : leftpos,
																	"fontSize" : "20px",
		}, 2800);
		$(".navlink").animate({ "fontSize" : "20px",
														"color" : "#7f7f7f",
													}, 2000);*/
													
		$(".navlink").fadeOut();
		
		navShrinked = true;
	}
	//$(".navlink:not('#nav_" + itemToSelect +  "')").animate({ "height" : "0px", "opacity" : 0 }, 1000);
}

function navShow () { // expands navigation and show menu page
	$("#navMenu").fadeOut();
	$(".contentType").fadeOut();
	
	if (navShrinked) {
		// shrink navigation
		/*$("#nav").animate({  
																	"top" : "120px",
																	"right" : "100px",
																	"fontSize" : "60px",
		}, 2800);
		$(".navlink").animate({ "fontSize" : "60px",
														"color" : "#000",
														"opacity" : "1",
														"height" : height,
													}, 2000);*/
		$(".navlink").fadeIn();
		navShrinked = false;
	}
}



function navSelectOld (itemToSelect, shrink) { // shrinks navigation and selects item
	$("#navMenu").fadeIn(2000);
	if (shrink) {
		// shrink navigation
		leftpos = parseInt($("#navMenu").css("right")) - 100;
		$("#nav").animate({  
																	"top" : "50px",
																	"right" : leftpos,
																	"fontSize" : "20px",
		}, 2800);
		$(".navlink").animate({ "fontSize" : "20px",
														"color" : "#7f7f7f",
													}, 2000);
	}
	$(".navlink:not('#nav_" + itemToSelect +  "')").animate({ "height" : "0px", "opacity" : 0 }, 1000);
}

function gallery () {
    loadImages();
	navSelect('gallery');
	$(".contentType[id!=gallery]").each(function(i) {
		$(this).fadeOut();
	}
	);
	$("#gallery").fadeIn();
}

function contact () {
	navSelect('contact');
	$(".contentType[id!=contact]").each(function(i) {
		$(this).fadeOut();
	}
	);
	$("#contact").fadeIn();
}

function imprint () {
	navSelect('imprint');
	$(".contentType[id!=imprint]").each(function(i) {
		$(this).fadeOut();
	}
	);
	$("#imprint").fadeIn();
}

function about () {
	navSelect('about');
	$(".contentType[id!=about]").each(function(i) {
		$(this).fadeOut();
	}
	);
	$("#about").fadeIn();
}

function news () {
	navSelect('news');
	$(".contentType[id!=news]").each(function(i) {
		$(this).fadeOut();
	}
	);
	$("#news").fadeIn();
}



/*
 * 	Easy Slider - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#images").easySlider();
 *	
 * 	<div id="images">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			orientation:	'', //  'vertical' is optional;
			speed: 			800
		}; 
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			obj = $(this);
			var s = $("li", obj).length;
			var w = parseInt(obj.css('width'));
			var h = obj.height();
			var ts = s-1;
			var t = 0;
			var id = obj.attr('id');
			$("ul", obj).css('width',s*w);
			
			var htmlNavPrev = '<span class="sliderPrev" title="previous"><a href="javascript:void(0);"></a></span>';
			var htmlNavNext = '<span class="sliderNext" title="next"><a href="javascript:void(0);"></a></span>';
			
			$("ul", obj).before(htmlNavPrev + htmlNavNext);
			
			var objNavNextButton = $('.sliderNext', obj);
			var objNavPrevButton = $('.sliderPrev', obj);
			
			// assign triggers to buttons
			$(objNavNextButton).click(function(){
				animate("next", id);
			});
			$(objNavPrevButton).click(function(){
				animate("prev", id);
			});
			

			function animate(dir, id){
				//console.log(obj.attr('id'));
				obj = $("#" + id);
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;
				} else {
					t = (t<=0) ? 0 : t-1;
				};
				p = (t*w*-1);
				$("ul", obj).animate(
					{ marginLeft: p },  options.speed );
				if (t+1 == s) {
					$(".sliderNext",obj).fadeOut();
				} else {
					$(".sliderNext",obj).fadeIn();
				}
				if (t == 0) {
					$(".sliderPrev",obj).fadeOut();
				} else {
					if (s > 1) {
						$(".sliderPrev",obj).fadeIn();
					};
				}
				
			};
			
			if(s>1) $(".sliderNext",obj).fadeIn();
			
		});
	  
	};

})(jQuery);