	var mp4Support; //true or false
	var auto_int;
	var auto_time = 3; //# seconds that each slide gets shown
	var muted = false; //for sound toggling in flash player only
		
	var carouselMode = false;
	var flashInited = false;
	var introVideo = false; //whether to play intro video
		
		$(function() {
			$('#skip_btn').hide();
			function addListeners() { //this only gets called for mp4 supporters
				var vid = document.getElementById('introVideo');
				vid.addEventListener('ended', function() {
					startCarousel();
				},false);
				
				$('#sound_btn #hit').click(function() {
				
					//toggle mute/ unmute
					//mp4 video
					if (mp4Support == true) {
						var vid = document.getElementById('introVideo');
						if (vid.volume == 1) {
							vid.volume = 0;
							$('#sound_btn').removeClass('soundon');
							$('#sound_btn').addClass('soundoff');
						}
						else {
							vid.volume = 1;
							$('#sound_btn').removeClass('soundoff');
							$('#sound_btn').addClass('soundon');
						}
					}
				});
				
				$('#sound_btn #hit').hover(function() {
					$('#sound_btn').addClass('sound_hover');
				}, function() {
					$('#sound_btn').removeClass('sound_hover');
				});
			}
			
			function initVideo() {
				if (navigator.userAgent.match(/Firefox/i) || navigator.userAgent.match(/MSIE/i)) { //Firefox or IE 
					mp4Support = false;
					
					//insert SWFObject
					var flashvars = {};
					flashvars.videoFile = "intro.mp4"; //pass in the MP4 file as a flashvar
					var params = {};
					params.play = "true";
					params.loop = "false";
					params.quality = "high";
					params.wmode = "transparent";
					params.allowscriptaccess = "always"; 
					params.bgcolor = "#000000";
					var attributes = {};
					attributes.align = "middle";
					attributes.id = "flashPlayer";
					swfobject.embedSWF("video/flash_player.swf", "vid_container", "614", "316", "9.0.0", "expressInstall.swf", flashvars, params, attributes,
					function(e) {
						if (!e.success) { //no flash detected - skip the intro
							if ($('.intro') != null) $('.intro').remove(); 
							startCarousel();
						}
					});
					
				} 
				else { //Safari or other MP4 supporter
					if (navigator.platform.indexOf('iPhone') > -1 || navigator.platform.indexOf('iPad') > -1 || 
						navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/WebOS/i))
					{ //we'll skip the intro on mobile devices
						if ($('.intro') != null) $('.intro').remove(); //remove the intro video tab
						startCarousel();
					}
					else {
						mp4Support = true;
						$('#vid_container').html('<video id="introVideo" src="video/intro.mp4" width="614" height="316" autoplay></video>');
						$('#sound_btn').show();
						addListeners();
					}
				}
				
			}
			
			$('#skip_btn').click(function() {
				startCarousel();
			});
			
			/**** START POINT OF THE SCRIPT ******/
			if (introVideo == true) {
				initVideo();
			}
			else { //skip the intro video (developer's choice)
				$('#skip_btn').hide();
				if ($('.intro') != null) $('.intro').remove(); //remove the intro video tab
				startCarousel();
			}
			
		});
		
		function flashReady() { //gets called when Flash is fully loaded
			if (!flashInited) {
				flashInited = true;
				$(function() {
					////////var timeout = setTimeout(function() { $('.intro').remove(); startCarousel(); }, 250);
					
					//flash video
					$('#sound_btn').show();
					$('#sound_btn #hit').click(function() {
						//alert("muted: "+muted);
						if (muted == true) {
							muted = false;
							getFlashMovie("flashPlayer").toggleSound('on');
							$('#sound_btn').removeClass('soundoff');
							$('#sound_btn').addClass('soundon');
						}
						else {
							muted = true;
							getFlashMovie("flashPlayer").toggleSound('off');
							$('#sound_btn').removeClass('soundon');
							$('#sound_btn').addClass('soundoff');
						}
					
					});
					
					$('#sound_btn #hit').hover(function() {
						$('#sound_btn').addClass('sound_hover');
					}, function() {
						$('#sound_btn').removeClass('sound_hover');
					});
				});
			}
		}
		
		function getFlashMovie(movieName) {
			var isIE = navigator.appName.indexOf("Microsoft") != -1;
			return (isIE) ? window[movieName] : document[movieName];
		}

				
		function startCarousel() {
		
			carouselMode = true;
			
			$(function() {
				
				clearInterval(auto_int);
				
				if (introVideo) { //stop the intro video if there is one
					//mp4 video
					if (mp4Support == true) {
						vid = document.getElementById('introVideo');
						vid.volume = 0;
						vid.pause();
						
					} //flash
					else {
						if (getFlashMovie("flashPlayer"))
							getFlashMovie("flashPlayer").stopVideo();
					}
				}
				
				//TOGGLING INTRO AND CAROUSEL
				$('#intro').hide();
				$('#container').fadeIn('slow');
				
				startAutoScroll();
			
				$top_tab = $('.tab:nth-child(1)');
				$middle_tab = $('.tab:nth-child(2)');
				$bottom_tab = $('.tab:nth-child(3)');
				
				$selected_tab = null; //initializing the variable
				$prev_tab = null; //initializing the variable
				selectTab($middle_tab, true); //start with middle tab selected
				
				$nav_pos = 0;
				$('#tabs').css('top', $nav_pos);
				$shift_amt = $('.tab').height() + parseInt($('.tab').css('margin-bottom'));
				
				$num_tabs = $('.tab').size();
				
				
				function startAutoScroll() {
					auto_int = setInterval(shiftDown, auto_time * 1000); //start auto-scrolling
				}
				
				$('.down_button').click(function() {
					clearInterval(auto_int);
					shiftDown();
				});
				
				$('.up_button').click(function() {
					clearInterval(auto_int);
					shiftUp();
				});
				
				
				function shiftDown() {
					
					$readjust = $nav_pos + $shift_amt;
				
					if ($nav_pos == -($shift_amt * ($num_tabs-3))) {
						//alert("end of line");
						$('.tab').first().insertAfter($('.tab').last());
						$('#tabs').css('top', $readjust+'px');
						//alert($('#tabs').css('top'));
					}
					else {
						$nav_pos -= $shift_amt;
					}
					
					slideTabs();
					
					//TAB SELECTION TO BLUE
					if ($selected_tab.attr('id') == $top_tab.attr('id')) { //currently top tab
						selectTab($bottom_tab, true);
					}
					else if ($selected_tab.attr('id') == $bottom_tab.attr('id')) { //currently bottom tab
						selectTab($bottom_tab, false);
					}
					else { //currently in the middle
						selectTab($selected_tab.next(), true);
					}
					
					$top_tab = $top_tab.next();
					$middle_tab = $middle_tab.next();
					$bottom_tab = $bottom_tab.next();
				}
				
				function shiftUp() {
			
					$readjust = $nav_pos - $shift_amt;
				
					if ($nav_pos == 0) {
						$('.tab').last().insertBefore($('.tab').first());
						$('#tabs').css('top', $readjust+'px');
					}
					else {
						$nav_pos += $shift_amt;
					}
					
					slideTabs();
					
					if ($selected_tab.attr('id') == $top_tab.attr('id')) { //currently top tab
						selectTab($top_tab, false);
					}
					else if ($selected_tab.attr('id') == $bottom_tab.attr('id')) { //currently bottom tab
						selectTab($top_tab, true);
					}
					else { //currently in the middle
						selectTab($selected_tab.prev(), true);
					}
					
					$top_tab = $top_tab.prev();
					$middle_tab = $middle_tab.prev();
					$bottom_tab = $bottom_tab.prev();
				}
				
				function slideTabs() {
					$('#tabs').dequeue().animate({
						top: $nav_pos+'px'
					}, 500, "easeOutCirc");
				}
				
				$('.tab').hover(function() {
					if ($(this).attr('id') == $top_tab.attr('id') || 
						$(this).attr('id') == $middle_tab.attr('id') || 
						$(this).attr('id') == $bottom_tab.attr('id')) {
						onTabHover($(this));
					}
				}, function() {
					if ($(this).attr('id') == $top_tab.attr('id') || 
						$(this).attr('id') == $middle_tab.attr('id') || 
						$(this).attr('id') == $bottom_tab.attr('id')) {
						onTabOut($(this));
					}
				});
				
				function onTabHover($tab) {
					if (!$tab.hasClass('double'))
						$tab.find('a').css('color', '#000'); //link color
						
					clearInterval(auto_int); //stop carousel from auto-scrolling
					if ($selected_tab.attr('id') != $tab.attr('id')) selectTab($tab, true); //only if not currently selected
				}
				
				function onTabOut($tab) {
					if (!$tab.hasClass('double'))
						$tab.find('a').css('color', '#fff'); //link color
				}
				
				$('.tab').click(function() {
				
					if ($(this).attr('link') != undefined) { //regular tab
					
						//add tracking here
						convertOmnitureName(this);
						window.location.href = $(this).attr('link');
					}
					else if ($(this).hasClass('intro')) { //intro tab
						//play intro video
						replayIntro();
						//////getFlashMovie("flashPlayer").startVideo();
					}
					
				});
				
				$('#wrapper').hover(function() {
					
				}, function() {
					clearInterval(auto_int);
					if (carouselMode == true) startAutoScroll();
				});
				
				function selectTab($tab, changeImage) {
					
					if ($selected_tab != null) {
						deselectTab($selected_tab);
						//////if (changeImage) fadeoutTile($selected_tab.attr('id'));
					}
					
					$prev_tab = $selected_tab;
					$selected_tab = $tab;
					///////$selected_tab.css('background', '#258cca'); //temp
					$selected_tab.find('.normal').dequeue().stop(false, true).fadeOut(500, 'easeOutCirc');
					$selected_tab.find('.selected').dequeue().stop(false, true).fadeIn(500, 'easeOutCirc');
					
					//OUTER GLOW EFFECT
					//$selected_tab.animate({boxShadow: '0 0 30px #44f'});
					
					/*if (!$selected_tab.hasClass('double'))
						$selected_tab.find('a').css('color', '#000'); //link color*/
					
					if (changeImage) 
						loadTile($tab.attr('id'));
				}
				
				function deselectTab($tab) {
				
					////////$tab.css('background', '#444'); //temp
					$tab.find('.selected').dequeue().stop(false, true).fadeOut(500, 'easeOutCirc');
					$tab.find('.normal').dequeue().stop(false, true).fadeIn(500, 'easeOutCirc');
					
					if (!$selected_tab.hasClass('double'))
						$selected_tab.find('a').css('color', '#FFF'); //link color
					
				}
				
				function loadTile(id) {
					
					if ($('#image'+id+'').find('img').attr('src') == undefined || $('#image'+id+'').find('img').attr('src') == '') {
							$('#image'+id+'').find('img').attr('src', $('#image'+id+'').find('img').attr('path') + "?v=" + Math.random()*99999);
							//alert($('#image'+id+'').find('img').attr('src'));
							$('#image'+id+'').find('img').load(imgLoadedHandler);
							$('#image_loader').show();
					}
					else {
						if ($prev_tab) {
							var prev_id = $prev_tab.attr('id');
							fadeoutTile(prev_id);
						}
						showTile(id);
					}
					
				}
				
				function imgLoadedHandler() {
					var id = $selected_tab.attr('id');
					//alert("id: "+id);
					if ($prev_tab) {
						var prev_id = $prev_tab.attr('id');
						fadeoutTile(prev_id);
					}
					
					showTile(id);
				}
				
				function showTile(id) {
					$('#image'+id+'').stop(false, true).fadeIn(500, "linear");
				}
				
				function fadeoutTile(id) {
					//alert(id);
					$('#image'+id+'').stop(false, true).fadeOut(500, "linear", onFadeoutComplete);
				}
				
				function onFadeoutComplete() {
					
					$('#image_loader').hide();
				}
				
	
			});

		}
		
		function replayIntro() {
			carouselMode = false;
			$(function() {
				deselectTab($selected_tab);
				var curr_id = $selected_tab.attr('id');
				fadeoutTile(curr_id);
				
				//remove click handlers
				$('.up_button').unbind('click');
				$('.down_button').unbind('click');
				$('#sound_btn').unbind('click');
				
				//restore to original state
				$('#sound_btn').removeClass('sound_hover');
				$('#sound_btn').removeClass('soundoff');
				$('#sound_btn').addClass('soundon');
				
				clearInterval(auto_int);
				
				//TOGGLE INTRO AND CAROUSEL
				$('#container').hide();
				$('#intro').show();
				$('#intro').css('opacity', 0);
				muted = false;
				
				//mp4 video
				if (mp4Support == true) {
					//unload the video
					vid = document.getElementById('introVideo');
					vid.currentTime = 0;
					vid.play();
					vid.volume = 1;
					
					var timeout = setTimeout(revealIntro, 250);
					addListeners();
				} 
				else { //flash
					if (getFlashMovie("flashPlayer").startVideo != undefined)
						getFlashMovie("flashPlayer").startVideo();	
						
					var timeout = setTimeout(revealIntro, 250);
				}
				
				
				function revealIntro() { 
					$('#intro').css('opacity', 1); 
				}
				
				function fadeoutTile(id) {
					//alert(id);
					$('#image'+id+'').fadeOut(500, "linear", onFadeoutComplete);
				}
				
				function onFadeoutComplete() {
					/////////var sel_id = $selected_tab.attr('id');
					///////if (id != sel_id) $('#image'+id+'').hide();
					
					$('#image_loader').hide();
				}
				
				function deselectTab($tab) {
				
					//////$tab.css('background', '#444'); //temp
					$tab.find('.selected').dequeue().stop(false, true).fadeOut(500, 'easeOutCirc');
					$tab.find('.normal').dequeue().stop(false, true).fadeIn(500, 'easeOutCirc');
					
					if (!$selected_tab.hasClass('double'))
						$selected_tab.find('a').css('color', '#FFF'); //link color
					
				}
				
			});

			
		}

