
// Define global _page object
var _page = (function () {	

	// Extend function class with bindArguments method 
	Function.prototype.bindArgs = function (scope, args, event) {
		var reference = this;
		return function (e) {
			reference.apply(scope, (event ?(args || []).concat([(e || window.event)]): (args || arguments))); // Only append event as last element when args and event has been set.
		};
	};

	// Backwards compatibility push array
	if (typeof Array.prototype.push !== "function") {
		Array.prototype.push = function (value) {
			this[this.length] = value;
		};
	}

	var Core = function () {
	
		var util = {
			trim: function (str) {
				return str.replace(/^\s+|\s+$/g, '');
			},		
			clean: function (str) {
				return util.trim(str.replace(/\s{2,}/g, ' '));
			},
			hasElement: function (obj, elem) {
				for (var i = 0; i < obj.length; i += 1) {
					if (obj[i] === elem) {
						return true;
					}	
				}	
				return false;
			},
			getTime: function () {
				return (new Date().getTime());
			} 	
		},
		
			dom = (function () {
				var d = document,
					l = d.layers,
					op = navigator.userAgent.indexOf('Opera') !== -1,
					px = 'px';
					
				return {	
					hasClass: function (el, sClassName) {
						if (el) {
							return (el.className.indexOf(sClassName, ' ') > -1)? true: false;
						}
					},
					addClass: function (el, sClassName) {
						if (el && !dom.hasClass(el, sClassName)) {
							el.className = util.clean(el.className + ' ' + sClassName);		
						}
					},
					setClass: function (el, sClassName) {
						if (el) {
							el.className = sClassName;		
						}
					},
					removeClass: function (el, sClassName) {
						if (el) {
							el.className = util.clean(el.className.replace(new RegExp('(^|\\s)' + sClassName + '(?:\\s|$)'), '$1'));
						}
					},
					findPosY: function (obj) {
						var curtop = 0;
						if (obj) {
							if (obj.offsetParent) {
								while (obj.offsetParent) {
									curtop += obj.offsetTop;
									obj = obj.offsetParent;
								}
							} else if (obj.y) {
								curtop += obj.y;
							}	
						}
						return curtop;
					},
					findPosX: function (obj) {
						var curleft = 0;
						if (obj) {
							if (obj.offsetParent) {			
								while (obj.offsetParent) {
									curleft += obj.offsetLeft;
									obj = obj.offsetParent;
								}
							} else if (obj.x) {
								curleft += obj.x;
							}	
						}
						return curleft;
					},
					getScreenHeight: function () {
						var pos = "";
						if (typeof self.innerHeight !== "undefined") { 
							pos = self.innerHeight; 
						} else if (document.documentElement && document.documentElement.clientHeight) { 	
							pos = document.documentElement.clientHeight; 
						} else if (document.body) { 
							pos = document.body.clientHeight; 
						}
						return pos;
					},
					getScreenWidth: function () {
						var pos = "";
						if (typeof self.innerWidth !== "undefined") { 
							pos = self.innerWidth; 
						} else if (document.documentElement && document.documentElement.clientWidth) { 
							pos = document.documentElement.clientWidth;
						} else if (document.body) { 
							pos = document.body.clientWidth; 
						}
						return pos;
					},
					getScrollPosTop: function () {
						var pos = "";
						if (typeof self.pageYOffset !== "undefined") { 
							pos = self.pageYOffset; 
						} else if (document.documentElement && document.documentElement.scrollTop) { 
							pos = document.documentElement.scrollTop; 
						} else if (document.body) { 
							pos = document.body.scrollTop; 
						}
						return pos;	
					},
					// Set opacity on an element 
					setOpacity: function (obj, opacity) {
						if (opacity === 0) {
							if (obj.style.visibility !== "hidden") {
								obj.style.visibility = "hidden";
							}	
						} else {
							if (obj.style.visibility !== "visible") {
								obj.style.visibility = "visible";
							}	
						}
						if (!obj.currentStyle || !obj.currentStyle.hasLayout) {
							obj.style.zoom = 1;
						}	
						if (_page.browser.isIE) {
							if (opacity === 1) {
								try {
									obj.style.cssText = obj.style.cssText.replace(/filter:[^;]*;/i, "");
								} catch (e) {
									obj.style.filter = '';
								}				
							} else {
								obj.style.filter = "alpha(opacity=" + opacity * 100 + ")";	
							}	
						}
						obj.style.opacity = opacity;
					},
					// Move the element to the garbage bin for proper garbage collection
					discardElement: function (el) {
						var garbageBin = document.getElementById('p-ieleakgarbagebin'); 
						if (!garbageBin) { 
							garbageBin = document.createElement('DIV'); 
							garbageBin.id = 'p-ieleakgarbagebin'; 
							garbageBin.style.display = 'none'; 
							document.body.appendChild(garbageBin); 
						} 
						garbageBin.appendChild(el); 
						garbageBin.innerHTML = '';
					},
					gE: function (e, f) {
						if (l) {
							var V, W, t;
							f = (f)? f: self;
							V = f.document.layers;
							if (V) {
								if (V[e]) {
									return V[e];
								}	
								for (W = 0;W < V.length; W += 1) {
									t = arguments.callee(e, V[W += 1]);
								}
								return t;
							}
						}
						if (d.getElementById) {
							return d.getElementById(e);
						}	
						if (d.all) {
							return d.all[e];
						} else { 
							return null;
						}	
					},
					sE: function (e) {
						if (l) {
							e.visibility = 'show';
						} else {
							e.style.visibility = 'inherit';
						}
					},
					hE: function (e) {
						if (l) {
							e.visibility = 'hide';
						} else {
							e.style.visibility = 'hidden';
						}
					},
					dE: function (e) {
						e.style.display = 'block';
					},
					nE: function (e) {
						e.style.display = 'none';
					},
					sZ: function (e, z) {
						if (l) {
							e.zIndex = z;
						} else {
							e.style.zIndex = z;
						}
					},
					sX: function (e, x) {
						if (l) {
							e.left = x;
						} else if (op) {
							e.style.pixelLeft = x;
						} else {
							e.style.left = x + 'px';
						}
					},
					sY: function (e, y) {
						if (l) {
							e.top = y;
						} else if (op) {
							e.style.pixelTop = y;
						} else {
							e.style.top = y + 'px';
						}
					},
					sW: function (e, w) {
						if (l) {
							e.clip.width = w;
						} else if (op) {
							e.style.pixelWidth = w;
						} else {
							e.style.width = w + 'px';
						}
					},
					gW: function (e) {
						if (l) {
							return e.clip.width;
						} else if (op) {
							return e.style.pixelWidth;
						} else {
							return e.style.width;
						}
					},
					sH: function (e, h) {
						if (l) {
							e.clip.height = h;
						} else if (op) {
							e.style.pixelHeight = h;
						} else {
							e.style.height = h + 'px';
						}
					},
					sC: function (e, t, r, b, x) {
						var X;
						if (l) {
							X = e.clip; 
							X.top = t; 
							X.right = r; 
							X.bottom = b; 
							X.left = x;
						} else {
							e.style.clip = 'rect(' + t + px + ' ' + r + px + ' ' + b + px + ' ' + x + px + ')';
						} 
					},
					wH: function (e, h) { 
						if (l) {
							var Y = e.document;
							Y.open();
							Y.write(h);
							Y.close();
						} 
						if (e.innerHTML) {
							e.innerHTML = h;
						}
					}
				};
			})(),
		
			/* STATIC CLASS : TRANSITION
				- Credits: Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>.
			*/
			transition = {
				bounce: {
					easeOut: function (t, b, c, d) {
						if ((t /= d) < (1 / 2.75)) {
							return c * (7.5625 * t * t) + b;
						} else if (t < (2 / 2.75)) {
							return c * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + b;
						} else if (t < (2.5 / 2.75)) {
							return c * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + b;
						} else {
							return c * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + b;
						}
					},
					easeIn: function (t, b, c, d) {
						return c - transition.bounce.easeOut(d - t, 0, c, d) + b;
					},
					easeInOut: function (t, b, c, d) {
						if (t < d / 2) {
							return transition.bounce.easeIn(t * 2, 0, c, d) * 0.5 + b;
						} else {
							return transition.bounce.easeOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
						}	
					}
				},
				expo: {
					easeIn: function (t, b, c, d) {
						return (t === 0)? b: c * Math.pow(2, 10 * (t / d - 1)) + b;
					},
					easeOut: function (t, b, c, d) {
						return (t === d)? b + c: c * (-Math.pow(2, -10 * t / d) + 1) + b;
					},
					easeInOut: function (t, b, c, d) {
						if (t === 0) {
							return b;
						}
						if (t === d) {
							return b + c;
						}	
						if ((t /= d / 2) < 1) {
							return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
						}	
						return c / 2 * (-Math.pow(2, -10 * (t -= 1)) + 2) + b;
					}
				},
				linear: function (t, b, c, d) {
					return c * t / d + b;
				}
			},
	
			// CLASS : Events	
			events = {
				__listeners: [],
				// Add event 
				add: function (el, type, fn) {
					if (el) {
						if (el.addEventListener) {
							el.addEventListener(type, fn, false);
						} else if (el.attachEvent) {
							el.attachEvent('on' + type, fn);
						}	
						var event = {
							el: el,
							type: type,
							fn: fn
						};
						_page.events.__listeners.push(event);
						return event;
					}
				},
				// Remove event
				remove: function (el, type, fn) {
					if (el) {
						if (el.removeEventListener) {
							el.removeEventListener(type, fn, false);
						}	
						else if (el.detachEvent) {
							el.detachEvent('on' + type, fn);
						}
					}	
				},
				// Remove SAFELY event to avoid mem leaks, only applicable if you have stored the element
				removeSafe: function (event) {
					if (event) {
						var el = event.el, i,
						type = event.type,
						fn = event.fn;
						_page.events.remove(el, type, fn);
						for (i = 0; i < this.__listeners.length; i += 1) {
							if (this.__listeners[i] === event) {
								_page.events.__listeners.splice(i, 1);
								break;
							}
						}
					}						
				},
				// Remove All events 
				removeAll: function () {
					while (_page.events.__listeners.length > 0) {
						_page.events.removeSafe(_page.events.__listeners[0]);
					}	
				},
				// Cancel event
				cancel: function (e) {
					if (!e) {
						e = window.event || {};
					}	
					if (e.stopPropagation) {
						e.stopPropagation();
					}	
					if (e.preventDefault) {
						e.preventDefault();
					}
					e.cancelBubble = true;
					e.cancel = true;
					e.returnValue = false;
					return false;
				},
				// Get target 
				getTarget: function (e) {
					var targ;
					if (!e) {
						e = window.event;
					}	
					if (e.target) {
						targ = e.target;
					} else if (e.srcElement) {
						targ = e.srcElement;
					}	
					if (targ.nodeType === 3) { // defeat Safari bug
						targ = targ.parentNode;
					}	
					return targ;
				},
				// Should be moved
				start: function (obj, type, args) {
					args = (!args? arguments: args);
					if (typeof obj[type] === "function") {
						obj[type].apply(obj, args);
					}
				}
			},
			BrowserDetect, Animation;
		

		/* CLASS: Browser detection   */
		BrowserDetect = function () {
			var ua = navigator.userAgent.toLowerCase(); 
			// browser engine name
			this.isGecko       = (ua.indexOf('gecko') !== -1 && ua.indexOf('safari') === -1);
			this.isAppleWebKit = (ua.indexOf('applewebkit') !== -1);
			// browser name
			if (ua.indexOf('opera') !== -1) {
				this.isOpera = true; 
				this.name = "Opera";
			}
			if ((ua.indexOf('msie') !== -1 && !this.isOpera && (ua.indexOf('webtv') === -1))) {
				this.isIE = true; 
				this.name = "Internet Explorer";
			}
			if (this.isGecko && ua.indexOf('gecko/') + 14 === ua.length) {
				this.isMozilla = true; 
				this.name = "Mozilla";
			}
			if (this.isGecko? (ua.indexOf('netscape') !== -1): ((ua.indexOf('mozilla') !== -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') === -1) && (ua.indexOf('compatible') === -1) && (ua.indexOf('webtv') === -1) && (ua.indexOf('hotjava') === -1))) {
				this.isNS = true; 
				this.name = "Netscape";
			}
			if (ua.indexOf('firebird/') !== -1) {
				this.isFirebird = true; 
				this.name = "Firebird";
			}
			if (ua.indexOf('firefox/') !== -1) {
				this.isFirefox = true; 
				this.name = "FireFox";
			}
			if (ua.indexOf('safari/') !== -1) {
				this.isSafari = true; 
				this.name = "Safari";
			}
			if (ua.indexOf('konqueror') !== -1) {
				this.isKonqueror = true; 
				this.name = "Konqueror";
			}
			if (ua.indexOf('omniweb') !== -1) {
				this.isOmniweb = true; 
				this.name = "Omniweb";
			}
			if (ua.indexOf('webtv') !== -1) {
				this.isWebtv = true; 
				this.name = "WebTV";
			}	
			if (ua.indexOf('icab') !== -1) {
				this.isICab = true; 
				this.name = "Icab";
			}
			if (ua.indexOf('camino') !== -1) {
				this.isCamino = true; 
				this.name = "Camino";
			}	
			// spoofing and compatible browsers
			this.isIECompatible = ((ua.indexOf('msie') !== -1) && !this.isIE);
			this.isNSCompatible = ((ua.indexOf('mozilla') !== -1) && !this.isNS && !this.isMozilla);
			// rendering engine versions
			this.geckoVersion = ((this.isGecko)? ua.substring((ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14)): -1);
			this.equivalentMozilla = ((this.isGecko)? parseFloat(ua.substring(ua.indexOf('rv:') + 3)): -1);
			// browser version
			this.versionMinor = parseFloat(navigator.appVersion); 
			// correct version number
			if (this.isGecko && !this.isMozilla) {
				if (this.isFirefox) {
					this.versionMinor = parseFloat(ua.substring(ua.indexOf('firefox/') + 8, ua.length));
				} else {
					this.versionMinor = parseFloat(ua.substring(ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1));
				}
			} else if (this.isMozilla) { 
				this.versionMinor = parseFloat(ua.substring(ua.indexOf('rv:') + 3));
			} else if (this.isIE && this.versionMinor >= 4) { 
				this.versionMinor = parseFloat(ua.substring(ua.indexOf('msie ') + 5));
			} else if (this.isSafari) { 
				this.versionMinor = parseFloat(ua.substring(ua.indexOf('safari/') + 7));
			} else if (this.isOmniweb) {
				this.versionMinor = parseFloat(ua.substring(ua.indexOf('omniweb/v') + 9));
			} else if (this.isOpera && !this.isMac) {
				this.versionMinor = parseFloat(ua.substring(ua.indexOf('opera') + 6));
			}
			this.versionMajor = parseInt(this.versionMinor, 10); 
			// dom support 
			this.isDOM = (document.getElementById && document.createElement? true: false);
			this.isDOM1 = (document.getElementById? true: false);
			this.isDOM2Event = (document.addEventListener && document.removeEventListener? true: false);
			// dhtml support
			this.isDHTML = (document.getElementById || document.all || document.layers? true: false);
			// css compatibility mode
			this.mode = document.compatMode? document.compatMode: 'BackCompat';
			// platform
			if (ua.indexOf('win') !== -1) {
				this.isWin = true;
				this.platform = "win";
			}
			if (this.isWin && (ua.indexOf('95') !== -1 || ua.indexOf('98') !== -1 || ua.indexOf('nt') !== -1 || ua.indexOf('win32') !== -1 || ua.indexOf('32bit') !== -1 || ua.indexOf('xp') !== -1)) {
				this.isWin32 = true;
				this.platform = "win32";
			}
			if (ua.indexOf('mac') !== -1) {
				this.isMac = true; 
				this.platform = "mac";
			}
			if (ua.indexOf('x11') !== -1) {
				this.isMac = true;
				this.platform = "unix";
			}
			if (ua.indexOf('linux') !== -1) {
				this.isMac = true;
				this.platform = "linux";
			}
			// specific browser shortcuts
			this.isNS6x = (this.isNS && this.versionMajor === 6);
			this.isNS6up = (this.isNS && this.versionMajor >= 6);
			this.isNS7x = (this.isNS && this.versionMajor === 7);
			this.isNS7up = (this.isNS && this.versionMajor >= 7);
			this.isIE5x = (this.isIE && this.versionMajor === 5);
			this.isIE55 = (this.isIE && this.versionMinor === 5.5);
			this.isIE5up = (this.isIE && this.versionMajor >= 5);
			this.isIE6x = (this.isIE && this.versionMajor === 6);
			this.isIE6up = (this.isIE && this.versionMajor >= 6);
			this.isIE7up = (this.isIE && this.versionMajor >= 7);
		};
	
		/* CLASS: ANIMATION   */
		Animation = function (obj, params) {
			this.initialize(obj, params);
		};
		Animation.prototype = {
			// Initialize object
			initialize: function (obj, params) {
				this.options = params;
				this.options.fps = parseInt(this.options.fps || 50, 10);
				this.options.duration = parseInt(this.options.duration || 0, 10);
				this.elNode = obj;
				this.running = false;
			},
			// Start animation
			start: function (obj) {
				this.running = true;
				this.onStart();
				for (var id in obj) {
					if (obj.hasOwnProperty(id)) {
						this.style = id;
						this.from = obj[id][0];
						this.to = obj[id][1];
					}
				}	
				this.change = this.to - this.from; 
				this.now = this.from;
				this.timeStart = util.getTime();
				this.set(this.from);
				this.timer = window.setInterval(this.tween.bindArgs(this), Math.round(1000 / this.options.fps));
			},
			// Actual tweening
			tween: function () {
				var time = util.getTime();
				if (time < this.timeStart + this.options.duration) {
					this.now = Math.round(this.options.transition.apply(this, [time - this.timeStart, this.from, this.change, this.options.duration]) * 100) / 100;
					this.set(this.now);
				} else {
					this.set(this.to);
					this.stop();
					this.onComplete();
				}
			},
			// Set the dimensions of the style
			set: function (value, obj) {
				obj = obj || this.elNode;
				switch (this.style) {
				case "height": 
				case "left": 
				case "right":
					obj.style[this.style] = value + 'px';
					break;    
				case "opacity":
					_page.dom.setOpacity(obj, value);
					break;
				default:
					obj.style[this.style] = value;
				}
			},
			// Stop animation
			stop: function () {
				window.clearInterval(this.timer);
				this.running = false;
				this.elNode = null;
			},
			// Function to call when the animation is ready
			onComplete: function () {
				if (this.options.onComplete) {
					events.start(this.options, 'onComplete');
				}	
			},
			// Function to call when the animation starts
			onStart: function () {
				if (this.options.onStart) {
					events.start(this.options, 'onStart');
				}	
			}
		};
		
				// Revised onContent ready function based at jQuery domReady
		this.onContentReady = (function () {
			var loadFn = [], initialized = false, ready = false,
				doLoad = function () {
					ready = true;
					for (var i = 0 ;i < loadFn.length; i += 1) {
						try {
							loadFn[i].call(document);
						} catch (err) {}
					}
					loadFn = [];
				},
				init = function () {
					if (initialized) {
						return;
					}
					initialized = true;
					// Mozilla, Opera, webkit nightlies
					if (document.addEventListener) {
						document.addEventListener("DOMContentLoaded", function () {
							document.removeEventListener("DOMContentLoaded", arguments.callee, false);
							doLoad();
						}, false);
					// IE
					} else if (document.attachEvent) {
						// Ensure firing before onload, maybe late but safe also for iframes
						document.attachEvent("onreadystatechange", function () {
							if (document.readyState === "complete") {
								document.detachEvent("onreadystatechange", arguments.callee);
								doLoad();
							}
						});
						// If IE and not an iframe
						if (document.documentElement.doScroll && !window.frameElement) {
							(function () {
								if (ready) {
									return;
								}
								try {
									// http://javascript.nwbox.com/IEContentLoaded/
									document.documentElement.doScroll("left");
								} catch (error) {
									setTimeout(arguments.callee, 0);
									return;
								}
								doLoad();
							})();
						}
					}
					// Fallback
					_page.onLoad(doLoad);
				};
			return function (fn) {
				if (ready) {
					fn.call(document);
				} else {
					loadFn[loadFn.length] = fn;
					init();
				}
			};
		})();
		
		this.onLoad = (function () {
			var loadFn = [], initialized = false, loaded = false, existing,
				doLoad = function () {
					loaded = true;
					for (var i = 0 ;i < loadFn.length; i += 1) {
						try {
							loadFn[i].call(document);
						} catch (err) {}
					}
					loadFn = [];
				},
				init = function () {
					if (initialized) {
						return;
					}
					initialized = true;
					if (typeof window.addEventListener !== 'undefined') {
						window.addEventListener('load', function () {}, false); // Dummy function inorder to prevent removal of doLoad listner
						window.addEventListener('load', doLoad, false);
					} else if (typeof document.addEventListener !== 'undefined') {
						document.addEventListener('load', doLoad, false);
					} else if (typeof window.attachEvent !== 'undefined') {
						window.attachEvent('onload', doLoad);
					} else {
						if (typeof window.onload === 'function') {
							existing = window.onload;
							window.onload = function () {
								existing();
								doLoad();
							};
						} else {
							window.onload = doLoad;
						}
					}
				};
			return function (fn) {
				if (loaded) {
					fn.call(document);
				} else {
					loadFn[loadFn.length] = fn;
					init();
				}
			};
		})();
		
		this.loadJSFile = function (src, test, callback , charset) {
			src = (src.indexOf('.') === false) ? src+'.js': src;
			var js = null, loadTimeout, done, timeStart, charSetType, isTimeout, complete, load;
			loadTimeout = 10000; //10 secs, only applicable for Safari / Opera < 9
			done = false;
			timeStart = new Date().getTime();
			charSetType = (charset)?charset:null;
			isTimeout = function () {
				var timeCur = new Date().getTime();
				return parseInt(timeCur, 10) - parseInt(timeStart, 10) > loadTimeout; 
			};
			complete = function () {
				if (!done) {
					done = true;
					callback();
					if (js) {
						js.parentNode.removeChild(js);
						js = null;
					}				
				}
			};
			load = (function () {
				var head, call;
				js = document.createElement('script');
				js.src = src;
				js.type = "text/javascript";
				if (charSetType) {
					js.charset = charSetType;
				}
				head = document.getElementsByTagName('head')[0];
				head.appendChild(js);
				js.onload = js.onreadystatechange = function () {
					if (!this.readyState || /loaded|complete/.test(this.readyState)) {
						complete();
					}
				};
				if (/WebKit|Khtml/i.test(navigator.userAgent) || (window.opera && (window.opera.version? parseInt(window.opera.version(), 10) <= 9: true))) {
					(function () {
						call = false;
						try {
							call = test.call();
						} catch (e) {}
						if (call) {
							complete();
						} else {
							if (!isTimeout()) {
								setTimeout(arguments.callee, 100);
							}	
						}
					})();
				}		
			});
			window.setTimeout(load, 100); // Need timeout for IE
		};
		
		// Attributes
		this.util = util;
		this.dom = dom;
		this.events = events;
		this.transition = transition;
		this.Animation = Animation;
		this.browser = new BrowserDetect();
	};
	
	return new Core();
})();

// Assign windows unload handler
_page.events.add(window, 'unload', _page.events.removeAll);
// Make gE function available within window
var gE = _page.dom.gE;

// This function determines the path to the global CRSC server.
_page.getCRSCServer = function () {
	// Get all script elements in page
	var script_files, i, global_location, global_id;
	script_files = document.getElementsByTagName("SCRIPT");
	for(i=0;i<script_files.length;i++){
		//Loop through all script elements
		global_location = script_files[i].src;
		global_id = global_location.indexOf('/crsc/scripts/lib_global');
		if(global_id!=-1){
			// Get location for Common Resources
			return global_location.substring(0,global_id);
		}
	}
	return (window.location.protocol == "https:"? "https:": "http:") + "//www.crsc.philips.com";
};

// This function determines the path to the global CRSC NAV server.
_page.getCRSCNavServer = function () {
	var crsc_server = _page.crsc_nav_server || _page.getCRSCServer();
	// If crsc domain found respect domain, i.e. www.staging.crsc.philips.com
	return ( crsc_server.indexOf('.crsc.philips.com') !=-1 ? crsc_server :(window.location.protocol=="https:"?"https:":"http:") + "//www.crsc.philips.com" );
};

_page.switchHandler = function (open_link, target, language_switch) {
	// This function will open the links clicked in the header and footer. This function can be overruled.
	// Check if there is a language switch
	var open_page = false, extra, w, intwidth, intheight;
	if (language_switch === "" || typeof(language_switch) === "undefined") {
		open_page = true;
	} else {
		// Check if person wants to switch language
		if (confirm(_page.text.confirmation2.replace("{LANGUAGE}", language_switch))) {
			open_page = true;
		} else {
			open_page = false;
		}
	}
	if (open_page) {
		if (target === "" || typeof(target) === "undefined") {
			// Open in same window if no extra parameters are send
			target = "_self";
			extra = "";
		} else if (target === "popup") {
			target = "_blank";
			extra = "height=500,width=700,toolbar=yes,scrollbars=yes";
		} else {
			extra = "";
		}
		w = window.open(open_link, target, extra);		
		if (target === "popup") {
			//Center popup window
			intwidth = parseInt(screen.availWidth, 10);
			intheight = parseInt(screen.availHeight, 10);
			if (intwidth > 0 && intheight > 0) {
				// Check: Where does popup_width and popup_height come from???
				w.moveTo(((intwidth - popup_width) / 2), ((intheight - popup_height) / 2));
				w.focus();
			}
		}
	} 
	// Return false to make sure links in a href are not followed
	return false;
};

_page.setlocale = function (locale, url) {
	// Set cookie with user locale
	//  if currently on philips.com domain
	var newLink, current_url, x, y, expires, new_str, str;
	newLink = escape(url || _page.getLocaleURL(locale));
	current_url = escape(window.location);
	x = current_url.indexOf("philips.com/"); 
	y = current_url.indexOf("philips.com%3A"); // allow philips with port
	if (x !== -1 || y !== -1) {
		// Set cookie when on philips.com domain
		expires = new Date();
		expires.setFullYear(expires.getFullYear() + 1);
		new_str = "Philips=userlocale=" + locale + ";expires=" + expires.toGMTString() + ";path=/;domain=philips.com";
		document.cookie = new_str;
		// Redirect to site using the switchHandler function
		_page.switchHandler(unescape(newLink), "");
	} else {
		//create unique code to protect caching
		str = Math.round(Math.random() * 100000).toString();
		// Set cookie on philips.com domain
		document.write('<script language="Javascript" type="text/javascript" src="http://www.crsc.philips.com/cookie/setcookie.asp?LocaleID=' + locale + '&URL=' + newLink + '&random=' + str + '"></script>');
	}
};

_page.changelocale = function (locale, url) {
	var strCheckLocale, newLink, blnRedirect;
	// Check if new country selected
	strCheckLocale = (_page.selectedLocale !== ""? _page.selectedLocale: _page.locale);
	// Redirect to site with new Locale	
	newLink = url || _page.getLocaleURL(locale);
	if (locale === "") {
		// No Locale selected
		alert(_page.text.alert2);
	} else if (locale === strCheckLocale) {
		// User is switching to the Locale that he is already using
		alert(_page.text.alert1);
	} else {
		blnRedirect = false;
		if (locale !== "others") {
			// Check if the user want to save this Locale
			// The function will also redirect the user
			if (confirm(_page.text.confirmation1)) {
				// Set locale
				_page.switchHandler("Javascript:_page.setlocale('" + locale + "','" + newLink + "');", "");
			} else {
				blnRedirect = true;
			}
		} else {
			blnRedirect = true;
		}
		if (blnRedirect) {
			// Redirect to site using the switchHandler function
			_page.switchHandler(newLink, "");
		}
	}
};

_page.getLocaleURL = function (locale) {
	// Get correct link to switch to
	return _page.locales[locale];
};

_page.getlocale = function () {
	var current_url, x, strCookie, start, end, return_cookie;
	// Check if currently on philips.com domain
	current_url = escape(window.location);
	x = current_url.indexOf("philips.com/");
	if (x !== -1) {
		strCookie = unescape(document.cookie);
		start = strCookie.indexOf("userlocale=");
		if (start !== -1) {
			start += 11;
			end = start + 5;
			if (strCookie.substring(start, end) === "globa") {
				return_cookie = "global";
			} else {
				return_cookie = strCookie.substring(start, end);
			}
			return return_cookie;
		} else {
			return "";
		}
	} else {
		// Currently not available
		return "N/A";
	}
};

// Return the site level based upon locale
_page.getSiteLevelByLocale = function (locale) {
	var country = locale.split("_")[0], level;
	for (level in _page.siteLevelList) {
		if (_page.util.hasElement(_page.siteLevelList[level], country)) {
			return level;
		}
	}	
	return "";
};

// Returns meta element by name
_page.getMetaElementByName = function () {
	var meta;
	return function (name, force) {
		var el, i, metatags;
		if (typeof meta === "undefined" || force) {
			meta = {};
			metatags = document.getElementsByTagName("meta");
			for (i = 0; i < metatags.length; i += 1) {
				el = metatags[i];				
				meta[el.name.toLowerCase()] = el || "";
			}
		}
		return meta[name.toLowerCase()] || {};
	};	
}();

_page.fieldValidation = function (fieldId, params) {
	fieldId = fieldId || "";
	params = params || {};
	var createWarning = function () {
			if (!elWarning) { // checks existence global variable
				elWarning = document.createElement("div");
				elWarning.id = warningId;
				elWarning.innerHTML = "<div><strong class=\"p-content\">" + warningText + "</strong></div>";
				elParent = gE(parentId);
				if (elParent) {
					elParent.appendChild(elWarning);
					return elWarning;
				}
			}
		},
		hideWarning = function () {
			elWarning = elWarning || gE(warningId);
			if (elWarning) {
				_page.dom.nE(elWarning);
				_page.events.removeSafe(evtClick);
				_page.events.removeSafe(evtKeydown);
			}
		},
		showWarning = function () {
			elWarning = elWarning || gE(warningId) || createWarning();
			elQuery = elQuery || gE(fieldId);
			if (elWarning && elQuery) {
				_page.dom.dE(elWarning);
				_page.events.cancel(); // avoid any bubbling of click events
				evtClick = _page.events.add(document, "click", hideWarning);
				evtKeydown = _page.events.add(elQuery, "keydown", hideWarning);
			}
		},
		isValid = function () {
			if (typeof params.isValidFn === "function") {
				return !params.isValidFn.apply(window, [getValue(fieldId), compareText]);
			} else { 
				return true;
			}
		},
		getValue = function (id) {
			id = id || fieldId;
			return (gE(fieldId))? (gE(fieldId).value || ""): "";
		},
		compareText = params.compareText || getValue(fieldId),
		warningText = params.warningText || "",
		parentId = params.parentId || "p-header-search",
		warningId = params.warningId || "p-header-warning-search",
		elWarning, elQuery, evtClick, evtKeydown, elParent;
	return {
		validate: function (e) {
			var blnSuccess = isValid();
			if (!blnSuccess) {
				showWarning();
				gE(fieldId).focus();
				_page.events.cancel(e);
			}
			return blnSuccess;
		}
	};
};

// Set properties of _page object
_page.useIframe = (_page.browser.isIE5up &&  !_page.browser.isIE7up && (!_page.browser.isIE5x || _page.browser.isIE55))? true: false; 
_page.text = {};										// Defined in locale files 
_page.link = {};										// Defined in locale files
_page.topNav = [];
_page.locales = {};
_page.area = "";										// Active area

// Determine which design to use...
_page.getDesignVersion = function () {
	var designLocalesList = {
		"me_en": 1,
		"ce_es": 1,
		"au_en": 1,
		"in_en": 1,
		"nz_en": 1,
		"ph_en": 1,
		"pk_en": 1,
		"sg_en": 1,
		"za_en": 1
	};
	// if not defined, return the default design number: 2
	return designLocalesList[_page.locale] || 2;
};

// If the design number equals 2, it's the new Contact & Support design...
_page.hasNewContactSupportDesign = function () {
	return (_page.getDesignVersion() == 2);
}

_page.crsc_server = _page.getCRSCServer();  			// Get location of the Global library file. Used to determine where the files need to be included from.
_page.crsc_nav_server = _page.getCRSCNavServer(); 		// Force location of the nav directory to the any production / staging CRSC server.
_page.consumer_nav_server = (window.location.protocol === "https:"? "https:": "http:") + "//www.consumer.philips.com";
_page.siteLevel = ""; 									// Current locale site level
_page.siteLevelList = {									// Based on countries
	"3": ["us", "de", "cn", "gb", "fr", "it", "br", "nl", "es", "ru", "jp", "in", "kr", "be", "se", "global", "ar", "at", "au", "ca", "ch", "cz", "dk", "hk", "mx", "nz", "pl", "pt", "ru", "tr", "tw"],
	"2": ["bg", "ce", "cl", "fi", "gr", "hu", "ie", "my", "me", "no", "pk", "ph", "ro", "sg", "sk", "th", "ua", "za", "co", "pe"],
	"1": ["kz", "id", "uy", "by", "hr", "lv", "lt", "si", "uz", "vn", "yu", "ve", "ee", "il"]
};
_page.sIFR = {
	"swf": {
		"GillSansLight": 	{"src": _page.crsc_server + "/crsc/images/sifr_gillsanslight_3.436.swf"}
	},	
	"js": {
		"core": 			{"src": _page.crsc_server + "/crsc/scripts/sifr-3.436.js"},
		"config": 			{"src": _page.crsc_server + "/crsc/scripts/sifr-config-3.436.js"} 
	}
};
_page.disabledLocalesSIFR = ["zh","ko","he","ja","cs","sk","pl","ro","ru","bg","el","th","tr","hu", "hr", "et", "lv", "lt", "vi", "id"];

_page.countryInfo = {
	"ar": {"en": {"name": "Argentina"}},
	"au": {"en": {"name": "Australia"}},
	"at": {"en": {"name": "Austria"}, "de": {"name": "\u00D6sterreich", "sortKey": "Ost"}},
	"be": {"en": {"name": "Belgium"}, "nl": {"name": "Belgi\u00EB"}, "fr": {"name": "Belgique"}},
	"bg": {"en": {"name": "Bulgaria"}, "bg": {"name": "\u0411\u044A\u043B\u0433\u0430\u0440\u0438\u044F", "sortKey": "Bul"}},
	"br": {"en": {"name": "Brazil"}, "pt": {"name": "Brasil"}},
	"ca": {"en": {"name": "Canada"}},
	"ce": {"en": {"name": "Central America"}},
	"cl": {"en": {"name": "Chile"}},
	"cn": {"en": {"name": "China"}, "zh": {"name": "\u4E2D\u56FD", "sortKey": "Chi"}},
	"co": {"en": {"name": "Colombia"}},
	"hr": {"en": {"name": "Croatia"}},
	"cu": {"en": {"name": "Cuba"}},
	"cy": {"en": {"name": "Cyprus"}},
	"cz": {"en": {"name": "Czech Republic"}, "cs": {"name": "\u010Cesk\u00E1 Republika", "sortKey": "Cze"}},
	"dk": {"en": {"name": "Denmark"}},
	"ee": {"en": {"name": "Estonia"}},
	"eg": {"en": {"name": "Egypt"}},
	"fi": {"en": {"name": "Finland"}, "fi": {"name": "Suomi"}},
	"fr": {"en": {"name": "France"}},
	"de": {"en": {"name": "Germany"}, "de": {"name": "Deutschland"}},
	"gr": {"en": {"name": "Greece"}, "el": {"name": "\u0395\u03BB\u03BB\u03AC\u03B4\u03B1", "sortKey": "Gre"}},
	"hk": {"en": {"name": "Hong Kong"}, "zh": {"name": "\u9999\u6E2F\u7279\u5225\u884C\u653F\u5340", "sortKey": "Hon"}},
	"hu": {"en": {"name": "Hungary"}, "hu": {"name": "Magyarorsz\u00E1g"}},
	"is": {"en": {"name": "Iceland"}},
	"in": {"en": {"name": "India"}},
	"id": {"en": {"name": "Bahasa Indonesia"}},
	"ir": {"en": {"name": "Iran"}},
	"iq": {"en": {"name": "Iraq"}},
	"ie": {"en": {"name": "Ireland"}},
	"il": {"en": {"name": "Israel"}},
	"it": {"en": {"name": "Italy"}, "it": {"name": "Italia"}},
	"jp": {"en": {"name": "Japan"}, "ja": {"name": "\u65E5\u672C", "sortKey": "Jap"}},
	"kr": {"en": {"name": "Korea"}, "ko": {"name": "\uD55C\uAD6D", "sortKey": "Kor"}},
	"lt": {"en": {"name": "Lithuania"}},
	"lu": {"en": {"name": "Luxembourg"}},
	"lv": {"en": {"name": "Latvia"}},
	"my": {"en": {"name": "Malaysia"}},
	"mx": {"en": {"name": "Mexico"}, "es": {"name": "M\u00E9xico"}},
	"me": {"en": {"name": "Middle East and Africa"}},
	"ma": {"en": {"name": "Morocco"}},
	"nl": {"en": {"name": "Netherlands"}, "nl": {"name": "Nederland"}},
	"nz": {"en": {"name": "New Zealand"}},
	"no": {"en": {"name": "Norway"}, "no": {"name": "Norge"}},
	"om": {"en": {"name": "Oman"}},
	"pk": {"en": {"name": "Pakistan"}},
	"pe": {"en": {"name": "Peru"}},
	"ph": {"en": {"name": "Philippines"}},
	"pl": {"en": {"name": "Poland"}, "pl": {"name": "Polska"}},
	"pt": {"en": {"name": "Portugal"}},
	"ro": {"en": {"name": "Romania"}, "ro": {"name": "Rom\u00E2nia"}},
	"ru": {"en": {"name": "Russian Federation"}, "ru": {"name": "\u0420\u043E\u0441\u0441\u0438\u0439\u0441\u043A\u0430\u044F \u0424\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u044F", "sortKey": "Rus"}},
	"sa": {"en": {"name": "Saudi Arabia"}},
	"sg": {"en": {"name": "Singapore"}},
	"sk": {"en": {"name": "Slovakia"}, "sk": {"name": "Slovensko"}},
	"si": {"en": {"name": "Slovenia"}},
	"za": {"en": {"name": "South Africa"}},
	"es": {"en": {"name": "Spain"}, "es": {"name": "Espa\u00F1a"}},
	"se": {"en": {"name": "Sweden"}, "sv": {"name": "Sverige"}},
	"ch": {"en": {"name": "Switzerland"}, "de": {"name": "Schweiz"}},
	"tw": {"en": {"name": "Taiwan"}, "zh": {"name": "\u53F0\u7063", "sortKey": "Tai"}},
	"th": {"en": {"name": "Thailand"}, "th": {"name": "\u0E1B\u0E23\u0E30\u0E40\u0E17\u0E28\u0E44\u0E17\u0E22", "sortKey": "Tha"}},
	"tn": {"en": {"name": "Tunisia"}},
	"tr": {"en": {"name": "Turkey"}, "tr": {"name": "T\u00FCrkiye", "sortKey": "Tur"}},
	"ua": {"en": {"name": "Ukraine"}, "ru": {"name": "\u0423\u043A\u0440\u0430\u0457\u043D\u0430", "sortKey": "Ukr"}},
	"ae": {"en": {"name": "United Arab Emirates"}},
	"gb": {"en": {"name": "United Kingdom"}},
	"us": {"en": {"name": "United States"}},
	"uy": {"en": {"name": "Uruguay"}},
	"ve": {"en": {"name": "Venezuela"}}
};

// backwards compatibility object
_page.countries = {};
for (cCode in _page.countryInfo) {
	if (_page.countryInfo.hasOwnProperty(cCode) && typeof cCode === "string") {
		_page.countries[cCode] = _page.countryInfo[cCode].en.name;
	}
}

_page.languages = {
	"bg": "\u0411\u044A\u043B\u0433\u0430\u0440\u0441\u043A\u0438",
	"cs": "\u010Ce\u0161tina",
	"da": "Dansk",
	"de": "Deutsch",
	"el": "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AE",
	"en": "English",
	"es": "Espa\u00F1ol",
	"et": "Eesti keel",
	"fi": "Suomeksi",
	"fr": "Fran\u00E7ais",
	"he": "\u05E2\u05D1\u05E8\u05D9\u05EA",
	"hr": "Croatian",
	"hu": "Magyar",
	"id": "Indonesian",
	"it": "Italiano",
	"ja": "\u65E5\u672C",
	"ka": "Georgian",
	"ko": "\uD55C\uAD6D\uC5B4",
	"lt": "Lietuvi\u0173",
	"lv": "Lietuvi\u0173",
	"my": "Burmese",
	"ms": "Bahasa Melay",
	"nl": "Nederlands",
	"no": "Norsk",
	"pl": "Polski",
	"pt": "Portugu\u00EAs",
	"ro": "Rom\u00E2n\u0103",
	"ru": "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
	"sk": "Sloven\u010Dina",
	"sv": "Svenska",
	"th": "\u0E44\u0E17\u0E22",
	"tr": "T\u00FCrk\u00E7e",
	"zh": "\u4E2D\u6587",
	"za": "Chuang"
};

// CLASS: Locale Selector
_page.altLocaleFlag = "";							// allow alternative locale flag (Country C)
_page.altLocaleText = "";							// allow alternative locale text (Country C)
_page.selectedLocale = "";							// allow other selected locale in localelist (Country C)
_page.LS = function (type, params) {
	// Constants
	this.hoverId = "p-ls-hover-";
	this.listId = "p-ls-container-";
	this.listHeaderId = "p-ls-header-";
	this.listBodyId = "p-ls-body-";
	this.listIframeId = "p-lsIF-";
	// Arguments
	params = params || {};
	this.options = {
		wrapperId: (params.wrapperId? params.wrapperId: undefined), 
		keepActive: (typeof(params.keepActive) !== "undefined"? params.keepActive: false),
		localeFlag: (params.localeFlag? params.localeFlag: _page.altLocaleFlag || _page.locale),
		localeText: (params.localeText? params.localeText: _page.altLocaleText),
		collapseDirection: (params.collapseDirection? params.collapseDirection: 'auto'),
		showRows: (params.showRows? params.showRows: 9), 										// Default rows 9
		listHeight: (params.listHeight? params.listHeight: 275), 								// Default height defined in styles, may be overruled for faillover
		data: (params.data? params.data: _page.getLocalesArray || []),							// Requires an array of locales, input can be array or function
		remoteUrl: (params.remoteUrl? params.remoteUrl: ""),
		remoteOptions: params.remoteOptions || {},
		removeLocaleList: params.removeLocaleList || []
	};
	this.type = type;	
	// Override remote options, set default output and oncomplete function when not defined by parameters			
	this.options.remoteOptions.onComplete = (this.options.remoteOptions.onComplete?this.options.remoteOptions.onComplete:this._remoteComplete.bindArgs(this));
	// Other declarations
	_page.LS.arrIndex += 1;
	this.arrIndex = _page.LS.arrIndex;
	this.id = this.options.wrapperId || "p-ls-" + this.arrIndex;
	this.timerShow = 0;
	this.timerHide = 0;
	this.rows = this.options.showRows;
	this.move = this.options.collapseDirection;
	this.switchOverflow = (_page.browser.isMac && _page.browser.isGecko?true:false);
	this.localeArray = [];
	this.dataLoaded = false;
	this.loading = false;
	this.elList = null;
	this.listActive = false;
	if (this.options.onContentReady) {
		_page.onContentReady(this.init.bindArgs(this));
	}
};
_page.LS.arrIndex = -1;
_page.LS.prototype = {
	init: function () {
		// tmp: set hover id automatically
		var elWrapper = gE(this.id),
			elHover = elWrapper.getElementsByTagName("div")[0];
		if (elHover) {
			elHover.id = 'p-ls-hover-' + this.arrIndex;
		}
		this.initEvents();
	},
	initEvents: function () {
		_page.events.add(gE('p-ls-hover-' + this.arrIndex), 'click', this._mClick.bindArgs(this));
		if (!this.options.keepActive) {
			_page.events.add(gE(this.id), 'mouseover', this._mOver.bindArgs(this));
			_page.events.add(gE(this.id), 'mouseout', this._mOut.bindArgs(this));
		}
	},
	_load: function (renderImages) {
		this.loading = true;
		this._getData();
		if (this.dataLoaded) {
			this._update();
			this._visible(true);
			if (renderImages) {
				this._renderImages();
			}
			this._resize();
			this._position();
			this._hidden(true);
			this.loading = false;
		}
	},
	_remoteComplete: function () {
		// This method is based at the current www.crsc.philips.com/crsc/locales/locale_section url 
		this.localeArray = _page.processLocales() || [];	
		if (this._localesTmp) {
			_page.locales = this._localesTmp;
		}	
		this.dataLoaded = true;
		this._show();			
	},
	_getData: function () {
		var id;
		if (this.dataLoaded === false) {
			if (this.options.remoteUrl !== "") {
				// Create local backup of current loaded _page.locales and reset _page.loaces
				this._localesTmp = {};	
				for (id in _page.locales) {
					if (_page.locales.hasOwnProperty(id)) {
						this._localesTmp[id] = _page.locales[id];
					}
				}	
				_page.locales = {};
				_page.loadJSFile(this.options.remoteUrl, function () {
					var filled = false;
					for (id in _page.locales) {
						if (_page.locales.hasOwnProperty(id)) {
							filled = true;
							break;
						}
					}
					return filled;
				}, this.options.remoteOptions.onComplete);
			} else {
				this.localeArray = typeof this.options.data === "function"? this.options.data(): this.options.data;
				this.dataLoaded = true;
			}
		}
	},
	_mClick: function (e) {
		_page.events.cancel(e);
		clearTimeout(this.timerHide);
		clearTimeout(this.timerShow);
		this._show();
	},
	_mOver: function () {
		clearTimeout(this.timerHide);
		this.timerShow = setTimeout(this._show.bindArgs(this), '1000');
	},
	_mOut: function () {
		clearTimeout(this.timerShow);
		this.timerHide = setTimeout(this._hide.bindArgs(this), '500');
	},
	_show: function (e) {
		var elList, elLSBody, elFlag, elIframe;
		if (this.listActive === false) {
			this._load(true);
		}	
		elList = gE(this.listId + this.arrIndex);
		if (elList) {						
			elLSBody = gE('p-ls-body-' + this.arrIndex);
			if (elLSBody && this.switchOverflow) { 
				elLSBody.style.overflow = "auto"; 
			}
			if (this.type === '1') {
				elFlag = gE('p-flag-' + this.arrIndex);
				if (elFlag) {
					_page.dom.addClass(elFlag, 'p-flag-on');
				}	
			}
			if (_page.useIframe) {
				elIframe = gE('p-lsIF-' + this.arrIndex);
				if (elIframe) {
					_page.dom.sE(elIframe);
				}	
			}
			this._visible();
			this.listActive = true;
		}
	},
	_hide: function () {
		var elList, elListBody, elFlag, elIframe;
		elList = gE(this.listId + this.arrIndex);
		if (elList) {
			elListBody = gE('p-ls-body-' + this.arrIndex);
			if (elListBody && this.switchOverflow) { 
				elListBody.style.overflow = "hidden";
			}	
			if (this.type === '1') {
				elFlag = gE('p-flag-' + this.arrIndex);
				if (elFlag) {
					_page.dom.addClass(elFlag, 'p-flag');
				}	
			}
			if (_page.useIframe) {
				elIframe = gE('p-lsIF-' + this.arrIndex);
				if (elIframe) {
					_page.dom.hE(elIframe);
				}	
			}
			this._hidden();
			this.listActive = false;
		}
	},
	html: function () {
		var strFlagLocale, strCountry, strLanguage, strFlagSource, strLocaleText, strHTML, crsc, strArrowName, classClick, strCountryLabel;
		// Get alternative locale flag
		strFlagLocale = this.options.localeFlag;
		strCountry = strFlagLocale.split("_")[0];
		strLanguage = strFlagLocale.split("_")[1] || "en";
		strFlagSource = "flag_" + strCountry + ".gif";
		if (this.options.localeText === "") {
			strCountryLabel = _page.countryInfo[strCountry]? (_page.countryInfo[strCountry][strLanguage] || _page.countryInfo[strCountry]["en"]).name: "Global";
			this.options.localeText = (strCountryLabel) + " / " + _page.languages[strLanguage];
		}	
		strLocaleText = this.options.localeText;
		strHTML = "";
		strHTML += "<div class=\"p-ls-wrapper-" + this.type + "\" id=\"p-ls-" + this.arrIndex + "\" >";
		crsc = _page.crsc_server;
		strArrowName = (_page.direction === 'ltr'? "arrow_bottom_right.gif": "arrow_bottom_left.gif");
		classClick = (this.options.keepActive !== true? "p-click": "");
		if (this.type === "1") {
			strHTML += "<div class=\"p-ls-hover-container-1 " + classClick + "\" id=\"p-ls-hover-" + this.arrIndex + "\"><nobr><img alt=\"" + strLocaleText + "\" src=\"" + crsc + "/crsc/images/" + strFlagSource + "\" id=\"p-flag-" + this.arrIndex + "\" class=\"p-flag\" />&nbsp;<img alt=\"Show locale list\" src=\"" + crsc + "/crsc/images/" + strArrowName + "\" id=\"p-arrow-bottom-right-" + this.arrIndex + "\" class=\"p-arrow-bottom-right\" /></nobr></div>\n";
		} else if (this.type === "2") {
			strHTML += "<div class=\"p-ls-hover-container-2\">\n<a href=\"javascript:void(0);\">\n<img alt=\"\" src=\"" + crsc + "/crsc/images/" + strFlagSource + "\" class=\"p-flag\" /><span>" + strLocaleText + "</span></a>\n</div>\n";
		}
		strHTML += "</div>";
		return strHTML;
	},
	_renderImages: function () {
		if (this.imagesRendered) {
			return;
		}	
		var arrLocales, strLocale, strCurCountry, elLink, strNewClass, i;
		arrLocales = this.localeArray;
		for (i = 0; i < arrLocales.length; i += 1) {
			strLocale = arrLocales[i][0];
			strCurCountry = (strLocale.indexOf("_") === -1? strLocale: strLocale.substring(0, 2));
			elLink = gE("p-ls-list-" + this.arrIndex + "-flag-" + strCurCountry);
			strNewClass = "p-flag-" + strCurCountry;	
			if (elLink) {
				_page.dom.addClass(elLink, strNewClass);
			}	
		}
		this.imagesRendered = false;	
	},
	_removeLocales: function () {
		// Remove locale element from array if needs to be removed
		var arrLocales, strLocale, i;
		if (this.options.removeLocaleList.length === 0) { 
			return;
		}	
		arrLocales = this.localeArray;
		for (i = 0; i < arrLocales.length; i += 1) {
			strLocale = arrLocales[i][0];
			if (_page.util.hasElement(this.options.removeLocaleList, strLocale)) {
				arrLocales.splice(i, 1);
			}	
		}	
	},
	_update: function () {	
		if (this.updated) { 
			return;
		}	
		var arrLocales, crsc, strCurCountry = '', strLastCountry = '', strLocale = '', strHTMLBody = '', overFlow, arrLocalesMax, elFlagDimensions, elContainer, strHTMLHeader, i, elWrapper, strHTML;
		this._setAutoMovement();
		this._removeLocales();
		arrLocales = this.localeArray;
		// Build body HTML and locales from array
		crsc = _page.crsc_server;
		overFlow = (this.switchOverflow? "style=\"overflow:hidden\"": "");
		strHTMLBody += "<div id=\"p-ls-body-" + this.arrIndex + "\" class=\"p-ls-body\" " + overFlow + ">\n";
		strHTMLBody += "<table class=\"p-ls-list\" cellspacing=\"0\" border=\"0\">\n";
		arrLocalesMax = arrLocales.length;
		for (i = 0; i < arrLocalesMax; i += 1) {
			strLocale = arrLocales[i][0];
			strCurCountry = (strLocale.indexOf("_") === -1? strLocale: strLocale.substring(0, 2));
			if (strCurCountry !== strLastCountry) {
				// Set flag dimensions;
				elFlagDimensions = {width: '17', height: '13'};
				if (strCurCountry === "global" || strCurCountry === "me_en" || strCurCountry === "ce_es" || strCurCountry === "others") {
					elFlagDimensions = {width: '14', height: '14'};
				}	
				strHTMLBody +=
				(i !== 0? "</ul></td></tr>\n": "") +
				"<tr><td class=\"p-ls-list-left\"><a id=\"p-ls-list-" + this.arrIndex + "-flag-" + strCurCountry + "\" href=\"" + arrLocales[i][3] + "\" onclick=\"_page.changelocale('" + strLocale + "');return false;\" /></td><td  class=\"p-ls-list-right\"><ul class=\"p-ls-localelist\">\n";
			}
			// Set country / language
			strHTMLBody += "<li><a href=\"" + arrLocales[i][3] + "\" onclick=\"_page.changelocale('" + strLocale + "','" + arrLocales[i][3] + "');return false;\">" +  arrLocales[i][1] + (arrLocales[i][2] !== ""? " / " + arrLocales[i][2]: "") + "</a></li>";
			strLastCountry = strCurCountry;	
		}
		strHTMLBody += "</ul></td></tr>\n";
		strHTMLBody += "</table>\n";
		strHTMLBody += "</div>\n";
		// Add Dropdown HTML, cannot initiated earlier because of the movement detection
		strHTML = "";
		elContainer = document.createElement("div");
		elContainer.id = "p-ls-container-" + this.arrIndex;
		elContainer.className = "p-ls-container-" + this.move;
		if (this.type === "1") {
			strHTMLHeader = "<div id=\"p-ls-header-" + this.arrIndex + "\" class=\"p-ls-header\"><table cellspacing=\"0\" class=\"p-ls-header-table\"><tr><td><span id=\"p-ls-header-text-" + this.arrIndex + "\">" + this.options.localeText + "</span></td></tr></table></div>\n";
			strHTML += strHTMLHeader + strHTMLBody;	// Header used which overlaps the topmenu
		} else if (this.type === "2") {
			strHTML += strHTMLBody;
		}
		// Add IFRAME html
		if (_page.useIframe) {
			strHTML += "		<iframe frameborder=0 id=\"p-lsIF-" + this.arrIndex + "\" src=\"" + crsc + "/crsc/images/t.gif\" scroll=none style=\"FILTER:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);visibility:hidden;height:0;position:absolute;width:0px;top:0px;z-index:0;\"></iframe>";
		}
		elContainer.innerHTML = strHTML;
		elWrapper = gE(this.id);
		if (elWrapper) {
			elWrapper.appendChild(elContainer);
		}	
		// this.elList = gE("p-ls-container-" + this.arrIndex);
		this.updated = true;
	},
	_resize: function () {
		if (this.resized) { 
			return;
		}	
		var intMaxRows, elListBody, arrRows, intHeight = 0, intVisibleRows = 0, elCellLeft, elCellRight, elList, elLS, elIframe, i;
		// Set dynamich height of dropdown by defined max rows;
		intMaxRows = this.rows;
		elListBody = gE(this.listBodyId + this.arrIndex);
		arrRows = elListBody.getElementsByTagName('tr');
		for (i = 0; i < arrRows.length; i += 1) {
			elCellLeft = arrRows[i].childNodes[0];
			elCellRight = arrRows[i].childNodes[1];
			if (i < intMaxRows) {	// Count visible height
				intHeight += elCellRight.offsetHeight;
				intVisibleRows += 1;
			}
			if (!arrRows[i + 1]) {	// Remove bottom border
				//_page.dom.addClass(elCellLeft, getStyle(elCellLeft) + " p-nobottomborder");
				//_page.dom.addClass(elCellRight, getStyle(elCellRight) + " p-nobottomborder");
				_page.dom.addClass(elCellLeft, "p-nobottomborder");
				_page.dom.addClass(elCellRight, "p-nobottomborder");
			}
		}
		intHeight = (intHeight === 0? this.options.listHeight: intHeight);  // Set failover height, if it can't be determined due to display:none in parent elements
		if (_page.browser.isSafari) { 
			intHeight = intHeight + intVisibleRows; // Safari doesn't include the borders in the height
		}	
		// Overflow is needed
		if (arrRows.length > intMaxRows) {
			if (!_page.browser.isIE5x) { 
				intHeight -= 1;  // Decrease 1px for border, except for border box model applicable browsers
			}	
			if (_page.browser.isSafari) { 
				intHeight = intHeight - 2;
			}	
		// Extend the width if there's no overflow / scrollbar, not applicable for Safari	
		} else {
			if (!_page.browser.isSafari) {
				elList = elListBody.getElementsByTagName("table")[0];
				_page.dom.sW(elList, elListBody.offsetWidth - 2); // - 2  due to border
			}
			if (_page.browser.isIE5x) {
				intHeight += 1; // increase 1px for border only for border box model applicable browsers
			}	
		} 
		_page.dom.sH(elListBody, intHeight); 
		if (_page.useIframe) {
			elList = gE(this.listId + this.arrIndex);
			elIframe = gE(this.listIframeId + this.arrIndex);
			_page.dom.sH(elIframe, (elList.offsetHeight));
			_page.dom.sW(elIframe, (elList.offsetWidth));
		}
		this.resized = true;
	},
	_setAutoMovement: function () {
		if (this.options.collapseDirection !== "auto") { 
			return;
		}	
		var scrollPosTop = _page.dom.getScrollPosTop(),  				// Positon top in scrolled browser window
			screenHeight = _page.dom.getScreenHeight(),				// Available height browser window
			scrollPosBottom = scrollPosTop + screenHeight,	// Positon bottom in scrolled browser window	
			elHover = gE(this.hoverId + this.arrIndex),
			elList = gE(this.listId + this.arrIndex),
			bottomPosContainer = _page.dom.findPosY(elHover) + (elList? elList.offsetHeight: this.options.listHeight),
			topPosContainer = _page.dom.findPosY(elHover) - (elList? elList.offsetHeight: this.options.listHeight);
		this.move = (bottomPosContainer > scrollPosBottom && topPosContainer > scrollPosTop? "up": "down");
	},
	_position: function () {
		this._setAutoMovement();
		var elHover, elList, elHeader, elBody;
		elHover = gE(this.hoverId + this.arrIndex);
		elList = gE(this.listId + this.arrIndex);
		elHeader = gE(this.listHeaderId + this.arrIndex);
		elBody = gE(this.listBodyId + this.arrIndex);
		if (this.move === "up") {
			if (this.type === "1") {
				if (elHeader && elBody) { 
					elHeader.parentNode.insertBefore(elBody, elHeader);
				}	
			}
			_page.dom.addClass(elList, "p-ls-container-up");
		} else if (this.move === "down") {
			if (this.type === "1") {
				if (elHeader && elBody) { 
					elHeader.parentNode.insertBefore(elHeader, elBody);
				}	
				if (elHover && elList) { 
					elHover.parentNode.insertBefore(elList, elHover);
				}	
			}		
			_page.dom.addClass(elList, "p-ls-container-down");
		}
	},
	_visible: function (visibility) {
		var elList = gE(this.listId + this.arrIndex);
		if (elList) {
			if (visibility) {
				_page.dom.hE(elList);
			}	
			_page.dom.dE(elList);
		}
	},
	_hidden: function (visibility) {
		var elList = gE(this.listId + this.arrIndex);
		if (elList) {
			if (visibility) { 
				_page.dom.sE(elList);
			}	
			_page.dom.nE(elList);
		}	
	}
};

_page.processLocales = function () {
	var arrLocales = [], i, anItem, strCountry, strLanguage, sortCol, sortOrder, lengthLocales, sortArray;
	// Build array
	if (_page.locales.others) {
		delete _page.locales.others;			// Delete current others var if exists, as it will be appended to the bottom
	}

	var getCountryNativeLangCode = function (countryCode) {
		// Extend this function with cache/memoization
		var langCode, 
			nativeLangCode = "en",
			objCountry = _page.countryInfo[countryCode];
		for (langCode in objCountry) {
			if (objCountry.hasOwnProperty(langCode) && langCode !== "en") {
				nativeLangCode = langCode;
				break;
			}
		}
		return nativeLangCode;
	};
	
	i = 0;
	for (locale in _page.locales) {
		if (locale !== "global") {
			localeCodes = locale.split("_");
			countryCode = localeCodes[0];
			langCode = localeCodes[1];
			languageName = _page.languages[langCode];
			objCountry = _page.countryInfo[countryCode];
			countryName = (objCountry[langCode] || objCountry.en).name; // Default to english if no native is available
			// Sorting - Native Country at the top and English language always at the bottom.
			strSortOrderLangCode = getCountryNativeLangCode(countryCode);
			strSortOrder = objCountry[strSortOrderLangCode].sortKey || objCountry[strSortOrderLangCode].name;
			if (langCode === "en") {
				strSortOrder +=  "_bottom";
			}
			arrLocales[i] = [];
			arrLocales[i][0] = locale;									// Store locale code
			arrLocales[i][1] = countryName;								// Store country
			arrLocales[i][2] = languageName; 							// Store language
			arrLocales[i][3] = _page.locales[locale]; 					// Store link
			arrLocales[i][4] = strSortOrder; 							// Store sort order (Native country and native language)
			i += 1;
		}
	}
	if (i > 0) {
		
		// Sort array
		sortArray = function (a, b) {
			if (a[sortCol] < b[sortCol]) {
				return (sortOrder === "asc"? -1: 1);
			}	
			if (a[sortCol] > b[sortCol]) {
				return (sortOrder === "asc"? 1: -1);
			}	
			return 0;
		};
		sortCol = 4;
		sortOrder = "asc";
		arrLocales.sort(sortArray); 
		
		// Insert global locale as first element
		arrLocales.splice(0, 0, [
			"global",
			"Global",
			"English",
			_page.locales.global,
			"Global" + " / " + "English"
		]);
				
		// Add others option at the last position in the list / Only applicable for normal internet site
		if (_page.headerType === "internet") {
			_page.locales.others = "http://www.philips.com/countries";
			arrLocales[arrLocales.length] = [
				"others",
				"Others",
				"",
				_page.locales.others,
				"Others"
			];
		}
	}	
	return arrLocales;
};

_page.localesProcessed = false;
_page.localesArray = [];	
// Build locale sorted array, used for i.e. locale selector list
_page.getLocalesArray = function () {
	if (_page.localesProcessed === false) {
		_page.localesArray = _page.processLocales();
		if (_page.localesArray.length > 0) {
			_page.localesProcessed = true;
		}	
	}	
	return _page.localesArray;
};