/**
 * @author scottkosman
 */

var adidasPop = {		
		// gets the id of the page and loads common elements (header, navbar, footer)   
		getPageName: function(data) {
			
			var pagename = $("html").data("pagename");
			var navbarParams = {};
			if($("body").attr("id") != "shortBody") {
				$("<div id='bgCap'></div>").prependTo("body");
				$("<div id='topgradContainer'><div id='topgrad'></div></div>").prependTo("body");
				$("<div id='bottomgrad'></div>").appendTo("#header");
		 		$("#topgradContainer").supersleight();
				$("#header").supersleight();
				var navbarParams = {wmode:"transparent"};
			}
			
			$.each(data, function(i,item) {
				for (x in item) {
					if (x == "pageid" && item.pageid == $("html").data("pagename")) {
						if (this.header[0].type == "single")  {
							$("<img />").attr("src", this.header[0].media).appendTo("#header");
						} else if (this.header[0].type == "flash") {
							
							//var and if statement are for Products page to show correct masthead based on collection
							var coll = getQs("collection");
							
							if ($("html").data("pagename") == "products" && coll == "techfit") { //
								$("<div>").attr("id",this.header[1].mediaID).appendTo("#header");
								var flashvars = createFlashVars(this.header[1]);
								var params = {wmode:"transparent", scale:"noScale", salign:"lT"};
								swfobject.embedSWF(this.header[1].media, this.header[1].mediaID, this.header[1].width, this.header[1].height, "9.0.0", false, flashvars,params);
							} else {
								$("<div>").attr("id",this.header[0].mediaID).appendTo("#header");
								var flashvars = createFlashVars(this.header[0]);
								var params = {wmode:"transparent", scale:"noScale", salign:"lT"};
								swfobject.embedSWF(this.header[0].media, this.header[0].mediaID, this.header[0].width, this.header[0].height, "9.0.0", false, flashvars,params);
							}

							
						} else if (this.header[0].type == "crossfade") {
							for (x in this.header[0].media) {
								var eachImg = $("<img />").attr("src",this.header[0].media[x]);
								var div = $("<div>").attr("id","cf"+x);
								eachImg.appendTo(div);
								div.appendTo("#header");
							}
							var cf = new Crossfader( new Array('cf0','cf1'), 1000, 4000 );
						}
					}
				}
			});
			
			
			//build navbar <ul> which will then be replaced by Flash navbar. This is a fallback in case no flash plugin is available (iPhones, etc.)
			$.each(data.navigation, function(i, item) {	
				var anchor = $("<a>").attr("href",item.url).html(item.title);
				var listItem = $("<li>");
				anchor.appendTo(listItem);
				listItem.appendTo("#navbar");
			});			
			
			
			var flashvars = {locale: locale, section: pagename, country: adidas_cc, configFile:"content/assets/xml/lang/"+locale+"/Navigation.xml", index: pagename=="index", techfit: pagename=="techfit", clima365: pagename=="clima365", products: pagename=="products", shopnow: pagename=="shopnow"};
			var navbarParams = {wmode:"transparent", scale:"noScale", salign:"lT"};
			// params set at beginning of this function
			swfobject.embedSWF("swf/com.adidas.core.Application.swf", "navbar", "976", "44", "9.0.0", false, flashvars,navbarParams);
		},
			
		
		isLocaleData: function(data,page) { //Check for locale data portlets
			if(data.locale) {				
				if(data.locale[page]) {
					return true;
				}
			}
			return false;
		},
		
		indexPortlet: function(item,target) {
			//Check for Local Data to Overwrite portlet. 						
			var w = item.width;
			switch(w) {
				case "0.25":
					var moduleWidth = "240px";
					break;
				case "0.3":
					var moduleWidth = "320px";
					break;
				case "0.5":
					var moduleWidth = "480px";
					break;
				case "1":
					var moduleWidth = "100%";
					break;
				default:
					var moduleWidth = "100%";
					break;
			}
			
		
				if(target == "#locale") var divClass = "localePortletDiv";
				else var divClass = "portletDiv";
				
				item.backgroundoffset ? os=item.backgroundoffset : os="left";
							
				var div = $("<div>").attr("id",item.title).attr("class",divClass).attr("style","width:"+moduleWidth+";height:"+item.height+"; background: url("+item.media+") "+os+" top no-repeat;");
				
				if (item.offset) {
					var offset = item.offset;
					if(item.headline) $("<h2>").text(item.headline).css('margin-left', offset).appendTo(div);
					if(item.subhead) $("<h3>").text(item.subhead).css('margin-left', offset).appendTo(div);
					if(item.copy) $("<p>").html(item.copy).css('margin-left', offset).appendTo(div);
				} else {					
					if(item.headline) $("<h2>").text(item.headline).appendTo(div);
					if(item.subhead) $("<h3>").text(item.subhead).appendTo(div);
					if(item.copy) $("<p>").html(item.copy).appendTo(div);
				}
				
				if (item.button) {
					$("<div>").addClass("buttonHolder").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+item.url+"\">"+item.button+"</a></div>").appendTo(div);
				};

				if (item.dualbutton) {
					var dbh = $("<div>").addClass("dualbuttonHolder").appendTo(div)
					$("<div>").addClass("leftbutton").html("<a href=\""+item.dualbutton[0].lefturl+"\">"+item.dualbutton[0].leftcopy+"</a>").appendTo(dbh);
					$("<div>").addClass("rightbutton").html("<a href=\""+item.dualbutton[0].righturl+"\">"+item.dualbutton[0].rightcopy+"</a>").appendTo(dbh);
				};
				
				if (item.link) {
					offset ? left=offset : left="0";
					$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left: "+left).html(item.link).appendTo(div);
				}
				
				div.appendTo(target);				
			
		},	
		
		equalHeights: function(group) {
			tallest = 0;
		    group.each(function() {
		        thisHeight = $(this).height();
		        if(thisHeight > tallest) {
		            tallest = thisHeight;
		        }
		    });
		    group.height(tallest);
		},
		
		applyFb: function() {
			$("a.thumbs").fancybox({
				//'zoomOpacity' : true, //Commented out due to IE6 JS errors
				'overlayShow' : true,
				'zoomSpeedIn' : 500,
				'zoomSpeedOut' : 500
			});

			$("a.adivid").fancybox({
				'overlayShow': true
			});
			
		},
	
		populateIndex: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			$('body').attr('class','index');
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);				
					//populate body content
					
		          	$.each(data.index.portlets, function(i,item){
						var w = item.width;
						switch(w) {
							case "0.25":
								var moduleWidth = "25%";
								break;
							case "0.5":
								var moduleWidth = "480px";
								break;
							case "1":
								var moduleWidth = "100%";
								break;
							default:
								var moduleWidth = "100%";
								break;
						}

							if (item.type == "flash") {	
								var div = $("<div>").attr("id",item.title).attr("class","portletDiv").attr("style","width:"+moduleWidth+";height:"+item.height+";");
								
								div.html("<a href='"+item.noflashUrl+"'><img src='"+item.noflash+"' alt='"+item.noflashAlt+"' /></a>");
								
								div.appendTo("#bodycontent");
						
								var flashvars = createFlashVars(item);
								var launcher = item.media;
								
/*
								if (item.launcher == "self") {
									var flashvars = {locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/"};
									var launcher = item.media;
								} else {
									var flashvars = {application: item.media, locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/"};
									var launcher = item.launcher;
								};
*/
								var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent"};
								swfobject.embedSWF(launcher, item.title, moduleWidth, item.height, "9.0.0", false,flashvars,params,{type:"application/x-shockwave-flash"});
								
								if (item.textContent) {
									$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
								};

							} else if (item.type == "img")  {

								var div = $("<div>").attr("id",item.title).attr("class","portletDiv").attr("style","width:"+moduleWidth+";height:"+item.height+"; background: url("+item.media+") left top no-repeat;");
								div.appendTo("#bodycontent");
							
							} else {
								var div = $("<div>").attr("id",item.title).attr("class","portletDiv").attr("style","width:"+moduleWidth+";height:"+item.height+"; background: url("+item.media+") left top no-repeat;");
								
								if (item.title == "seamless") {
									$("<img />").addClass("logo").attr("src",item.headline).appendTo(div);
								} else {
									$("<h2>").text(item.headline).appendTo(div);
								}
								
								$("<h3>").text(item.subhead).appendTo(div);
								$("<p>").html(item.copy).appendTo(div);
								
								if (item.button) {										
									if (item.buttoncolor)
										$("<div>").addClass("buttonHolder").addClass("button"+item.buttoncolor).html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+item.url+"\">"+item.button+"</a></div>").appendTo(div);							
									else											
										$("<div>").addClass("buttonHolder").addClass("buttonBlack").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+item.url+"\">"+item.button+"</a></div>").appendTo(div);																		
								};

								if (item.dualbutton) {
									var dbh = $("<div>").addClass("dualbuttonHolder").appendTo(div)
									$("<div>").addClass("leftbutton").html("<a href=\""+item.dualbutton[0].lefturl+"\">"+item.dualbutton[0].leftcopy+"</a>").appendTo(dbh);
									$("<div>").addClass("rightbutton").html("<a href=\""+item.dualbutton[0].righturl+"\">"+item.dualbutton[0].rightcopy+"</a>").appendTo(dbh);
								};
								
								if (item.link) {
									$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left: 20px").html(item.link).appendTo(div);
								}
								div.appendTo("#bodycontent");
														
							}

			        });
					
					if (adidasPop.isLocaleData(data,"index")) {						
						if (data.locale.index.portlets) {									
					
							$("<div>").attr("id","locale").appendTo("#bodycontent"); //Create Locale Bar
											
							$.each(data.locale.index.portlets, function(i,item){ //Loop locale portlets and add										
								adidasPop.indexPortlet(item,"#locale");										
							});
						}
					}	
				//populate localized content
				//Localized content not launching with initial site launch, so removed for now: 20/05/09 - SK
					
				/*	
					$.each(data.index.local, function(i, item) {	
						var content = $("<img />").attr("src", item.media);
						var div = $("<div>").attr("id",item.title).css("float","left");
						content.appendTo(div);
						div.appendTo("#local");
					});
				*/
						
					//Add clearing Div
					var clear = $("<div>").attr("class","clear");
					clear.appendTo("#bodycontent");
					if (data.index.legal) {
						$("<div>").addClass("legal").html(data.index.legal).appendTo("#bodycontent");
						var clear2 = $("<div>").attr("class","clear");
						clear2.appendTo("#bodycontent");
					}												
		   		});				
		  	},
		
		populateAthletes: function(who){
			$("body").addClass("index");
			
			var who = getQs("athlete") ? getQs("athlete") : "mario";
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
					function(data){	
					$("html").data("data",data);
					adidasPop.getPageName(data);		
					//populate left-hand column
					$.each(data[who].sidebar, function(i, item) {	
						for (x in item) {
							if (item.title == $("html").data("pagename")) {
								var bkgd = item.active;
							} else {
								var bkgd = item.media;
							};
						};
						//var pads = "padding-left:"+item.alignleft+"; padding-top:"+item.aligntop+";";
						var a = $("<a>").addClass("ps_"+item.title).attr("href",item.url).html(item.subhead+"<br /><span>"+item.athlete+"</span>");
						var li = $("<li>").attr("id",item.title).attr("style","background: url("+bkgd+") left top no-repeat;");

						a.appendTo(li);
						li.appendTo("#personalitiesSubnav");
						a.hover(
							function() {
								a.attr("style","background: url("+item.active+") left top no-repeat;");
							},
							function() {
								a.attr("style","background: none;");
						});
					});
					//populate main column content
					$.each(data[who].centerContent,function(i,item) {
						$("#rightContent").html(item.copy);
					});
					
					//populate social media links
					if(data[who].social) {
						$("<h2>").html("Links").addClass("socialHeader").appendTo("#rightContent");
						var ul = $("<ul>").addClass("social");						
						$.each(data[who].social,function(i,item) {
							var li = $("<li>");
							$("<a>").addClass(item.type).html(item.copy).attr("href",item.href).attr("target","_blank").appendTo(li);
							li.appendTo(ul);
						});
						ul.appendTo("#rightContent");
					}

					$.each(data[who].rightContent,function(i,item) {
					
						var w = item.width;
						switch(w) {
							case "0.25":
								var moduleWidth = "225px";
								break;
							case "0.5":
								var moduleWidth = "50%";
								var paragraphWidth = "240px";
								break;
							case "1":
								var moduleWidth = "100%";
								var paragraphWidth = "390px";
								break;
							default:
								var moduleWidth = "100%";
								break;
						}
					
						var galleries = $("<div>").attr("id","galleries").appendTo("#sidebar");
						
						//Video Gallery
						if(item.videoGallery) {
						
							$("<h2>").html("Video Gallery").appendTo("#galleries");
							
							$("<div>").attr("id","videoGallery").appendTo("#galleries");
							
							var flashvars = createFlashVars(item.videoGallery[0]);
							flashvars.swf = "swf/com.adidas.core.Application.swf";
							
					
							
							var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent", scale:"noScale", align:"lT" };
							swfobject.embedSWF(item.videoGallery[0].media, "videoGallery", item.videoGallery[0].width, item.videoGallery[0].height, "9.0.0", false, flashvars,params);
							
						}							
						
						//Photo Gallery
						if(item.photoGallery){
							$("<h2>").html("Photo Gallery").appendTo("#galleries");
							var ul = $("<ul>").attr("id","photoGallery");
							for (x in item.photoGallery) {
								var li = $("<li>");
								var content = $("<img />").attr("src", item.photoGallery[x].media);
								//var div = $("<div>").attr("id",item.photoGallery[x].title);
								//console.log(item.photoGallery[x].title)
								if (item.photoGallery[x].fancybox) {
									if (item.photoGallery[x].fancybox == "image") {
										var anchor = $("<a>").attr({"href":item.photoGallery[x].url,"rel":"group"}).addClass("thumbs");
										content.appendTo(anchor);
										anchor.appendTo(li);
										li.appendTo(ul);
										
									} else {
										content.appendTo(div);
									};
								} else {
									content.appendTo(div);
								};
							};
							ul.appendTo("#galleries");
							$("#photoGallery").paginate();
						}
						$("a.thumbs").fancybox({
							'zoomOpacity' : true,
							'overlayShow' : true,
							'zoomSpeedIn' : 500,
							'zoomSpeedOut' : 500
						});
						
						$("<div>").attr("id","sideBarTout").appendTo("#sidebar");
						
						
						var flashvars = createFlashVars(data[who].sidebarFlash[0]);
						//flashvars.swf = "swf/com.adidas.core.Application.swf";
							
						var params = {wmode:"transparent", scale:"noScale", salign:"lT" };
						swfobject.embedSWF(data[who].sidebarFlash[0].media, "sideBarTout", data[who].sidebarFlash[0].width, data[who].sidebarFlash[0].height, "9.0.0", false, flashvars,params);
							
						
						if(item.featuredProduct) {
							var fpdiv = $("<div>").attr({'id': 'featured-product'});
							$("<h3>").html(item.featuredProduct.title).appendTo(fpdiv);
							$("<img />").attr({'src': item.featuredProduct.media, 'alt': item.featuredProduct.title}).appendTo(fpdiv);
							$("<div id='athletesButton'>").html("<div class=\"left\"><a class=\"featuredButtonLeft\" href=\""+item.featuredProduct.buttonLeftUrl+"\">"+item.featuredProduct.buttonLeft+"</a></div><div class=\"right\"><a class=\"featuredButtonRight\" href=\""+item.featuredProduct.buttonRightUrl+"\">"+item.featuredProduct.buttonRight+"</a></div><div class='clear'></div>").appendTo(fpdiv);
							//$("<div class='clear'></div>").appendTo("#sidebar");
							fpdiv.appendTo("#sidebar");
						}
						
						adidasPop.applyFb();
					});
					//Add clearing Div
					var clear = $("<div>").attr("class","clear");
					clear.appendTo("#bodycontent");
					
				});
		},
		populateAthletes2: function(who) {
			$('body').attr('class','athletes');
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					var pagename =who;
					$("html").data("data",data);
					adidasPop.getPageName(data);
					$.each(data.athletes[who].sidebar, function(i, item) {	
						for (x in item) {
							if (item.title == $("html").data("pagename")) {
								var bkgd = item.active;
							} else {
								var bkgd = item.media;
							};
						};
						//var pads = "padding-left:"+item.alignleft+"; padding-top:"+item.aligntop+";";
						var a = $("<a>").addClass("ps_"+item.title).attr("href",item.url).html(item.subhead+"<br /><span>"+item.athlete+"</span>");
						var li = $("<li>").attr("id",item.title).attr("style","background: url("+bkgd+") left top no-repeat;");

						a.appendTo(li);
						li.appendTo("#personalitiesSubnav");
						a.hover(
							function() {
								a.attr("style","background: url("+item.active+") left top no-repeat;");
							},
							function() {
								a.attr("style","background: none;");
						});
					});
					//populate main column content
					$.each(data[who].centerContent,function(i,item) {
						$("#rightContent").html(item.copy);
					});
					
					//populate social media links
					if(data.athletes[who].social) {
						$("<h2>").html("Links").addClass("socialHeader").appendTo("#rightContent");
						var ul = $("<ul>").addClass("social");						
						$.each(data[who].social,function(i,item) {
							var li = $("<li>");
							$("<a>").addClass(item.type).html(item.copy).attr("href",item.href).attr("target","_blank").appendTo(li);
							li.appendTo(ul);
						});
						ul.appendTo("#rightContent");
					}

					$.each(data.athletes[who].portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "0.75":
									var moduleWidth = "705px";
									var paragraphWidth = "390px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "100%";
									break;
							}

							if (item.type == "flash") {	

								var div = $("<div>").attr("id",item.title);
								
								div.appendTo("#sidebar");

								var flashvars = createFlashVars(item);
								flashvars.play = "true";
								flashvars.loop = "true";
								flashvars.scale = "showall";
								var launcher = item.media;

								
								var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent", scale:"noScale", salign:"lT"};
								swfobject.embedSWF(launcher, item.title, moduleWidth, item.height, "9.0.0", false,flashvars,params);
								
								if (item.textContent) {
									$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
								};

							} else if(item.type == "photoGallery") {
								var galleries = $("<div>").attr("id","galleries").appendTo("#sidebar");
						
								//Photo Gallery
								$("<h2>").html("Photo Gallery").appendTo("#galleries");
								var ul = $("<ul>").attr("id","photoGallery");
								for (x in item.imageSet) {
									var li = $("<li>");
									var content = $("<img />").attr("src", item.imageSet[x].media);
									if (item.imageSet[x].fancybox) {
										if (item.imageSet[x].fancybox == "image") {
											var anchor = $("<a>").attr({"href":item.imageSet[x].url,"rel":"group"}).addClass("thumbs");
											content.appendTo(anchor);
											anchor.appendTo(li);
											li.appendTo(ul);
											
										} else {
											content.appendTo(div);
										};
									} else {
										content.appendTo(div);
									};
								};
								ul.appendTo("#galleries");
								$("#photoGallery").paginate();
								$("a.thumbs").fancybox({
									'zoomOpacity' : true,
									'overlayShow' : true,
									'zoomSpeedIn' : 500,
									'zoomSpeedOut' : 500
								});
							} else {
						
								if (item.backgroundoffset) {
									var bgoffset = item.backgroundoffset;
								} else {
									var bgoffset = "left";
								};
	
								var div = $("<div>").attr("id",item.title).attr("style","width:"+moduleWidth+"; height:"+item.height+"; background: url("+item.media+") "+bgoffset+" top no-repeat;");
								$("<h3>").html(item.headline).appendTo(div);
								$("<div>").addClass("text").html("<p>"+item.copy+"</p>").attr("style","width:"+paragraphWidth).appendTo(div);
								if (item.button) {
									$("<div>").addClass("buttonTechfit").html("<a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a>").appendTo(div);
								};	
	
								if (item.link) {
									var link = item.link;
									var newLink = link.replace("{0}",item.headline);
									if (item.collection) {
										if (fv !=false) {
										}
									} else {
									$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left:"+offset).html(newLink).appendTo(div);
									};
								};
								div.appendTo("#sidebar");
							};
					});
				},
				
			$("#loading").hide());
			//Add clearing Div
			var clear = $("<div>").attr("class","clear");
			clear.appendTo("#bodycontent");
		},
		
		
			populateCollections: function() {
//				var locale = getQs("locale");
//				if (locale == "") {locale = "en-en"};
				var fv = getFlashVersion();
			$('body').attr('class','clima');
				$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
					function(data){
						$("html").data("data",data);
						adidasPop.getPageName(data);
						
						
						$("img.collThumbs").live("click", function() {
							if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
								if (!galleryViewed) {
									var colltop = ($(document).scrollTop())+"px";
								} else {
									var collTop = "0"
								}
							} else {
								var colltop = "0";
							}
							
							$("<div id='collGallery'></div><div id='collPop'></div>").prependTo("body");
							$("").supersleight();
							var imgId = $(this).attr("rel");
							var flashvars = {startupImageName: imgId, collection: "adilibra", countryCode:adidas_cc, pidUrl: pidWsdl, locale: locale, countryCode:adidas_cc};
							var params = {wmode:"transparent", base:"swf/collectionsFPV",salign:"lt"};
							swfobject.embedSWF("swf/collectionsFPV/swf/Main.swf", "collPop", "100%", "100%", "9.0.0", false, flashvars,params);		
							$("#collPop").css("top",colltop);
							var galleryViewed = "1";
						}).live("mouseover",function() {$(this).css("cursor","pointer")});
						
						$("a.collGalleryPop").live("click", function() {
							if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
								if (!galleryViewed) {
									var colltop = ($(document).scrollTop())+"px";
								} else {
									var collTop = "0"
								}
							} else {
								var colltop = "0";
							}
							
							$("<div id='collGallery'></div><div id='collPop'></div>").prependTo("body");
							$("").supersleight();
							var coll = $(this).attr("rel"); 
							if (coll == "clima365") {
								var imgId = "Q3_clima365_jessica_01";
							} else if (coll == "yatra") {
								var imgId = "Q3_yatra_rosa_05";
							};
							var flashvars = {startupImageName: imgId, collection: coll, countryCode:adidas_cc, pidUrl: pidWsdl, lang: locale};
							var params = {wmode:"transparent", base:"swf/collectionsFPV",salign:"lt"};
							swfobject.embedSWF("swf/collectionsFPV/swf/Main.swf", "collPop", "100%", "100%", "9.0.0", false, flashvars,params);	
							$("#collPop").css("top",colltop);
							var galleryViewed = "1";
						}).live("mouseover",function() {$(this).css("cursor","pointer")});
						
						$.each(data.collections.portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "100%";
									break;
							}
							
							if (item.backgroundoffset) {
								var bgoffset = item.backgroundoffset;
							} else {
								var bgoffset = "left";
							};

							var div = $("<div>").addClass("collPortlet").attr("id",item.title).attr("style","width:"+moduleWidth+"; height:"+item.height+"; background: url("+item.media+") "+bgoffset+" top no-repeat;");

							if (item.offset) {
								var offset = item.offset;
							} else {
								var offset = "20px;";
							};
							
							$("<h2>").text(item.headline).appendTo(div).attr("style","margin-left:"+offset);
							$("<div>").html(item.copy).attr("style","width:"+paragraphWidth+"; float: none; margin-left:"+offset).appendTo(div);

							if (item.button) {
								$("<div>").addClass("buttonHolder").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a></div>").appendTo(div);
							};

							if (item.link) {
								var link = item.link;
								var newLink = link.replace("{0}",item.headline);
								if (item.collection) {
									if (fv !=false) {
										$("<a>").addClass("collPortletLink collGalleryPop").attr("style","margin-left:"+offset).attr("rel",item.collection).html(newLink).appendTo(div);
									}
								} else {
								$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left:"+offset).html(newLink).appendTo(div);
								};
							};

							div.appendTo("#bodycontent");
							
							if (item.gallery) {
								
								var galleryDiv = $("<div>").addClass("galleryDiv");
								galleryDiv.appendTo(div);
								for (x in item.gallery) {
									var img = $("<img />").attr("src",item.gallery[x].thumb). attr("alt",item.gallery[x].altText).attr("rel",item.gallery[x].imgId).attr("width",item.gallery[x].twidth).attr("height",item.gallery[x].theight).addClass("collThumbs");
									img.appendTo(galleryDiv);
								}
								galleryDiv.supersleight();
							};
							
				        });
					});
			},
		
		populateClima365: function() {
//				var locale = getQs("locale");
//				if (locale == "") {locale = "en-en"};
			$('body').attr('class','clima');
				var fv = getFlashVersion();
				$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
					function(data){
						$("html").data("data",data);
						adidasPop.getPageName(data);
						$("img.collThumbs").live("click", function() {
							if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
								if (!galleryViewed) {
									var colltop = ($(document).scrollTop())+"px";
								} else {
									var collTop = "0"
								}
							} else {
								var colltop = "0";
							}
							
							$("<div id='collGallery'></div><div id='collPop'></div>").prependTo("body");
							$("").supersleight();
							var imgId = $(this).attr("rel");
							var flashvars = {startupImageName: imgId, collection: "climacool", countryCode:adidas_cc, pidUrl: pidWsdl, locale: locale, countryCode:adidas_cc};
							var params = {wmode:"transparent", base:"swf/collectionsFPV",salign:"lt"};
							swfobject.embedSWF("swf/collectionsFPV/swf/Main.swf", "collPop", "100%", "100%", "9.0.0", false, flashvars,params);		
							$("#collPop").css("top",colltop);
							var galleryViewed = "1";
						}).live("mouseover",function() {$(this).css("cursor","pointer")});
						
						$("a.collGalleryPop").live("click", function() {
							if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
								if (!galleryViewed) {
									var colltop = ($(document).scrollTop())+"px";
								} else {
									var collTop = "0"
								}
							} else {
								var colltop = "0";
							}
							
							$("<div id='collGallery'></div><div id='collPop'></div>").prependTo("body");
							$("").supersleight();
							var coll = $(this).attr("rel"); 
							if (coll == "clima365") {
								var imgId = "Q3_clima365_jessica_01x";
							} else if (coll == "yatra") {
								var imgId = "Q3_yatra_rosa_05";
							};
							var flashvars = {startupImageName: imgId, collection: coll, countryCode:adidas_cc, pidUrl: pidWsdl, lang: locale};
							var params = {wmode:"transparent", base:"swf/collectionsFPV",salign:"lt"};
							swfobject.embedSWF("swf/collectionsFPV/swf/Main.swf", "collPop", "100%", "100%", "9.0.0", false, flashvars,params);	
							$("#collPop").css("top",colltop);
							var galleryViewed = "1";
						}).live("mouseover",function() {$(this).css("cursor","pointer")});

						
						$.each(data.clima365.portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "auto";
									break;
							}
							
							if (item.backgroundoffset) {
								var bgoffset = item.backgroundoffset;
							} else {
								var bgoffset = "left";
							};

							var div = $("<div>").addClass("collPortlet").attr("id",item.title).attr("style","width:"+moduleWidth+"; background: url("+item.media+") "+bgoffset+" top no-repeat;");
							$("<div></div>").addClass('climaSpace').prependTo(div);
							

							if (item.offset) {
								var offset = item.offset;
							} else {
								var offset = "0";
							};
							
							
							if (item.type == "flash") {	
										var tempId = item.title + "-container";
										var divContainer = $("<div>").attr("id",tempId);
										divContainer.prependTo(item.appendto);
										var div = $("<div>").attr("id",item.title); //.attr("style","width:"+moduleWidth+";height:"+item.height+";");
										//div.html("<a href='"+item.noflashUrl+"'><img src='"+item.noflash+"' alt='"+item.noflashAlt+"' /></a>");
										div.prependTo(divContainer);
										
										var flashvars = createFlashVars(item);
										
										//var flashvars = {locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/", play:"true"  };
										
										var launcher = item.media;
										var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent"};
										swfobject.embedSWF(launcher, item.title, moduleWidth, item.height, "9.0.0", false,flashvars,params);
										if (item.textContent) {
											$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
										};
							} else if (item.title != "climabenefits") {
								var img = $("<img />").addClass("logo").attr("src",item.headline).appendTo(div).attr("style","margin-left:"+offset);
								$("<div>").addClass("text").html("<p>"+item.copy+"</p>").appendTo(div);
							} else  {
								
								$("<h2>").html(item.headline).appendTo(div);
								$("<div>").addClass("benefits").html("<h3>"+item.headlineBenefits+"</h3>"+item.copyBenefits).appendTo(div);
								var ventilation = $("<div>").addClass("ventilation").html("<h3>"+item.headlineVentilation+"</h3>"+item.copyVentilation).appendTo(div);
							};							
							
							if (item.button) {
									$("<div>").addClass("buttonHolder").addClass("buttonBlue").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a></div>").appendTo(div);
							};	

							if (item.link) {
								var link = item.link;
								var newLink = link.replace("{0}",item.headline);
								if (item.collection) {
									if (fv !=false) {
										$("<a>").addClass("collPortletLink").attr("href",item.linkurl)/*.attr("style","margin-left:"+offset)*/.attr("rel",item.collection).html(newLink).appendTo(div);
									}
								} else {
								$("<a>").attr("href",item.linkurl).addClass("collPortletLink")/*.attr("style","margin-left:"+offset)*/.html(newLink).appendTo(div);
								};
							};

							div.appendTo("#bodycontent");
							if (item.gallery) {
								
								var galleryDiv = $("<div>").addClass("galleryDiv");
								galleryDiv.appendTo(div);
								for (x in item.gallery) {
									var img = $("<img />").attr("src",item.gallery[x].thumb). attr("alt",item.gallery[x].altText).attr("rel",item.gallery[x].imgId).attr("width",item.gallery[x].twidth).attr("height",item.gallery[x].theight).addClass("collThumbs");
									img.appendTo(galleryDiv);
								}
								galleryDiv.supersleight();
							};							
				        }
						);
						adidasPop.equalHeights($(".collPortlet:not(#climacool):not(#climabenefits)"));
						adidasPop.equalHeights($(".collPortlet .text:gt(0)"));
						
						if (locale=="es-es" || locale=="ru-ru"){
							var heights = $(".collPortlet:not(#climacool):not(#climabenefits)").height();
							$(".collPortlet:not(#climacool):not(#climabenefits)").height(heights+10);
						}
						
						var clear = $("<div>").attr("class","clear");	
						clear.appendTo("#bodycontent");
					});
			},
		populateTechfit: function() {
//				var locale = getQs("locale");
//				if (locale == "") {locale = "en-en"};
				$('body').attr('class','techfit').addClass('techfit-inside');
				var fv = getFlashVersion();
			$('body').attr('class','techfit');				
				$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
					function(data){
						$("html").data("data",data);
						adidasPop.getPageName(data);
						$("img.collThumbs").live("click", function() {
							if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
								if (!galleryViewed) {
									var colltop = ($(document).scrollTop())+"px";
								} else {
									var collTop = "0"
								}
							} else {
								var colltop = "0";
							}
							
							$("<div id='collGallery'></div><div id='collPop'></div>").prependTo("body");
							$("").supersleight();
							var imgId = $(this).attr("rel");
									
							$("#collPop").css("top",colltop);
							var galleryViewed = "1";
						}).live("mouseover",function() {$(this).css("cursor","pointer")});
						
						$("a.collGalleryPop").live("click", function() {
							if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7) {
								if (!galleryViewed) {
									var colltop = ($(document).scrollTop())+"px";
								} else {
									var collTop = "0"
								}
							} else {
								var colltop = "0";
							}
							
							$("<div id='collGallery'></div><div id='collPop'></div>").prependTo("body");
							$("").supersleight();
							var coll = $(this).attr("rel"); 
							if (coll == "techfit") {
								var imgId = "Q3_clima365_jessica_01x";
							} else if (coll == "yatra") {
								var imgId = "Q3_yatra_rosa_05";
							};
							var flashvars = {startupImageName: imgId, collection: coll, countryCode:adidas_cc, pidUrl: pidWsdl, lang: locale};
							var params = {wmode:"transparent", base:"swf/collectionsFPV",salign:"lt"};
							swfobject.embedSWF("swf/collectionsFPV/swf/Main.swf", "collPop", "100%", "100%", "9.0.0", false, flashvars,params);	
							$("#collPop").css("top",colltop);
							var galleryViewed = "1";
						}).live("mouseover",function() {$(this).css("cursor","pointer")});
						
						$.each(data.techfit.portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "auto";
									break;
							}
							
							if (item.type == "flash") {	
								var tempId = item.title + "-container";
								var divContainer = $("<div>").attr("id",tempId);
								divContainer.prependTo(item.appendto);
								var div = $("<div>").attr("id",item.title);								
								div.appendTo(divContainer);

								var flashvars = createFlashVars(item);
								flashvars.play = "true";
								flashvars.loop = "true";
								flashvars.scale = "showall";
								
								var launcher = item.media;
									
								/*
								if (item.launcher == "self") {
									var flashvars = {locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/", play:"true", loop:'true', scale:'showall'  };
									var launcher = item.media;
								} else {
									var flashvars = {application: item.media, locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/"};
									var launcher = item.launcher;
								};
								*/

								var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent"};
								swfobject.embedSWF(launcher, item.title, moduleWidth, item.height, "9.0.0", false,flashvars,params);
								
								if (item.textContent) {
									$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
								};
						
							} else if (item.type == "seperator") {
	
							// create seperator/divider
								var div = $("<div>").addClass("collPortlet techfit-sep").attr("id",item.title);
	  							div.appendTo("#bodycontent");

							} else {
  							
								if (item.backgroundoffset) {
									var bgoffset = item.backgroundoffset;
								} else {
									var bgoffset = "left";
								};
								
								if (item.topoffset) {
									var topoffset = item.topoffset;
								} else {
									var topoffset = "top";
								};
								

								var div = $("<div>").addClass("collPortlet").attr("id",item.title).attr("style","width:"+moduleWidth+"; height:"+item.height+"; background: url("+item.media+") "+bgoffset+" "+topoffset+" no-repeat;"); 

								if (item.offset) {
									var offset = item.offset;
								} else {
									var offset = "0;";
								};

								if (item.title == "techfit-ben" || item.title == "techfit-tech") {
									$("<h2>").html(item.headline).appendTo(div);
									$("<div>").addClass("text").html("<p>"+item.copy+"</p>").appendTo(div);
									if (item.button) {
											$("<div>").html("<div class=\"buttonTechfit\"><a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a></div>").appendTo(div);
									};
								} else {
									var img = $("<img />").addClass("logo").attr("src",item.headline).appendTo(div).attr("style","margin-left:"+offset);
									$("<div>").addClass("text").html("<p>"+item.copy+"</p>").attr("style","width:"+paragraphWidth+"; margin-left:"+offset).appendTo(div);
									if (item.button) {
											$("<div>").addClass("buttonHolder").addClass("buttonBlack").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a></div>").appendTo(div);
									};
								};

								if (item.link) {
									var link = item.link;
									var newLink = link.replace("{0}",item.headline);
									if (item.collection) {
										if (fv !=false) {
											//$("<a>").addClass("collPortletLink collGalleryPop").attr("style","margin-left:"+offset).attr("rel",item.collection).html(newLink).appendTo(div);
										}
									} else {
									$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left:"+offset).html(newLink).appendTo(div);
									};
								};

								div.appendTo("#bodycontent");
							}
							
							if (item.gallery) {
								
								var galleryDiv = $("<div>").addClass("galleryDiv");
								galleryDiv.appendTo(div);
								for (x in item.gallery) {
									var img = $("<img />").attr("src",item.gallery[x].thumb). attr("alt",item.gallery[x].altText).attr("rel",item.gallery[x].imgId).attr("width",item.gallery[x].twidth).attr("height",item.gallery[x].theight).addClass("climaCoolThumbs").attr("style","display: none;");
									img.appendTo(galleryDiv);
								}
								galleryDiv.supersleight();
							};
							
				        });

						//Add clearing Div
						var clear = $("<div>").attr("class","clear");
						clear.appendTo("#bodycontent");
						if (data.index.legal) {
							$("<div>").addClass("legal").html(data.index.legal).appendTo("#bodycontent");
							var clear2 = $("<div>").attr("class","clear");
							clear2.appendTo("#bodycontent");
						}													
					});
			},
		populateTechfitben: function(){

			$('body').attr('class','techfit techfitbenefits').attr('id','techfitbenefits');						
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);				
					
					//$("#maincontent").html(data.techfitben.description);

					var tmp = '';
					var desc = data.techfitben.description;
					var descLen = desc.length;
					
					for (var i=0; i < descLen; i++) {
						tmp += "<h3>"+desc[i].subhead+"</h3>";
						tmp += "<p>"+desc[i].para+"</p>";
						if (desc[i].link) {
							tmp += '<a class="buttonLink" id="'+desc[i].linkId+'" href="'+desc[i].linkUrl+'">'+desc[i].link+'</a>';
						};
					};
					$('#maincontent').append(tmp);

/*					$("<img />").attr("src",data.techfitben.media).prependTo("#maincontent");			*/
					$("<h1>").prependTo("#maincontent");


					var title = $("<div>").attr("id","detail-title-container").prependTo("#bodycontent");
					$("<div>").attr("id","detail-title").html(data.techfitben.headline).appendTo(title);
					$("<div>").attr("id","detail_back_button").appendTo(title);				
					
					
					$("<div>").addClass("buttonHolder").addClass("buttonBlack").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+data.techfitben.backtoURL+"\">"+data.techfitben.backtotext+"</a></div>").appendTo($("#detail_back_button"));						

						$.each(data.techfitben.portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "100%";
									break;
							}

							if (item.type == "flash") {	

								var div = $("<div>").attr("id",item.title)/*.attr("style","width:"+moduleWidth+";height:"+item.height+";");
								
								div.html("<a href='"+item.noflashUrl+"'><img src='"+item.noflash+"' alt='"+item.noflashAlt+"' /></a>")*/;
								
								div.appendTo(item.appendto);
													
								var flashvars = createFlashVars(item);
								flashvars.play = "true";
								flashvars.loop = "true";
								flashvars.scale = "showall";
								var launcher = item.media;
																
								/*
								if (item.launcher == "self") {
									var flashvars = {lang: adidas_cc, locale: locale, country: adidas_cc, configDirectory:"content/assets/xml/lang/"+locale+"/", play:"true"  };
									var launcher = item.media;
								} else {
									var flashvars = {lang: adidas_cc, application: item.media, locale: locale, country: adidas_cc, configDirectory:"content/assets/xml/lang/"+locale+"/"};
									var launcher = item.launcher;
								};
								*/

								
								var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent", scale:"noScale", salign:"lT"};
								swfobject.embedSWF(launcher, item.title, item.width, item.height, "9.0.0", false,flashvars,params);
								
								if (item.textContent) {
									$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
								};

							} else {
						
								if (item.backgroundoffset) {
									var bgoffset = item.backgroundoffset;
								} else {
									var bgoffset = "left";
								};
	
								var div = $("<div>").attr("id",item.title).attr("style","width:"+moduleWidth+"; height:"+item.height+"; background: url("+item.media+") "+bgoffset+" top no-repeat;");
								$("<h3>").html(item.headline).appendTo(div);
								$("<div>").addClass("text").html("<p>"+item.copy+"</p>").attr("style","width:"+paragraphWidth).appendTo(div);
								if (item.button) {
									$("<div>").addClass("buttonTechfit").html("<a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a>").appendTo(div);
								};	
	
								if (item.link) {
									var link = item.link;
									var newLink = link.replace("{0}",item.headline);
									if (item.collection) {
										if (fv !=false) {
											//$("<a>").addClass("collPortletLink collGalleryPop").attr("style","margin-left:"+offset).attr("rel",item.collection).html(newLink).appendTo(div);
										}
									} else {
									$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left:"+offset).html(newLink).appendTo(div);
									};
								};
							};
							div.appendTo(item.appendto);
				        });
					
					//Add clearing Div
					var clear = $("<div>").attr("class","clear");
					clear.appendTo("#bodycontent");
					// add legal copy
					if (data.index.legal) {
						$("<div>").addClass("legal").html(data.index.legal).appendTo("#bodycontent");
						var clear2 = $("<div>").attr("class","clear");
						clear2.appendTo("#bodycontent");
					}

		   		});
		},
		populateTechfittech: function(){
			$('body').attr('class','techfit techfitbenefits');			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);				
					

	/*				$("<h1>").text("Description").prependTo("#maincontent");
					$("#maincontent").html(data.techfittech.description);

					$("<img />").attr("src",data.techfittech.media).prependTo("#maincontent");			
					$("<h1>").text(data.techfittech.headline).prependTo("#maincontent");*/

					var title = $("<div>").attr("id","detail-title-container").prependTo("#bodycontent");
					$("<div>").attr("id","detail-title").html(data.techfittech.headline).appendTo(title);
					$("<div>").attr("id","detail_back_button").appendTo(title);				
					
					$("<div>").addClass("buttonHolder").addClass("buttonBlack").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+data.techfittech.backtoURL+"\">"+data.techfittech.backtotext+"</a></div>").appendTo($("#detail_back_button"));						


						$.each(data.techfittech.portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "0.75":
									var moduleWidth = "705px";
									var paragraphWidth = "390px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "100%";
									break;
							}

							if (item.type == "flash") {	

								var div = $("<div>").attr("id",item.title)/*.attr("style","width:"+moduleWidth+";height:"+item.height+";");
								
								div.html("<a href='"+item.noflashUrl+"'><img src='"+item.noflash+"' alt='"+item.noflashAlt+"' /></a>")*/;
								
								div.appendTo(item.appendto);

								var flashvars = createFlashVars(item);
								flashvars.play = "true";
								flashvars.loop = "true";
								flashvars.scale = "showall";
								var launcher = item.media;

								/*
								if (item.launcher == "self") {
									var flashvars = {lang: adidas_cc, locale: locale, country: adidas_cc, configDirectory:"content/assets/xml/lang/"+locale+"/", play:"true", loop:'true', scale:'showall'  };
									var launcher = item.media;
								} else {
									var flashvars = {application: item.media, lang: adidas_cc, locale: locale, country: adidas_cc, configDirectory:"content/assets/xml/lang/"+locale+"/"};
									var launcher = item.launcher;
								};
								 */
								
								var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent", scale:"noScale", salign:"lT"};
								swfobject.embedSWF(launcher, item.title, moduleWidth, item.height, "9.0.0", false,flashvars,params);
								
								if (item.textContent) {
									$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
								};

							} else {
						
								if (item.backgroundoffset) {
									var bgoffset = item.backgroundoffset;
								} else {
									var bgoffset = "left";
								};
	
								var div = $("<div>").attr("id",item.title).attr("style","width:"+moduleWidth+"; height:"+item.height+"; background: url("+item.media+") "+bgoffset+" top no-repeat;");
								$("<h3>").html(item.headline).appendTo(div);
								$("<div>").addClass("text").html("<p>"+item.copy+"</p>").attr("style","width:"+paragraphWidth).appendTo(div);
								if (item.button) {
									$("<div>").addClass("buttonTechfit").html("<a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a>").appendTo(div);
								};	
	
								if (item.link) {
									var link = item.link;
									var newLink = link.replace("{0}",item.headline);
									if (item.collection) {
										if (fv !=false) {
											//$("<a>").addClass("collPortletLink collGalleryPop").attr("style","margin-left:"+offset).attr("rel",item.collection).html(newLink).appendTo(div);
										}
									} else {
									$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left:"+offset).html(newLink).appendTo(div);
									};
								};
							};
							div.appendTo(item.appendto);
				        });
					
					//Add clearing Div
					var clear = $("<div>").attr("class","clear");
					clear.appendTo("#bodycontent");
					if (data.index.legal) {
						$("<div>").addClass("legal").html(data.index.legal).appendTo("#bodycontent");
						var clear2 = $("<div>").attr("class","clear");
						clear2.appendTo("#bodycontent");
					}
			
		   		});
		},				
		populateClima365ben: function(){
			$('body').attr('class','clima365 techfitbenefits').attr('id','clima365benefits');
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);				
					

/*					$("<h1>").text("Description").prependTo("#maincontent");
					$("#maincontent").html(data.clima365ben.description);

					$("<img />").attr("src",data.clima365ben.media).prependTo("#maincontent");			
					$("<h1>").text(data.clima365ben.headline).prependTo("#maincontent");*/

					var title = $("<div>").attr("id","detail-title-container").prependTo("#bodycontent");
					$("<div>").attr("id","detail-title").html(data.clima365ben.headline).appendTo(title);
					$("<div>").attr("id","detail_back_button").appendTo(title);				
					
					
					$("<div>").addClass("buttonHolder").addClass("buttonBlue").html("<div class=\"buttonArrow\"></div><div class=\"buttonBody\"><a class=\"buttonLink\" href=\""+data.clima365ben.backtoURL+"\">"+data.clima365ben.backtotext+"</a></div>").appendTo($("#detail_back_button"));						

						$.each(data.clima365ben.portlets, function(i,item){
							var w = item.width;
							switch(w) {
								case "0.25":
									var moduleWidth = "225px";
									break;
								case "0.5":
									var moduleWidth = "50%";
									var paragraphWidth = "240px";
									break;
								case "0.75":
									var moduleWidth = "705px";
									var paragraphWidth = "390px";
									break;
								case "1":
									var moduleWidth = "100%";
									var paragraphWidth = "390px";
									break;
								default:
									var moduleWidth = "100%";
									break;
							}

							if (item.type == "flash") {	

								var div = $("<div>").attr("id",item.title)/*.attr("style","width:"+moduleWidth+";height:"+item.height+";");
								
								div.html("<a href='"+item.noflashUrl+"'><img src='"+item.noflash+"' alt='"+item.noflashAlt+"' /></a>")*/;
								
								div.appendTo(item.appendto);
								
								var flashvars = createFlashVars(item);
								flashvars.play = "true";
								flashvars.loop = "true";
								flashvars.scale = "showall";
								
								var launcher = item.media;
								
								//if (item.launcher == "self") {
								//	var flashvars = {locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/", play:"true", loop:'true', scale:'showall'  };
								//	var launcher = item.media;
								//} else {
								//	var flashvars = {application: item.media, locale: locale, country: adidas_cc, configDirectory:"/mens-en/content/assets/xml/lang/"+locale+"/"};
								//	var launcher = item.launcher;
								//};

								
								var params = {allowFullScreen: "true", allowScriptAccess: "always", wmode:"transparent", scale:"noScale", salign:"lT"};
								swfobject.embedSWF(launcher, item.title, moduleWidth, item.height, "9.0.0", false,flashvars,params);
								
								if (item.textContent) {
									$("<div>").addClass(item.textContent[0].type).append("<a href="+item.textContent[0].linkurl+">"+item.textContent[0].link+"</a>").insertAfter($("#"+item.title+""));
								};

							} else {
						
								if (item.backgroundoffset) {
									var bgoffset = item.backgroundoffset;
								} else {
									var bgoffset = "left";
								};
	
								var div = $("<div>").attr("id",item.title).attr("style","width:"+moduleWidth+"; height:"+item.height+"; background: url("+item.media+") "+bgoffset+" top no-repeat;");
								$("<h3>").text(item.headline).appendTo(div);
								$("<div>").addClass("text").html(item.copy).attr("style","width:"+paragraphWidth).appendTo(div);
								if (item.button) {
									$("<div>").addClass("buttonTechfit").html("<a class=\"buttonLink\" href=\""+item.buttonUrl+"\">"+item.button+"</a>").appendTo(div);
								};	
	
								if (item.link) {
									var link = item.link;
									var newLink = link.replace("{0}",item.headline);
									if (item.collection) {
										if (fv !=false) {
											//$("<a>").addClass("collPortletLink collGalleryPop").attr("style","margin-left:"+offset).attr("rel",item.collection).html(newLink).appendTo(div);
										}
									} else {
									$("<a>").attr("href",item.linkurl).addClass("collPortletLink").attr("style","margin-left:"+offset).html(newLink).appendTo(div);
									};
								};
							};
							div.appendTo(item.appendto);
				        });
					//Add clearing Div
					var clear = $("<div>").attr("class","clear");
					clear.appendTo("#bodycontent");
		   		});
		},
		
		populateProducts: function(){
			//empty function left in place for now
		},
		
		populateEvents: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);				
					
					$("<span>").css("float","left").text(data.events.headline).prependTo("#eventsHeadline");
					$("<h2>").text("Description").prependTo("#eventsLeft");
					$("#eventsLeft").html(data.events.description);
					$("<h2>").text("Schedule").appendTo("#eventsLeft");
					
					$.each(data.events.schedule, function(i,item) {
						var div = $("<div>").addClass("singleEvent");
						$("<h3>").html(item.date).prependTo(div);
						$("<p>").addClass("eventTime").text(item.time).appendTo(div);
						$("<p>").text(item.text).appendTo(div);
						div.appendTo("#eventsLeft");
					});
					adidasPop.equalHeights($('.singleEvent'));
		   		});
		},
		
/*		populateProducts: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
					
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					
					
		   		});
		},*/
		
/*		populateProductsDetail: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			var fv = getFlashVersion();
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					
		   		});
		},*/
	
		populateStyle: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);
					$("<img src='img/style_dummy.jpg'>").appendTo("#bodycontent");
		   		});
		},
		
		populateStyleYourself: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			
			var st = getQs("st");
			var sm = getQs("sm");
			var sb = getQs("sb");
			var sa = getQs("sa");
			
			if (st == "") {st = "P09617"};
			if (sm == "") {sm = "P09602"};

			// AMS removed if (sb == "") {sb = "G01710"};
			
			if (sb == "") {sb = "G01690"};
			if (sa == "") {sa = "E43616"};
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);

					var flashvars = {country: adidas_cc, startupTop:st, startupMid:sm, startupBot:sb, startupAcc:sa, lang: locale, pidUrl: pidWsdl};
					var params = {base:"swf/styleyourself", bgcolor:"#FFFFFF", wmode:"transparent"};
					swfobject.embedSWF("swf/styleyourself/MixAndMatchModule08.swf", "bodycontent", "975", "502", "9.0.0", false, flashvars,params);

					//$("#shortBody").supersleight();	
		   		});
		},
		
		populateMemyself: function() {
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);
					
					var flashvars = {country: adidas_cc, lang: locale, pidUrl: pidWsdl};
					var params = {base:"meMyself/build/", wmode:"transparent"};
					swfobject.embedSWF("meMyself/build/Main.swf", "bodycontent", "975", "502", "9.0.0", false, flashvars,params);
			
					//$("#shortBody").supersleight();
				});
		},
		
		populatePersonalities: function(){
//			var locale = getQs("locale");
//			if (locale == "") {locale = "en-en"};
			
			$.getJSON("content/assets/xml/lang/"+locale+"/data.js",
				function(data){
					$("html").data("data",data);
					adidasPop.getPageName(data);		
					
					//populate left-hand column
					$.each(data.personalities.sidebar, function(i, item) {	
						for (x in item) {
							if (item.title == $("html").data("pagename")) {
								var bkgd = item.active;
							} else {
								var bkgd = item.media;
							};
						};
						var pads = "padding-left:"+item.alignleft+"; padding-top:"+item.aligntop+";";
						var a = $("<a>").addClass("ps_"+item.title).attr("href",item.url).attr("style",pads).html(item.subhead+"<br /><span>"+item.athlete+"</span>");
						var li = $("<li>").attr("id",item.title).attr("style","background: url("+bkgd+") left top no-repeat;");

						

						a.appendTo(li);
						li.appendTo("#personalitiesSubnav");
					 	a.hover(
							function() {
								a.attr("style","background: url("+item.active+") left top no-repeat;"+pads+";");
							},
							function() {
								a.attr("style","background: none;"+pads+";");
						});
					});
					
					//populate main column content
					$.each(data.personalities.centerContent,function(i,item) {
						$("#rightContent").html(item.copy);
					});
					
					//populate right-hand column
					$.each(data.personalities.rightContent,function(i,item) {
						
						for (x in item.featuredProduct) {
							var content = $("<img />").attr("src", item.featuredProduct[x].media);
							var div = $("<div>").attr("id",item.featuredProduct[x].title);
							content.appendTo(div);
							$("<h2>").html("Featured Product").appendTo("#sidebar");
							div.appendTo("#sidebar");
						};
						adidasPop.applyFb();
					});
					
					//populate adiTV player
					$.each(data.personalities.adiTv, function(i,item) {
						var title=(item.title);
						var content = $("<img />").attr("src",item.media);
						var anchor = $("<a>").attr("href","#"+title).addClass("adivid");
						content.appendTo(anchor); anchor.appendTo("#aditvPlayer");
						$("<div>").attr("style","display: none").attr("id",title).html(item.content).appendTo("body");
						adidasPop.applyFb();
					});
		   		});
		}
};

