JQ(document).ready(function() {
	var trackerString;
	var localePrefix;
	
	Bootroom.init();
	// Bootroom.initFb(); // initialises variables for FB button
	//Bootroom.search();
	Bootroom.tabs();
	// Temporary athlete panel with no filter
//	Bootroom.athletepanelnofilter();
	Bootroom.athletepanel();
	Bootroom.comments();
	toutpanel();
	Bootroom.mostpopularpanel();
	Bootroom.wallpapers();
	
});

var Bootroom = new function() {

	var init = this.init = function() {

		if(jQuery.browser.msie){
			var ie6SearchBar = '<span class="png"><img style="position:absolute;left:0;" src="/nikefootball/assets/bootroom/images/common/bg-searchbar-x.png" alt="" width="910" height="73" /></span>';
			JQ("div#pagesearch").prepend(ie6SearchBar);
		}
		
		Bootroom.heropanel();
		Bootroom.bindTracking();
		
		// Open any required footer links in new window
		JQ('.pop_footer').click(function() {
			window.open(JQ(this).attr('href'), '_blank');
			// Handle privacy policy tracking
			if (this.id == "footer_link_privacy") {
				tracking.click(localePrefix + 'privacy');
			}
			return false;
		});
		
	};

	var search = this.search = function() {
		JQ("div#pagesearch").find('span.png').pngFix(); // IE 6 only png fix
		
		JQ("div.searchbox span input").bind("focus blur", function() { 
			if(JQ(this).attr("value") == ''){
				JQ(this).toggleClass("has-js");
			}
		});
		JQ("div.searchbox span input").trigger('blur');
		
		JQ("div.searchbox form").bind("submit", function() {
			tracking.click(localePrefix + 'bootroom>search>go','o');

			if(JQ("div.searchbox input:first").attr("value") == ""){
				return false;
			}
		});
		
		if(JQ.browser.msie && jQuery.browser.version < "8"){
		
			JQ("div.searchbox form strong").click(function(){
				JQ("div.searchbox form").trigger('submit');
			});
			
			var t1, t2;
			JQ("div.searchbox form strong").hover(function(){
				clearTimeout(t2);
				t1 = setTimeout(JQ(this).parent().addClass("hover"),1000);
			}, function(){
				clearTimeout(t1);
				t2 = setTimeout(JQ(this).parent().removeClass("hover"),1000);
			});
			
		} else {
			JQ("div.searchbox form strong > input").hover(
				function(){
					JQ(this).parent().parent().addClass("hover");
				},
				function(){
					JQ(this).parent().parent().removeClass("hover");				
				}
			);	
		}
	};
	
	var tabs = this.tabs = function() {
		
		// check if default view is defined in the querystring bookmark, if not uses first found trigger
		var targetTab = JQ("div#tabs").attr("class").toLowerCase().replace("[","").replace("]","");
		
		//var targetTab = window.location.href.split('#');
		
		var makeTabs = makeTabs();
		if(makeTabs != ''){
			JQ("div.tabtriggers").replaceWith(makeTabs);
			if(targetTab.length > 1 && JQ("div#" + targetTab).length > 0){
				var targetView = targetTab;
			} else {
				var targetView = JQ("div.tabtriggers li a:first").attr('href').split('#')[1];
			}
			
			// Replace text within tabs
			if (useSiteFont == 1) {
				Cufon.replace('div.tabtriggers ul li a', { fontFamily: "Rockwell" });
			} 
			else if (useSiteFont == 2) {
				Cufon.replace('div.tabtriggers ul li a', { fontFamily: "Arial" });
			}
		}
		
		// show initial view
		if(targetView){
			showTabView(targetView);
		}
		
		// add click event to all triggers
		JQ("div.tabtriggers li a").each(function(i,trigger){
			JQ(trigger).click(function(){
				showTabView(JQ(trigger).attr('href').split('#')[1]);
				tabText = JQ(trigger).text();
				
				if (i == 0) {
					tracking.click(trackerString + 'media_feed>tab_click','o');
				}
				else if (i == 1) {
					tracking.click(trackerString + 'players>tab_click','o');
				}
				else if (i == 2) {
					tracking.click(trackerString + 'extras>tab_click','o');
				}
				return false;
			});
		});
		
		// make tabs if more than 1
		function makeTabs(){
			var tabPanels = JQ("div.tabpanels div.tabcontent");
			if(tabPanels.length > 1){
				var triggerHTML = '<div class="tabtriggers"><ul>';
				JQ("div.tabpanels div.tabcontent").each(function(i,panel){
					var tabID = JQ(this).attr("id");
					var tabText = JQ(this).attr("title");
					JQ(this).removeAttr("title");
					
					triggerHTML += '<li><a href="#' + tabID + '">' + tabText + '</a></li>';
					
				});
				
				triggerHTML += '</ul></div>';
				return triggerHTML;	
			} else {
				JQ("div.tabtriggers").remove();
			}
			
			return '';

		}
		
		// hides all tab panels
		function hideAllTabs(){
			JQ("div.tabpanels div.tabcontent").each(function(i,panel){
				var paneltarget = JQ(panel).attr('id');
				JQ(panel).fadeOut(0);
				JQ("a[href$='#" + paneltarget + "']").parent().removeClass('selected');
			});
		}
		
		// shows selected tab panel
		function showTabView(targetView){
			targetView = targetView.replace(/#/,'');
			hideAllTabs();
			generateShareLinks(targetView);
			
			// loads real images if not already loaded
			if(JQ("div[id='" + targetView + "']").hasClass("hiddenimages")){
				//loadTabImages(targetView);
			}
			
			JQ("a[href$='#" + targetView + "']").parent().addClass('selected');
			// Refresh text within tabs
			Cufon.refresh('div.tabtriggers ul li a');
				
			JQ("div[id='" + targetView + "']").fadeIn(300);
			JQ("div[id='" + targetView + "']").find('a.png').pngFix(); // IE 6 only png fix
			
		}
		
		// load visible tab images
		/*function loadTabImages(targetView){
			// get all images with class "replace"
			var panelImages = JQ("div[id='" + targetView + "'] img.replace");
			// load image src using path stored in rel attribute
			panelImages.each(function(i,panel){
				if(JQ(panel).attr('title') != ''){
					JQ(panel).attr('src', JQ(panel).attr('title'));
					JQ(panel).removeAttr('title');	
				}
			});
			
			JQ("div[id='" + targetView + "']").removeClass("hiddenimages");
		}*/

		// Generate & populate link hrefs for twitter and fb sharing
		function generateShareLinks(targetView) {
			var fbLinkOut = "http://www.facebook.com/sharer.php?u=";
			var fbLinks = JQ("div[id='" + targetView + "'] li.facebook a");
			var twitterLinks = JQ("div[id='" + targetView + "'] li.twitter a"); 
			
			fbLinks.each(function(i,link){
				JQ(link).click(function() {
					var u = JQ(this).attr('rel');
					var t = "";
					window.open(fbLinkOut + encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
					tracking.click(trackerString + "media_feed>facebook");
					return false;
				});						
			});
			
			twitterLinks.each(function(i,link){
				JQ(link).click(function() {
					tracking.click(trackerString + "media_feed>twitter");
					return true;
				});
			});
		}
        
		// Store clicked media image for use later
		var mediaParent = '';
		var mediaPlaying = '';
		// Click event to load latest media video
		JQ('#blogfeed li .video a').live('click', function() {
			tracking.click(trackerString + 'media_feed>play>' + JQ(this).closest('li.blog').find('.post h3 a').text());
			
			var guid = JQ(this).attr('rel');
			
			if(mediaPlaying != ''){
				mediaParent.find('object').replaceWith(mediaPlaying);
			}
			mediaParent = JQ(this).parent();
			mediaPlaying = JQ(this).parent().html();
			
            var flashVars = {
                locale: GLOBAL_VARIABLES.locale,
                guid: guid,
                regionConfig: "http://www.nike.com/nikefootball/emea/en_GB/xml/regVideoConfig.xml",
                siteConfig: "http://www.nike.com/nikefootball/global/xml/videoSiteConfig.xml",
				autoPlay: 'true'
             };

             var flashParams = {
				bgColor: '#ebebeb',
                wmode: 'opaque',
                scale: 'noscale',
                allowScriptAccess: 'always',
                allowFullScreen: 'true'
             };
			 var flashAttributes = {};

            //swfobject.embedSWF("http://www.nike.com/nikeos/global/modules/video/v1/swf/video_player_v2_0.swf", "vid_" + guid, "384", "216", "9", "#ebebeb", flashVars, flashParams, flashAttributes);
			JQ("#vid_" + guid).videoplayer({guid: guid, width: "384", height: "216", locale: GLOBAL_VARIABLES.locale});
			return false;
		});
		
	}
	
	var athletepanelnofilter = this.athletepanelnofilter = function(){
		var list = JQ('#team');
		if(!list.length > 0){
			return;
		}
		list.wrap('<div class="results"></div>');
		
		// May need to add to athletepanel depending on implementation at a later date.
		JQ('#team li').each(function(){
			if(JQ(this).find("a").length > 0){
				JQ(this).click(function(){
					tracking.click(trackerString + 'players>player>click');
					window.location = JQ(this).find("a").attr("href");
				});
			}
		});
	}
	
	var athletepanel = this.athletepanel = function(){
		
		var text = JQ('#team').attr("class");
		if(text != undefined)
			text = text.split('|');
		
		JQ('#team').removeAttr("class");
		var list = JQ('#team');
		if(!list.length > 0){
			return;
		}
		if(list.length == 1 && list.find("li.noplayers").length > 0){
			return;
		}
		var filterTerms = ['','','',''];
		var currentPage = 1;
		var totalPages = null;
		var allAthletes = JQ("ul#team li");
		JQ("ul#team li").css("display","none");
		
		addFilterBar();
		filterList();
		
		JQ('#team li a').live("click", function(){
			tracking.click(trackerString + 'players>player>click');
			window.location = JQ(this).attr("href");
		});
		
		// Set up filter anchors
		JQ('.team li.filter').live("click", function() {
			filterClick(0, 'team', JQ(this));
			return false;
		});
		
		JQ('.national li.filter').live("click", function() {
			filterClick(1, 'national', JQ(this));
			return false;
		});
		
		JQ('.position li.filter').live("click", function() {
			filterClick(2, 'position', JQ(this));
			return false;
		});
		
		JQ('.boot li.filter').live("click", function() {
			filterClick(3, 'boot', JQ(this));
			return false;
		});
		
		// Set up filter remove anchors
		JQ('.team li.remove').live("click", function() {
			filterRemove(0, 'team');
			return false;
		});
		
		JQ('.national li.remove').live("click", function() {
			filterRemove(1, 'national');
			return false;
		});
		
		JQ('.position li.remove').live("click", function() {
			filterRemove(2, 'position');
			return false;
		});
		
		JQ('.boot li.remove').live("click", function() {
			filterRemove(3, 'boot');
			return false;
		});
		
		function filterClick(filterId, filterName, filter){
			if(filterTerms[filterId] != ''){
				clearFilters(filterId);
			}
			filterTerms[filterId] = filter.text().replace(/^\s*|\s*$/g,'');
			filter.addClass('selected');
			filter.parent().parent().addClass('selected');
			JQ('.' + filterName + ' span').text(filterTerms[filterId].toString());
			JQ('.' + filterName + ' li:first').before('<li class="remove"><a href="#">' + JQ('.clearText').text() + ' ' + filterTerms[filterId].toString() + '</a></li>');
			filterList();
		}
		
		function filterRemove(filterId, filterName){
			clearFilters(filterId);
			filterList();
			JQ('.' + filterName + ' li.selected').removeClass('selected');
			JQ('.' + filterName + '.selected').removeClass('selected');
		}
		
		JQ('span.nextpage').live("click", function() {
			if((currentPage+1) <= totalPages){
				showNewPage((currentPage+1));
			}
			return false;
		});
		JQ('span.previouspage').live("click", function() {
			if((currentPage-1) >= 1){
				showNewPage((currentPage-1));
			}
			return false;
		});
		
		JQ('.all').live("click", function() {
			clearFilters();
			filterList();
			return false;
		});
		
		JQ("ul[id='filterList'] > li").hover(
			function() {
				JQ(this).find('ul').show();
				JQ(this).addClass('hover');
			},
			function() {
				JQ(this).find('ul').hide();
				JQ(this).removeClass('hover');
			}
		);
		
		function filterList(){
			var aryToFilter = allAthletes;
			var emptyFilters = 0;
			aryToFilter = jQuery.grep(aryToFilter, function(n, i){
				var searchText = JQ(n).text().toString().toLowerCase();
				for(i=0;i<filterTerms.length;i++){
					if(filterTerms[i] != ''){
						if(searchText.match(filterTerms[i].toLowerCase()) == null){
							return false;
						}
					}
					emptyFilters++;
				}
				return true;
			});
			if(emptyFilters == (allAthletes*4)){
				aryToFilter = allAthletes;
			}
			displayList(aryToFilter);
			
		}
		
		// Clear filter terms
		function clearFilters(filter){
			switch(filter){
				case 0:
					filterTerms[0] = ''; JQ('.team span').text(''); JQ('.team li.remove').remove(); JQ('.team li.selected').removeClass('selected'); JQ('.team.selected').removeClass('selected'); break;
				case 1:
					filterTerms[1] = ''; JQ('.national span').text(''); JQ('.national li.remove').remove(); JQ('.national li.selected').removeClass('selected'); JQ('.national.selected').removeClass('selected'); break;
				case 2:
					filterTerms[2] = ''; JQ('.position span').text(''); JQ('.position li.remove').remove(); JQ('.position li.selected').removeClass('selected'); JQ('.position.selected').removeClass('selected'); break;
				case 3:
					filterTerms[3] = ''; JQ('.boot span').text(''); JQ('.boot li.remove').remove(); JQ('.boot li.selected').removeClass('selected'); JQ('.boot.selected').removeClass('selected'); break;
				default:
					filterTerms = ['','','',''];
					JQ("#filterList span").text('');
					JQ("#filterList li.remove").remove();
					JQ("#filterList li").removeClass('selected');
			}
		}
		
		// Display list of matches from passed in array
		function displayList(aryItems){
			if(aryItems.length > 0){
				var pages = Math.ceil(aryItems.length/12);
			} else {
				var pages = 1;
			}

			list.find('li').fadeOut(200);

			setTimeout(function() {
				list.empty();
				aryItems = jQuery.makeArray(aryItems);
				for(i=0;i<aryItems.length;i++){
					var pageClass = (Math.floor(i/12)+1);
					JQ(aryItems[i]).attr("class","");
					JQ(aryItems[i]).addClass("page-" + pageClass);
					list.append(JQ(aryItems[i]));
				}
				setUpPagination(pages,aryItems.length);
				
			}, 350);
		}
		
		// Set up pagination and athlete count
		function setUpPagination(pageCount,totalItems){
			if(pageCount > 1){
				var pagedBar = 	'<li class="pageination">'
								+ '<p>' + totalItems + ' ' + text[1] + ' &nbsp; '
								+ '<span class="previouspage" style="display:none;"><img src="/nikefootball/assets/bootroom/images/common/btn-previous-page.gif" alt="Previous page" width="16" height="16" /></span> <span class="nextpage"><img src="/nikefootball/assets/bootroom/images/common/btn-next-page.gif" alt="Next page" width="16" height="16" /></span></p>' 
								+ '</li>';
				list.prepend(pagedBar);
				if(totalItems != 0){
					list.append(pagedBar);	
				}
			} else {
				var countBar = 	'<li class="pageination"><p>' + totalItems + ' ' + text[1] + ' &nbsp; </p></li>';
				list.prepend(countBar);
				if(totalItems != 0){
					list.append(countBar);	
				}
			}
						
			list.find('li.page-1').fadeIn(300);
			currentPage = 1;
			totalPages = pageCount;
		}
		
		// Show next/previous page of results
		function showNewPage(newPage){
			list.find('li.page-' + currentPage).fadeOut(300);
							
			if(newPage == totalPages){
				JQ('span.nextpage').attr('style','display:none;');
			} else {
				JQ('span.nextpage').attr('style','');
			}
			
			if(newPage == 1){
				JQ('span.previouspage').attr('style','display:none;');
			} else {
				JQ('span.previouspage').attr('style','');
			}
			
			setTimeout(function() {
				list.find('li.page-' + newPage).fadeIn(300);
			}, 300);
			currentPage = newPage;
		}
		
		// Add filter bar
		function addFilterBar(){
			var getFilterText = list.next().attr("title").split("|");
			
			var getFilterTeamOptions = JQ("ul#team li p span.team");
			var getFilterNationalOptions = JQ("ul#team li p span.national");
			var getFilterPositionOptions = JQ("ul#team li p span.position");
			var getFilterBootOptions = JQ("ul#team li p span.boot");

			list.before('<div class="filter">'
				+ '<strong>' + text[0] + '</strong>'
				+ '<ul id="filterList">'
					+ '<li class="team"><em>' + getFilterText[1] + '</em><span></span>'
						+ '<ul class="sub" style="display:none;">'
							+ makeFilterOptions(getFilterTeamOptions)
						+ '</ul>'
					+ '</li>'
					+ '<li class="national"><em>' + getFilterText[2] + '</em><span></span>'
						+ '<ul class="sub" style="display:none;">'
							+ makeFilterOptions(getFilterNationalOptions)
						+ '</ul>'
					+ '</li>'
					+ '<li class="position"><em>' + getFilterText[3] + '</em><span></span>'
						+ '<ul class="sub" style="display:none;">'
							+ makeFilterOptions(getFilterPositionOptions)
						+ '</ul>'
					+ '</li>'
					+ '<li class="boot"><em>' + getFilterText[4] + '</em><span></span>'
						+ '<ul class="sub" style="display:none;">'
							+ makeFilterOptions(getFilterBootOptions)
						+ '</ul>'
					+ '</li>'
					+ '<li class="all"><em>' + getFilterText[5] + '</em></li>'
				+ '</ul>'
			+ '</div>');
			
			list.wrap('<div class="results"></div>');
			JQ('ul#filterList > li').each(function(){ if(JQ(this).attr('class') == GLOBAL_VARIABLES.filterType){JQ(this).css('display','none')} });
		}
		
		function makeFilterOptions(aryOfOptions){
			var aryOfOptionsSorted = [];
			
			JQ.each(aryOfOptions, function(i, item){
				var optText = JQ.trim(item.innerHTML.replace("|",""));
				if(JQ.inArray(optText, aryOfOptionsSorted) == -1){
					aryOfOptionsSorted.push(optText);
				}
			});
			
			aryOfOptionsSorted = aryOfOptionsSorted.sort();
			
			var strHTML = populateFilterOptions(aryOfOptionsSorted);
			
			return strHTML;
		}
		
		function populateFilterOptions(aryOfOptionsSorted){
			var strHTML = '';
			
			JQ.each(aryOfOptionsSorted, function(i, item){ if(item != ""){ strHTML += '<li class="filter"><a href="">' + item + '</a></li>'; } });
			
			return strHTML;
		}
		
	}
	
	var wallpapers = this.wallpapers = function(){
		
		if(JQ("div#extras p a img").length > 0){
			
			var arySizes = ["1024x768","1280x1024","1680x1050"];
			
			JQ("div#extras p.wallpaper").each(function(){
				var wallpaperSrc = JQ(this).find("a").attr("href");
				wallpaperSrc = wallpaperSrc.replace("downloads","wallpapers");
				wallpaperSrc = wallpaperSrc.replace("nikefootball","nikefootball/content");
				var wallpaperHTML = '<span class="wallpaperoverlay"><img src="/nikefootball/assets/bootroom/images/common/overlay-hr-top.gif" class="hrTop" alt="" />';
				for(i=0;i<arySizes.length;i++){
					wallpaperHTML += '<a href="' + wallpaperSrc.replace(".zip", "_" + arySizes[i] + ".jpg") + '" target="_blank">' + arySizes[i].replace(/x/i," X ") + '</a>';
				}
				wallpaperHTML += '<img src="/nikefootball/assets/bootroom/images/common/overlay-hr-base.gif" class="hrBase" alt=""/></span>';
				JQ(this).append(wallpaperHTML);
				JQ(this).find("a:first").replaceWith(JQ(this).find("img:first"));
				Cufon.set('fontFamily', 'Helvetica Bold Cond');
				Cufon.replace('span.wallpaperoverlay a');
			
				JQ(this).find("span.wallpaperoverlay").fadeTo("fast",0);
				
				JQ(this).mouseenter(function(){
					JQ(this).find("span.wallpaperoverlay").fadeTo("slow",0.75);
				});
				
				JQ(this).find("span.wallpaperoverlay").mouseleave(function(){
					JQ(this).fadeTo("slow",0);
				});
				
			});
			
			
		}
	
	}
	
	var comments = this.comments = function(){

		var commentData = JQ("ul#commentsfeed li");
		var index = 0;
			
		function displayComments(commentData) {
						
			JQ("ul#commentsfeed").empty();
			
			//index = commentData.length-6;
			for (i = 0; i < 5; i++) {
				var item = commentData[i];
				JQ('ul#commentsfeed').prepend(item);
			}
			
			JQ("ul#commentsfeed li:first").addClass("highlight");
			//highlightComment(JQ('ul#commentsfeed li:first'));
			
			index--;
		}

		function refresh() {
			
			if (index >= 0) {
				var item = commentData[index];
				
				JQ('ul#commentsfeed').prepend(item);
				
				/* Animate old content out */
				JQ('ul#commentsfeed li:last').fadeOut(1200, function() { JQ(this).remove(); });
									
				/* Animate new comment in */
				var height = JQ('ul#commentsfeed li:first').height();
				JQ('ul#commentsfeed li:first').css({
					marginTop: '-' + height + 'px', 
					'visibility': 'visible',
					'opacity': '0'
				}).animate({
					marginTop: '0px',
					'opacity': '1'
				}, 1200, function() {
					//highlightComment(JQ('ul#commentsfeed li:first'));
				});
				
				index--;
			}
		}
			
		function highlightComment(targetComment){
			var oldHighlight = JQ('.highlight:eq(0)');
			
			if(targetComment.hasClass("highlight")){
				return;
			}
			
			if(oldHighlight[0] != undefined){
				oldHighlight.animate({opacity:0.3}, {queue:true, duration:500});
				oldHighlight.find("div.body").slideToggle(500, function(){ 
					oldHighlight.removeClass("highlight");
					oldHighlight.find("div.body").slideToggle(400, function(){ 
						oldHighlight.animate({opacity:1}, {queue:true, duration:500}); });
				});
				animateNewHighlight(targetComment);
				
			} else {
				animateNewHighlight(targetComment);
			}
			
		}
		
		function animateNewHighlight(newHighlight){
			newHighlight.animate({opacity:0.3}, {queue:true, duration:400});
			newHighlight.find("div.body").slideToggle(400, function(){ 
				newHighlight.addClass("highlight");
				newHighlight.find("div.body").slideToggle(400, function(){ 
					newHighlight.animate({opacity:1}, {queue:true, duration:400}); });
			});

		}
		
		JQ('ul#commentsfeed li').live("click", function() {
			highlightComment(JQ(this));
		});
		
		JQ('ul#commentsfeed li').live("mouseover", function() {
			JQ(this).addClass('itemhighlight');
		});
		JQ('ul#commentsfeed li').live("mouseout", function() {
			JQ(this).removeClass('itemhighlight');
		});
		
		if(commentData.length < 5){
			JQ("ul#commentsfeed li:first").addClass("highlight");
			return;
		}
		
		/*var countdown = 30;
		setInterval(function() {
			countdown--;
			if (!countdown) {
				countdown = 15;
				refresh();
			}	
		}, 1000);*/
		
		displayComments(commentData);

	}
	
	
	
	var mostpopularpanel = this.mostpopularpanel = function(){
		
		if(JQ("div.mostpopular").length > 0){
			JQ("div.mostpopular").each(function(i){
				JQ(this).find("div:first").css({overflow:"hidden",height:"177px"});
				
				var path = "/nikefootball/global/swf/modules/mostpopular/v1_0/Application.swf";
				var swfHeight = "177px";
				var swfWidth = "878px";

				var so = new SWFObject(path, "popularFlash", swfWidth, swfHeight, "9", "#ebebeb");
				so.addParam("allowScriptAccess","always");
				so.addParam("base", "/nikefootball/global/swf/modules/mostpopular/v1_0/");
				so.addParam("allowFullScreen", "true");
				so.addParam("scale", "scale");
				so.addParam("wmode", "opaque");
				so.addParam("bgColor", "#ebebeb");
				so.addVariable("locale", GLOBAL_VARIABLES.locale);
				so.addVariable("trackerObj", tracker_obj);
				so.write("mostpopular");

			});
		}
	
	}
	
	var heropanel = this.heropanel = function(){
		
		JQ("div#flashPanel").removeAttr("title");
		var swfWidth = "910px";
			
		if (JQ("div#flashVive").length > 0 ) {
		
			var path = "/nikefootball/content/teams/flash/nationalkits/vive_le_football_libre/bin/main.swf";
			var lang = GLOBAL_VARIABLES.locale.split("_")[0];
			
			var swfHeight = JQ("div#flashVive").attr("title") + "px";
			JQ("div#flashVive").removeAttr("title");
			
			var so = new SWFObject(path, "heroFlash", swfWidth, swfHeight, "9", "#000000");
			so.addParam("allowScriptAccess","always");
			so.addParam("base", "/nikefootball/global/swf/modules/contentpage/application/v1_0_0/");
			so.addParam("allowFullScreen", "true");
			so.addParam("scale", "scale");
			so.addParam("wmode", "opaque");
			so.addParam("bgColor", "#000000");
			so.addParam("width", "910");
			so.addParam("height", "1040");
			so.addVariable("application", GLOBAL_VARIABLES.flashApplication);
			so.addVariable("pageType", GLOBAL_VARIABLES.flashType);
			so.addVariable("pageName", GLOBAL_VARIABLES.flashName);
			so.addVariable("locale", GLOBAL_VARIABLES.locale);
			so.addVariable("fv_config", "/nikefootball/content/teams/flash/nationalkits/vive_le_football_libre/xml/conf-" + lang +".xml");
			so.addVariable("trackerObj", tracker_obj);
			so.addVariable("commerceLocale", Bootroom.commercelocale());
			so.addVariable("commerceCountry", Bootroom.commercecountry());
			so.addVariable("commerceEnabledCountries", "GB|US|DK|FI|GR|HU|IE|IT|LU|NL|PL|PT|SI|ES|SE|CZ|DE|AT|ES|FR|BE|PT|PL");
			so.write("flashVive");	
			
			if (JQ('#flashVive noscript').length > 0) {
				JQ('#flashVive div').append('<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Download Adobe Flash Player"><img src="/nikefootball/emea/' + GLOBAL_VARIABLES.locale + '/image/no_flash.jpg" alt="Download Adobe Flash Player" /></a>');
			}
		}
		else {
			var path = "/nikefootball/global/swf/modules/contentpage/application/v1_0_0/BootroomContentPage.swf";
			
			var swfHeight = JQ("div#flashInner").attr("title") + "px";
			JQ("div#flashInner").removeAttr("title");
			
			
			var so = new SWFObject(path, "heroFlash", swfWidth, swfHeight, "9", "#333333");
			so.addParam("allowScriptAccess","always");
			so.addParam("base", "/nikefootball/global/swf/modules/contentpage/application/v1_0_0/");
			so.addParam("allowFullScreen", "true");
			so.addParam("scale", "scale");
			so.addParam("wmode", "opaque");
			so.addParam("bgColor", "#333333");
			so.addVariable("application", GLOBAL_VARIABLES.flashApplication);
			so.addVariable("pageType", GLOBAL_VARIABLES.flashType);
			so.addVariable("pageName", GLOBAL_VARIABLES.flashName);
			so.addVariable("locale", GLOBAL_VARIABLES.locale);
			so.addVariable("trackerObj", tracker_obj);
			so.addVariable("commerceLocale", Bootroom.commercelocale());
			so.addVariable("commerceCountry", Bootroom.commercecountry());
			so.addVariable("commerceEnabledCountries", "GB|US|DK|FI|GR|HU|IE|IT|LU|NL|PL|PT|SI|ES|SE|CZ|DE|AT|ES|FR|BE|PT|PL");
			so.write("flashInner");	
			
			if (JQ('#flashInner noscript').length > 0) {
				JQ('#flashInner div').append('<a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Download Adobe Flash Player"><img src="/nikefootball/emea/' + GLOBAL_VARIABLES.locale + '/image/no_flash.jpg" alt="Download Adobe Flash Player" /></a>');
			}

		}
	}
	
	var replacetext = this.replacetext = function(){
		
		// IE does not support a hover state on links - generates errors when clicked
		var useHover = true;
		if(JQ.browser.msie){
			useHover = false;
		}
	
		// List of text/elements Cufon replaces
		// Exceptions:	- tabs are called from JS that generates them [Bootroom.tabs()]
		if (useSiteFont == 1) {
			Cufon.set('fontFamily', 'Rockwell');
				// See exceptions above //Cufon.replace('div.tabtriggers ul li a', { hover: true });
				
			Cufon.set('fontFamily', 'Rockwell Bold');
				Cufon.replace('div#pagesearch div.searchbox div')('h2 > span')('div.bootfinder span a', { hover: useHover });
				
			Cufon.set('fontFamily', 'Helvetica Bold Cond');
				Cufon.replace('a.btn-download-pdf', { hover: useHover })('div.bootfinder a.btn-bootfinder', { hover: useHover });
				
			Cufon.set('fontFamily', 'Helvetica Neue');
				Cufon.replace('a.btn-register')('div.tabcontentlink a', { hover: useHover });//('h2 a span');
		}
		else if (useSiteFont == 2) {
			Cufon.set('fontFamily', 'Arial');
			Cufon.replace('div#pagesearch div.searchbox div')('h2 > span')('div.bootfinder span');
			Cufon.replace('a.btn-download-pdf', { hover: useHover })('div.bootfinder a', { hover: useHover });
			Cufon.replace('a.btn-register')('div.tabcontentlink a', { hover: useHover });
		}
	}
	
	var commercecountry = this.commercecountry = function(){
	
		var cookie = "NIKE_COMMERCE_COUNTRY";
		var countrycode = "";
		var index = -1;
		
		if((index = document.cookie.indexOf(cookie)) != -1) {
			countrycode = document.cookie.substring(index+cookie.length+1).substring(0,2);
		}
		
		return countrycode;	
	
	}

    var commercelocale = this.commercelocale = function(){

        var cookie = "NIKE_COMMERCE_LANG_LOCALE";
        var localecode = "";
        var index = -1;

        if((index = document.cookie.indexOf(cookie)) != -1) {
            index = index + cookie.length + 1;
            localecode = document.cookie.substring(index, document.cookie.indexOf(';', index));
        }

        return localecode;

    }

	// Tracking event handler for any links that don't already have click events bound
	var bindTracking = this.bindTracking = function() {
		// Initialise the tracker string prefix
		localePrefix = nav_tracker_obj.prefix;
		
		if (GLOBAL_VARIABLES.collectionName == "bootroom") {
			trackerString = localePrefix + "bootroom>";
		}
		else if (GLOBAL_VARIABLES.collectionName == "boots") {
			trackerString = localePrefix + "bootroom>boots>";
		}
		else if (GLOBAL_VARIABLES.flashType == "clubkits") {
			trackerString = localePrefix + "teams>clubkits>";
		}
		else if (GLOBAL_VARIABLES.flashType == "nationalkits") {
			trackerString = localePrefix + "teams>nationalkits>";
		}
		else if (GLOBAL_VARIABLES.flashType == "training") {
			trackerString = localePrefix + "bootroom>training_gear>";
		}
		else if (GLOBAL_VARIABLES.flashType == "nikepro") {
			trackerString = localePrefix + "bootroom>nike_pro>";
		}
		else if (GLOBAL_VARIABLES.flashType == "equipment") {
			trackerString = localePrefix + "bootroom>equipment>";
		}
		else if (GLOBAL_VARIABLES.flashType == "players") {
			trackerString = localePrefix + "players>";
		}
		else if (GLOBAL_VARIABLES.collectionName == "players") {
			trackerString = localePrefix + "players>";
		}
		else {
			trackerString = localePrefix + "bootroom>";
		}
		
		/** 
			Most of the tracking click event captures (some are also within existing event handlers)
		**/
		// Bootfinder link
		JQ('.bootfinder a').click(function() {
			tracking.click(localePrefix + 'bootroom>bootfinder>click','e');
		});
		
		// Community - Comments RSS
		JQ('#comments h2 a').click(function() {
			tracking.click(trackerString + 'community>rss');
		});
		// Community - View Comment link 
		JQ('#comments #commentsfeed li .head a').click(function() {
			tracking.click(trackerString + 'community>view_comment_' + JQ(this).text());
		});
		JQ('#comments #commentsfeed li .body .timestamp a').click(function() {
			tracking.click(trackerString + 'community>view_comment_' + JQ(this).text());
		});
		
		// Latest Media RSS
		JQ('#media .leftcol h2 a').click(function() {
			tracking.click(trackerString + 'media_feed>rss');
		});
		
		// Latest Media Facebook & Twitter links
		// See function generateShareLinks
		
		// Latest media video play
		JQ('#blogfeed li .video a').click(function() {
			tracking.click(trackerString + 'media_feed>play>' + JQ(this).closest('li.blog').find('.post h3 a').text());
		});

		// Latest media article link out
		JQ('#blogfeed .blog .asset:not(.video) a').click(function() {
			tracking.click(trackerString + 'media_feed>click>' + JQ(this).closest('li.blog').find('.post h3 a').text());
		});
		JQ('#blogfeed .blog h3 a').click(function() {
			tracking.click(trackerString + 'media_feed>click>' + JQ(this).text());
		});
		
		// Latest media article view/post comments
		JQ('#blogfeed .blog .post .links li.viewcomment a').click(function(){	
			tracking.click(trackerString + 'media_feed>view_comments>' + JQ(this).closest('div.post').find('h3').text());
		});
		JQ('#blogfeed .blog .post .links li.postcomment a').click(function(){	
			tracking.click(trackerString + 'media_feed>post_comments>' + JQ(this).closest('div.post').find('h3').text());
		});
		
		// Players tab - Player click
		//JQ('#wornby .athletepanel .team li a').click(function() {
			// see function athletepanelnofilter
		//});
		
		// Extras tab 
		JQ('#extras .wallpaper a').live('click', function() {
			tracking.click(trackerString + 'extras>download');
		});
		
		// Left tout click
		JQ('#tout-1 a').click(function() {
			tracking.click(trackerString + 'tout_left>' + this.id);
		});
		// Right tout click
		JQ('#tout-2 a').click(function() {
			tracking.click(trackerString + 'tout_right>' + this.id);
		});
		
		// Footer - Store Locator link
		JQ('#footer_link_store_locator').click(function() {
			tracking.click(localePrefix + '>store_locator');
		});
		
		// Footer - Privacy link
		JQ('#footer_content_privacy').click(function() {
			// see init() funtion
		});
	}
	
	// quick function to show / hide the fb 'like' button when the 
	// lightbox gallery viewer is launched by the flash
	var togFbBtn = this.togFbBtn = function(){
		JQ('#fbLikeButtId').toggle();
	};	
	
	
};
/*
function setMenuArea(id, width, height) {
	JQ("#" + id).width(width+'px').height(height+'px'); 
}*/
