jQuery(function($){
	$("#rolearrow, #functionarrow, #industryarrow").click(function(){
	    var $this = $(this), submenu = $this.parent().find('div');

	    if ( submenu.is(':visible') )
	    {
	    	$this.attr('src', $this.attr('src').replace(/arrowdown.gif/, 'arrow.gif'));
	    	submenu.slideUp();
	    }
	    else
	    {
	    	$this.attr('src', $this.attr('src').replace(/arrow.gif/, 'arrowdown.gif'));
	    	submenu.slideDown();
	    }
	}).css('cursor', 'pointer');

	var videoDiv = $("#videoDiv"), videos = videoDiv.find('.video div'), list = videoDiv.find('.list div'),
		vNames = ['', 'Chaos, Order, & Alive', 'Overview'],
		pauseAll = function(){
			var vTags = videos.find('video');
			
			if ( vTags.length )
	    	{
    	    	vTags.each(function(){
                    this.pause();
                });
	    	}
	    	else
	    	{
	    		videos.each(function(){
		    		var span = $(this).find('span'), ele = span.get(0);

		    		if ( span.length )
		    		{
		    			$f(ele).stop();
		    		}
		    	});
	    	}
		},
		playVideo = function(id){
			videoDiv.dialog('open');
			
			var curVideoDiv = videos.hide().filter('.video' + id).show(), videoTag = curVideoDiv.find('video');
			list.removeClass('selected').filter('.video' + id).addClass('selected');
			
			pauseAll();
			
			if (_gaq)
				_gaq.push(['_trackEvent', 'Videos', 'Play', vNames[id]]);
			
			if ( videoTag.length )
			{
				videoTag.each(function(){
                    this.play();
                });
			}
			else
			{
				curVideoDiv.each(function(){
		    		var span = $(this).find('span'), ele = span.get(0);

		    		if ( span.length )
		    		{
		    			$f(ele).play();
		    		}
		    	});
			}
		};

	videoDiv.dialog({
		autoOpen: false,
	    modal: true,
	    width: 900,
	    open: function(event, ui){
		    $('.ui-widget-overlay').click(function(){
			    videoDiv.dialog('close');
			});
	    },
	    close: function(){
	        videos.find('video').each(function(){
		        this.pause();
		    });
	        
	        if (_gaq)
				_gaq.push(['_trackEvent', 'Videos', 'Close Window']);
	    }
	});

	list.hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	}).click(function(){
	    var cName = $(this).get(0).className, matches = /video(\d+)/.exec(cName), id = parseInt(matches[1], 10);

	    if ( id > 0 )
	    {
	    	playVideo(id);
	    }
	});
	
	window.playVideo = playVideo;
	
	if (isHome !== undefined && isHome)
	{
		var imgs = $("#cust img"), sizeOf = imgs.length, curImg = 0;
		window.setInterval(function(){
			imgs.eq(curImg).fadeOut("slow");
			curImg++;
			if (curImg >= sizeOf) curImg = 0;
			imgs.eq(curImg).fadeIn("slow");
		}, 7500);
	}
});