/* MIIS Effects (requires jQuery 1.3+)  */
/* by White Whale Web Services */

/* Rollover variables */
var rollovers = {
	beforeShow:100, // ms delay before a menu is initially shown
	beforeHide:500 // ms delay before a menu is hidden when exiting
};

/*var solutions = {
	distance:2, // pixels each item should move per frame
	fps:30 // frames per second
};*/

$(function() { // on DOM ready
	if($('body').is('#homepage')) { // on the homepage only
		// Nav mouseovers
		$('#navigation').addClass('has_dropdowns').find('li').hover( // attach hover events to nav items
			function() { // onmouseenter
				var self = $(this); // store the element
				clearTimeout(self.data('hideTimer')); // prevent hiding
				self.data('showTimer',setTimeout(function() { // set (and store) the timeout
						self.addClass('hover') // add the hover class
							.siblings().removeClass('hover'); // and remove it from any siblings
						self.find('input').focus(); // focus any input
						if($.browser.msie&&$.browser.version>=7) { // if IE  /* DT-fix */
							var feature = self.find('.nav_feature'),
								copy = feature.clone();
							feature.remove();
							self.find('.nav_dropdown').prepend(copy);
						}
					},rollovers.beforeShow)
				);
			},function() { // onmouseleave
				var self = $(this); // store the element
				clearTimeout(self.data('showTimer')); // prevent showing
				self.data('hideTimer',setTimeout(function() { // set (and store) the timeout
						self.removeClass('hover'); // add the hover class
						self.find('input').blur(); // blur any input
					},rollovers.beforeHide)
				);
			}
		);
		// Quickaccess
		if($.fn.quickaccess) {
			$('input.quickaccess').quickaccess({selector:'.qa_links a'});	
		}
		// Header photo caption popup
		$('#header_caption_more').click(function() {
			$('#header_caption_location,#header_caption_more,#header_caption_about').toggle();
			return false;
		});
		$('#header_caption_close').click(function() { /* DT-fix */
			$('#header_caption_more').click();
			return false;
		});
	}
	/*
	// Solutions
	$('#solutions').each(function() { // find the solutions div (if there is one)
		var items = new Array(), // the individual solutions
			animate = function(item) { // animation function
				item.position = item.position-solutions.distance; // calculate the new position
				if(item.position<0-item.width) { // if the element has scrolled off the left side of the screen
					item.position = 600; // reset it to the right edge
				}
				item.element.css({left:item.position+'px'}); // and move it
				return;
			},
			interval = Math.floor(1000/solutions.fps); // how often should the animation function run
		$(this).find('li').each(function() { // with each solution
			var index = items.push({ // add it to the items array and store the index
				element:$(this),
				position:$(this).position().left,
				width:$(this).width()
			})-1;
			$(this).data('index',index); // store the index with the item
			items[index].timer = setInterval(function() { animate(items[index]) },interval); // and start the animation		
		}).hover(function() { // onmouseenter
			$(this).css('z-index',300); // bump up the z-index
			clearInterval(items[$(this).data('index')].timer);	
		},function() { // onmouseleave
			$(this).css('z-index',''); // reset the z-index
			var index = $(this).data('index');
			items[index].timer = setInterval(function() { animate(items[index]) },interval); // and start the animation
		});
	});*/
	// Youtube SWFObject Embed/Overlays
	if($('.open_video').length) { // if there are videos to embed on this page
		$.getScript('http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js',function() { // grab swfObject, then
			$('.open_video').click(function() { // attach a click event
				var blackout = $('<div class="blackout"/>').fadeTo(0,0.5).prependTo('body'),
					overlay = $('<div class="video_overlay"><div class="close_overlay">×</div><div id="youtube_embed">Watching this video requires Flash Player 8 or higher.</div></div>').prependTo('body'),
					swf = $(this).attr('href');
					overlay.css('top',($('html').scrollTop()+100)+'px');
					swfobject.embedSWF(swf, // embed the linked SWF
						'youtube_embed', // replacing the item with this ID
						'560', '320', // width&height
						'8', null, null,
						{allowScriptAccess:'always',wmode:'transparent'}, // needed for JS api
						{id:'youtube_embed'}
					);
				blackout.add('.close_overlay').click(function() { // clicking the blackout or close button
					blackout.add(overlay).remove(); // closes the overlay
				});
				return false; // cancel the original click
			});
		});	
	}
	// FAQ and courses pages
	$('.faq .answer,.coursedesc').hide(); // Sep2-fix
	$('.faq .question,.coursetitle').css('cursor','pointer').click(function() { // Sep2-fix
		$(this).next().slideToggle();
	});
        // Sidebar Images
        $('#sidebar a img').parents('a').hover(
          function() {
            $(this).css('border', 'none');
          },
          function() {
            $(this).css('border', 'none');
          }
        );
});

function onYouTubePlayerReady() { // called when YouTube embeds are ready for interaction
	var yt = document.getElementById('youtube_embed');
	yt.playVideo();
}