// $Id: at.js,v 1.1.2.3 2010/12/01 13:48:24 jmburnz Exp $
(function ($) {
  /**
   * Insert WAI-ARIA Landmark Roles (Roles for Accessible Rich Internet Applications)
   * http://www.w3.org/TR/2006/WD-aria-role-20060926/
   */
  Drupal.behaviors.adaptivetheme = {
    attach: function(context) {

      // Set role="banner" on the header element.
      $("#page > header").attr("role", "banner");

      // Set role="main" on #main-content div.
      $("#main-content").attr("role", "main");

      // Set role="search" on search forms.
      $("#search-theme-form").attr("role", "search");

      // Set role="contentinfo" on the page footer.
      $("footer").attr("role", "contentinfo");

      // Set role=article on nodes.
      $(".article").attr("role", "article");

      // Set role="nav" on navigation-like blocks.
      $("nav, .admin-panel, #breadcrumb").attr("role", "navigation");
      
      // Set role="complementary" on navigation-like blocks.
      $("aside").attr("role", "complementary");

      // Set role="region" on section elements.
      $("section").attr("role", "region");

      // Set role="region" on section elements.
      $("#search-block-form, #search-form").attr("role", "search");

    }
  };

  /**
   * In most instances this will be called using the built in theme settings.
   * However, if you want to use this manually you can call this file
   * in the info file and user the ready function e.g.:
   * 
   * This will set sidebars and the main content column all to equal height:
   *  (function ($) {
   *    Drupal.behaviors.adaptivetheme = {
   *      attach: function(context) {
   *        $('#content-column, .sidebar').equalHeight();
   *      }
   *    };
   *  })(jQuery);
   */
  jQuery.fn.equalHeight = function () {
    var height = 0;
    var maxHeight = 0;

    // Store the tallest element's height
    this.each(function () {
      height = jQuery(this).outerHeight();
      maxHeight = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
      var t = jQuery(this);
      var minHeight = maxHeight - (t.outerHeight() - t.height());
      var property = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

      t.css(property, minHeight + 'px');
   });
  };

})(jQuery);;
(function($) {
    
    // CSS properties which contain references to images.
    $.waitForImages = {
        hasImageProperties: [
        'backgroundImage',
        'listStyleImage',
        'borderImage',
        'borderCornerImage'
        ]
    };
    
    // Custom selector to find `img` elements that have a valid `src` attribute and have not already loaded.
    $.expr[':'].uncached = function(obj) {
        // Firefox will always return `true` even if the image has not been downloaded.
// Doing it this way works in Firefox.
        var img = document.createElement('img');
        img.src = obj.src;
        return $(obj).is('img[src!=""]') && ! img.complete;
    };
    
    $.fn.waitForImages = function(finishedCallback, eachCallback, waitForAll) {

        // Handle options object.
        if ($.isPlainObject(arguments[0])) {
            eachCallback = finishedCallback.each;
            waitForAll = finishedCallback.waitForAll;
            finishedCallback = finishedCallback.finished;
        }

        // Handle missing callbacks.
        finishedCallback = finishedCallback || $.noop;
        eachCallback = eachCallback || $.noop;

        // Convert waitForAll to Boolean
        waitForAll = !! waitForAll;

        // Ensure callbacks are functions.
        if (!$.isFunction(finishedCallback) || !$.isFunction(eachCallback)) {
            throw new TypeError('An invalid callback was supplied.');
        };

        return this.each(function() {
            // Build a list of all imgs, dependent on what images will be considered.
            var obj = $(this),
                allImgs = [];

            if (waitForAll) {
                // CSS properties which may contain an image.
                var hasImgProperties = $.waitForImages.hasImageProperties || [],
                    matchUrl = /url\((['"]?)(.*?)\1\)/g;
                
                // Get all elements, as any one of them could have a background image.
                obj.find('*').each(function() {
                    var element = $(this);

                    // If an `img` element, add it. But keep iterating in case it has a background image too.
                    if (element.is('img:uncached')) {
                        allImgs.push({
                            src: element.attr('src'),
                            element: element[0]
                        });
                    }

                    $.each(hasImgProperties, function(i, property) {
                        var propertyValue = element.css(property);
                        // If it doesn't contain this property, skip.
                        if ( ! propertyValue) {
                            return true;
                        }

                        // Get all url() of this element.
                        var match;
                        while (match = matchUrl.exec(propertyValue)) {
                            allImgs.push({
                                src: match[2],
                                element: element[0]
                            });
                        };
                    });
                });
            } else {
                // For images only, the task is simpler.
                obj
                 .find('img:uncached')
                 .each(function() {
                    allImgs.push({
                        src: this.src,
                        element: this
                    });
                });
            };

            var allImgsLength = allImgs.length,
                allImgsLoaded = 0;

            // If no images found, don't bother.
            if (allImgsLength == 0) {
                finishedCallback.call(obj[0]);
            };

            $.each(allImgs, function(i, img) {
                
                var image = new Image;
                
                // Handle the image loading and error with the same callback.
                $(image).bind('load error', function(event) {
                    allImgsLoaded++;
                    
                    // If an error occurred with loading the image, set the third argument accordingly.
                    eachCallback.call(img.element, allImgsLoaded, allImgsLength, event.type == 'load');
                    
                    if (allImgsLoaded == allImgsLength) {
                        finishedCallback.call(obj[0]);
                        return false;
                    };
                    
                });

                image.src = img.src;
            });
        });
    };
})(jQuery);


(function(jQuery) {
	
jQuery.fn.fadeInSequence = function(fadeInTime, timeBetween)
{
    //Default Values
    timeBetween = typeof(timeBetween) == 'undefined' ? 0 : timeBetween;
     fadeInTime = typeof(fadeInTime) == 'undefined' ? 500 : fadeInTime;
 
    //The amount of remaining time until the animation is complete.
    //Initially set to the value of the entire animation duration.
    var remainingTime = jQuery(this).size() * (fadeInTime+timeBetween);
 
    var i=0; //Counter
    return jQuery(this).each(function()
    {
        //Wait until previous element has finished fading and timeBetween has elapsed
        jQuery(this).delay(i++*(fadeInTime+timeBetween));
 
        //Decrement remainingTime
        remainingTime -= (fadeInTime+timeBetween);
 
        if(jQuery(this).css('display') == 'none')
        {
            jQuery(this).fadeIn(fadeInTime);
        }
        else //If hidden by other means such as opacity: 0
        {
            jQuery(this).animate({'opacity' : 1}, fadeInTime);
        }
 
        //Delay until the animation is over to fill up the queue.
        jQuery(this).delay(remainingTime+timeBetween);
 
    }); 
 
};
 
})(jQuery);

jQuery(window).load(function () {

	jQuery(".view-front-projects .row-1 img").css({opacity:0});
	jQuery(".view-front-projects .row-2 img").css({opacity:0});
	jQuery(".view-front-projects .row-3 img").css({opacity:0});

	jQuery('.view-front-projects').waitForImages(function() {
		jQuery(".view-front-projects .row-1 img").delay(120).fadeInSequence(240);
		jQuery(".view-front-projects .row-2 img").delay(240).fadeInSequence(240);
		jQuery(".view-front-projects .row-3 img").delay(360).fadeInSequence(240); 
	});

	jQuery('#block-block-4 #welcome-text').hide();
	jQuery('#block-block-4 #welcome-text').show('slide', { direction: 'right' }, 600);
	
	jQuery('#block-block-4 img').hide();
	jQuery('#block-block-4 img').show('slide', { direction: 'up' }, 600);
	
	jQuery('li a').hover(	
		function() {
			jQuery(this).animate({ color: '#313342' }, 80);
		}, 
		function() {
			jQuery(this).animate({ color: '#f2f2f2' }, 80);
	})
	
	jQuery('.icon img').hover(	
		function() {
			jQuery(this).animate({ opacity: .75 }, 120);
		}, 
		function() {
			jQuery(this).animate({ opacity: 1.0 }, 120);
	})
	
	//show('slide', {direction: 'left' }, 140).
	
	// Projects Page
	jQuery(".view-front-projects .grid-item").hover(
		function () {
			jQuery(this).find(".views-field-field-front-desc").animate({opacity:1}, 120); 
		},
		function () {
			jQuery(this).find(".views-field-field-front-desc").animate({opacity:0}, 120); 
		}
	);
	
	if(window.location.hash) {
	    var which = window.location.hash.substring(1);
	    jQuery("#publications").find("a#" + which).parent().addClass("pub-selected");
	} 

	
	
	
});;

