/**
 * common theme behaviours
 * 
 */

jQuery(document).ready(function($){
	$("*").removeClass("marinelli-hide-no-js"); // remove the hide class (see common.css)
	
	// sticky navigation
	$(window).bind('scroll', function(){
		if ($(document).scrollTop() > 145) {
			$("#sticky-top").css({'position' : 'fixed', 'top' : -100+'px'});
			$("#totalContainer").css({'padding-top':'180px'});
		} else {
			$("#sticky-top").css({'position' : '', 'top' : ''});
			$("#totalContainer").css({'padding-top':''});
		}
	});
});

/**
 * jQuery cssParentSelector 1.0.3
 * http://idered.pl
 *
 * Copyright 2011, Kasper Mikiewicz
 * Released under the MIT and GPL Licenses.
 * Date 2011-08-14
 */
 (function($, b, s, i, h, a, c, d, e, f, g) {
    $.fn.cssParentSelector = function() {
		$('link[rel=stylesheet]').each(function() {
			$.get(this.href, function(d){
				a = (d.match(/[a-zA-Z0-9#\.\-_:\[\]= ]*::parent[a-zA-Z0-9#\.\-_: ]*(\{[a-zA-Z0-9\s\/\.\-:#\(\);]*\})/g));
				for (;a[++i], c = a[i];) {
					d = c[s]('{')[0];
					e = d[s]('::parent')[0][s](/:|::/)[1];
					f = $.trim(d[s]('::parent')[1]);
					g = c[s](/\{|\}/)[1].replace(/[\t\n]*/g, '');
					d = d[s](':')[0];	
					
					$(d).each(function(k, m, n, t) {
						t = $(this);
						k = t.parent();
						f && (k = k.find(f));
						m = 'cps' + h++;
						n = function() { k.toggleClass(m) };
						
						!e ? n() : 
						e == 'focus' ? t.focus(n).blur(n) : 
						e == 'selected' ? t.change(n) : t[e](n);
						
						b += '.' + m + '{' + g + '}';
					});
				};
				$('<style type="text/css">' + b + '</style>').appendTo('head')
			});
		});
		
    };
})(jQuery, '', 'split', -1, 0);;
/**
 * Top region js
 * bartext and bartext2 come from theme settings through template.php
 */
jQuery(document).ready(function($) {

  	// Hide region (don't hide in the demo block page)
	if(!Drupal.settings.marinelli.blockdemo){
		$('#topBar').hide();
	}
	
	// set the right text in the blcok demo page
	if(Drupal.settings.marinelli.blockdemo){
		$('#topBarLink a').text("↑ " + Drupal.settings.marinelli.bartext2 + "");
	}
	
	// Make the spy effect
	$('#topBarLink a').live('mouseover mouseout', function(event) {
    if (event.type == 'mouseover' && $(this).text() == "↓ " + Drupal.settings.marinelli.bartext + "") {
      $('#topBarLink').animate({
        'padding-top':'5px'
      });
    }
    else if (event.type == 'mouseout' && $(this).text() == "↓ " + Drupal.settings.marinelli.bartext + "") {
    $('#topBarLink').animate({
      'padding-top':'0px'
    });
    }
	});
  
	// Click logics
	$('#topBarLink a').click(function () {
    if ($(this).text()=="↓ " + Drupal.settings.marinelli.bartext + "") {
      $(this).text("↑ " + Drupal.settings.marinelli.bartext2 + "");
      $(this).attr('title','Close this region');
    }
    else if ($(this).text()=="↑ " + Drupal.settings.marinelli.bartext2 + "") {
      $(this).text("↓ " + Drupal.settings.marinelli.bartext + "");
      $(this).attr('title','Open this region');
    }
    $('#topBar').slideToggle("slow");
    return false;
  });

	// Link positioning
	var linkWidth = $('#topBarLink a').width();
	var windowWidth = $(window).width();

  	// Set start margin
	$('#topBarLink a').css('margin-left', ((windowWidth / 2) - (linkWidth / 2) -10) + 'px');

	$(window).bind('resize', function(event) {
		$('#topBarLink a').css('margin-left', (($(window).width() / 2) - (linkWidth / 2) - 10) + 'px');
	});

});;
/**
 * quickMenu behaviours
 * 
 */
 
jQuery(document).ready(function($){
	// wenn jQuery vorhanden,... dann nehm' ich's auch
	var quickMenu = $('#block-menu-menu-quicklinks'), quickMenus = $('#block-menu-menu-quicklinks > div > ul > li > ul');
	
	
	quickMenu.current = quickMenus.get(0);
	
	quickMenus.hide();
	$(quickMenus.get(0)).show();
	
	$('#block-menu-menu-quicklinks > div > ul > li > a').click(function(){
		var that = $(this).parent().children('ul');
		that.show(200);
		if (that[0] != quickMenu.current) {
			$(quickMenu.current).hide(200);
			quickMenu.current = that;
		}
		return false;
	});

	/*var top = document.getElementById('top'),
			doScroll = function () {
				var scrollTop = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : 
						document.body.scrollTop  ? document.body.scrollTop : window.scrollY;
						// console.log(scrollTop);
				if (scrollTop >= 148 && !top.className) {
					document.body.className = 'scroll-top';
					top.className = 'top';
				} else if (scrollTop < 148 && top.className) document.body.className = top.className = '';
			};

	if(!navigator.userAgent.match(/(iPad|iPhone)/i))	{
		if (document.body.style.position.fixed) {
			doScroll();
			document.onscroll = doScroll;
		}
	} else document.body.style.cssText += ';margin-top:0;margin-bottom:0;';*/
});

	;

