// Delay Plugin for jQuery
// - http://www.evanbot.com
// - copyright 2008 Evan Byrne
/*
 * Jonathan Howard
 * jQuery Pause
 * version 0.2
 * Requires: jQuery 1.0 (tested with svn as of 7/20/2006)
 * Feel free to do whatever you'd like with this, just please give credit where
 * credit is do.
 * pause() will hold everything in the queue for a given number of milliseconds,
 * or 1000 milliseconds if none is given.
 */
// Wait Plugin for jQuery
// http://www.inet411.com
// based on the Delay and Pause Plugin
 (function($) {
    $.fn.wait = function(option, options) {
        milli = 0; 
        if (option && (typeof option == 'function' || isNaN(option)) ) { 
            options = option;
        } else if (option) { 
            milli = option;
        }
        // set defaults
        var defaults = {
            msec: milli,
            onEnd: options
        },
        settings = $.extend({},defaults, options);

        if(typeof settings.onEnd == 'function') {
            this.each(function() {
                setTimeout(settings.onEnd, settings.msec);
            });
            return this;
        } else {
            return this.queue('fx',
            function() {
                var self = this;
                setTimeout(function() { $.dequeue(self); },settings.msec);
            });
        }

    }
})(jQuery);

$(document).ready(function(){
	function animateHeader(position) {
		$("#headerImgs .headerImgElement").eq(position).fadeIn(3500, function() {
			var nextPosition = position + 1;
			if (nextPosition == $("#headerImgs .headerImgElement").length) {
				var nextPosition = 0;
			}
			if($("#header #headerSlide,#header #headerSlideText").length > 0) {
				$("#header #headerSlide,#header #headerSlideText").animate(
						{ width:"180px",paddingLeft:"15px",paddingRight:"15px"},
						3500,
						'linear',
						function(){
                                                    if($(this).attr('id') == "headerSlideText") {
							$("#header #headerSlide,#header #headerSlideText").wait(3500).animate(
									{ width:"0px",paddingLeft:"0",paddingRight:"0"},
									3500,
									'linear',
									function(){
                                                                            if($(this).attr('id') == "headerSlideText") {
                                                                                $("#header #headerSlide,#header #headerSlideText").remove();
										$("#headerImgs .headerImgElement").eq(position).fadeOut(3500,animateHeader(nextPosition));
                                                                            }
									}
							); 
						    }
                                                }
				); 
			} else {
				$("#headerImgs .headerImgElement").wait(3500).eq(position).fadeOut(3500,animateHeader(nextPosition));
			}
		});
	}
	animateHeader(0);
});

/*
slide: $("#header .cloud").animate(
  { 
   top: "208px",
   height:"224px"
  },
  2500 
 );*/
