
Array.prototype.each = function(callback) {
for (var i=0; i<this.length; i++) {
callback(this[i], i);
};
}
var System = new Object();
System.isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
System.isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
System.isFF = function() {
return System.getBrowser() == "Firefox";
}
System.getBrowser = function() {
return this._searchString(this.dataBrowser);
}
System._searchString = function (data) {
for (var i=0; i<data.length; i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
} else if (dataProp)
return data[i].identity;
}
},
System.isIE = function(v1, v2) {
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
return ((v1 == null || version > v1) && 
(v2 == null || version < v2) && 
document.body.filters);
}
System.needHoverHack = function() {
return System.isIE(5.5, 7.0);
}
System.needRoundedCornersHack = function() {
return System.isIE(5.5, 7.0);
}
System.hasDisplayTable = function() {
return !System.isIE(null, 8.0);
}
System.isIE = function(v1, v2) {
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
return ((v1 == null || version > v1) && 
(v2 == null || version < v2) && 
document.body.filters);
}
System.hasDisplayTable = function() {
return !System.isIE(null, 8.0);
}
System.dataBrowser = [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
},
{
string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{		// for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ 		// for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
]


Evt = new Object();
Evt.extend = function(e) {
e.stop = function() {
cancelBubble(this);
cancelEvent(this);
}
return e;
}
Evt._handlers = {};
Evt.add = function(obj, type, fn) {
return addEvent(obj, type, fn);
}
Evt.remove = function(obj, type, fn) {
return removeEvent(obj, type, fn);
}
function addEvent(obj, type, fn) {
if (!obj) { return; };



if (obj instanceof Array) {
obj.each(function(item) { addEvent(item, type, function(e) { fn(e, item); }) });
return;
};

if (type instanceof Array) {
type.each(function(item) { addEvent(obj, item, fn); });
return;
};
var wrappedFn = function(e) { fn(Evt.extend(e)); };
Evt._handlers[fn] = wrappedFn;
_addEvent(obj, type, wrappedFn);
}
function _addEvent(obj, type, fn) {
if (obj.addEventListener) {
var mappings = {};
switch (obj.tagName) { 
case "body":
mappings["load"] = "DOMContentLoaded";
default:
};
if (System.isFF()) {
mappings["mousewheel"] = "DOMMouseScroll";
};
if (mappings[type]) {
type = mappings[type];
};
obj.addEventListener( type, fn, false );
} else if (obj.attachEvent) {
var eName = "e"+type+fn;
var name = type+fn;

while (obj[eName]) {
eName += "_";
name += "_";
};
obj[eName] = fn;
obj[name] = function() { obj[eName]( window.event ); }
obj.attachEvent( "on" + type, obj[name] );
}
}
function cancelBubble(e) {
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
};
}
function cancelEvent(e) {
if (e.preventDefault) { 
e.preventDefault();
} else {
e.returnValue = false;
};
}
function getEventTarget(e) {
var target;
if (e.target) {
target = e.target;
} else if (e.srcElement) {
target = e.srcElement;
};
if (target.nodeType == 3) { // fix for Safari bug
target = target.parentNode;  
};
return target;
}
function removeEvent(obj, type, fn) {

if (type instanceof Array) {
type.each(function(item) { removeEvent(obj, item, fn); });
return;
};
var wrappedFn = Evt._handlers[fn];
if (obj.removeEventListener) {
if (type == "mousewheel") {
type = "DOMMouseScroll";
};
obj.removeEventListener( type, wrappedFn, false );
} else if (obj.detachEvent) {
obj.detachEvent( "on"+type, obj[type+wrappedFn] );
obj[type+wrappedFn] = null;
obj["e"+type+wrappedFn] = null;
}
};

Object.prototype.each = function(callback) {
for (var i in this) {
if (!Object.prototype[i] || 
Object.prototype[i] != this[i]) {
callback(this[i], i);
};
};
}
String.prototype.ucfirst = function() {
return this.substr(0, 1).toUpperCase() + this.substr(1);
}

function $A(item) {
if (item instanceof Array) {
return item;
};
if (!item) {
return [];
};
var newItem = [];
for (var i=0; i<item.length; i++) {
newItem.push(item[i]);
};
return newItem;
} 

Function.prototype.bind = function() {
var _fun = this;
var obj = arguments[0];
var boundArguments = [];
if (arguments.length > 1) {
boundArguments = $A(arguments).slice(1);
};
return function() {
return _fun.apply(obj, boundArguments.concat($A(arguments)));
};
}




var Cls = {};
Cls.inherit = function(subClass, baseClass, methods) {
function inheritance() {};
inheritance.prototype = baseClass.prototype;
subClass.prototype = new inheritance();
subClass.prototype.constructor = subClass;
subClass.baseConstructor = baseClass;
subClass.superClass = baseClass.prototype;
if (methods) { 
this.extend(subClass, methods);
};
}

Cls.extend = function(destination, source) {
source.each(function(value, key) {
destination.prototype[key] = value;
});  
}
Cls.extendDirect = function(destination, source) {
source.each(function(value, key) {
destination[key] = value;
});  
}
Cls.extendDumb = function(destination, source) {
for (var key in source) {
destination.prototype[key] = source[key];
};  
}
Cls.property = function(baseClass, propertyName, defaultValue) {
var getterName = "get" + propertyName.ucfirst();
var setterName = "set" + propertyName.ucfirst();
var memberName = "_" + propertyName;
if (!baseClass.prototype[getterName]) {
baseClass.prototype[getterName] = function() {
return this[memberName];
};
};
if (!baseClass.prototype[setterName]) {
baseClass.prototype[setterName] = function(value) {
this[memberName] = value;
return this;
};
};
if (typeof(defaultValue) != "undefined") {
var oldBaseConstructor = baseClass.baseConstructor;
baseClass.baseConstructor = function() {
oldBaseConstructor.apply(this, arguments);
this[memberName] = defaultValue;
};
};
return this.addTo(baseClass);
};
Cls.propertyLazy = function(baseClass, propertyName, initializer) {
var getterName = "get" + propertyName.ucfirst();
var setterName = "set" + propertyName.ucfirst();
var memberName = "_" + propertyName;
var initializerFlagName = "_lazy_" + propertyName;
if (!baseClass.prototype[getterName]) {
baseClass.prototype[getterName] = function() {
if (!this[initializerFlagName]) {
this[initializer]();
};
return this[memberName];
};
};
if (!baseClass.prototype[setterName]) {
baseClass.prototype[setterName] = function(value) {
this[initializerFlagName] = true;
this[memberName] = value;
return this;
};
};
return this.addTo(baseClass);
}
Cls.addTo = function(baseClass) {
return {
property: Cls.property.bind(Cls, baseClass),
propertyLazy: Cls.propertyLazy.bind(Cls, baseClass)
};
}


Array.prototype.map = function(callback) {
var result = [];
this.each(function(item, key) {
result.push(callback(item, key));
});
return result;
}
function getElementComputedStyle(element, property) {
if (document.defaultView && document.defaultView.getComputedStyle) {
return getElementComputedStyleMozilla(element, property);
}

if (element.currentStyle) {
return getElementComputedStyleIE(element, property);
}
return "";
}
function getElementComputedStyleIE(element, property) {
return element.currentStyle[propertyCssToPropertyDom(property)];
}
function getElementComputedStyleMozilla(element, property) {
return document.defaultView.getComputedStyle(element, "").getPropertyValue(property);
}
function propertyCssToPropertyDom(property) {
var i;
while ((i = property.indexOf("-")) != -1) {
property = property.substr(0, i) + property.substr(i+1,1).toUpperCase() + property.substr(i+2);
};
return property;
}





var element = window.Element;
window.Element = function(tagName, attributes) {
attributes = attributes || {};
tagName = tagName.toLowerCase();
var el = document.createElement(tagName);
attributes.each(function(value, name) { el.setAttribute(name, value); });
return window.Element.extend(el);
};
window.Element.extend = function(el) {
if (!el) { 
return el; 
};
if (el.__rpExtended) {
return el;
}
el.__rpExtended = true;
Cls.extendDirect(el, {
show: function() {
this.style.display = "";
if (getElementComputedStyle(this, "display") == "none") {
this.style.display = "block";
};
return this;
},
hide: function() {
this.style.display = "none";
return this;
},
css: function(properties) {
properties.each(function(value, key) {
this.style[this.propertyToName(key)] = value;
}.bind(this));
return this;
},
down: function(selector) {
return $$(selector, this);
},
up: function(selector) {
var currentNode = window.Element.extend(this.parentNode);
while (currentNode && currentNode.tagName.toUpperCase() != "HTML") {
if (Selector.match(currentNode, selector)) {
return currentNode;
};
currentNode = window.Element.extend(currentNode.parentNode);
};
return null;
},
clear: function() {
while (this.childNodes.length > 0) {
this.removeChild(this.childNodes[0]);
};
return this;
},
txt: function(text) {
this.clear()
.appendChild(document.createTextNode(text));
return this;
},
html: function(html) {
this.innerHTML = html;
return this;
},
remove: function() {
this.parentNode.removeChild(this);
return this;
},
positionScreen: function(x, y) {
this.css({ 
left: (x - getLeft(this.offsetParent)).toString() + "px",
top: (y - getTop(this.offsetParent)).toString() + "px"
});
},
propertyToName: function(property) {
var parts = property.split(/-/);
return parts[0] + parts.slice(1).map(function(part) { return part.ucfirst(); }).join("");
},
addClass: function(name) {
ac(this, name);
return this;
},
removeClass: function(name) {
rc(this, name);
return this;
},
hasClass: function(name) {
return hasClass(this, name);
}
});
return el;
};


Cls.extendDumb(window.Element, element || {});
function $E(tagName, className, content, attrs, children) {
attrs = attrs || {};
children = children || [];
var el = new Element(tagName);
if (className) { 
el.className = className;
};
if (content) {
el.appendChild(document.createTextNode(content));
};

attrs.each(function(value, key) {
el[key] = value;
});
children.each(function(child) { 
el.appendChild(child); 
});
return el;
}



function $(id) {
if (typeof(id) == "string") {
var el = document.getElementById(id);
return el ? window.Element.extend(el) : el;
} else {
return window.Element.extend(el);
};
}
function $T(id, tag) {
return $(id).getElementsByTagName(tag).map(window.Element.extend);
}
function $F(id) {
return $(id).value;
}
var page = new Object();
page.m = new Object();
page.v = new Object();
page.c = new Object();

page._forms = {};
page._inputFeatures = [];
page.addForm = function(id, form) {
page._forms[id] = form;
var target = form.getTarget();
if (target) {
Evt.add($(target), "load", function(e) {  
if (form.getSubmitting()) { form.doOnTargetLoaded(e); };
});
};
return form;
}
page.getForm = function(id) {
return page._forms[id];
}
page.addInputFeature = function(feature) {
page._inputFeatures.push(feature);
}

page._components = {};
page._componentTypes = {};
page.addComponent = function(type, name, component) {
page._components[name] = component;
if (!page._componentTypes[type]) {
page._componentTypes[type] = [];
};
page._componentTypes[type].push(component);
return component;
}
page.getComponentsByType = function(type) {
return page._componentTypes[type] || [];
}
page.getComponent = function(name) {
return page._components[name];
}


function EventInfo(params) {
EventInfo.baseConstructor.call(this);
params.each(function(value, key) {
this[key] = value;
}.bind(this));
}
Cls.inherit(EventInfo, Object, {
stop: function() {
this.setStopped(true);
}              
});
Cls.addTo(EventInfo)
.property("stopped");



function MulticastCallback() {
MulticastCallback.baseConstructor.call(this);
this._callbacks = [];
}
Cls.inherit(MulticastCallback, Object, {
add: function(cb) {
this._callbacks.push(cb);
},
fire: function(params) {
var e = new EventInfo(params);
this._callbacks.each(function(cb) {
cb.call(null, e);
});
return e;
}
});

Cls.event = function(baseClass, eventName) {
var memberName = "_event_" + eventName;
var addName = "on" + eventName.ucfirst();
var fireName = "doOn" + eventName.ucfirst();
if (!baseClass.prototype[addName]) {
baseClass.prototype[addName] = function(callback) {
this[memberName].add(callback);
return this;
};
};
if (!baseClass.prototype[fireName]) {
baseClass.prototype[fireName] = function(params) {
params = params || {};
return this[memberName].fire.call(this[memberName], params);
};
};
var oldBaseConstructor = baseClass.baseConstructor;
baseClass.baseConstructor = function() {
oldBaseConstructor.apply(this, arguments);
this[memberName] = new MulticastCallback();
};
return this.addTo(baseClass);
};
Cls.addTo = function(baseClass) {
return {
property: Cls.property.bind(Cls, baseClass),
propertyLazy: Cls.propertyLazy.bind(Cls, baseClass),
event: Cls.event.bind(Cls, baseClass)
};
}



page.events = {
_registered: {},
getRegisteredFor: function(event) {
if (!this._registered[event]) {
this._registered[event] = new MulticastCallback();
};
return this._registered[event];
},
bind: function(event, handler) {
this.getRegisteredFor(event).add(handler);
},
fire: function(event, params) {
params = params || {};

params.event = event;
return this.getRegisteredFor(event).fire(params);
}
};







page._loadHandlers = [];
page.onLoad = function(callback) {
var env = { m: {}, v: {}, c: {} };
page._loadHandlers.push({ callback: callback, env: env });
}
page.onUnload = function() {

};
page.getXMLRPCGateway = function() {
return "xmlrpc.php";
};
addEvent(window, "unload", page.onUnload );
page.init = function() {
if (page._done) return;
page._done = true;
page._loadHandlers.each(function(handler) {
handler.callback(handler.env);
});
};
/* Mozilla/Firefox/Opera 9 */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", page.init, false);
}
/* Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=\"__ie_onload\" defer=\"defer\" src=\"javascript:void(0)\"><\/script>");
var script = document.getElementById("__ie_onload");
if (script) {
script.onreadystatechange = function() {
if (this.readyState == "complete") {
page.init(); 
}
};
};
/*@end @*/
/* Safari */
if (/WebKit/i.test(navigator.userAgent)) {
var _timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
clearInterval(_timer);
page.init();
}
}, 10);
}
window.onload = page.init;
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/, "");
}


Array.prototype.reduce = function(callback, seed) {
var result = seed;
this.each(function(item) {
result = callback(result, item);
});
return result;
}


Array.prototype.filter = function(predicate) {
if (!predicate) {
predicate = function(item) { return item; };
};
var filtered = this.reduce(function(result, item) {
if (predicate && predicate(item) || !predicate && item) {
result.push(item);
};
return result;
}, []);
return filtered;
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(val, fromIndex) {
if (typeof(fromIndex) != 'number') { 
fromIndex = 0; 
}
for (var index = fromIndex,len = this.length; index < len; index++) {
if (this[index] == val) { return index; };
}
return -1;
};
}




function tc(element, cls) {
if (hasClass(element, cls)) {
rc(element, cls);
} else {
ac(element, cls);
};
}
function ac(element, cls) {
if (!element) return;
if (element instanceof Array) {
element.each(function(e) { ac(e, cls); });
return;
};
if (!hasClass(element, cls)) {
element.className += " " + cls;
};
}
function rc(element, cls) {
if (!element) return;
if (element instanceof Array) {
element.each(function(e) { rc(e, cls); });
return;
};
element.className = element.className.split(/\s+/).filter(function(className) {
return className != cls;
}).join(" ");
}
function hasClass(element, cls) {
if (!element) return false;
return element.className.split(/\s+/).indexOf(cls) != -1;
}
function addRemoveClass(element, cls, guard) {
if (guard) {
ac(element, cls);
} else {
rc(element, cls);
};
}
function getSrcElement(e) {
return e.target || e.srcElement;
}









function GuiSwitch(elements, activeClass, inactiveClass) {
GuiSwitch.baseConstructor.call(this);
this.setElements(elements);
this.setActiveClass(activeClass || "current");
this.setInactiveClass(inactiveClass || "");
this.bind();
}
Cls.inherit(GuiSwitch, Object, {
bind: function() {
Evt.add(this.getElements(), "click", function(event, element) { 
this.switchTo(element); 
}.bind(this));
ac(this.getElements(), "rp_control_switch");
return this;
},
disableAll: function() {
rc(this.getElements(), this.getActiveClass());
rc(this.getElements(), this.getIE6FirstActiveClass());
rc(this.getElements(), this.getIE6LastActiveClass());
ac(this.getElements(), this.getInactiveClass());
return this;
},
switchTo: function(element) {
var elementIndex = this._elements.indexOf(element);
if (this.doOnSwitching({ element: element, index: elementIndex }).getStopped()) {
return this;
}
this.disableAll();
rc(element, this.getInactiveClass());
ac(element, this.getActiveClass());

if (element == this.getElements()[0]) {
ac(element, this.getIE6FirstActiveClass());
} else if (element == this.getElements()[this.getElements().length - 1]) {
ac(element, this.getIE6LastActiveClass());
};
this.doOnSwitched({ element: element, index: elementIndex });
return this;
},
switchToIndex: function(index) {
return this.switchTo(this.getElements()[index]);
},
getIE6FirstActiveClass: function() {
return "first-child_" + this.getActiveClass();
},
getIE6LastActiveClass: function() {
return "last_" + this.getActiveClass();
}
});
Cls.addTo(GuiSwitch)
.property("elements")
.property("activeClass")
.property("inactiveClass")
.event("switching")
.event("switched");



var TransitionMethods = {
Linear: function(frame, frames) {
return frame / frames;
},
Accelerated: function(frame, frames) {
var t = frame / frames;
if (frame < frames / 2) {
return 2 * t * t; 
} else {
return 1 - 2 * (1 - t) * (1 - t);
};
},
Immediate: function(frame, frames) {
return 1;
}
};
function Transition() {
Transition.baseConstructor.call(this);
this.setFrames(20);
this.setTimeout(20);
this.setHandle(null);
this.setMethod(TransitionMethods.Linear);
}
Cls.inherit(Transition, Object, {
cancel: function() {
clearTimeout(this.getHandle());
this.setHandle(null);
return this;
},
run: function() {
this.cancel();
this.doOnStart();
this.doOnFrame({ frame: 0, fraction: this.getMethod()(0, this.getFrames()) });
this.setupTimeout();
return this;
},
timeoutStep: function(frame) {
this.doOnFrame({ frame: frame, fraction: this.getMethod()(frame, this.getFrames()) });
if (frame >= this.getFrames()) {
this.doOnComplete();
this.cancel();
};
},
setupTimeout: function() {
var index = 0;
this.setHandle(setInterval(function() {
index++;
this.timeoutStep(index);
}.bind(this), 
this.getTimeout()));
}
});
Cls.addTo(Transition)
.property("frames")
.property("timeout")
.property("handle")
.property("method")
.event("complete")
.event("start")
.event("frame");
/* Function printf(format_string,arguments...)
* Javascript emulation of the C printf function (modifiers and argument types 
*    "p" and "n" are not supported due to language restrictions)
*
* Copyright 2003 K&L Productions. All rights reserved
* http://www.klproductions.com 
*
* Terms of use: This function can be used free of charge IF this header is not
*               modified and remains with the function code.
* 
* Legal: Use this code at your own risk. K&L Productions assumes NO resposibility
*        for anything.
********************************************************************************/
function sprintf(fstring)
{ var pad = function(str,ch,len)
{ var ps='';
for(var i=0; i<Math.abs(len); i++) ps+=ch;
return len>0?str+ps:ps+str;
}
var processFlags = function(flags,width,rs,arg)
{ var pn = function(flags,arg,rs)
{ if(arg>=0)
{ if(flags.indexOf(' ')>=0) rs = ' ' + rs;
else if(flags.indexOf('+')>=0) rs = '+' + rs;
}
else
rs = '-' + rs;
return rs;
}
var iWidth = parseInt(width,10);
if(width.charAt(0) == '0')
{ var ec=0;
if(flags.indexOf(' ')>=0 || flags.indexOf('+')>=0) ec++;
if(rs.length<(iWidth-ec)) rs = pad(rs,'0',rs.length-(iWidth-ec));
return pn(flags,arg,rs);
}
rs = pn(flags,arg,rs);
if(rs.length<iWidth)
{ if(flags.indexOf('-')<0) rs = pad(rs,' ',rs.length-iWidth);
else rs = pad(rs,' ',iWidth - rs.length);
}    
return rs;
}
var converters = new Array();
converters['c'] = function(flags,width,precision,arg)
{ if(typeof(arg) == 'number') return String.fromCharCode(arg);
if(typeof(arg) == 'string') return arg.charAt(0);
return '';
}
converters['d'] = function(flags,width,precision,arg)
{ return converters['i'](flags,width,precision,arg); 
}
converters['u'] = function(flags,width,precision,arg)
{ return converters['i'](flags,width,precision,Math.abs(arg)); 
}
converters['i'] =  function(flags,width,precision,arg)
{ var iPrecision=parseInt(precision);
var rs = ((Math.abs(arg)).toString().split('.'))[0];
if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
return processFlags(flags,width,rs,arg); 
}
converters['E'] = function(flags,width,precision,arg) 
{ return (converters['e'](flags,width,precision,arg)).toUpperCase();
}
converters['e'] =  function(flags,width,precision,arg)
{ iPrecision = parseInt(precision);
if(isNaN(iPrecision)) iPrecision = 6;
rs = (Math.abs(arg)).toExponential(iPrecision);
if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) rs = rs.replace(/^(.*)(e.*)$/,'$1.$2');
return processFlags(flags,width,rs,arg);        
}
converters['f'] = function(flags,width,precision,arg)
{ iPrecision = parseInt(precision);
if(isNaN(iPrecision)) iPrecision = 6;
rs = (Math.abs(arg)).toFixed(iPrecision);
if(rs.indexOf('.')<0 && flags.indexOf('#')>=0) rs = rs + '.';
return processFlags(flags,width,rs,arg);
}
converters['G'] = function(flags,width,precision,arg)
{ return (converters['g'](flags,width,precision,arg)).toUpperCase();
}
converters['g'] = function(flags,width,precision,arg)
{ iPrecision = parseInt(precision);
absArg = Math.abs(arg);
rse = absArg.toExponential();
rsf = absArg.toFixed(6);
if(!isNaN(iPrecision))
{ rsep = absArg.toExponential(iPrecision);
rse = rsep.length < rse.length ? rsep : rse;
rsfp = absArg.toFixed(iPrecision);
rsf = rsfp.length < rsf.length ? rsfp : rsf;
}
if(rse.indexOf('.')<0 && flags.indexOf('#')>=0) rse = rse.replace(/^(.*)(e.*)$/,'$1.$2');
if(rsf.indexOf('.')<0 && flags.indexOf('#')>=0) rsf = rsf + '.';
rs = rse.length<rsf.length ? rse : rsf;
return processFlags(flags,width,rs,arg);        
}  
converters['o'] = function(flags,width,precision,arg)
{ var iPrecision=parseInt(precision);
var rs = Math.round(Math.abs(arg)).toString(8);
if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
if(flags.indexOf('#')>=0) rs='0'+rs;
return processFlags(flags,width,rs,arg); 
}
converters['X'] = function(flags,width,precision,arg)
{ return (converters['x'](flags,width,precision,arg)).toUpperCase();
}
converters['x'] = function(flags,width,precision,arg)
{ var iPrecision=parseInt(precision);
arg = Math.abs(arg);
var rs = Math.round(arg).toString(16);
if(rs.length<iPrecision) rs=pad(rs,' ',iPrecision - rs.length);
if(flags.indexOf('#')>=0) rs='0x'+rs;
return processFlags(flags,width,rs,arg); 
}
converters['s'] = function(flags,width,precision,arg)
{ var iPrecision=parseInt(precision);
var rs = arg;
if(rs.length > iPrecision) rs = rs.substring(0,iPrecision);
return processFlags(flags,width,rs,0);
}
farr = fstring.split('%');
retstr = farr[0];
fpRE = /^([-+ #]*)(\d*)\.?(\d*)([cdieEfFgGosuxX])(.*)$/;
for(var i=1; i<farr.length; i++)
{ fps=fpRE.exec(farr[i]);
if(!fps) continue;
if(arguments[i]!=null) retstr+=converters[fps[4]](fps[1],fps[2],fps[3],arguments[i]);
retstr += fps[5];
}
return retstr;
}
/* Function printf() END */



var Opacity = {
set: function(nodes, opacity) {
if (!(nodes instanceof Array)) {
nodes = [nodes];
}
nodes.each(function(node) {
node.css({ opacity: opacity,
filter: sprintf("progid:DXImageTransform.Microsoft.Alpha(opacity=%s)", Math.round(opacity*100)) });
});
}
};



function TransitionOpacity(nodes, startOpacity, stopOpacity) {
if (!(nodes instanceof Array)) {
nodes = [nodes];
}
TransitionOpacity.baseConstructor.call(this);
this
.setNodes(nodes)
.setStart(startOpacity)
.setStop(stopOpacity);
this.onFrame(this.handleFrame.bind(this));
if (stopOpacity == 1 || stopOpacity == 0) {
this.onComplete(this.handleComplete.bind(this));
};
}
Cls.inherit(TransitionOpacity, Transition, {
handleFrame: function(e) {
Opacity.set(this.getNodes(), this.getStart() + (this.getStop() - this.getStart()) * e.fraction);
},
handleComplete: function() {
this.getNodes().each(function(node) {
node.style.filter = null;
});
}
});
Cls.addTo(TransitionOpacity)
.property("nodes")
.property("start")
.property("stop");
Function.prototype.delayed = function(timeout) {
var original = this;
original._handle = null;
original.call = function() {
original.call.cancel();
original._handle = setTimeout(function() { original._handle = null; original(); }, timeout);
};
original.call.cancel = function() {
if (!original._handle) { return; };
clearTimeout(original._handle);
original._handle = null;
};
return original.call;
}


Array.prototype.findFirstIndex = function(predicate) {
if (!(predicate instanceof Function)) {
testValue = predicate;
predicate = function(value) {
return value == testValue;
};
};
for (var i = 0; i < this.length; i++) {
if (predicate(this[i])) {
return i;
};
};
return null;
}

Array.prototype.flatten = function() {
return this.reduce(function(result, item) {
return result.concat(item);
}, []);
}

Array.prototype.contains = function(item) {
return (this.indexOf(item) != -1);
}


Array.prototype.unique = function() {
var result = this.reduce(function(res, item) {
if (!res.values.contains(item)) {
res.values.push(item);
};
return res;
}, { values: [], found: {}});
return result.values;
}
function isAncestorOf(parent, node) {
while (node.parentNode && node.parentNode != parent) {
node = node.parentNode;
};
return node.parentNode;
}










var Selector = {

find: function(compositeSelector, context) {
var selectorParts = compositeSelector.split(/\s*,\s*/);
var matches = selectorParts.map(function(simpleSelector) { return Selector.findSimple(simpleSelector, context); });
return matches.flatten().map(window.Element.extend);
},

findSimple: function(simpleSelector, context) {
var subselectors = simpleSelector.split(/\s+/);
var finalContext = subselectors.reduce(Selector.applySubselector.bind(Selector), { nodes: [context || document.body], mode: "normal" });
return finalContext.nodes;
},
match: function(node, simpleSelector) {
var subselectors = simpleSelector.split(/\s+/);
if (subselectors.length == 0) { 
return true; 
};
if (!this.subselectorMatch(node, subselectors[subselectors.length - 1])) { 
return false; 
};
if (subselectors.length == 1) { 
return true; 
};
return node.up(subselectors.slice(0, subselectors.length - 1).join(" ")) != null;
},
subselectorMatch: function(node, selector) {
var selectorData = this.parseSubselector(selector);
if (selectorData.tagName) {
if (node.tagName.toUpperCase() != selectorData.tagName.toUpperCase()) { return false; };
};
switch (selectorData.subselectorType) {
case ".":
if (!hasClass(node, selectorData.subselectorData)) { return false; };
break;
case "#":
if (node.id != selectorData.subselectorData) { return false; };
break;
default:
break;
};
return true;
},
traverseChildren: function(root, predicate, result) {
return $A(root.childNodes).filter(function(node) { 
return node.nodeType == 1 && predicate(node) // nodeType=1: Element node
});
},
traverseTree: function(root, predicate, result) {
if (root.nodeType != 1) { // nodeType=1: Element node
return;
};
if (predicate(root)) { 
result.push(root); 
};
$A(root.childNodes).each(function(node) { 
Selector.traverseTree(node, predicate, result); 
});
return result;
},
parseSubselector: function(subselector) {
var matches = subselector.match(/^(.*?)(?:([.#])(.*?))?$/);
return {
tagName: matches[1],
subselectorType: matches[2],
subselectorData: matches[3]
};
},
applySubselector: function(context, subselector) {
var nodes = context.nodes;
var data = this.parseSubselector(subselector);
var newContext = {
nodes: context.nodes,
state: "normal"
};
if (subselector == ">") {
newContext.state = ">";
return newContext;
};
var traverseFun = null;
switch (context.state) {
case ">":
traverseFun = Selector.traverseChildren.bind(Selector);
break;
default:
traverseFun = Selector.traverseTree.bind(Selector);
break;
};
switch (data.subselectorType) {
case ".":
var matchRegexp = new RegExp("\\b" + data.subselectorData + "\\b");
newContext.nodes = nodes.map(function(node) {
return traverseFun(node, function(n) { 
return n.className.match(matchRegexp) && (data.tagName == "" || n.tagName.toUpperCase() == data.tagName.toUpperCase());
}, []);
}).flatten().unique();
break;
case "#":
newContext.nodes = nodes.map(function(node) { 
if (node.getAttribute("id") == data.subselectorData) {
return [node];
};
var newNode = $(data.subselectorData);


if (!newNode ||
!isAncestorOf(node, newNode)) {
return [];
};
return [newNode];
}).flatten().unique();
break;
default:
if (data.tagName != "") {
newContext.nodes = nodes.map(function(node) {
return traverseFun(node, function(n) { 
return n.tagName.toUpperCase() == data.tagName.toUpperCase();
}, []);
}).flatten().unique();
};
};
return newContext;
}
}

function $$(selector, context) {
var matches = Selector.find(selector, context);
return matches.length > 0 ? matches[0] : null;
}






page.onLoad(function(env) {
env.AUTOSWITCH_TIMEOUT = 10000;
page.uiSwitch = new GuiSwitch(Selector.find(".layout-promo li"))
.onSwitched(function(e) {
Selector.find(".layout-promo img")
.each(function(node) { node.hide(); });
var node = Selector.find(".layout-promo img")[e.index];
node.show();
new TransitionOpacity(node,
0, 1)
.run();
env.autoswitchCallback();
});
env.handleSwitchInterval = function() {
env.autoswitchCallback();
var activeIndex = page.uiSwitch.getElements().findFirstIndex(function(item) { return hasClass(item, "current"); });
page.uiSwitch.switchToIndex((activeIndex + 1) % page.uiSwitch.getElements().length);
};
env.autoswitchCallback = env.handleSwitchInterval.bind(env).delayed(env.AUTOSWITCH_TIMEOUT);
env.autoswitchCallback();
});
var I18N = { 
strings: {}
};
function _(string) {
return I18N.strings[string] || string;
}
Lang = {
NOMINATIVE: 1,
getWordForm: function(word, value, wordCase) {

if (value == 1) {
return word;
};

var last = word[word.length - 1];
var suffix2 = word.substr(word.length - 2, 2);
if (suffix2 == "ay") { // e.g. day, gay
return word + "s";
};
if (suffix2[1] == "y") {
return word.substr(0, word.length - 1) + "ies";   
};
if (suffix2[1] == "h") {
return word + "es";
};
return word + "s";
}
}

