// This function runs once the DOM is loaded
$(document).ready(function() {

//	$("#container #custom-doc #bd .tabs .tab .inner, #container #custom-doc #bd .tabs table").css("display", "block");
	$("#container #custom-doc #bd .tabs .tab .inner, #container #custom-doc #bd .tabs table").show();	
	$("#container #custom-doc #bd .tabs").css("background-image", "none");

//	if ((($("#map-systems").length > 0) || ($("#map-homepage")).length > 0) && ($.browser.msie == true)) {
	if (($("#map-systems").length > 0) && ($.browser.msie == true)) {
		$(".didyouknow .panel, .promotions .panel").hide();
		$(".didyouknow .panel:first, .promotions .panel:first").show();
		$(".promotions .corners").hide();
	} else {
		$(".widebox .panel, .promotions .panel, .didyouknow .panel").css("display", "block");
		$(".accordion .accordion-inner").css("display", "block");
		$("#container #custom-doc #bd .tabs").css("display", "block");
		
	
		// Replace HTML content with SWF
		$('#flash').flash({
			src: 'includes/flash/qrnetwork.swf',
			width: '100%',
			height: 257,
			flashvars: { featuresxml: 'Includes/xml/FlashData/Feature.xml.axd', performancexml: 'Includes/xml/FlashData/Performance.xml.axd' }
		});	
		
		// Add js class to the body for JS only styles
		$("body").addClass("js");
	
		// Blur and focus events for search textbox
		$("#header .search .search-query-box input, .basic-search-query, .advanced-search-query").each(function() {
			if ($(this).attr("value") == "") {
				$(this).attr("value","Enter search keywords...");	
			}
		});
		$("#header .search .search-query-box input, .basic-search-query, .advanced-search-query").focus(function (){
			if ($(this).attr("value") == "Enter search keywords...") {
				if ($(this).hasClass("basic-search-query")) {		
					$(".advanced-search-query").attr("value","");
				}
				if ($(this).hasClass("advanced-search-query")) {
					$(".basic-search-query").attr("value","");
				}
				$(this).attr("value","");
			} 
		});
		$("#header .search .search-query-box input, .basic-search-query, .advanced-search-query").blur(function (){ 
			if ($(this).attr("value") == "") {
				if ($(this).hasClass("basic-search-query")) {
					$(".advanced-search-query").attr("value","Enter search keywords...");
				}
				if ($(this).hasClass("downloads-advanced-search-query")) {
					$(".basic-search-query").attr("value","Enter search keywords...");
				}
				$(this).attr("value","Enter search keywords...");
			}
		});		
		$(".search-tabs .basic-search .site-search").attr("value", $("#header .search .search-query-box input").attr("value"));
	
		$(".yui-gc .yui-u:last-child .box").wrapAll('<div class="rightcolwrap"></div>');
	
		// Slider 
		if ($(".widebox .scrollContainer, .didyouknow .scrollContainer, .promotions .scrollContainer").length > 0) {
			var sliderID = 0;			
		
			$(".widebox .panel, .promotions .panel, .didyouknow .panel").css("display","block");
		
			$(".widebox, .didyouknow, .promotions").each(function () {
				
				if($(this).find(".scrollContainer").length > 0) {
	//				if($(this).find(".panel").length > 1) {				
						sliderID++;
						
						$(this).attr("id","slider"+sliderID);
						
						var $panels = $('#slider'+sliderID+' .scrollContainer > div');
						var $container = $('#slider'+sliderID+' .scrollContainer');
						
						
					
						// if false, we'll float all the panels left and fix the width 
						// of the container
						var horizontal = true;
			
						// float the panels left if we're going horizontal
						if (horizontal) {
							$panels.css({
								'float' : 'left',
								'position' : 'relative' // IE fix to ensure overflow is hidden
							});
			
							// calculate a new width for the container (so it holds all panels)
							$container.css('width', $panels[0].offsetWidth * $panels.length);
						}
			
						
						
						
						
			
						// collect the scroll object, at the same time apply the hidden overflow
						// to remove the default scrollbars that will appear
						var $scroll = $('#slider'+sliderID+' .scroll').css('overflow', 'hidden');
			
						// apply our left + right buttons
						$scroll
							.before('<a href="#" class="scroll-buttons scroll-buttons'+sliderID+' left"></a>')
							.after('<a href="#" class="scroll-buttons scroll-buttons'+sliderID+' right"></a>');
					
						// handle nav selection
						function selectNav() {
							$(this).parents('ul').find('a').removeClass('selected');
							$(this).addClass('selected');
							
							
							
						}
					
						$('#slider'+sliderID+' .navigation').find('a').click(selectNav);
					
						// go find the navigation link that has this target and select the nav
						function trigger(e, elem, $pane, $items, pos) {
							var el = $('.navigation').find('a[href$="' + elem.id + '"]').get(0);
							selectNav.call(el);
						}
			
			
						if (window.location.hash) {
							if ($('#slider'+sliderID+' #'+window.location.hash.substr(1)).length > 0) {
			//					trigger({ id : window.location.hash.substr(1) });
							} else {
								$('#slider'+sliderID+' .navigation a:first').click();					
							}
						} else {
							$('#slider'+sliderID+' .navigation a:first').click();
						}
					
						// offset is used to move to *exactly* the right place, since I'm using
						// padding on my example, I need to subtract the amount of padding to
						// the offset.  Try removing this to get a good idea of the effect
						var offset = parseInt((horizontal ? 
							$container.css('paddingTop') : 
							$container.css('paddingLeft')) 
							|| 0) * -1;
					
					
						var $navButtons = "#slider"+sliderID+" .navigation a";
					
						
					
						var scrollOptions = {
							target: $scroll, // the element that has the overflow
					
							// can be a selector which will be relative to the target
							items: $panels,
					
							navigation: $navButtons,
					
							// selectors are NOT relative to document, i.e. make sure they're unique
							prev: '.scroll-buttons'+sliderID+'.left', 
							next: '.scroll-buttons'+sliderID+'.right',
					
							// allow the scroll effect to run both directions
							axis: 'xy',
					
							onBefore: trigger,
							onAfter: trigger, // our final callback
					
							offset: offset,
			
							cycle: false, // stop from looping
					
							// duration of the sliding effect
							duration: 500,
					
							// easing - can be used with the easing plugin: 
							// http://gsgd.co.uk/sandbox/jquery/easing/
							easing: 'swing'
						};
					
						// apply serialScroll to the slider - we chose this plugin because it 
						// supports// the indexed next and previous scroll along with hooking 
						// in to our navigation.
						$('#slider'+sliderID).serialScroll(scrollOptions);
					
						// now apply localScroll to hook any other arbitrary links to trigger 
						// the effect
						$('#slider'+sliderID).localScroll(scrollOptions);
					
						// finally, if the URL has a hash, move the slider in to position, 
						// setting the duration to 1 because I don't want it to scroll in the
						// very first page load.  We don't always need this, but it ensures
						// the positioning is absolutely spot on when the pages loads.
						
						
						
						//disabled this as we may have more than one slide per page
			//			scrollOptions.duration = 1;
			//			$('#slider'+sliderID).localScroll.hash(scrollOptions);
			
						if($(this).find(".panel").length <= 1) {
							$(this).find(".scroll-buttons").hide();
						}
					}
	//			}
			 });
		}
		
	
		
		
			
			



		$("#slider1 .navigation li a").each(function() {

//		$(this).prepend(''+
//		'<span class="topleft"></span>'+
//		'<span class="topright"></span>'+
//		'<span class="bottomleft"></span>'+
//		'<span class="bottomright"></span>');
		
		});

		// Add spans for rounded corners
		$('.yui-gc .first, '+
		  '.single, '+
		  '.box, '+
		  '.box ul, '+
		  '.box ol, '+
		  '.pagefooter .box h2, '+
		  '.didyouknow p, '+
		  '#map-leftpane .item, '+
		  '.nav-sections ul, '+
		  '.intro, '+
		  '.intro-dark, '+
		  '.block, '+
		  '.promotions .panel, '+
		//  '.widebox .navigation a, '+
		  '.search-tabs .tab .inner, '+
		  '.search-tabs .tab-nav a, '+
		  '.yui-gb, '+
		  '.yui-gb .yui-u, '+
		  '.accordion, '+
		  '.map-tools .item, '+
		  '.contact-details').prepend(''+
		'<span class="topleft"></span>'+
		'<span class="topright"></span>'+
		'<span class="bottomleft"></span>'+
		'<span class="bottomright"></span>');
	
	
		

		
		

		

		
		
		
	
		
		// Add spans for rounded corners
	//	$(".widebox .navigation, .promotions").prepend(''+
	//	'<span class="corners"></span>');
	
		// Add last-child classes for IE6 styles
		$(".networks ul li:last-child").addClass("last-child");
		$(".box ul li:last-child").addClass("last-child");
		$(".nav-secondary ul li:last-child").addClass("last-child");
		$(".image-list ul li:last-child").addClass("last-child");
		$(".image-list3 ul li:last-child").addClass("last-child");
			
		// Add functionality to allow users to select all or none for checkboxes in forms
		$(".search-tabs .checkboxes .instructions").append('<ul>'+
												'<li><a class="select-all">Select all</a></li>'+
												'<li><a class="select-none">Clear selection</a></li>'+
												'</ul>');
	
	
	
	
	
	
	
	
	
	
	
	
		$(".search-tabs .checkboxes .instructions .select-all").click(function() {
			$(this).parents(".checkboxes").find("input").attr("checked","checked");	
			return null;
		});
		
		$(".search-tabs .checkboxes .instructions .select-none").click(function() {
			$(this).parents("fieldset").find("input").attr("checked","");
			return null;		
		});	
	
	
		$(".basic-search-query").change(function(){
			$(".advanced-search-query").attr("value",$(this).attr("value"));
		});
	
		$(".advanced-search-query").change(function(){
			$(".basic-search-query").attr("value",$(this).attr("value"));
		});
		
		
		// Accordion
		$(".accordion").accordion({
			header: "h3",
			autoHeight: true
		});
		
		function getURL() {
			var qrlink = $("#other-qr-sites option:selected").attr("value");
			if (qrlink != "null"){
				window.location.href=qrlink;
			}
		}
		
		
		$(".sf_PagerSelItem").attr("disabled","");

	}

	
	
	
		//$('.navigation li a').width(140)	
	
			//set width
				var aWidth = 0;
		
			//$(".navigation li").each(function() {
				//	if (aWidth < $(this).width()) {
			//		//	aWidth = $(this).width()
				//	} 
				
				//alert($(this).width());
					
					
		
					
			//});
	
	
	
	
	
	
	
	
	
	(function($){
			$.fn.ellipsis = function(){
					$(this).css({marginRight: '-10000px'});
					var w = $(this).width() - 10000;
					var t = $(this).html();
					$(this).html('<span>'+ $(this).html() +'</span>');
					while (t.length> 0 && $(this).children().width()>= w) {
							t = t.substr(0, t.length - 1);
							$(this).children().html(t + "...");
					}
			}
	})(jQuery);
	
	$(".pagefooter .quicklinks li div").each(function() {
		$(this).ellipsis();
	});

	// Setup inline tabs
	if ($(".search-tabs .search-results table").length >0) {
		$(".search-tabs .tab-nav").tabs({ selected: eval($(".search-tabs .tab-nav li").length-1) });
	} else {
		$(".search-tabs .tab-nav").tabs();
	}
	$(".tabs .tab-nav").tabs();
	
	// Override refine search link
	$(".search-tabs .refine-search").click(function(){
		$(this).parents(".search-tabs").find(".tab-nav").tabs("select",0);
	});

	if(($.browser.msie == true) && ($.browser.version < 7)){	
		$('img[@src$=.png], .png, .corners').ifixpng(); 
	}	

});




function getURL2() {
	var qrlink = $(".iwantto option:selected").attr("value");
	if (qrlink != "null"){
		window.location.href=qrlink;
	}
}




		