/*Modified 06.13.2010 by James Schellhorn*/
(function() {
	$(document).ready(function() {
		var
		w = $("#slider ul.slides li:first").width(),
		n = $("#slider ul.slides li").length,
		currentSlide = 0,
		timer = null,
		slideInterval = function() {
			if (currentSlide >= n - 1) { currentSlide = -1; }
			gotoSlide(++currentSlide);
		}
		initSlider = function() {
			var dots = '<li><a class="back" href="javascript:void(0);">Back</a></li>', width = n * 20 + 60;
			for (var i = 0; i < n; i++) {
				dots += '<li><a class="dot' + (i == 0 ? ' selected' : '') + '" href="javascript:void(0);">' + i + '</a></li>';
			}
			dots += '<li><a class="next" href="javascript:void(0);">Next</a></li>';
			$("#slider ul.navigation").html(dots).width(width).css({"left":(921 - width) + "px"});
			$("#slider ul.slides").css({"width":(w * n) + "px", "position":"relative"});
			$("#slider ul.navigation a").click(slideEvent);
			$("a.shadow").attr("href", $("#slider ul.slides a:eq(" + currentSlide + ")").attr("href"));
			timer = setInterval(slideInterval, 6000);
		},
		gotoSlide = function() {
			$("a.shadow").attr("href", $("#slider ul.slides a:eq(" + currentSlide + ")").attr("href"));
			$("#slider ul.slides").animate({"left":"-" + (currentSlide * w) + "px"});
			$("#slider ul.navigation li a").removeClass("selected").eq(currentSlide + 1).addClass("selected");
		},
		slideEvent = function(e) {
			clearInterval(timer);
			switch ($(e.target).attr("class")) {
				case "next":
					if (currentSlide >= n - 1) {
						currentSlide = -1;
					}
					gotoSlide(++currentSlide);
					break;
				case "back":
					if (currentSlide <= 0) {
						currentSlide = n;
					}
					gotoSlide(--currentSlide);
					break;
				default:
					currentSlide = $(e.target).parents("li:first").index() - 1;
					gotoSlide();
			}
		},
		changeTab = function(e) {
			var t = $(e.target).parents("li:first").index();
			$("#tabs li a").removeClass("selected").eq(t).addClass("selected");
			$("#tabs div").hide().eq(t).show();
		},
		rollUpEvent = function(e) {
			if ($(e.target).val() != "Please Select") {
				window.location = $(e.target).val();
			}
		},
		initTabs = function() {
			if ($("#tabs").length < 1) { return; }
			var h = 0;
			$("#tabs > div").each(function() {
				if ($(this).height() > h) { h = $(this).height(); }
			});
			$("#tabs ul a").click(changeTab);
		},
		initPage = function() {
			if ($("#pageData").length < 1) { return; }
			var d = $("#pageData"), t = null;

			// Bread crumbs
			if (d.find("crumbs").length > 0) {
				t = "<ul><li>You are here: </li>";
				d.find("parent").each(function() {
					var n = $(this).attr("title"), h = $(this).text();
					t += '<li><a href="' + h + '">' + n + ' &raquo; </a></li>';
				});
				t += '<li class="page">' + d.find("crumbs").attr("page") + '</li></ul>';
				$(".breadCrumbs").html(t);
			}
			
			// Top navigation
			if (d.find("nav").length > 0) {
				t = d.find("nav").attr("selected");
				$("#navigation li." + t + " a").addClass("selected");
			}
			
			// Slider
			if (d.find("coda").length > 0) {
				var c = d.find("coda");
				if (c.attr("nav") === "false") { $("#slider ul.navigation").hide(); clearInterval(timer); }
				if (c.attr("slide") !== null) { currentSlide = parseInt(c.attr("slide")); gotoSlide(); }
			}
			
			// Drop downs
			/* if ($("select.rollup").length > 1) {
				var i = 0;
				$("select.rollup").each(function() {
					i++;
					var o = '<a href="javascript:void(0);" class="dropDown" id="dropDown' + i + '" rel="dropDownMenu' + i + '">Please Select Your Simulator &raquo;</a><ul id="dropDownMenu' + i + '" class="dropDown">';
					$(this).find("option").not("[value='empty']").each(function() {
						o += '<li><a href="' + $(this).attr("value") + '">' + $(this).text() + '</a></li>';
					});
					o += '</ul>';
					$(this).replaceWith(o);
					var e = $("#dropDown" + i), p = e.position(), w = e.outerWidth(true);
					$("#dropDownMenu" + i).css({left:(p.left + w) + "px", top:(p.top + 11) + "px"});
					e.mouseover(function() {
						$("#" + e.attr("rel")).show();
					})
					.mouseout(function() {
						window.dropDownTimer = setTimeout(function() { $("#" + e.attr("rel")).hide(); }, 100);
					});
					
					$("#dropDownMenu" + i).mouseover(function() {
						clearTimeout(window.dropDownTimer);
						window.dropDownTimer = null;
					})
					.mouseleave(function() {
						$(this).hide();
					});
					
					
				});
			} */
			
var ss = d.find("slideshow").text() || "/wp-content/themes/ssi/slides/images.xml";
			$("#slideshow").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});


/* FLIGHT DIVISION SLIDESHOWS 

			var ss = d.find(".ss_flightdiv").text() || "/wp-content/themes/ssi/slides/flight/flightdiv/images.xml";
			$(".ss_flightdiv").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});	
			var ss = d.find(".ss_act").text() || "/wp-content/themes/ssi/slides/flight/act/images.xml";
			$(".ss_act").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
				var ss = d.find(".ss_airbusfms").text() || "/wp-content/themes/ssi/slides/flight/airbusfms/images.xml";
			$(".ss_airbusfms").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});	
			var ss = d.find(".ss_airbusflight").text() || "/wp-content/themes/ssi/slides/flight/airbusflight/images.xml";
			$(".ss_airbusflight").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			var ss = d.find(".ss_aptflight").text() || "/wp-content/themes/ssi/slides/flight/aptflight/images.xml";
			$(".ss_aptflight").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			var ss = d.find(".ss_boeingflight").text() || "/wp-content/themes/ssi/slides/flight/boeingflight/images.xml";
			$(".ss_boeingflight").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			var ss = d.find(".ss_boeingfms").text() || "/wp-content/themes/ssi/slides/flight/boeingfms/images.xml";
			$(".ss_boeingfms").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			var ss = d.find(".ss_ecam").text() || "/wp-content/themes/ssi/slides/flight/ecam/images.xml";
			$(".ss_ecam").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			var ss = d.find(".ss_mtd").text() || "/wp-content/themes/ssi/slides/flight/mtd/images.xml";
			$(".ss_mtd").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
				var ss = d.find(".ss_regionalflight").text() || "/wp-content/themes/ssi/slides/flight/regionalflight/images.xml";
			$(".ss_regionalflight").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
				var ss = d.find(".ss_regionalfms").text() || "/wp-content/themes/ssi/slides/flight/regionalfms/images.xml";
			$(".ss_regionalfms").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
				var ss = d.find(".ss_touchscreen").text() || "/wp-content/themes/ssi/slides/flight/touchscreen/images.xml";
			$(".ss_touchscreen").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			
 VEHICLE DIVISION SLIDESHOWS 
			
			var ss = d.find(".ss_vehiclediv").text() || "/wp-content/themes/ssi/slides/vehicle/vehiclediv/images.xml";
			$(".ss_vehiclediv").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			var ss = d.find(".ss_vehiclesafety").text() || "/wp-content/themes/ssi/slides/vehicle/vehiclesafety/images.xml";
			$(".ss_vehiclesafety").flash({swf:"/wp-content/themes/ssi/slides/slideshow.swf", width:450, height:332, flashvars:{"xmlfile":ss,"xmlfiletype":"Default"}});
			
			*/
		};
		$("ul.rollup").hide();
		$("select.rollup").change(rollUpEvent);
		initSlider();
		initTabs();
		initPage();
		
		/* home banner boxes */
		$(".banner_ad").hover(
			function () {
				$(this).addClass("hovered");
				$(".hovered .banner_text").animate({"height": "toggle", "opacity": "toggle"}, { duration: 300 });
			},
			function () {
				$(".hovered .banner_text").animate({"height": "toggle", "opacity": "toggle"}, { duration: 300 });
				$(this).removeClass("hovered");
			}
		);
		/* end home banner boxes */
		
		/* Product Inquiry Form Dialog Popup */
		$('#inquiry').dialog({autoOpen: false, width: 570, height: 600, modal: true, title: 'Product Inquiry Form'});

		$('.colorbox').click(function() {
			$('#inquiry').dialog('open');
			return false;
		});
		/* End Product Inquiry Form Dialog Popup */

		/* YouTube Popup */
		$('.youtube').click(function() {
			var temp = $(this).attr('href').split('?v=');
			var youtube_video = temp[1];
			var youtube_title = $(this).attr('title');
			$(this).prepend('<div id="youtube_player"><iframe width="640" height="360" src="http://www.youtube.com/embed/'+youtube_video+'?rel=0&autoplay=1&showinfo=0&modestbranding=1" frameborder="0" allowfullscreen></iframe></div>');
			$('#youtube_player').dialog({
				autoOpen: false, 
				width: 675, 
				height: 430, 
				modal: true, 
				title: youtube_title,
				beforeClose: function(event, ui) { 
					$("#youtube_player").remove();
				}
			});
			$('#youtube_player').dialog('open');
			return false;
		});
		/* End YouTube Popup */


	});
})();

/* Google Analytics */

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17267828-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

/* End Google Analytics */
