﻿var boolSlideOutTracked = false;

$(document).ready(function() {
	boolSlideOutTracked = false;
	var navHoverTimeout;
	var navOpen = false;

	/* Local campaigns should be added to the logic below to exclude the shim iframe */
	if (!$('#LayoutWrapper').hasClass('SeattleCiniminiCoupon') && !$('#LayoutWrapper').hasClass('NewMoon') && !$('#LayoutWrapper').hasClass('Latenight') && !$('#LayoutWrapper').hasClass('TruthAboutTony') && !$('#LayoutWrapper').hasClass('TruthAboutTonyLiveEvent') && ($('#BKRacingWrapper').length == 0) && ($('#FutbolKingdomWrapper').length == 0)) {
		if (navigator.appVersion.indexOf("Win") != -1 && $('#PageWrapper').hasClass('Campaigns')) {
			$('body').append('<iframe id="shim" transparency="true" frameborder="0"></iframe>');
			$('#shim').css({
				position: 'absolute',
				top: '0px',
				left: '0px',
				background: '#000',
				height: $('#GlobalHeader').outerHeight(),
				width: '51px'
			});
		}
	}

	$('#GlobalHeader').mouseenter(function() {
		navOpen = true;
		navHoverTimeout = setTimeout(function() {
			if (!boolSlideOutTracked) {
				boolSlideOutTracked = true;
				try {
					//dcsMultiTrack('DCS.dcsuri', 'ui/slidenavOpen');
					pageTracker._trackEvent(CulturePrefix + 'navigation_tray', 'open_tray', 'tray/' + document.title);
				}
				catch (e) { }
			}
			$('#GlobalHeader').animate(
				{ left: '0px' },
				250,
				'easeOutCirc',
				function() {
					//$('body').append('<div id="UiBlock"></div>');
				});
			$('body').append('<div id="UiBlock"></div>');
			if ($.browser.opera) {
				$('iframe').hide();
			}
			if (navigator.appVersion.indexOf("Win") != -1) {
				$('#shim').animate({
					width: '100%'
				}, 250, 'easeOutCirc');
			}
			if ($.browser.msie && $.browser.version < 7) {
				var intContentHeight = parseInt(($('#Content').height() + 35), 10);
				$('#UiBlock').css({ 'height': intContentHeight });

				$('#sort').hide();
				$('#narrow').hide();
				$('#AngryGram').hide();
			}
		}, 250);
	});
	$('#GlobalHeader').mouseleave(function() {
		clearTimeout(navHoverTimeout);
		if (navOpen) {
			$('#UiBlock').remove();
			$(this).animate(
			{ left: '-860px' },
			250,
			'easeOutCirc',
			function() {
				//$('#UiBlock').remove();
				if ($.browser.opera) {
					$('iframe').show();
				}
			});
			if (navigator.appVersion.indexOf("Win") != -1) {
				$('#shim').animate({
					width: '51px'
				}, 250, 'easeOutCirc');
			}
			navOpen = false;

			if ($.browser.msie && $.browser.version < 7) {
				$('#sort').show();
				$('#narrow').show();
				$('#AngryGram').show();
			}
		}
	});

	$('#MenuTab a').click(function() {
		$('#UiBlock').remove();
		$('#GlobalHeader').animate(
			{ left: '-860px' },
			250,
			'easeOutCirc',
			function() {
				//$('#UiBlock').remove();
			});

		return false;
	});

	$('input[type=text], textarea').each(function() {
		$(this).focus(function() {
			if ($(this).val() == this.defaultValue) $(this).val('');
		});
		$(this).blur(function() {
			if ($(this).val() == '') $(this).val(this.defaultValue);
		});
	});

	if ($.browser.msie && $.browser.version < 7) {
		var intContentHeight = parseInt(($('#Content').height() + 25), 10);
		$('#MenuTab').css({ 'height': intContentHeight });
		$('#GlobalHeader').css({ 'height': intContentHeight });
	}
});

function slideSite(urlPath, target) {
    try{
        //dcsMultiTrack('DCS.dcsuri', 'ui/slidenavClicked', 'DCSext.hp_linkto', urlPath);
        pageTracker._trackEvent(CulturePrefix + 'tile_navigation', 'tile_click', 'tile/' + document.title + urlPath);
    }
    catch(e){}
	
	if(target == "_blank"){
		window.open(urlPath);
	}else{
	
		$('#GlobalHeader').unbind('hover').stop().animate({
			left: '-860px'
		}, 250, 'easeOutCirc');
		setTimeout(function() { window.location = urlPath; }, 250);
	}
}

function addFlashUpgradeMessage() {
	$('#GlobalHeader').prepend('<div id="NoFlashUpgrade"><p>BK.com is optimized for best use with Flash Player 10. Please Upgrade. <a href="http://www.adobe.com/products/flashplayer/" class="utility" target="_blank">Download the latest Flash Player &gt;</a></p></div>');
	$('#FlashHolder').css('margin-top', '28px');
}
