﻿var $ = jQuery.noConflict();
$('document').ready(function() {
	var name = '#floatMenu';
	var menuYloc = parseInt(0);
	$('#accordion li p').hide();

	// Accordion stuff on frontpage:
	maxWidth = 180;
	norWidth = 154;
	minWidth = 148;

	$('#accordion li').each(function(){
		$(this).hover(
			function(){
				//$('h1.accordion').hide();
				//$('h2.accordion').hide();
				$('p', this).fadeIn('fast');
				$(this).css('background-color','#34689a')},
			function(){
				$('p', this).fadeOut('fast');;
				$(this).css('background-color','#fff');
				//$('h1.accordion').show();
				//$('h2.accordion').show();
			});
		});

	// Set blocks to act like links:
	$('#accordion li').biggerlink();

	// Actual Accordion animations:
	jQuery("#accordion li").hover(function() {
		var elements = jQuery("#accordion li");
		jQuery.each(elements, function(i, v) {
			if(jQuery(v) != jQuery(this)) {
				jQuery(v).animate({width: minWidth+"px"}, { queue:false, duration:400});
			}
		});
		jQuery(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
	}, function() {
		var elements = jQuery("#accordion li");
		jQuery.each(elements, function(i, v) {
			jQuery(v).animate({width: norWidth+"px"}, { queue:false, duration:400});
		});
	});

	function getScroll() {
		if (window.pageYOffset > $('html,body').scrollTop()) {
			return window.pageYOffset;
		} else {
			return $('html,body').scrollTop();
		}
	}

	$(window).scroll(function () {
		if (!$('#logo:in-viewport').get(0)) {
			if ($('#backtoplink:in-viewport').get(0)) {
				var offset = -200+$(document).scrollTop()+"px";
				$(name).animate({top:offset},{duration:400,queue:false});
			} else {
				var offset = menuYloc+$(document).scrollTop()+"px";
				$(name).animate({top:offset},{duration:400,queue:false});
			}
		} else {
			var offset = menuYloc+$(document).scrollTop()+"px";
			$(name).animate({top:offset},{duration:400,queue:false});
		}
	});

	// Scroll initially if there's a hash (#something) in the url
	$.localScroll.hash({
		queue:true,
		duration:800
	});

	$.localScroll({
		queue:true,
		duration:800,
		hash:true
	});

	// Set the backgroundpositionY since there's no standardized / crossbrowser way to do it with a variable X:
	var pox = $('.current_page_item').css('backgroundPosition');
	var pox2 = $('.current_page_parent').css('backgroundPosition');
	if (pox=='undefined' || pox==undefined) {
	} else {
		var x= '';
		x = pox.split(' ');
		$('ul.menu li.current_page_item').css({backgroundImage: 'url(/wp-content/themes/betterorange/img/menu.gif)'});	//http://www.m-schulz-ag.de/wp-content/themes/mschulz/img/menu.gif
		$('ul.menu li.current_page_item').css({backgroundPosition: '' + x[0] +' '+ ' -24px'});
	};
	if (pox2=='undefined' || pox2==undefined) {
	} else {
		var x= '';
		x = pox2.split(' ');
		$('ul.menu li.current_page_parent').css({backgroundImage: 'url(/wp-content/themes/betterorange/img/menu.gif)'});	//
		$('ul.menu li.current_page_parent').css({backgroundPosition: '' + x[0] +' '+ ' -24px'});
	};

});

// Biggerlink plugin:
(function($){$.fn.biggerlink=function(options){var settings={biggerclass:'bl-bigger',hoverclass:'bl-hover',hoverclass2:'bl-hover2',clickableclass:'bl-hot',otherstriggermaster:true,follow:'auto'};if(options){$.extend(settings,options)}$(this).filter(function(){return $('a',this).length>0}).addClass(settings.clickableclass).css('cursor','pointer').each(function(i){var big=$(this).data('biggerlink',{hovered:false,focused:false,hovered2:false,focused2:false});var links={all:$('a',this),big:$(this),master:$('a:first',this).data('biggerlink',{status:'master'}).addClass(settings.biggerclass),other:$('a',this).not($('a:first',this)).data('biggerlink',{status:'other'})};$('a',this).andSelf().each(function(){var newdata=$.extend($(this).data('biggerlink'),links);$(this).data('biggerlink',newdata)});var thistitle=big.attr('title');var newtitle=big.data('biggerlink').master.attr('title');if(newtitle&&!thistitle){big.attr('title',newtitle)}big.mouseover(function(event){window.status=$(this).data('biggerlink').master.get(0).href;$(this).addClass(settings.hoverclass);$(this).data('biggerlink').hovered=true}).mouseout(function(event){window.status='';if(!$(this).data('biggerlink').focused){$(this).removeClass(settings.hoverclass)}$(this).data('biggerlink').hovered=false}).bind('click',function(event){if(!$(event.target).closest('a').length){$(this).data('biggerlink').master.trigger({type:'click',source:'biggerlink'});event.stopPropagation()}});links.all.bind('focus',function(){$(this).data('biggerlink').big.addClass(settings.hoverclass);$(this).data('biggerlink').big.data('biggerlink').focused=true}).bind('blur',function(){if(!$(this).data('biggerlink').big.data('biggerlink').hovered){$(this).data('biggerlink').big.removeClass(settings.hoverclass)}$(this).data('biggerlink').big.data('biggerlink').focused=false});links.master.bind('click',function(event){if(event.source=='biggerlink'){if(settings.follow===true||settings.follow=='auto'&&event.result!==false){window.location=$(this).attr('href')}else{event.stopPropagation()}}});if(settings.otherstriggermaster){links.other.addClass(settings.biggerclass).bind('click',function(event){$(this).data('biggerlink').master.trigger({type:'click',source:'biggerlink'});event.preventDefault();event.stopPropagation()})}else{links.other.bind('focus',function(){$(this).data('biggerlink').big.addClass(settings.hoverclass2);$(this).data('biggerlink').big.data('biggerlink').focused2=true}).bind('blur',function(){if(!$(this).data('biggerlink').big.data('biggerlink').hovered2){$(this).data('biggerlink').big.removeClass(settings.hoverclass2)}$(this).data('biggerlink').big.data('biggerlink').focused2=false}).bind('mouseover',function(event){$(this).data('biggerlink').big.addClass(settings.hoverclass2);$(this).data('biggerlink').big.data('biggerlink').hovered2=true;event.stopPropagation()}).bind('mouseout',function(event){if(!$(this).data('biggerlink').big.data('biggerlink').focused2){$(this).data('biggerlink').big.removeClass(settings.hoverclass2)}$(this).data('biggerlink').big.data('biggerlink').hovered2=false;event.stopPropagation()});if(!links.other.attr('title')){links.other.attr('title','')}}});return this}})(jQuery);

/* jQuery Viewport plugin from http://www.appelsiini.net/projects/viewport/3x2.html */
(function($){$.belowthefold=function(element,settings){var fold=$(window).height()+$(window).scrollTop();return fold<=$(element).offset().top-settings.threshold;};$.abovethetop=function(element,settings){var top=$(window).scrollTop();return top>=$(element).offset().top+$(element).height()-settings.threshold;};$.rightofscreen=function(element,settings){var fold=$(window).width()+$(window).scrollLeft();return fold<=$(element).offset().left-settings.threshold;};$.leftofscreen=function(element,settings){var left=$(window).scrollLeft();return left>=$(element).offset().left+$(element).width()-settings.threshold;};$.inviewport=function(element,settings){return!$.rightofscreen(element,settings)&&!$.leftofscreen(element,settings)&&!$.belowthefold(element,settings)&&!$.abovethetop(element,settings);};$.extend($.expr[':'],{"below-the-fold":function(a,i,m){return $.belowthefold(a,{threshold:0});},"above-the-top":function(a,i,m){return $.abovethetop(a,{threshold:0});},"left-of-screen":function(a,i,m){return $.leftofscreen(a,{threshold:0});},"right-of-screen":function(a,i,m){return $.rightofscreen(a,{threshold:0});},"in-viewport":function(a,i,m){return $.inviewport(a,{threshold:0});}});})(jQuery);
