jQuery(document).ready(function(){

//Fire Fancybox
	jQuery(".inlinecode").fancybox();


//Set Logo Positions
	jQuery(".logo").ready(function (){
		jQuery(".logo")
		.animate({
			backgroundPosition: '-1150px 0'
		}, 1200 );
	});
		
	jQuery("#g").ready(function (){
		jQuery("#g")
		.animate({
			backgroundPosition: '-1160px 0'
		}, 1200 );
	});

	jQuery("#infokontaktlayer").ready(function (){
		jQuery("#infokontaktlayer")
		.animate({
			backgroundPosition: '-1161px 0'
		}, 1200 );
	});


//Logo Hovers
	jQuery(".blog").hover(function() {
		jQuery(".blog").addClass("hover").stop()
			.animate({
				marginTop: '-12px', 
				marginLeft: '-10px'
			}, 800);
		jQuery("#g, #infokontaktlayer").addClass("hover").stop()
			.animate({
				backgroundPosition: '-701px 0'
			}, 400);
		jQuery(".logo").addClass("hover").stop()
			.animate({
				backgroundPosition: '-690px 0'
			}, 400);
		} , function() {
		jQuery(".blog").removeClass("hover").stop()
			.animate({
				marginTop: '0',
				marginLeft: '0'
			}, 600);
		jQuery("#g, #infokontaktlayer").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-930px 0'
			}, 400);
		jQuery(".logo").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-920px 0'
			}, 400);
	});
				
	jQuery(".portfolio").hover(function() {
		jQuery("#g, #infokontaktlayer").addClass("hover").stop()
			.animate({
				backgroundPosition: '-471px 0'
			}, 500);
		jQuery(".logo").addClass("hover").stop()
			.animate({
				backgroundPosition: '-460px 0'
			}, 500);
		jQuery(".portfolio").addClass("hover").stop()
			.animate({
				marginTop: '-5px', 
				marginLeft: '34px', 
				rotate: '-15deg'
			}, 800);
		} , function() {
		jQuery("#g, #infokontaktlayer").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-930px 0'
			}, 500);
		jQuery(".logo").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-920px 0'
			}, 500);
		jQuery(".portfolio").removeClass("hover").stop()
			.animate({
				marginTop: '10px', 
				marginLeft: '27px',
				rotate: '0'
			}, 600);
		});
	
	jQuery(".info").hover(function() {
		jQuery("#g, #infokontaktlayer").addClass("hover").stop()
			.animate({
				backgroundPosition: '-241px 0'
			}, 600);
		jQuery(".logo").addClass("hover").stop()
			.animate({
				backgroundPosition: '-230px 0'
			}, 600);
		jQuery(".info").addClass("hover").stop()
			.animate({
				marginTop: '28px', 
				marginLeft: '75px',
				rotate: '-10deg'
			}, 800);
		} , function() {
		jQuery("#g, #infokontaktlayer").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-930px 0'
			}, 600);
		jQuery(".logo").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-920px 0'
			}, 600);
		jQuery(".info").removeClass("hover").stop()
			.animate({
				marginTop: '38px', 
				marginLeft: '61px',
				rotate: '0'
			}, 600);
		});

	jQuery(".kontakt").hover(function() {
		jQuery("#g, #infokontaktlayer").addClass("hover").stop()
			.animate({
				backgroundPosition: '-7px 0'
			}, 700);
		jQuery(".logo").addClass("hover").stop()
			.animate({
				backgroundPosition: '0px 0'
			}, 700);
		jQuery(".kontakt").addClass("hover").stop()
			.animate({
				marginLeft: '67px', 
				rotate: '-5deg'
			}, 800)
		} , function() {
		jQuery("#g, #infokontaktlayer").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-930px 0'
			}, 700);
		jQuery(".logo").removeClass("hover").stop()
			.animate({
				backgroundPosition: '-920px 0'
			}, 700);
		jQuery(".kontakt").removeClass("hover").stop()
			.animate({
				marginLeft: '57px', 
				rotate: '0'
			}, 600)
		});


//Navigation Function
	jQuery(".blog, .bloglink").click(function() {
		jQuery(".content").stop()
			.animate({
				width: '0'
			}, 800);
		jQuery("#blogpage").stop()
			.animate({
				width: '400px'
			}, 800)
		});

	jQuery(".portfolio, .portfoliolink").click(function() {
		jQuery(".content").stop()
			.animate({
				width: '0'
			}, 800)
		jQuery("#portfoliopage").stop()
			.show()
			.animate({
				width: '400px'
			}, 800)
		});

	jQuery(".info, .infolink").click(function() {
		jQuery(".content").stop()
			.animate({
				width: '0'
			}, 800)
		jQuery("#infopage").stop()
			.show()
			.animate({
				width: '400px'
			}, 800)
		});

	jQuery(".kontakt, .kontaktlink").click(function() {
		jQuery(".content").stop()
			.animate({
				width: '0'
			}, 800)
		jQuery("#kontaktpage").stop()
			.show()
			.animate({
				width: '400px'
			}, 800)
		});

	jQuery(".impressum, .impressumlink").click(function() {
		jQuery(".content").stop()
			.animate({
				width: '0'
			}, 800)
		jQuery("#impressumpage").stop()
			.animate({
				width: '400px'
			}, 800)
		});


//Check for Navigated		
	var url = document.location.toString();

	if (url.match('/single/')) {	
	} else {
		if (url.match('#')) {
			
			var myAnchors = url.split('#')[1];
			
			jQuery('a.' + myAnchors).ready(function() {
				jQuery(".content").stop()
					.animate({
						width: '0'
						}, 800);
				jQuery("#" + myAnchors).stop()
					.animate({
						width: '400px'
					}, 800);
			});
		} else {
		}
	}


//Portfolio Hover
	jQuery("ul.thumb li").hover(function() {
		jQuery(this).css({'z-index' : '10'});
		jQuery(this).find('img').addClass("hover").stop()
			.animate({
				marginTop: '-98px', 
				marginLeft: '-98px', 
				top: '50%', 
				left: '50%', 
				width: '174px', 
				height: '174px'
			}, 200);
		jQuery(this).find('.portfolio_link').addClass("hover").stop()
			.animate({
				marginTop: '-31px', 
				marginLeft: '-31px',
				width: '164px',
				background: '#555555',
				opacity: 0.8
			}, 200)
	} , function() {
		jQuery(this).css({'z-index' : '0'});
		jQuery(this).find('img').removeClass("hover").stop()
			.animate({
				marginTop: '12px', 
				marginLeft: '12px',
				top: '0', 
				left: '0', 
				width: '100px', 
				height: '100px'
			}, 400);
		jQuery(this).find('.portfolio_link').removeClass("hover").stop()
			.animate({
				marginTop: '0px', 
				marginLeft: '0px', 
				width: '90px',
				opacity: 0
			}, 400)
	});


//Input Value Script
	jQuery("input[type!=submit]").each(function(){
		var wert = jQuery(this).val();
		jQuery(this).focus(function(){
				if (jQuery(this).val() == wert) {
					jQuery(this).val("")
				}
			})
			.blur(function(){
				if (jQuery.trim(jQuery(this).val()) == "") {
					jQuery(this).val(wert)
				}
			})
	});


//Footer Links Hover
	jQuery(".links li a").hover(function() {
		jQuery(this).stop()
			.animate({
				opacity: 1
			}, 200)
	} , function() {
		jQuery(this).stop()
			.animate({
				opacity: 0.5
			}, 400)
	});
	
	jQuery(".links #partner .partnercollapse").hover(function() {
		jQuery(this).stop()
			.animate({
				width: '103px'
			}, 200)
	} , function() {
		jQuery(this).stop()
			.animate({
				width: '29px'
			}, 400)
	});

});


//Bilder Wall
jQuery.fn.aPosition = function() {
thisLeft = this.offset().left;
thisTop = this.offset().top; 
thisParent = this.parent();
parentLeft = thisParent.offset().left;
parentTop = thisParent.offset().top;
return {
left: thisLeft-parentLeft, 
top: thisTop-parentTop
}
}

jQuery(window).load(

function flickrimgs() {
	
	var page_offset = jQuery("#page").offset().left;

	if ( page_offset >= 200 ) {
		flickrimga()
	};

	function flickrimga() { 
		jQuery('.flickrs').each(function(index,element){ 

			var getRandom = function(maxValue,minValue){ 
				var rnd = Math.round(minValue + maxValue*(Math.random())); 
				return rnd
			}

			var maxH = jQuery(element).height()*(page_offset/800);
			var maxW = jQuery(element).width()*(page_offset/800);
			var minH = jQuery(element).height()*(page_offset/1400);
			var minW = jQuery(element).width()*(page_offset/1400);
			var imgW = getRandom(maxW,minW);
			var imgH = imgW*(maxH/maxW);

			var maxL = Math.round(page_offset - imgW);
			var maxT = jQuery(window).height() - imgH;
			var minL = -20;
			var minT = -20;
			var imgT = getRandom(maxT,minT);
			var imgL = getRandom(maxL,minL);
			var minR = -5;
			var maxR = 10;
			var R	 = getRandom(maxR,minR);

			jQuery(this).css({ 
				"margin-top" : imgT, 
				"margin-left" : imgL,
				"height" : imgH,
				"width" : imgW,
				"transform" : "rotate("+R+"deg)",
				"opacity" : "0.75"
			});
			
			jQuery("#flickrsbtn, .flickrslink").css({
				"opacity" : "0.75",
				"margin-left" : page_offset - 100
			});
			
			jQuery(".flickrimg",this).animate({ 
				"height" : imgH, 
				"width" : imgW
			});

			jQuery(".flickrlink",this).css({
				"width" : imgW - 10
			});

			jQuery(this).draggable({ stack: ".flickrs" });
			
		});
		
		jQuery("#flickr").animate({
			left: 100 - page_offset
		});
		
		jQuery("#flickrsbtn").toggle(function() {
			jQuery("#flickr").stop()
				.animate({
					left: 0
				}, 1000, function() {
					jQuery("#flickrsbtn").css("background-image","url(http://grafagoggel.de/wp-content/themes/grafagoggel/images/buttons/flickrh.png)")
				});
		} , function() {
			jQuery("#flickr").stop()
				.animate({
					left: 100 - page_offset
				}, 1000, function() {
					jQuery("#flickrsbtn").css("background-image","url(http://grafagoggel.de/wp-content/themes/grafagoggel/images/buttons/flickrs.png)")
			})
		}).hover(function() {
			jQuery("#flickrsbtn").stop()
				.animate({
					opacity: 1
				}, 400)
		} , function() {
			jQuery("#flickrsbtn").stop()
				.animate({
					opacity: 0.75
				}, 400)
		});

		jQuery(".flickrs").hover(function() {
			jQuery(this).stop()
				.animate({
					opacity: 1
				}, 400);
			jQuery(".flickrlink",this).stop()
				.animate({
					opacity: 0.8
				}, 400)
		} , function() {
			jQuery(this).stop()
				.animate({
					opacity: 0.75
				}, 400);
			jQuery(".flickrlink",this).stop()
				.animate({
					opacity: 0
				}, 400)
		});

   }

}

)