﻿$(document).ready(function() {
	var strUrl = new String(document.location);
	var arrUrl = splitURLVars(strUrl);
	var strFlashLoaderPath = '/flash' + CulturePrefix + 'main_navLoader.swf';
	var strFlashMainPath = '/flash' + CulturePrefix + 'main_nav.swf';

	if (arrUrl['prototype'] == 'sound') {
	    strFlashMainPath = '/flash' + CulturePrefix + 'main_nav_prototype_sound.swf';
	}
	else if (arrUrl['prototype'] == 'grid') {
	    strFlashMainPath = '/flash' + CulturePrefix + 'main_nav_prototype_grid.swf';
	}

	$('#TilesFlash').flash({
		src: strFlashLoaderPath,
		width: 860,
		height: 557,
		wmode: 'transparent',
		allowscriptaccess: 'always',
		allownetworking: 'external',
		flashvars: { slidersXMLPath: '/cms' + CulturePrefix + 'cms_in/home_tile_arch.xml', targetPath: '', mainNavPath: strFlashMainPath }
	},
	{ version: '9.0.128', expressInstall: true },
	//{ version: '99' }, 
	null,
	function() {
		var tileCss = document.createElement('link');
		tileCss.rel = 'stylesheet';
		tileCss.href = CulturePrefix + 'css/home-grids.css';
		tileCss.type = 'text/css';
		document.getElementsByTagName('head')[0].appendChild(tileCss);
		$('#FlashHolder').addClass('enhanced');
		addFlashUpgradeMessage();
		$('#TileGrid ul li a').each(function() {
			var $this = $(this);
			var $tile = $('<img src="' + $this.attr('rel') + '" width="' + $this.metadata().width + '" height="' + $this.metadata().height + '" alt="' + $this.html() + '" title="' + $this.html() + '" />');
			$this.html($tile);
		});
	}
	);

	$(document).unload(
		getSwfId('main_nav')
	);

	$('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);
		});
	});

	$('a[target=_blank]').click(function(e) {
		var $this = $(this);
		e.preventDefault();

		$('body').append('<div class="UIBlock"></div>');

		$('body').append('<div class="modal_overlay overlay_prompt"><p>You are now leaving the Burger King Corporation website. The policies including the privacy policy, on the website or websites you are going to may vary from Burger King Corporation\'s policies. Please be sure to review the policies of every website you visit as Burger King Corporation is not responsible for the policies and practices of other companies.</p><ul><li class="cancel"><a href="#">cancel</a></li><li class="continue"><a href="#">continue</a></li></ul></div>');
		$('.UIBlock').css({
			display: 'block',
			opacity: 0
		}).animate({
			opacity: 0.8
		}, 'fast');

		if ($.browser.msie && $.browser.version < 7) {
			var intContentHeight = parseInt(($('#Content').height() + 35), 10);
			$('.UIBlock').css({ 'height': intContentHeight });
		}

		$('div.overlay_prompt ul li.cancel a').click(function() {
			$('.UIBlock').remove();
			$('.modal_overlay').remove();
		});

		$('div.overlay_prompt ul li.continue a').click(function() {
			$('.UIBlock').remove();
			$('.modal_overlay').remove();

			window.open($this.attr('href'));
		});
	});

	$('a[rel=noprompt]').click(function(e) {
		var $this = $(this);
		e.preventDefault();
		window.open($this.attr('href'));
	});

	$('#pdf_downloads span.select_wrapper select').change(function() {
		window.open($(this).val());

		return false;
	});
});

splitURLVars = function(url) {
	var getData = new Array();

	var vars = url.split('?')[1];
	if (vars) {
		vars = vars.substr(0);

		var pairs = vars.split("&");

		for (var i = 0; i < pairs.length; i++) {
			var formData = pairs[i].split("=");

			var name = formData[0];
			var value = formData[1];
			getData[name] = value;
		}
	}

	return getData;
};

var bk;

function getSwfId(strSwfId) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		bk = window[strSwfId];
	} else {
		bk = document[strSwfId];
	}
}

function commJsAs(arrUrlData) {
	bk.onChange(arrUrlData);
}

function generalCallJsAs(arrUrlData) {
	bk.onChange(prompt(arrUrlData));
}

function turnFlashTextOn() {
	var strUrl = new String(document.location);
	var arrUrlData = strUrl.split('?');

	if (arrUrlData[1] == undefined) {
		return false;
	} else if (arrUrlData[1].length < 1) {
		return false;
	}

	return true;
}
