/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

/* Simple jQuery DropDown 
	- Markup is simply an Unordered List
   $("#menu").gdcDropDown();
   
*/
	$.fn.gdcDropDown = function(options) {
		var defaults = {
			rollover: true,
			bgcolor: '#000',
			rollovercolor: '#232323'
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			$(this).find("ul li").each(function() {
				var li = $(this);
				var on = false;
				if ( $(this).find('ul').width() && $(this).find('ul').width() < $(this).outerWidth(true) ) { 
					$(this).find('ul').css('width',$(this).outerWidth(true)+'px'); 
				}
				li.bind('mouseenter',function() {
					if ( !on ) {
						li.find('ul').slideDown('fast', function(){ on = true; } );
						if ( options.rollover ) li.css('background',options.rollovercolor);
					}
				});
				li.bind('mouseleave',function() {
					if ( on ) {
						li.find('ul').slideUp('fast', function(){ on = false; } );
						if ( options.rollover ) li.css('background',options.bgcolor);
					} else {
						setTimeout( function(){ 
							li.find('ul').slideUp('fast', function(){ on = false; } ); 
							if ( options.rollover ) li.css('background',options.bgcolor); 
							}, 500 );
					}
				});
			});
		} );
	} ;
	
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

/* Simple jQuery Marquee Flipper 
	- BRIT Header
   $("#marqueeContainer").Flipper({autostart:false});
	<div id='marqueeContainer'>
		<div class='highlight'>
			<div class='image'><img src='images/tmpNews.jpg' /></div>
			<div class='text'><h2>Mark Philips</h2><div>This year's MVP had it all.  Aden Bowman is proud to call Mark their own.</div></div>
		</div>
	</div>
   
*/

	$.fn.extend({
		Flipper: function(settings) {
			var obj = this;
			var intervalId = false;
			// default config 
			var defaults = jQuery.extend({
				autostart : true,
				timeDelay: 5000,
				fadeType: 'swing',
				itemClass : 'highlight'
			},settings);

			var options = $.extend(defaults, options);
			
			this.flipBack = function() {
				var current = obj.find("."+options.itemClass+":visible");
				var next = current.prev("."+options.itemClass);
				if ( next.length == 0 ) next = obj.find("."+options.itemClass+":last");
				current.find(".text")
					.animate({right:'-450px'}).
					parent().fadeOut();
				next.
					fadeIn().
					find(".text").animate({right:'0px'});
			}
			this.flipAhead = function() {
				var current = obj.find("."+options.itemClass+":visible");
				var next = current.next("."+options.itemClass);
				if ( next.length == 0 ) next = obj.find("."+options.itemClass+":first");
				current.find(".text")
					.animate({right:'-450px'}).
					parent().fadeOut();
				next.
					fadeIn().
					find(".text").animate({right:'0px'});
			}
			/// INIT FUNCTION
			return this.each(function () {
				obj.find( "."+options.itemClass ).each( function() { $(this).hide(); });
				obj.find( "."+options.itemClass+":first" ).show().find(".text").animate({right:'0px'},'slow');;
				obj.find( "#marqueePrev" ).bind('click',function(){ 
					clearInterval(obj.intervalId);
					obj.flipBack(); 
				});
				obj.find( "#marqueeNext" ).bind('click',function(){ 
					clearInterval(obj.intervalId);
					obj.flipAhead(); 
				});
				if ( options.autostart ) obj.intervalId = setInterval( function() { obj.flipAhead(); }, options.timeDelay );
			});
		}
	} );

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

/* jQuery gdcMarquee 
   
*/
	
	$.fn.gdcMarquee = function(options) {
		var defaults = {
			easing : '',
			rolloverFade: 300
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			var container = $(this);
			container.find(".timelineItem").each( function() {
				$(this).css('cursor','pointer');
				$(this).bind('mouseenter',function(){ 
					if ( !$("#item_"+$(this).attr('itemid')).is(':visible') ) $(this).animate({backgroundColor:'#dedede'}, options.rolloverFade); 
				});
				$(this).bind('mouseleave',function(){ 
					if ( !$("#item_"+$(this).attr('itemid')).is(':visible') ) $(this).animate({backgroundColor:'#ededed'}, options.rolloverFade); 
				});
				$(this).bind('click',function(){
					$(".timelineItem").animate({backgroundColor:'#ededed'}, options.rolloverFade);
					$(this).animate({backgroundColor:'#aeaeae'}, options.rolloverFade);
					$("#timelineContent .itemPane:visible").fadeOut(200);
					$("#item_"+$(this).attr('itemid')).fadeIn();
				});
			});
			container.find(".timelineItem:first").trigger('click');
		} );
	} ;
	
	
	
  $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
	
