// Create the tooltips only on document load
$(document).ready(function() {
						   
	// countrySelect controls
	$('#countrySelect').hide();
	$('.bsbf_navCountrySelect').click(function() {
		$('#countrySelect').slideToggle('normal');
	});
	
	// set redTab Widths || add margin-left to non linked items
	if ($('.bsbf_redTabWrap').size() !== 0) {
		$('.bsbf_redTabWrap').each(function() {
			var startWidth = $(this).find('.redTitleText').width();
			$(this).css('width',startWidth + 60 + 'px');
			if ($(this).find('.bsbf_redTabTitle a').size() === 0) {
				$(this).find('.bsbf_redTabTitle').css('margin-left','23px');
			}
		});
	}
	
	// Setup Fancybox(overlay items)
	/* ===== Items that are not swfs will be handled as defined by fancybox
				-Items of type .swf however require some special attention:
					IF WIDTH/HEIGHT/FLASHVARS ARE PASSED THEY MUST BE IN THAT ORDER
					-Altering will break the overlay.
					DO NOT INCLUDE ATTRIBUTE NAMES:
						width is assumed, height is assumed, flashvars is assumed.
					-Altering will break the overlay.
	===== */
	$('a[rel^="fancybox"]').each(function() {		
		var fBoxVals = new Array();
		var setWidth = 'auto';
		var setHeight = 'auto';
		var setFlashvars = 'null';
		fBoxVals = $(this).attr('rel').split(":");		
		
		if (fBoxVals[1] !== undefined) {
			log('width: ' + fBoxVals[1]);
			setWidth = fBoxVals[1];
		}
		
		if (fBoxVals[2] !== undefined) {
			log('height: ' + fBoxVals[2]);
			setHeight = fBoxVals[2];
		}
		
		if (fBoxVals[3] !== undefined) {
			log('flashvars: ' + fBoxVals[3]);
			setFlashvars = fBoxVals[3];
		}
		
		$(this).fancybox({
			'autoScale'	: false,
			'width'		: fBoxVals[1],
			'height'	: fBoxVals[2],
			'swf'		: { 'flashvars' : fBoxVals[3] }
		});
		
	});
	
	// Bold last word in buttons
	if ($('.bsbfButton').size() !== 0) {
		$('.bsbfButton').each(function() {
			var textNode = $(this).find('p a').text().toString();
			var textArray = textNode.split(" ");
			var boldItem = '<strong>' + textArray[textArray.length - 1].toString() + '</strong>';
			textArray.pop();
			var joinArray = textArray.join(" ");
			var updatedText = joinArray.toString() + '&nbsp;' + boldItem;
			$(this).find('p a').html(updatedText);
		});
	}
	
	// show tooltips
	/*
	if ($('.hasTooltip').size() !== 0) {
		$('.hasTooltip').each(function() {
			if ($(this).hasClass('tipTypePDF')) {
				log('PDF');
				var hPath = $(this).attr('href');
				var iPath = hPath.replace('.pdf','.jpg');
				$(this).qtip({
					content: '<img src="' + iPath + '" />'
				});
			}
			if ($(this).hasClass('tipTypeTEXT')) {
				log('TEXT');
				$(this).qtip({
					content: '<div class="tipText">' + $(this).attr('title') + '</div>'
				});
			}
		});
	}
	*/
	
	// form submit using bsbfButton
	if($('#bsbfButtonSubmit').size() !== 0) {
		$('#bsbfButtonSubmit').click(function() {
			var formId = $(this).find('p a').attr('href');
			$('#' + formId).submit();
			return false;
			this.blur();
		});
	}
	
});

// For legacy games, closes fancybox game when Quit is pressed
var locate = function() {
	$.fancybox.close();
};

// show/hide navigation
var navDisplay = function() {
	log('navDisplay() fired');
	$('#bsbf_mainNav').toggle();
};
