/* by skinofstars - jan 2010 */

$(document).ready(function(){

	/* nav */
	jQuery(function(){
		jQuery('#nav ul').superfish({
			//delay		: 500,
			autoArrows	: false,
			dropShadows	: false,
			pathClass	: 'active'
		});
	});
	
	/* carousel */
	if($("#carousel").length > 0) {
		$("#carousel ul").carouFredSel({
			height: 44,
			width: 877,
			items: {
				//visible: "variable"
		      visible: 1,  //  trick the plugin to think only 1 item will be shown
		      width: "variable"
			},
			scroll: {
				easing: "linear",
				duration: 0.05,
				pauseOnHover: true
			},
			auto: 0
		});
	}
	
	//alert($(".caroufredsel_wrapper").width());
	
	/* homepage diagram nav */
	/*
	if ($('#process-diagram').length > 0) {
		context = $('#process-diagram');
		
		// TODO: could do with an image pre-loader here
		// images/tab-bid.png
		// images/tab-delivery.png
		// images/tab-panel.png
		// images/tab-post-bid.png
		// images/tab-pre-bid.png
		
		// check for clicks away
		$(document).bind('click', function(e){
			
			var clickedItem = $(e.target);
	
			if (clickedItem.is('.process-info-link')) {
				
				// grab the target
				pageTarget = clickedItem.attr('href');
				
				// add the diagram fade over if it doesn't exist
				if (!$('#diagram-fifty').length > 0) {
					context.append('<img src="images/diagram-50.png" style="opacity: 0" id="diagram-fifty" />');
				}
				
				// and animate the faded diagram in
				$('#diagram-fifty').animate({opacity: 1}, 500, function(){
					
					// then animate the header
					clickedItem.siblings('h3').show(200, function(){
						
						// then the list
						$(this).siblings('ul').slideDown(500);
						
					});

				});
				

				
				return false;
				
			} else if (clickedItem.attr('href') || clickedItem.is('img')) {
				
				// do nothing if this is a normal link 

				// btw, check for img is really hacky for a single case, under the diagram img. but it is gone 1am ;) 
				
			} else {

				// this is for 'click-off'
				// basically, anywhere on document that isn't a link 
				
				// if the fade over is there, remove 
				if ($('#diagram-fifty').length > 0) {
					
					// just hide everything on a click away
					$('ul', context).slideUp(300, function(){
						$('h3', context).hide(300);
					});
					
					$('#diagram-fifty').animate({opacity: 0}, 500, function(){
						$(this).remove();
					});
					
				}
				
				return false;
			}
			
			
		});
		
	}*/
	
});
