if (!tacoBell.DriveThru.isIE6) { tacoBell.DriveThru.isIE6 = false; };
if (!tacoBell.DriveThru.navSelected) { tacoBell.DriveThru.navSelected = null; };

/*
 * Create rollovers for images and buttons.
 * @param baseName String Base name for image or button type.
 * @param id String ID of image.
 * @param arttext Boolean Whether button arttext has rollover.
 */ 
if (!tacoBell.DriveThru.rollover) {
	tacoBell.DriveThru.rollover = function(id, baseName, arttext) {
		var _baseName = baseName;
		var _id = id;
		var _arttext = arttext;
		var _imgOver;	
		// determine rollover type
		var _rolloverType = 'btn';
		if (_id != '') {
			_rolloverType = 'img';
		}
		// preload over images based on rollover type
		function _preloadOver(rolloverType) {
			if (rolloverType == 'btn') {
				// preload arttext over images
				$('.btn' + _baseName).each(function() {
					if (_arttext && ($(this).find('img').length)) {
						var arttextImg = $(this).find('img');
						var arttextOverImg = new Image();
						arttextOverImg.src = arttextImg.attr('src').replace(/off/gi, 'over');
					}
				});
			}
			if (rolloverType == 'img') {
				if ($('#' + _id).attr('src')) {
				    var imgOverName = $('#' + _id).attr('src').replace(/off/gi, 'over');
				}
				_imgOver = new Image();
				_imgOver.src = imgOverName;
			}
		}
		_preloadOver(_rolloverType);
		// create rollover(s) based on rollover type
		function _createRollover(rolloverType){
			if (rolloverType == 'btn') {
				// add event listeners, and if there's an arttext image, change it too
				$('.btn' + _baseName).hover(
					function() {
						$(this).addClass('btn' + _baseName + 'Over');
						if (($(this).find('img').length) && arttext) {
							var imgArttext = $(this).find('img');
							if (tacoBell.DriveThru.isIE6) {
								imgArttext.attr('src', imgArttext.attr('oSrc').replace(/off/gi, 'over'));
								var thisEl = $(imgArttext).get(0)
								IEPNGFix.process(thisEl, 1);
							} else {
								imgArttext.attr('src', imgArttext.attr('src').replace(/off/gi, 'over'));
							}
						}
					},
					function() {
						$(this).removeClass('btn' + _baseName + 'Over');
						if (($(this).find('img').length) && arttext) {
							var imgArttext = $(this).find('img');
							if (tacoBell.DriveThru.isIE6) {
								imgArttext.attr('src', imgArttext.attr('oSrc').replace(/over/gi, 'off'));
								var thisEl = $(imgArttext).get(0)
								IEPNGFix.process(thisEl, 1);
							} else {
								imgArttext.attr('src', imgArttext.attr('src').replace(/over/gi, 'off'));								
							}
						}
					}
				);
			}
			if (rolloverType == 'img') {
				$('#' + _id).hover(
					function() {
						$(this).attr('src', _imgOver.src);
					},
					function() {
						if ((tacoBell.DriveThru.isIE6) && ($(this).attr('oSrc'))) {
							$(this).attr('src', $(this).attr('oSrc').replace(/over/gi, 'off'));
							var thisEl = $(this).get(0);
							IEPNGFix.process(thisEl, 1);
						} else {
							$(this).attr('src', $(this).attr('src').replace(/over/gi, 'off'));
						}
					}
				);
			}
		}
		_createRollover(_rolloverType);
	}
}

if (!tacoBell.DriveThru.share) {
	tacoBell.DriveThru.share = function(options) {
		function _openOverlay() {
			_changeText('e-card', 'page');
			if (options['ecardID']) {
				_changeText('page', 'e-card');
			}
			$('#shareOverlay').modal({
				appendTo: '#shareOverlayContainer',
				opacity: 60,
				overlayClose: true
			});
			if (tacoBell.DriveThru.isIE6) {
				var thisEl;
				$('#shareOverlay, #shareOverlay img, #shareOverlay li, #shareOverlay li a, #shareOverlayContainer .modalCloseImg').each(function() {
					thisEl = $(this).get(0);
					IEPNGFix.process(thisEl, 1);
				});
			}
		}
		function _changeText(oldText, newText) {
			$('#shareTabs div p').each(function() {
				$(this).text($(this).text().replace(oldText, newText));
			});
		}
		function _updateLinks() {
			$('#btnPostItFb').attr('href', $.param.querystring($('#btnPostItFb').attr('href'), {
				't': options['text'], 
				'u': options['url']
			}));
			$('#btnPostItMs').attr('href', $.param.querystring($('#btnPostItMs').attr('href'), {
				't': options['text'], 
				'u': options['url']
			}));
			$('#btnPostItTw').attr('href', $.param.querystring($('#btnPostItTw').attr('href'), {
				'status': options['text'] + ' ' + options['url']
			}));
		}
		_openOverlay();
		_updateLinks();
		$("#shareTabs").tabs({
			show: function(event, ui) {
				if (tacoBell.DriveThru.isIE6) {
					IEPNGFix.update();
				}
			}
		});
	};
}

if (!tacoBell.DriveThru.NavManager) {
	tacoBell.DriveThru.NavManager = (function(){
		// possible nav assignments:
		// All, Christine, Options, Frescolution, None 
		var _thisNavAssign;
		var _navEls;
		function _setUp() {
			_getPageNavAssignment();
			_showNav(_thisNavAssign);
			_addShareObservers();
			_addLoginObserver();
		}
		function _getPageNavAssignment() {
			_thisNavAssign = tacoBell.DriveThru.navSelected;
		}
		function _showNav(navAssign) {
			$('#arrowDown, #arrowUp').hide();
			$('#arrowDown, #arrowUp').unbind('click');
			$('.navVersion').hide();
			if (navAssign == 'All') {
				$('#arrowUp').show();
				_addArrowObserver('Up');
				$('#navAll').css('display','block');
				if (tacoBell.DriveThru.isIE6) {
					IEPNGFix.update();
				}
				_addAllRollovers();
			} else {
				$('#arrowDown').show();
				_addArrowObserver('Down');
				$('#navOne' + navAssign).css('display','block');
				if (tacoBell.DriveThru.isIE6) {
					IEPNGFix.update();
				}
			}
			if (tacoBell.DriveThru.isIE6) {
				IEPNGFix.update();
			}
		}
		function _addArrowObserver(upDown) {
			$('#arrow' + upDown).bind('click', function() {
				if (upDown == 'Up') {
					if (_thisNavAssign == 'All') {
						_showNav('None');
					} else {
						_showNav(_thisNavAssign);
					}
				} else if (upDown == 'Down') {
					_showNav('All');
				}
			});
		}
		function _addAllRollovers() {
			tacoBell.DriveThru.rollover('navAllItemChris', '');
			tacoBell.DriveThru.rollover('navAllItemOpts', '');
			tacoBell.DriveThru.rollover('navAllItemFresco', '');
		}
		function _addShareObservers() {
			$('#shareThis').hover(
				function() {
					$(this).addClass('over');
					if (tacoBell.DriveThru.isIE6) {
						var thisEl = $(this).get(0);
						IEPNGFix.process(thisEl, 1)
					}
				},
				function() {
					$(this).removeClass('over');
					if (tacoBell.DriveThru.isIE6) {
						var thisEl = $(this).get(0);
						IEPNGFix.process(thisEl, 1)
					}
				}
			);
			
			$('#shareThis').bind('click', function(event) {
				//alert(document.body.title);
				tacoBell.DriveThru.share({
				'url': window.location.href,
					'text': $.trim(document.title)
				});
			});
			
			$('#tabFbItem a').click(function() {
			    try {
			        Tracker.trackClick('share>web>facebook', {}, 'share', 'TBUS');
			    } catch(e) {}
			});
			
			$('#tabMsItem a').click(function() {
			    try {
			        Tracker.trackClick('share>web>myspace', {}, 'share', 'TBUS');
			    } catch(e) {}
			});
			
			$('#tabTwItem a').click(function() {
			    try {
			        Tracker.trackClick('share>web>twitter', {}, 'share', 'TBUS');
			    } catch(e) {}
			});
			
			$('#btnPostItFb').click(function()
			{
			    try {
			        Tracker.trackClick('share>web>facebook>post_it', {}, 'share', 'TBUS');
			    } catch(e) {}
			});
			
			$('#btnPostItMs').click(function()
			{
			    try {
			        Tracker.trackClick('share>web>myspace>post_it', {}, 'share', 'TBUS');
			    } catch(e) {}
			});
			
			$('#btnPostItTw').click(function()
			{
			    try {
			        Tracker.trackClick('share>web>twitter>post_it', {}, 'share', 'TBUS');
			    } catch(e) {}
			});
		}
		function _addLoginObserver() {
			$('#login').bind('click', function(event) {
				$('#loginOverlay').modal({
					opacity: 60,
					overlayClose: true
				});
			});
		}
 		return {
			setUp: function() {
				_setUp();
			}
		}
	})();
}


$(function()
{
	var exitOver = function()
	{
		var o = $(this).offset(),
			v = 'site_intl',
			d = 'arrow_left',
			t = $(this).width();
		
		if ($(this).hasClass('3rd'))
			v = 'site_3rd';
		
		if (o.left + 200 > $(window).width() / 2)
		{
			d = 'arrow_right';
			t = v == 'site_intl'? -295 : -375;
		}
		
		$('#exit_tooltip')
			.css({
				left: o.left + t,
				top: Math.max(0, ($(this).height() / 2) + o.top - 52)
			})
			.removeClass(d == 'arrow_left'? 'arrow_right' : 'arrow_left')
			.addClass(d)
			.removeClass(v == 'site_intl'? 'site_3rd' : 'site_intl')
			.addClass(v)
			.show();
	}
	
	var exitOut = function()
	{
		$('#exit_tooltip').hide();
	}
	
	window.ExitLinkController = {
		scan: function()
		{
			$('a.exit_link')
				.unbind('mouseover', exitOver)
				.unbind('mouseout', exitOut)
				.bind('mouseover', exitOver)
				.bind('mouseout', exitOut);
		}
	};
	
	ExitLinkController.scan();
});