﻿var preload = new Array();
var fxInterval = 50;
jQuery.fx.interval = fxInterval;

/********** CocaCola **********/
(function($) {
	$.extend({
		CocaCola:{
			home:false,
			changing:false,
			activezone:null,
			/***** Init *****/
			init:function(components,area){
				var _area = (!area)? document : $("#"+area).get(0);
				for(var i in components){
					switch(components[i]){
						case "navigation":
							$.CocaCola.navigation.build(_area);
						break;
						case "scroll":
							$.CocaCola.scroll.build(_area);
						break;
						case "tabs":
							$.CocaCola.tabs.build(_area);
						break;
						case "dateselector":
							$.CocaCola.dateselector.build(_area);
						break;
						case "ajaxnews":
							$.CocaCola.ajaxnews.build(_area);
						break;
						case "linksnews":
							$.CocaCola.ajaxnews.newslinks();
						break;
						case "faq":
							$.CocaCola.faq.build(_area);
						break;
						case "strip":
							$.CocaCola.strip.build(_area);
						break;
						case "scale":
							$.CocaCola.scale.build(_area);
						break;
						case "fieldcleaner":
							$.CocaCola.fieldcleaner.build(_area);
						break;
						case "tgs":
							$(".tg, .tglike",_area).each($.CocaCola.tg.build);
						break;
					}
				}
				$.CocaCola.setsize();
			},
			/***** Refresh *****/
			request:false,
			refresh:function(url,ids,rebuild,callback){
				if(!$.CocaCola.request){
					$.CocaCola.request = true;
					var zones = ids.split(",");
					$.ajax({
						url: url,
						success: function(data) {
							for(var i in zones){
								var response = $(data).find("#"+zones[i]).html();
								var landing = $("#"+zones[i]).html(response).get(0);
								$.CocaCola.init(rebuild,zones[i]);
							}
							// Change title
							var start = data.indexOf("<title>");
							var end = data.indexOf("</title>");
							document.title = data.substring(start+7,end);
							// Update Share
							if(GigyaAct){
								GigyaAct.setTitle(document.title);
								GigyaAct.setLinkBack(url);
							}
							// Hash
							document.location = "#"+url;
							// If callback
							if(callback){
								callback();
							}
							$.CocaCola.request = false;
						},
						error:function(){
							$.CocaCola.request = false;
						}
					});
				}
			},
			/***** Navigation *****/
			navigation:{
				active:null,
				delay:null,
				build:function(area){
					var active = null;
                     $(".nav span.roll",area).each(function(){
                        $(this).mouseover(function(e){
                             $(".container").append("<div class=\"rollin\" id=\"rollin\" style=\"left:"+ (e.pageX-$(".container").get(0).offsetLeft + 12 )+"px;top:"+(this.offsetTop + 26)+"px\">"+this.title+"</div>");
                             this.title = "";  
					    }).mouseout(function(e){
                            this.title = $("#rollin").html();
                             $("#rollin").remove();
					    }).mousemove(function(e){
							$("#rollin").css({ left:(e.pageX-$(".container").get(0).offsetLeft + 12 )+"px" });
						})
                    });

					$(".nav a, .nav span",area).each(function(){
						// if span or anchor (wheel) open
						var index = $.store(this)._index;
						
						if(this.tagName.toLowerCase() == "span" || index){

							if(index){
								
								$(this)/*.mouseenter(function(){
									$.CocaWheel.enter(index);
								}).mouseleave(function(){
									$.CocaWheel.leave(index);
								})*/.click(function(){
									$.CocaWheel.direct = true;
									$.CocaWheel.activate(index);
								});
								// If is active in URL
								if(document.location.href.indexOf($(this).attr("href")) != -1){
									$.CocaCola.activezone = index;
									$.CocaCola.navigation.active = this;
								}
								
							}
							else {
								
								$(this).click(function(){
									$.CocaCola.navigation.activate(this);
								});
								
							}
							
						} else if(document.location.href.indexOf(this.href) != -1 && $(this).attr("href") != ""){
                            $.CocaCola.navigation.active = this;
						}						
						
					});
					// Activate nav
					if($.CocaCola.navigation.active != null){
						$.CocaCola.navigation.activate($.CocaCola.navigation.active);
					}
					
					// Hover
					$(".nav ul",area).mouseover(function(){
						clearTimeout(this.delay);
						$(this).addClass("hover").parent("li").parent("ul").removeClass("hover");
						return false;
					}).mouseout(function(){
						var _this = this;
						clearTimeout(_this.delay);
						_this.delay = setTimeout(function(){
							$(_this).removeClass("hover");
						},50);
						return false;
					});
					
					/*				
						
					Useful ... ?
					
					if($.CocaCola.navigation.active != null){
						$(".nav ul",area).mouseleave(function(){
							$.CocaCola.navigation.activate($.CocaCola.navigation.active);
						});
					}
					
					*/
					
				},
				activate:function(item){
					var parent = item.parentNode;
					var root = $(".nav").get(0);
					var latest = null;
					while(parent && parent != root){
						if(parent.tagName.toLowerCase() == "ul"){
							$("> li",parent).each(function(){
								if(this != latest){
									$(this).removeClass("open").addClass("off")/*.find("li").each(function(){
										$(this).removeClass("open").addClass("off");
									})*/;
								}
							});
						}
						if(parent.tagName.toLowerCase() == "li"){
							latest = parent;
							$(parent).removeClass("off").addClass("open");
						}
						parent = parent.parentNode;
					}
				}
			},
			/***** Wills *****/
			wills:{
				build:function(){
					$("#wills").each(function(){
						// Hide
						var _this = this;
						$("li",_this).each(function(i){
							if(i == 0){
								$(this).addClass("visible");
								_this.current = this;
							}
						});
						_this.interval = null;
						$.CocaCola.wills.start(_this);
						// Events
						/*$(_this).mouseenter(function(){
							$.CocaCola.wills.stop(_this);
						}).mouseleave(function(){
							$.CocaCola.wills.start(_this);
						});*/
					});
				},
				start:function(_this){
					$.CocaCola.wills.stop(_this);
					_this.interval = setInterval(function(){
						var next = $(_this.current).next();
						$(_this.current).removeClass("visible");
						if(next.length == 0){
							_this.current = $("li:eq(0)",_this).addClass("visible");
						} else {
							_this.current = next.addClass("visible");
						}
					},3000);
				},
				stop:function(_this){
					clearInterval(_this.interval);
				}
			},
			/***** Section *****/
			section:{
				mask:function(){
					if(!$.CocaWheel.direct){
						var bg = $("#background").get(0);
						$("#mask").css({ width:bg.offsetWidth, height:bg.offsetHeight, marginLeft:-bg.offsetWidth/2, opacity:1 }).removeClass("hidden").addClass("visible");
					}
				},
				clear:function(){
					$("#mask").removeClass("visible").addClass("hidden");
				},
				change:function(content){								
					var current = content.parentNode.current;			
					if(content != current){
						if(!$.CocaWheel.direct){
							// Change background
							$("#mask").stop(true,false).animate({ opacity:0 }, 1000, function(){
								$.CocaCola.section.callback.apply(this,[content]);
							});
						} else {
							$.CocaCola.section.callback.apply($("#mask").get(0),[content]);
						}
					}
					$.CocaWheel.direct = false;
				},
				callback:function(content){
					var current = content.parentNode.current;
					var src = $("#background").get(0).src;					
					this.src = src.substring(0,src.lastIndexOf("."))+"-mask.jpg";
					$.CocaCola.changing = false;
					// Show content and hide others
					if(current){
						$(current).removeClass("visible").addClass("hidden");
					}
					$("#homeintro").removeClass("visible").addClass("hidden");
					$(content).removeClass("hidden").addClass("visible");
					if(!$.CocaWheel.preventshow){
						$(".bodies").removeClass("hidden").addClass("visible");
					}
					content.parentNode.current = content;
				}
			},
			/***** Loaded *****/
			loaded:function(){
				$(".loader").stop(true,false).delay(250).animate({ opacity:0 }, 250, function(){
					$(this).hide().removeClass("nologo");
					$("#countdown").stop(true,true).delay(500).css({ opacity:0, visibility:"visible" }).animate({ opacity:1 }, 1000, function(){
						this.style.filter = "";
					});
				});
				// Home
				if($.CocaCola.home){
					$(".backgrounds img").removeClass("invisible");
					$("#intro").animate({ opacity:0 }, 1000, function(){
						$(this).remove();
					});
					// News
					$("#widgets .news .title").each(function(){
						var parent = this.parentNode;
						setTimeout(function(){
							$.CocaCola.news.close(parent);
						},1000);
					});
					// Dock
					$("#widgets .dock").each(function(){
						var _this = this;
						setTimeout(function(){
							$.CocaCola.dock.close(_this);
						},1133);
					});
					// Customers
					$("#widgets .customers").each(function(){
						// Events
						var _this = this;
						setTimeout(function(){
							$.CocaCola.customers.close(_this);
						},1300);
					});
					// Happiness
					$("#widgets .happiness img").each(function(){
						var _this = this;
						setTimeout(function(){
							$.CocaCola.happiness.close(_this);
						},1500);
					});
					$(".wheel .back").css({ width:0, height:0, marginTop:120, marginLeft:100, display:"block" }).animate({ width:242, height:242, marginTop:0, marginLeft:20 },1500,"easeInOutBack",function(){
						// If default
						if($.CocaCola.activezone == null){
							$("#homeintro").removeClass("hidden").addClass("visible");
						} else {
							$.CocaWheel.preventshow = false;
							$(".bodies").removeClass("hidden").addClass("visible");
						}
						// Alpha + Canva + IE8 = no alpha ... here is the logic
						if(!navigator.userAgent.indexOf("MSIE 8") != -1){
							$("#wheel").css({ visibility:"visible" });
							if(
								$.CocaCola.activezone
								/*
								 Add exception for sub part not depending of the wheel
								*/
								&& $.CocaWheel.config.items[$.CocaCola.activezone]
							){
								var geom = $.CocaWheel.geom;
								
								$.CocaWheel.core = $.CocaWheel.paper.image($.CocaWheel.config.rep+$.CocaWheel.config.items[$.CocaCola.activezone].center, geom.cx-95/2, geom.cy-95/2, 95, 95);
							}
						}
						$("#wheel").stop(true,false).animate({ opacity:1 },500,function(){
							this.removeAttribute("style");
						});
					});
				}

				// Pre load backgrounds
				if (!$("#background").get(0)) return;
				var url = $("#background").get(0).src.substring(0,$("#background").get(0).src.lastIndexOf("/")+1);
				var backgrounds = new Array(
					"univers-default.jpg",
					"univers-drinks.jpg",
					"univers-engagment.jpg",
					"univers-gaz.jpg",
					"univers-life.jpg",
					"univers-recycle.jpg",
					"univers-water.jpg",
					"univers-planbottle.jpg",
					"univers-work.jpg",
					"univers-default-mask.jpg",
					"univers-drinks-mask.jpg",
					"univers-engagment-mask.jpg",
					"univers-gaz-mask.jpg",
					"univers-life-mask.jpg",
					"univers-recycle-mask.jpg",
					"univers-water-mask.jpg",
					"univers-planbottle-mask.jpg",
					"univers-work-mask.jpg",
					"univers-default-blur.jpg",
					"univers-drinks-blur.jpg",
					"univers-gaz-blur.jpg",
					"univers-life-blur.jpg",
					"univers-recycle-blur.jpg",
					"univers-water-blur.jpg",
					"univers-planbottle-blur.jpg",
					"univers-work-blur.jpg"
				);
				for(var i=0; i<backgrounds.length; i++){
					var img = new Image();
					img.src = url+backgrounds[i];
				}
			},
			/***** Transition *****/
			transition:{
				build:function(area){
					/*var baseurl = $(".logo img").get(0).src;
					baseurl = baseurl.substring(baseurl.indexOf("//")+2).split("/")[0];*/
					$("a",area).each(function(){
						var href = $(this).attr("href");
						if(href){
							var target = $(this).attr("target");
							if(target != "_blank" && (href.charAt(0) != "#" || href == "#dummy") && href.substring(0,11) != "javascript:" && href.substring(0,7) != "mailto:"){
								this._href = href;
								this.removeAttribute("href");
								this.style.cursor = "pointer";
								$(this).click(function(){
									$.CocaCola.transition.show(this);
								});
							}
						}
					});
				},
				show:function(link){
					$(".loader").css({ zIndex:10 }).show().stop(true,false).animate({ opacity:0.8 }, 250);
					document.location = link._href;
				}
			},
			/***** Diapo *****/
			diapo:{
				speed:750,
				build:function(){
					// Params
					var _this = this;
					_this._current = 0;
					_this._count = $("img, object",_this).length;
					_this.progress = false;
					// Tools
					$(_this).append("<div class=\"prev\"></div><div class=\"next\"></div>");
					// Events
					$(".prev",_this).click(function(){ $.CocaCola.diapo.prev.apply(_this); });
					$(".next",_this).click(function(){ $.CocaCola.diapo.next.apply(_this); });
				},
				prev:function(){
					var _this = this;
					if(!_this._progress){
						_this._progress = true;
						var index = (_this._current == 0)? _this._count-1 : _this._current-1;
						$(".item:eq("+index+")",_this).css({ left:"-200%" }).stop(true,true).animate({ left:"50%" }, $.CocaCola.diapo.speed);
						$(".item:eq("+_this._current+")",_this).stop(true,true).animate({ left:"200%" }, $.CocaCola.diapo.speed, function(){
							_this._progress = false;
							_this._current = index;
						});
					}
				},
				next:function(){
					var _this = this;
					if(!_this._progress){
						_this._progress = true;
						var index = (_this._current == _this._count-1)? 0 : _this._current+1;
						$(".item:eq("+index+")",_this).css({ left:"200%" }).stop(true,true).animate({ left:"50%" }, $.CocaCola.diapo.speed);
						$(".item:eq("+_this._current+")",_this).stop(true,true).animate({ left:"-200%" }, $.CocaCola.diapo.speed, function(){
							_this._progress = false;
							_this._current = index;
						});
					}
				}
			},
			/***** TGs *****/
			tgs:new Array(),
			tg:{
				build:function(){
					this._data = $.CocaCola.getdata.apply(this);
					if(this._data){
						this._render = "";
						this._index = $.CocaCola.tgs.length;
						$(this).click($.CocaCola.tg.open);
					}
					$.CocaCola.tgs.push(this)
				},
				open:function(){
					var callback = null;
					if(this._render == ""){
						var _this = this;
						// Type image
						if(this._data.img){
							// Multiple or single
							if(this._data.img.length){
								this._render = "<div class=\"popin layertg\" id=\"tg"+this._index+"\">";
								// Multiple
								for(var i=0; i<this._data.img.length; i++){
									var img = this._data.img[i];
									var _class = (i == 0)? "" : " outright";
									this._render += "<img class=\"item"+_class+"\" src=\""+img.url+"\" width=\""+img.sizew+"\" height=\""+img.sizeh+"\" style=\"margin:"+(-img.sizeh/2)+"px 0 0 "+(-img.sizew/2)+"px;\" />";
								}
								this._render += "</div>";
								callback = function(){ 
									var diapo = $("#tg"+_this._index).get(0);
									$.CocaCola.diapo.build.apply(diapo);
								}
							} else {
								// Singles
								var img = this._data.img;
								this._render = "<div class=\"popin layertg\" id=\"tg"+this._index+"\" style=\"width:"+img.sizew+"px;height:"+img.sizeh+"px;\">";
								this._render += "<img src=\""+img.url+"\" width=\""+img.sizew+"\" height=\""+img.sizeh+"\" style=\"position:absolute; top:50%; left:50%; margin:"+(-img.sizeh/2)+"px 0 0 "+(-img.sizew/2)+"px;\" />";
								this._render += "</div>";
							}
						// Type video
						} else if(this._data.video){
							var video = this._data.video;
							this._render = "<div class=\"popin layertg layervideo\" id=\"tg"+this._index+"\" style=\"width:"+video.sizew+"px;height:"+video.sizeh+"px;\">";
							this._render += "<div class=\"item\" style=\"margin:"+(-video.sizeh/2)+"px 0 0 "+(-video.sizew/2)+"px;\">";
							this._render += "<object type=\"application/x-shockwave-flash\" data=\""+video.url+"\" width=\""+video.sizew+"\" height=\""+video.sizeh+"\">";
							this._render += "<param name=\"movie\" value=\""+video.url+"\" />";
							this._render += "<param name=\"wmode\" value=\"transparent\" />";
							this._render += "<param name=\"allowFullScreen\" value=\"true\" />";
							this._render += "</object>";
							this._render += "</div>";
							this._render += "</div>";
						}
					}
					$(this).append(this._render);
					//console.log(this._render);
					// Has "Callback"
					if(callback != null){
						callback();
					}
					// Open layer
					$.CocaCola.popin.open("tg"+this._index);
				}
			},
			/***** Get Data *****/
			databuffer:null,
			getdata:function(){
				if($.CocaCola.databuffer == null){
					$.CocaCola.databuffer = document.createElement("div");
				}
				// Get comment string
				var params = $(this).html(), start = params.indexOf("<!--<data>"), end = params.indexOf("</data>-->");
				params = params.substring(start+10,end);
				// Buffer string
				$($.CocaCola.databuffer).html(params);
				// Create object
				var object = new Object(), filled = false, childs = $.CocaCola.databuffer.childNodes;
				for(var i=0; i<childs.length; i++){
					var node = childs[i].nodeName.toLowerCase();
					if(node != "#text" && node.charAt(0) != "/"){
						// Store attributes
						var attr = new Object();
						for(var j=0; j<childs[i].attributes.length; j++){
							var value = childs[i].attributes[j].value
							if(value != null && value != "null" && value != "" && value != 0 && value != "false" && value != "inherit"){
								attr[childs[i].attributes[j].name] = value;
							}
						}
						// If not first type
						if(object[node]){
							if(!object[node].length){
								var buffer = object[node];
								object[node] = new Array(buffer);
							}
							object[node].push(attr);
						} else {
							if(!filled){
								filled = true;
							}
							object[node] = attr;
						}
					}
				}
				delete $.CocaCola.databuffer;
				if(filled){
					return object;
				} else{
					return null;
				}
			},
			/***** News *****/
			news:{
				build:function(){
					$("#widgets .news .title").each(function(){
						// Params
						var parent = this.parentNode;
						var cont = $(".slider",parent).get(0);
						var items = $(".item",cont);
						// Slider
						$.CocaCola.slider.build(cont,items);
						// Events
						$(this).parent().mouseenter(function(){
							$.CocaCola.news.open(parent);
						}).mouseleave(function(){
							$.CocaCola.news.close(parent);
						});
						// Autoclose
						if($.CocaCola.home){
							$(parent).addClass("open");
						}
					});
				},
				open:function(news){
					$(news).addClass("open").stop(true,false).animate({ height:157 }, 300);
				},
				close:function(news){
					$(news).removeClass("open").stop(true,false).animate({ height:32 }, 300);
				}
			},
			/***** Happiness *****/
			happiness:{
				build:function(){
					$("#widgets .happiness img").each(function(){
						// Events
						var _this = this;
						$(_this).mouseenter(function(){
							$.CocaCola.happiness.open(_this);
						}).mouseleave(function(){
							$.CocaCola.happiness.close(_this);
						});
					});
				},
				open:function(_this){
					$(_this).stop(true,false).animate({ width:78, height:74, opacity:1 }, 300, function(){
						$.CocaCola.happiness.debug(_this);
					});
				},
				close:function(_this){
					$(_this).stop(true,false).animate({ width:35, height:35, opacity:0 }, 300);
				},
				debug:function(_this){
					_this.style.filter = "";
				}
			},
			/***** Dock *****/
			dock:{
				build:function(){
					$("#widgets .dock").each(function(){
						// Events
						var _this = this;
						$(_this).mouseenter(function(){
							$.CocaCola.dock.open(_this);
						}).mouseleave(function(){
							$.CocaCola.dock.close(_this);
						});
						$("a",_this).mouseenter(function(){
							$(this).addClass("hover");
						}).mouseleave(function(){
							$(this).removeClass("hover");
						}).each(function(){
							// If is active in URL
							if(document.location.href.indexOf($(this).attr("href")) != -1){
								$(this).addClass("on");
							}
						});
					});
				},
				open:function(_this){
					$("a",_this).each(function(){
						if(!$(this).hasClass("on")){
							this._restore = false;
							$(this).stop(true,false).animate({ width:23 }, 300);
							$("img",this).stop(true,false).animate({ height:63, width:23 }, 300);
						} else {
							this._restore = true;
							$(this).css({ zIndex:1 }).stop(true,false).animate({ marginTop:-14, marginLeft:-18, marginRight:-18 }, 300, function(){
								$(this).removeClass("on").css({ marginTop:0, marginLeft:0, marginRight:0 }).find("img").css({ width:23, height:63 });
							});
						}
					});
					$(".inner",_this).stop(true,false).animate({ height:54 }, 300);
				},
				close:function(_this){
					$("a",_this).each(function(){
						if(!this._restore){
							$(this).stop(true,false).animate({ width:26 }, 300);
							$("img",this).stop(true,false).animate({ height:53, width:19 }, 300);
						} else {
							this._restore = false;
							$(this).addClass("on").css({ zIndex:3, marginTop:-14, marginLeft:-18, marginRight:-18 }).stop(true,false).animate({ marginTop:-24, marginLeft:-15, marginRight:-15 }, 300);
						}
					});
					$(".inner",_this).stop(true,false).animate({ height:13 }, 300);
				}
			},
			/***** Customers *****/
			customers:{
				build:function(){
					$("#widgets .customers").each(function(){
						// Events
						var _this = this;
						$(_this).mouseenter(function(){
							$.CocaCola.customers.open(_this);
						}).mouseleave(function(){
							$.CocaCola.customers.close(_this)
						});
					});
				},
				open:function(_this){
					$(_this).children().stop(true,false).animate({ paddingRight:85, paddingTop:7 },300);
					$("img",_this).stop(true,false).animate({ width:74, height:64 },300);
					$(".a",_this).stop(true,false).animate({ marginTop:0, marginBottom:17, width:115 },300);
				},
				close:function(_this){
					$(_this).children().stop(true,false).animate({ paddingRight:15, paddingTop:3 },300);
					$("img",_this).stop(true,false).animate({ width:0, height:0 },300);
					$(".a",_this).stop(true,false).animate({ marginTop:-8, marginBottom:5, width:190 },300);
				}
			},
			/***** Slide *****/
			slider:{
				build:function(main,slides){
					// Params
					main.current = 0;
					// Default style
					$(main).css({ position:"relative", overflow:"hidden" });
					slides.each(function(i){
						var coord = (slides.length > 1 && i == 0)? 0 : 1000;
						$(this).css({ position:"absolute", left:coord, width:main.offsetWidth });
						// Events
						if(slides.length > 1){
							// DOM load
							$(document).ready(function(){
								if(!main.pager){
									main.pager = document.createElement("div");
									main.pager.className = "pager";
									main.appendChild(main.pager);
								}
								var bullet = document.createElement("span");
								if(i == 0){ bullet.className = "on" }
								main.pager.appendChild(bullet);
								bullet.onclick = function(){
									$.CocaCola.slider.slide(main,i);
								}
							});
						}
					});
				},
				slide:function(main,to){
					if(main.current != to){
						if(main.current > to){
							$(".item:eq("+main.current+")",main).css({ left:0 }).stop(true,true).animate({ left:main.offsetWidth },500);
							$(".pager span:eq("+main.current+")",main).removeClass("on");
							$(".item:eq("+to+")",main).css({ left:-main.offsetWidth }).stop(true,true).animate({ left:0 },500);
							$(".pager span:eq("+to+")",main).addClass("on");
							main.current = to;
						} else if(main.current < to) {
							$(".item:eq("+main.current+")",main).css({ left:0 }).stop(true,true).animate({ left:-main.offsetWidth },500);
							$(".pager span:eq("+main.current+")",main).removeClass("on");
							$(".item:eq("+to+")",main).css({ left:main.offsetWidth }).stop(true,true).animate({ left:0 },500);
							$(".pager span:eq("+to+")",main).addClass("on");
							main.current = to;
						}
					}
				}
			},
			/***** Tabs *****/
			tabs:{
				build:function(area){
					$(".tabs",area).each(function(){
						// Tabs
						var parent = this;
						var active = null;
						this.current = null;
						var tabs = new Array();
						$(this).find(".tabbed").each(function(i){
							// Prepare
							var title = $("> .h3:first-child",this).get(0);
							tabs.push({title:title.innerHTML,content:this,tall:$(this).hasClass("tall"),tall2:$(this).hasClass("tall2")});
							$(title).addClass("hidden");
							$(this).addClass("hidden");
						});
						// Build tabs on load
						(function(){
							// Navigation
							var tabnav = document.createElement("div");
							tabnav.className = "tabnav";
							var inner = document.createElement("div");
							inner.className = "inner";
							tabnav.appendChild(inner);
							// Items
							for(var i in tabs){
								var tab = document.createElement("div");
								tab.innerHTML = tabs[i].title;
								// Append
								inner.appendChild(tab);
								// Events
								tab.content = tabs[i].content;
								tab.index = i;
								tab.onclick = function(){
									document.location = "#"+this.index;
									$.CocaCola.tabs.change(parent,this);
								}
								// Active ?
								var anchor = document.location.hash.substring(1);
								if(active == null && anchor == i){
									active = tab;
								}
								// Last ?
								if(i == tabs.length-1){
									$(tab).addClass("last");
								}
								// Tall ?
								if(tabs[i].tall){
									$(tab).addClass("tall");
								} else if(tabs[i].tall2) {
									$(tab).addClass("tall2");
								}
							}
							// Append
							$(tabnav).prependTo(parent);
							// Active
							if(active != null){
								$.CocaCola.tabs.change(parent,active);
							} else {
								var tab = $(".inner div",parent).get(0);
								$.CocaCola.tabs.change(parent,tab);
							}
						})(jQuery);
					});
				},
				change:function(tabs,item){
					if(tabs.current != null){
						$(tabs.current.content).removeClass("visible").addClass("hidden");
						$(tabs.current).removeClass("on");
					}
					$(item.content).removeClass("hidden").addClass("visible");
					$(item).addClass("on");
					tabs.current = item;
					$.CocaCola.scroll.update();
				},
				update:function(tabs,index){
					var tab = $(".inner div",tabs).get(index);
					$.CocaCola.tabs.change(tabs,tab);
				}
			},
			/***** Global size *****/
			setsize:function(){
                if(!$(".container").get(0)) return;
				// Size
				var w = document.documentElement.offsetWidth;
				var h = $(".container").get(0).offsetHeight;
				h = (h < document.documentElement.offsetHeight)? document.documentElement.offsetHeight : h;
				// Site
				var container = $("#container").get(0);
				var cw = (1178-((1600-w)/576)*200);
				cw = (cw > 1178)? 1178 : cw;
				cw = (cw < 978)? 978 : cw;
				
				// Size
				$.CocaCola.offset = (100-(1178-cw)/2)/100;
				$.CocaCola.scale.update();
				container.style.width = cw+"px";
				if(w < container.offsetWidth){
					w = container.offsetWidth;
				}
				var screenRatio = w/h;
				// Background
				var bg = $("#background").get(0);
				var bgRatio = bg.offsetWidth/bg.offsetHeight;
				if(bgRatio < screenRatio){
					bg.width = w;
					bg.removeAttribute("height");
				} else {
					bg.height = h;
					bg.removeAttribute("width");
				}
				$(bg).parent().css({ height:h, width:cw });
				bg.style.marginLeft = "-"+(bg.offsetWidth/2)+"px";
				// Update scrolls
				$.CocaCola.scroll.update();
			},
			/***** Scale *****/
			scalable:new Array(),
			offset:0,
			scale:{
				build:function(area){
					$(".scalable",area).each(function(){
						// Store params
						$.store(this);
						$.CocaCola.scalable.push(this);
					});
					$.CocaCola.scale.update();
				},
				update:function(){
					$($.CocaCola.scalable).each(function(){
						$.CocaCola.scale.set(this);
					});
				},
				set:function(item){
					var properties = item._properties.split(",");
					var from = item._from.split(",");
					var to = item._to.split(",");
					// Update
					var obj = new Object();
					for(var i = 0; i < properties.length; i++){
						// New value
						var ref1 = (from[i])? from[i] : from[0];
						var ref2 = (to[i])? to[i] : to[0];
						var value = Math.round(parseFloat(ref1)+( parseFloat(ref2)- parseFloat(ref1))*$.CocaCola.offset);
						obj[properties[i]] = value;
					}
					$(item).css(obj);
				}
			},
			/***** Strip *****/
			strip:{
				build:function(area){
					$(".strip",area).each(function(){
						var _this = this;
						var stuff = $(".stuff",this).get(0);
						_this._width = $.store(stuff)._width;
						$(".in",stuff).css({ width:stuff._width });
						$(_this).mouseenter(function(){
							$.CocaCola.strip.tease(_this);
						}).click(function(){
							$.CocaCola.strip.open(_this);
						}).mouseleave(function(){
							$.CocaCola.strip.close(_this);
						});
					});
				},
				tease:function(o){
					$(".stuff",o).stop(true,false).animate({ width:82 }, 200);
				},
				open:function(o){
					$(".stuff",o).stop(true,false).animate({ width:o._width }, 500);
				},
				close:function(o){
					$(".stuff",o).stop(true,false).animate({ width:48 }, 500);
				}
			},
			/***** Scroll *****/
			scrollable:new Array(),
			scroll:{
				speed:20,
				build:function(area){
					$(".scrollable",area).each(function(){
						// Store params
						var _this = this;
						$.store(_this);
						$.CocaCola.scrollable.push(_this);
						// Add container
						$(_this).html("<div class=\"scrolled\">"+$(_this).html()+"</div>").css({ position:"relative", overflow:"hidden" });
						_this.content = $(".scrolled",_this).get(0);
						_this.active = false;
						// Set sizes
						$.CocaCola.scroll.set(this);
						// Add tools
						$(_this).prepend("<div class=\"tools\"><div class=\"cursor\"></div></div>");
						$(".cursor",this).draggable({
							containment:"parent",
							axis:"y",
							drag:function(){
								var prct = (this.offsetTop+(this.offsetHeight*this.offsetTop/this.parentNode.offsetHeight))/this.parentNode.offsetHeight;
								$(_this.content).css({ marginTop:Math.ceil(prct*_this._delta) });
							}
						});
						// Wheel
						$(_this).bind('mousewheel', function(event, delta) {
							if(_this.active){
								var n = _this.content.offsetTop+delta*$.CocaCola.scroll.speed;
								n = (n < _this._delta)? _this._delta : (n > 0)? 0 : n;
								$(_this.content).css({ marginTop:n });
								$.CocaCola.scroll.sync(_this,n);
								return false;
							}
						});

					});
				},
				update:function(){
					$($.CocaCola.scrollable).each(function(){
						$.CocaCola.scroll.set(this);
					});
				},
				set:function(item){
					// Set params
					$(item.content).css({ width:"94%" });
					item._delta = item.offsetHeight-item.content.offsetHeight;
					if(item._delta >= 0){
						item.active = false;
						$(".tools",item).hide();
						$(item.content).css({ marginTop:0 });
					} else {
						item.active = true;
						$(item.content).css({ width:item.content.offsetWidth-20 });
						item._delta = item.offsetHeight-item.content.offsetHeight;
						$(".tools",item).show();
						var n = item.content.offsetTop;
						n = (n < item._delta)? item._delta : (n > 0)? 0 : n;
						$(item.content).css({ marginTop:n });
						$.CocaCola.scroll.sync(item,n);
					}
				},
				sync:function(item,n){
					// Update cursor
					var cursor = $(".cursor",item).get(0);
					if(cursor){
						var prct = n/item._delta;
						var offset = ((cursor.parentNode.offsetHeight*prct)-(cursor.offsetHeight*prct));
						$(".cursor",item).css({ top:offset });
					}
				}
			},
			/***** FAQ *****/
			faqs:new Array(),
			faq:{
				build:function(area){
					$(".faq",area).each(function(){
						var _this = this;
						_this._item = new Array();
						_this._on = null;
						$("dt",_this).each(function(i){
							this._content = $(this).next().addClass("hidden").get(0);
							this._index = i;
							$(this).click(function(){
								$.CocaCola.faq.open(_this,this._index);
								$.CocaCola.scroll.update();
							});
							_this._item.push(this);
						});
						$.CocaCola.faqs.push(this);
					});
				},
				open:function(faq,index){
					if(faq._on != index){
						if(faq._on != null){
							$.CocaCola.faq.close(faq,faq._on);
						}
						$(faq._item[index]).addClass("on");
						$(faq._item[index]._content).removeClass("hidden").addClass("visible");
						faq._on = index;
					} else {
						$.CocaCola.faq.close(faq,faq._on);
					}
				},
				close:function(faq,index){
					$(faq._item[index]).removeClass("on");
					$(faq._item[index]._content).removeClass("visible").addClass("hidden");
					faq._on = null;
				}
			},
			/***** Fieldcleaner *****/
			fieldtocheck:null,
			fieldcleaner:{
				build:function(area){
					$(".fieldcleaner",area).each(function(){
						$(this).addClass("tobefilled");
						this._timer = null;
						this._label = $(this).prev().get(0);
						// Default state
						$.CocaCola.fieldtocheck = this;	
						$.CocaCola.fieldcleaner.check();
						this.onchange = function(){
							$.CocaCola.fieldtocheck = this;
							$.CocaCola.fieldcleaner.check();
						}
						this.onfocus = function(){
							clearInterval(this._timer);
							$.CocaCola.fieldtocheck = this;
							this._timer = setInterval($.CocaCola.fieldcleaner.check,50);
							$(this._label).addClass("filling");
						}
						this.onblur = function(){
							clearInterval(this._timer);
							$.CocaCola.fieldtocheck = null;
							$(this._label).removeClass("filling");
						}
					});
				},
				check:function(){
					var _field = $.CocaCola.fieldtocheck;
					if(_field.value == ""){
						$(_field).removeClass("filled");
					} else {
						$(_field).addClass("filled");
					}
				}
			},
			/***** Popin *****/
			popin:{
				opened:null,
				bg:null,
				closer:null,
				over:null,
				from:null,
				open:function(idlayer, queryString){

                    var layer = $("#"+idlayer).get(0);

					if (idlayer== 'popcontact') {
						
						// Querystring to object
						var qso = queryString.split("&");
						var kv = new Object();
						for(var i=0; i<qso.length; i++){
							var kvs = qso[i].split("=");
							kv[kvs[0]] = kvs[1];
						}

						$('#popcontact').html(
							'<iframe frameborder="0" src="'+BaseUrlSsl+'/Footer/Contact/ContactForm.aspx?'+queryString+'" width="735" height="'+
							(kv.openSrc!='9999'?460:610)+
							'"></iframe>'
						);						
					}
					
					// Move node
					if(layer.parentNode){
						// Add mark
						$(layer).after("<div id=\"popinfrom\"></div>");
						$.CocaCola.popin.from = $("#popinfrom").get(0);
						$(layer).appendTo(document.body);
					}
					// Background & closer
					if($.CocaCola.popin.bg == null){
						$("<div class=\"popinbg\"></div><div class=\"popincloser\" onclick=\"$.CocaCola.popin.close();\"></div><div class=\"popinover\"></div>").appendTo(document.body);
						$.CocaCola.popin.bg = $(".popinbg").get(0);
						$.CocaCola.popin.closer = $(".popincloser").get(0);
						$.CocaCola.popin.over = $(".popinover").get(0);
					}
					// Animation
					var w = layer.offsetWidth;
					var h = layer.offsetHeight;
					$($.CocaCola.popin.over).css({ display:"block", opacity:0 }).stop(true,false).animate({ opacity:0.5 }, 300);
					$($.CocaCola.popin.bg).css({ display:"block", opacity:0, width:0, height:0, margin:0 }).stop(true,false).animate({ opacity:1, width:w, height:h, marginTop:-(h/2)-5, marginLeft:-(w/2)-5 }, 500);
					$(layer).css({ opacity:0, marginTop:-h/2, marginLeft:-w/2 }).addClass("visible").stop(true,false).delay(500).animate({ opacity:1 }, 500, function(){
						this.style.filter = "";
					});
					$($.CocaCola.popin.closer).css({ display:"block", opacity:0, marginTop:-(h/2)-17, marginLeft:(w/2)-17 }).stop(true,false).delay(500).animate({ opacity:1 }, 150, function(){
						this.style.filter = "";
					});
					// Settings
					$.CocaCola.popin.opened = layer;
					$(document.body).addClass("poped");
				},
				close:function(callback){
					$($.CocaCola.popin.closer).stop(true,false).animate({ opacity:0 }, 150, function(){
						$(this).css({ display:"none" });
					});
					$($.CocaCola.popin.opened).stop(true,false).animate({ opacity:0 }, 500, function(){
						if($.CocaCola.popin.from != null){
							$($.CocaCola.popin.opened).insertBefore($.CocaCola.popin.from);
							$($.CocaCola.popin.from).remove();
						}
						$($.CocaCola.popin.opened).removeClass("visible");
						// Settings
						$(document.body).removeClass("poped");
						$.CocaCola.popin.opened = null;
					});
					$($.CocaCola.popin.bg).stop(true,false).delay(300).animate({ opacity:0, width:0, height:0, marginTop:-5, marginLeft:0-5 }, 500, function(){
						$(this).css({ display:"none" });

                    if(callback){
                        setTimeout(function(){
							callback();
						},50);
                    }
					});
					$($.CocaCola.popin.over).stop(true,false).delay(500).animate({ opacity:0 }, 300, function(){
						$(this).css({ display:"none" });
                        
					});
				}
			},
			/***** Date selector *****/
			dateselector:{
				build:function(area){
					$(".dateselector",area).each(function(){
						var _this = this;
						_this._on = null;
						$.store(_this);
						$(_this.parentNode).css({ position:"relative" });
						// Deactivate links
						$("a",_this).each(function(){
							this._href = $(this).attr("href");
							this.removeAttribute("href");
							this._list = _this;
							if(this.parentNode.className == "on"){
								_this._on = this.parentNode;
							}
						}).click($.CocaCola.dateselector.load);
						// Need drag ?
						if(_this.offsetHeight > _this.parentNode.offsetHeight){
							// Drag
							$(_this).draggable({
								axis:"y",
								start:function(){
									$("a",_this).unbind("click");
								},
								stop:function(){
									$("a",_this).animate({ marginTop:0 }, 10, function(){ $(this).click($.CocaCola.dateselector.load); });
									if(!_this._max){
										_this._max = _this.parentNode.offsetHeight-_this.offsetHeight;
									}
									// Restrict
									if(_this.offsetTop > 0){
										$(_this).stop(true,false).animate({ top:0 }, 500);
									} else if(_this.offsetTop < _this._max){
										$(_this).stop(true,false).animate({ top:_this._max }, 500);
									}
								}
							});
							// Mousewheel
							$(_this).bind('mousewheel', function(event, delta) {
								if(!_this._max){
									_this._max = _this.parentNode.offsetHeight-_this.offsetHeight;
								}
								var n = _this.offsetTop+delta*$.CocaCola.scroll.speed;
								n = (n < _this._max)? _this._max : (n > 0)? 0 : n;
								$(_this).css({ top:n });
								return false;
							});
						}
					});
				},
				load:function(){
					var _this = this;
					$.CocaCola.refresh(this._href,this._list._refresh,["scroll","scale","dateselector"],function(){
						if(_this._list._on != null){
							$(_this._list._on).removeClass("on");
						}
						$(_this.parentNode).addClass("on");
						_this._list._on = _this.parentNode;
						// Image bug
						$("#datecontent img").load(function(){
							// Update scrolls
							$.CocaCola.scroll.update();
						});
					});
				}
			},
			/***** Ajax news *****/
			ajaxnews:{
				build:function(area){
					// Main nav
					$(".subnav",area).each(function(){
						var _this = this;
						// Store
						$.store(_this);
						// Accordion
						$("> ul > li",_this).each(function(){
							// Store
							this._list = _this;
							var ul = $("> ul",this);
							this._height = ul.height();
							// Has active
							if($(this).hasClass("open")){
								_this._open = this;
							} else {
								ul.hide();
							}
							if(this._height != null){
								$(this).click($.CocaCola.ajaxnews.fold);
							}
						})
						// Deactivate links if AJAX
						if(!_this._classic){
							$("a",_this).each(function(){
								this._href = $(this).attr("href");
								this.removeAttribute("href");
								this._list = _this;
								if($(this.parentNode).hasClass("on")){
									_this._on = this.parentNode;
								}
							}).click(function(){
								$.CocaCola.ajaxnews.load.apply(this,[["scroll","scale","linksnews"]]);
							});
						}
					});
					// Build news links
					$.CocaCola.ajaxnews.newslinks();
				},
				fold:function(){
					if(!this._list._open || this._list._open != this){
						var _this = this;
						if(_this._list._open){
							$("ul",_this._list._open).css({ height:"auto" }).stop(true,false).animate({ height:0 }, 250, function(){
								$(_this._list._open).removeClass("open");
								$(this).css({ display:"none" });
								$.CocaCola.setsize();
							});
						}
						$("ul",_this).css({ display:"block", height:0 }).stop(true,false).animate({ height:_this._height }, 250, function(){
								$(_this).addClass("open");
								_this._list._open = _this;
						});
					}
				},
				newslinks:function(){
					var _this = $("#newslist").get(0);
					if(_this){
						if(!_this._length){
							$.store(_this);
						}
						// Deactivate links
						$("a",_this).each(function(){
							this._href = $(this).attr("href");
							this.removeAttribute("href");
							this._list = _this;
							if(this.parentNode.className == "on"){
								_this._on = this.parentNode;
							}
						}).click(function(){
							$.CocaCola.ajaxnews.load.apply(this,[["scroll","scale"]]);
						});
					}
				},
				load:function(rebuild){
					var _this = this;
					if(_this._list._on != _this.parentNode){
						$.CocaCola.refresh(this._href,this._list._refresh,rebuild,function(){
							if(_this._list._on != null){
								$(_this._list._on).removeClass("on");
							}
							$(_this.parentNode).addClass("on");
							_this._list._on = _this.parentNode;
						});
					}
				}
			}
		}
	});
})(jQuery);

(function($) {
	$.fn.extend({
		pi_seo:function(o){
			return this.each(function(index,dom){
				// Previous version didn't work with images. Due to the ".parent()" instruction that targets the <img /> tag, not the <a>.
				var $this = $(this),
					_target = $this.attr("data-target") || "_self",
					_href = $this.attr("data-href") || "#dummy",
					_onclick = $this.attr("data-onclick") || "";
				
				$this.wrap('<a href="'+_href+'" target="'+_target+'" onclick="'+_onclick+'">'+$this.html()+'</a>');
				$this.remove();
				
			});
		}
	});	
})(jQuery);

/***** Get params from CSS class *****/
(function($) {
	$.extend({
		store: function(o) {
			if(!o._length){ o._length = 0; }
			var css = o.className.split(" ");
			// Parse classes
			for (var i = 0; i < css.length; i++) {
				if (css[i].indexOf(":") != -1) {
					// Store params
					var k = css[i].substring(0,css[i].indexOf(":"));
					var v = css[i].substring(css[i].indexOf(":")+1);
					o["_"+k] = decodeURI(v);
					$(o).removeClass(css[i]);
					o._length++;
				}
			}
			return o;
		},
		addparam:function(k,v,o){
			if(!o._length){ o._length = 0; }
			o["_"+k] = v;
			o._length++;
		}
	});
})(jQuery);

(function($) {
	$.fn.extend({
		coca_link_infos:function(o){
			return this.each(function(index,dom){
				
				var $this = $(this),
					$cont = $this.find('.cont');
				
				$this
					.css({ 'cursor':'pointer' })
					.click(function(){
						$cont.css({ 'display':$cont.css('display')==='block'?'none':'block' });
						$.CocaCola.scroll.update();
					});
				
			});
		}
	});	
})(jQuery);

/***** Events & Builders *****/
$(window).resize($.CocaCola.setsize);
$(window).load(function(){
	$(document.body).addClass("loaded");
	$.CocaCola.setsize();
	$.CocaCola.transition.build();
	// Cookie
	if(cooked != "" || $.CocaCola.home == false || $.CocaCola.activezone != null){
		$.CocaCola.loaded();
	}
});
$(document).ready(function(){
	$.CocaCola.fieldcleaner.build();
	$.CocaCola.setsize();
	$('.seoa').pi_seo();
	$('.linkinfos').coca_link_infos();
});

window.onbeforeunload = function () {

}

// Widgets
$.CocaCola.dock.build();
$.CocaCola.customers.build();
$.CocaCola.happiness.build();

// Size
$.CocaCola.setsize();

// Init
$.CocaCola.init([
	"navigation",
	"scroll",
	"tabs",
	"dateselector",
	"faq",
	"strip",
	"scale",
	"ajaxnews",
	"tgs"
]);

// Scripted
var cooked = lit_cook("init");

var ipad = navigator.userAgent.indexOf('iPad')!=-1,
	iphone = navigator.userAgent.indexOf('iPhone')!=-1;

$(".loader").show().css({ opacity:0.8 });
if($(".home").get(0)){
	$.CocaCola.home = true;
	$.CocaCola.news.build();
	$.CocaCola.wills.build();
	$("#homeintro h1").addClass("hidden");
	$("#homeintro").removeClass("visible").addClass("hidden");
	$(document.body).addClass("scripted");
	// Cookie
	
	var $loader = $("#loader");
	
	if(cooked == "" && $.CocaCola.activezone == null && !ipad && !iphone){
		$(".backgrounds img").addClass("invisible");
		$("#intro").show();
		
		$loader.addClass("nologo").animate({ opacity:0 }, 250, function(){
			$loader.hide();
		});
		cre_cook("init","true",1);
	} else {
		if (ipad || iphone) {
			$.CocaCola.loaded();
		}
		$("#intro").remove();
	}
} else {
	$(document.body).addClass("widgetsclosed scripted");
}

// Cookie
function cre_cook0(nom, contenu) {
	document.cookie = nom + "=" + escape(contenu);
}
function cre_cook(nom, contenu, jours) {
	var expireDate = new Date();
	expireDate.setTime(expireDate.getTime() + jours * 24 * 3600 * 1000);
	document.cookie = nom + "=" + escape(contenu) + ";path=/;expires=" + expireDate.toGMTString();
}
function lit_cook(nom) {
	var deb, fin;
	deb = document.cookie.indexOf(nom + "=")
	if (deb >= 0) {
		deb += nom.length + 1;
		fin = document.cookie.indexOf(";", deb);
		if (fin < 0){ fin = document.cookie.length }
		return unescape(document.cookie.substring(deb, fin))
	}
	return "";
}

function contactFormIFrame () {
	$.CocaCola.popin.close(function(){ $.CocaCola.popin.open('contactResult'); });
}

