var timer;
var cancel = false;

$(document).ready(function(){
	
	$('#gallery').find('li:first').addClass('active');
	$('#gallery').galleria({
		history   : false, // deactivates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable. Let's not have that in this example.
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { 
			image.hide().fadeIn(1500);
			thumb.parent().fadeTo(200, 1).siblings().fadeTo(200, 0.5);
			
			if (!cancel){
				timer = setTimeout(function(){$.galleria.next();}, 5000);
				
			}
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			var $li = thumb.parent(), 
			opacity = $li.is('.active') ? 1 : 0.5;
	 
	        $li.hover(
	            function() { $li.fadeTo(200, 1); },
	            function() { $li.not('.active').fadeTo(200, opacity); }
	        );
		}
	});
	$("#gallery li").click(function(){
		clearTimeout(timer);
		cancel = true;
	});
	
	$('#searchbox').watermark("Type here to search...", {className: 'watermarktext'});
	//$(".terms").colorbox({width: "75%", height: "75%"});
	
	$('ul.sf-menu').superfish({ 
        delay:       400,                            // one second delay on mouseout 
        speed:       'fast',                          // faster animation speed 
        autoArrows:  true,                          // disable generation of arrow mark-up 
        dropShadows : false
    });
	
	if (swfobject.hasFlashPlayerVersion("9.0.18")) {
		var scribd_doc;
		var onDocReady = function(e){
			jQuery(".eq").equalHeights();
		}
		 
		//if there is no container for the menus, and there are menus, then create one after the last menu
		if ($('.menu').length){
			$(".menu>a").click(function(obj){
				var url = $(this).attr('href');
				var prefix = '';
				if (url.indexOf('http')<0){
					prefix = 'http://' + document.location.host;
				}
				scribd_doc = scribd.Document.getDocFromUrl(prefix+$(this).attr('href'),'pub-53568874855958149577' );
				scribd_doc.addParam( 'jsapi_version', 2 );
				scribd_doc.addParam('default_embed_format', 'flash')
				scribd_doc.addParam( 'disable_related_docs', false );
				scribd_doc.addParam( 'hide_disabled_buttons', true );
				scribd_doc.addEventListener( 'docReady', onDocReady );
				scribd_doc.addParam( 'auto_size', 'true' );
				$('.enlarger').live('click', function(){
					if (scribd_doc.api){
						scribd_doc.api.setFullscreen(true);
				     }
					return false;
				});
				
				scribd_doc.write( 'menuviewer' );
				$('#menuviewer').prepend('<div class="viewertitle">'+$(this).next().html()+' <a href="#" class="enlarger">(view full screen)</a></div>');
				
				return false;
			});
			
			$(".menu>a:first").click();
			
			
			if ($('#menuviewer').length==0){
				$('.menu').last().after('<div class="clear"></div><div id="menuviewer"><div class="viewertitle">Select a Menu Above</div><p style="padding: 10px;">Please click on a menu from the selection(s) above.</p></div>');
			}
		}
	}
	else {
	  // no Flash
	}
	
	
		

});
