/*------------------------------------------------------------------------------
    JS Document (https://developer.mozilla.org/en/JavaScript)

    project:    Capgemini
    created:    2009-04-20
    author:     yvevan

    summary:    CONSTANTES
                UTILITIES
                WINDOW.ONLOAD
                INPUTLABEL
                NOSCRIPT_SELECTS
                LANGUAGES
                NAVIGATION
                TABS
                SLIDERS
                BUTTONS
                LOGOUT
                INTERACTIVE_ELEMENTS (PRINT / SHARE)
                SEARCH_FILTERS
                LABEL_FOCUS
                BUBBLES_TOOLTIPS
                TABS_CAROUSEL
                VERTICAL_ALIGN_IE6
                FORM_VALIDATION
                FORM_REGISTER
                GMAPS
                FORM_CONTROLS
                HOVER_PEOPLE_IE6
                
----------------------------------------------------------------------------- */

/*  =CONSTANTES
----------------------------------------------------------------------------- */
jQuery.noConflict();
var d = document;
var w = window;
var addthis_options = 'email, favorites, twitter, facebook, stumbleupon, digg, diigo, netvibes, reddit, newsvine, delicious, simpy, faves, google';
var addthis_offset_top = -15;
var addthis_offset_left = 6;
var addthis_language = 'en'; 
var addthis_localize = {
    share_caption: ' '
}; 
var debug = null;
window.config = {
    debug : false, // true: enable textarea console, false: disable textarea console
    focus : 'focus',
    inputs : {
        name : '.inside-label'
    },
    navigation : {
        name : '#nav',
        active : {
            first  : 'active-1',
            second : 'active-2'
        },
        ie6 : {
            className : 'hover',
            delay : 125
        }
    },
    language : {
        name : '#change-country',
        label : '[Close menu]'
    },
    replaceSelect : {
        scope  : '.replace-select',
        remove : '.remove-me',
        noscript : '.noscript'
    },
    tabs : {
        tabs1 : {
            id          : '#scrolling-banners',
            zones       : '.tab',
            menu        : '#banners-nav',
            active      : 'active',
            container   : '#banners-content',
            linkParent  : 'li',
            scrollToTop : true,
            callbacks : {
                prev  : function(obj){
                    slidersInterface.callbacks(obj, w.config.sliders.sliders1);
                },
                next  : function(obj){
                    slidersInterface.callbacks(obj, w.config.sliders.sliders1);
                }
            }
        },
        tabs2 : {
            id          : '#tabs2',
            zones       : '.tab',
            menu        : '#tabs2-menu',
            active      : 'active',
            container   : '#tabs2-content',
            linkParent  : 'li',
            scrollToTop : true,
            callbacks : {
                prev  : function(obj){
                    slidersInterface.callbacks(obj, w.config.sliders.sliders1);
                },
                next  : function(obj){
                    slidersInterface.callbacks(obj, w.config.sliders.sliders1);
                }
            }
        },
        tabs3 : {
            id          : '#tabs3',
            zones       : '.tab',
            menu        : '#tabs3-menu',
            active      : 'active',
            container   : '#tabs3-content',
            linkParent  : 'li',
            scrollToTop : true,
            timer : 5000
        },
        tabs4 : {
            id          : '#tabs4',
            zones       : '.tab',
            menu        : '#tabs4-menu',
            active      : 'active',
            container   : '#tabs4-content',
            linkParent  : 'li',
            scrollToTop : true,
            timer : 5000
        }
    },
    sliders : {
        sliders1 : {
            name   : '.slider-1',
            slider : '.slider',
            links  : '.slider-linked',
            dom    : {
                bar   : 'bar',
                start : 'start',
                end   : 'end',
                inner : 'inner',
                slider : 'slider'
            }
        }
    },
    buttons : {
        buttons1 : {
            elm : '.button-type-1',
            initHeight : 30
        }
    },
    logout : {
        elm : '#login',
        label : '.sign-out'
    },
    interactive : {
        elm : '.interactive-elements',
        txtPrint : 'Print',
        txtShare : 'Share &amp; bookmark'
    },
    searchs : {
        elm   : '.button-field',
        init  : '<img src="/img/data/bt_ico_search.png" alt="" />Refine your search',
        close : '<img src="/img/data/bt_ico_close.png" alt="" />Close',
        button : '<a href="#" class="button-style-1 button-2 bullet-ie"><span></span></a>'
    },
    bubbles : {
        elm : '.bubble-zone',
        content : '.bubble-content'
    },
    vAlignIE6 : {
        elms : '.valign-ie6'
    },
    formValidation : {
        elms : '.form-required',
        form : '.form-verify',
        intro : '#form-intro',
        messages : formValidation_messages,
        html : {
            error : '<img src="/img/data/ico_invalid.png" alt="" /><span class="error"><span></span></span>',
            valid : '<img src="/img/data/ico_valid.png" alt="" />'
        }
    },
    formRegister : {
        button : '.register-1 > a.button-4',
        form   : '.form-3'
    },
    maps : {
        elm : '#map-zone-1',
        details : '.map-1 > .map-details',
        cities  : '.map-1 #cities',
        coords : '#map-coordinates'
    },
    hoverPeopleIE6 : {
        elm : '.grid-view-2 .col .people'
    },
    controls : {
        elm         : '.form-controls',
        txtLabel    :'Select',
        txtLinkAll  : 'all',
        txtLinkNone : 'none'
    }
};


/*  =UTILITIES
----------------------------------------------------------------------------- */
/* getElementsByClassName when not supported */
var matchAll = function() {
    var node = arguments[1] || document;
    var elms = node.getElementsByTagName('*');
    var className = arguments[0];
    if (d.getElementsByClassName) {
        return node.getElementsByClassName(className);
    }
    else {
        var regExp = new RegExp('\\b'+className+'\\b');
        var array = [];
        for (var i = 0; i < elms.length; i++) {
            var current = elms[i];
            if (current.className.match(regExp)) {
                array.push(current);
            }
        }
        return array;
    }
};

/* logs into a textarea for IE and in the console for others */
var debuger = function() {
    if (window.config.debug && !debug && typeof console == 'undefined') {
        var parent = d.getElementsByTagName('div')[0];
        var body   = d.getElementsByTagName('body')[0];
        var debug  = d.createElement('textarea');
        debug.setAttribute('rows', 10);
        debug.setAttribute('cols', 80);
        debug.setAttribute('name', 'debug');
        body.insertBefore(debug, parent);
        window.debug = debug;
    }
    else if (window.config.debug && console) {
        log('Debug mode : on');
    }
};
var log = function(x) {
    if (typeof console != 'undefined')
        console.log(x);
    else if (debug) {
        debug.value += x + '\n';
        debug.scrollTop = debug.scrollHeight;
    }
};


/*  =WINDOW.ONLOAD
----------------------------------------------------------------------------- */
jQuery(document).ready(function () {
    
    // Configs
    var configTabs1 = w.config.tabs.tabs1;
    var configTabs2 = w.config.tabs.tabs2;
    var configTabs3 = w.config.tabs.tabs3;
    var configTabs4 = w.config.tabs.tabs4;
    var configSlider1 = w.config.sliders.sliders1;
    
    // Functions
    debuger();              // build a log console for IE
    inputLabel();           // handle labels in input fields
    navigation();           // handle navigation across modern browsers
    noscriptSelects();      // rebuild selects to lists
    language();             // handle language selection
    tabs(configTabs1);      // handle banners on homepage
    tabs(configTabs2);      // handle "highlights" tabs on homepage
    tabs(configTabs3);      // handle news module in the right sidebar
    tabs(configTabs4);      // handle search tabs
    sliders(configSlider1); // handle sliders
    buttons1();             // handle blue list/buttons
    logout();               // hide logout button
    interactiveElements();  // handle print and share/bookmark buttons
    searchFilters();        // handle search panels toggle
    labelFocus();           // handle focus on label when focusing on associate element
    bubblesTooltips();      // handle bubbles
    formValidation();       // handle form validation in JS
    setMaps();              // set google maps
    formControls();         // handle all/none links (checkboxes)
    formRegister();         // handle register button
    verticalAlignIE6();
    
    // Classes
    
    if (jQuery.browser.msie && jQuery.browser.version == 6) {
        // IE 6 FUNCTIONS ONLY
        navigationIE6(); 
        hoverPeopleIE6();
    }
    
    if (jQuery.browser.opera) {
        jQuery(document.body).addClass('isOpera');
    }

});

jQuery(window).load(function(){
    verticalAlignIE6();
});

/*window.onunload = function() {
    GUnload();
};*/


/*  =INPUTLABEL
----------------------------------------------------------------------------- */
function inputLabel() {
    var inputs = jQuery(w.config.inputs.name);
    
    var setField = function(current) {
        if (current.parentNode.getElementsByTagName('label')[0]) {
            var title = current.parentNode.getElementsByTagName('label')[0].innerHTML;
        }
        current.value = title;
        current.state = 0;
    };

    var init = function() {
        inputs.each(function() {
            jQuery(this).keypress(function() {
                this.state = 1;
            });
            jQuery(this).focus(function() {
                if (this.state != 1) {
                    this.value = '';
                }
            });
            jQuery(this).blur(function() {
                if (this.state == 0 || this.value == '') {
                    setField(this);
                }
            });
            setField(this);
        });
    }();
}


/*  =NOSCRIPT_SELECTS
----------------------------------------------------------------------------- */
function noscriptSelects() {
    var scope = w.config.replaceSelect.scope;
    var rElms = w.config.replaceSelect.remove;
    var noscripts = jQuery(scope + ' ' + w.config.replaceSelect.noscript);

    var launch = function() {

        var rebuildSelects = function() {
            noscripts.each(function() {
                
                if (this.id == 'change-country' && jQuery.browser.opera) {
                    return;
                }
                
                var elm = jQuery(this);
                var optionsArr = [];
                
                elm.find('select').each(function() {
                    var options = this.getElementsByTagName('option');
                    jQuery(options).each(function(i) {
                        if (i > 0) {
                            optionsArr.push(this);
                        }
                    });
                });
                
                var items = '<ul>';
                jQuery(optionsArr).each(function(){
                    items += '<li><a href="'+this.value+'">'+this.innerHTML+'</a></li>';
                });
                items += '</ul>';
                
                elm.empty();
                elm.removeClass('noscript');
                elm.append(items);
                // elm.append('<div class="border-shadow"></div>');
            });
            
        }();
        
    };

    var init = function() {
        if (jQuery(scope)[0] && noscripts) {
            launch();
        }
    }();
}


/*  =LANGUAGE
----------------------------------------------------------------------------- */
function language() {
    var elm = w.config.language.name;
    var animated = null;
    var owidth = null;
    
    var launch = function(){
        var initLabel = null;
        var txtElm = null;
        
        var openList = function() {
            if (!initLabel) {
                // txtElm = jQuery(this);
                // initLabel = txtElm.text();
            }
            if (jQuery(elm).hasClass('active')) {
                jQuery(elm).removeClass('active');
                // txtElm.text(initLabel);
            }
            else {
                jQuery(elm).addClass('active');
                // txtElm.text(w.config.language.label);
            }
            // return false;
        };
        
        var setEvents = function(){
            jQuery('a[href="'+elm+'"]').click(function(){
                openList();
                return false;
            });
        
            jQuery('a[href="'+elm+'"]').parent().parent().hover(function(){
                if (!animated) {
                    openList();
                    animated = true;
                }
                return false;
            },function(){
                blurOut();
                animated = null;
            });    
            
        }();
        
        var blurOut = function() {
            if (jQuery(elm).hasClass('active')) {
                jQuery(elm).removeClass('active');
                // txtElm.text(initLabel);
            }
        };

        jQuery(document).keyup(function(e){
            if (e.keyCode == 27) { // escape key
                blurOut();
            }
        });

    };

    var init = function() {
        if (jQuery(elm)[0] && !jQuery.browser.opera) {
            launch();
        }
    }();
}

/*  =NAVIGATION
----------------------------------------------------------------------------- */
function navigation() {
    var firstActiveLevel  = w.config.navigation.active.first;
    var secondActiveLevel = w.config.navigation.active.second;
    var nav = jQuery(w.config.navigation.name);
    // var hoverClass = w.config.navigation.ie6.className;
    // var mouseOffDelay = w.config.navigation.ie6.delay;

    var launch = function() {
        
            var handleEvents = function(){
            var listItems = nav.children('li');
            listItems.hover(function(){
                var elm = jQuery(this);
                var sublist = elm.find('.sublist');
                elm.children('a').addClass(firstActiveLevel);
                
                sublist.hover(function(){
                    jQuery(this).addClass(secondActiveLevel);
                },function(){
                    jQuery(this).removeClass(secondActiveLevel);
                });
            },function(){
                var that = this;
                jQuery(that).children('a').removeClass(firstActiveLevel);
            });
        }();
    };
    
    var init = function() {
            if (nav[0] && firstActiveLevel && secondActiveLevel) {
            launch();
        }
    }();
}

function navigationIE6() {
    var dropdownId = w.config.navigation.name.replace('#','');
    var hoverClass = w.config.navigation.ie6.className;
    var mouseOffDelay = w.config.navigation.ie6.delay;
        
    if (dropdown = document.getElementById(dropdownId)) {
        var listItems = dropdown.getElementsByTagName('li');
        for (var i = 0, n = listItems.length; i < n; i++) {
            jQuery(listItems[i]).hover(function(e) {
                // e.stopPropagation()
                var that = this;
                that.className = addClass(that);
            },function() {
                var that = this;
                setTimeout(function() {
                    that.className = removeClass(that);
                }, mouseOffDelay);
                this.className = that.className;
            });
        }
    }
        
    function addClass(li) { return li.className + ' ' + hoverClass; }
    function removeClass(li) { return li.className.replace(hoverClass, ""); }
}


/* =TABS
------------------------------------------------------------------------------*/
function tabs(config) {
    var elements   = null;
    var active     = config.active;
    var linkParent = config.linkParent;
    var scroll     = config.scrollToTop;
    var id         = jQuery(config.id);
    var zones      = id.find(config.zones);
    var menu       = id.find(config.menu);
    var container  = id.find(config.container);
    if (config.callbacks) {
        var callNext   = config.callbacks.next || null;
        var callPrev   = config.callbacks.prev || null;
    }
    
    function launch() {
        var setStyles = function() {
            var containerHeight = container.css("height");
            var focus           = jQuery("." + w.config.focus).length;
            zones.css('height', containerHeight);
            // zones.css('overflow','auto');
            container.css('overflow','hidden');
            zones.hide();
            if(!focus) {
                id.addClass(w.config.focus);
            }
        }();
        
        var handleBehaviours = function() {
            var idExists = id.find(w.location.hash);
            var isActive   = menu.find('.' + active);
            var zoneActive = jQuery(isActive.find('a').attr('href'));
            if (w.location.hash && w.location.hash != '' && idExists.length) {
                menu.find(linkParent).removeClass(active);
                idExists.show();
                idExists.attr("tabindex","-1");
                idExists.focus();
                idExists.removeAttr("tabindex");
                jQuery('a[href='+ w.location.hash +']').parents(linkParent).addClass(active);
                if (scroll) {
                    w.scrollTo(0,0);
                }
            }
            else if (isActive.length) {
                zoneActive.show();
            }
            else {
                zones.eq(0).show();
                menu.find(linkParent).eq(0).addClass(active);
            }
        }();
        
        var handleEvents = function() {
            var tabs = menu.find(linkParent).find('a');
            tabs.click(function(){
                jQuery("." + w.config.focus).removeClass(w.config.focus);
                id.addClass(w.config.focus);
                var zoneActive = jQuery(jQuery(this).attr("href"));
                menu.find(linkParent).removeClass(active);
                jQuery(this).parents(linkParent).addClass(active);
                zones.hide();
                zoneActive.show();
                zoneActive.attr("tabindex","-1");
                zoneActive.focus();
                zoneActive.removeAttr("tabindex");
                return false;
            });
            tabs.focus(function(e) {
                jQuery("." + w.config.focus).removeClass(w.config.focus);
                id.addClass(w.config.focus);
            });
            
            // fixes a reflow issue on IE 7
            if (jQuery.browser.msie && jQuery.browser.version == 7) {
                try {
                    document.getElementsByTagName('div')[0].focus();
                } catch(e) {}
            } 
        }();
        
        var handleKeyboard = function() {
            return false;
            // this need to be patched
            /*
            jQuery(document).keyup(function(e) {
                var isActive = jQuery(config.id + '.' + w.config.focus).find(config.menu).find('.' + active);
                if (isActive.length) {
                    var zoneActive = jQuery(isActive.find('a').attr('href'));
                    if (e.keyCode == 39 || e.keyCode == 37) {
                        var position  = null;
                        var afterZone = null;
                        
                        isActive.removeClass(active);
                        var action = function(position,move) {
                             if (isActive[move]().length) {
                                afterZone = jQuery(isActive[move]().children("a").attr("href"));
                                isActive[move]().addClass(active);
                            }
                            else {
                                afterZone = zones.eq(position);
                                menu.children(linkParent).eq(position).addClass(active);
                            }
                        };
                        zones.hide();
                        switch(e.keyCode) {
                            case 39: // right arrow
                                var position = 0;
                                action(position,"next");
                                if (typeof callNext == 'function') {
                                    callNext(config);
                                }
                                break;
                            case 37: //  left arrow 
                                var position = zones.length - 1;
                                action(position,"prev");
                                if (typeof callPrev == 'function') {
                                    callPrev(config);
                                }
                                break;
                        }
                        afterZone.show();
                        afterZone.attr("tabindex","-1");
                        afterZone.focus();
                        afterZone.removeAttr("tabindex");
                    }
                }
            });*/
        }();
        
    }
    var init = function() {
        if (config) {
            launch();
        }
    }(); 
}


/* =SLIDERS
------------------------------------------------------------------------------*/
var sliders = function(config) {
    var sliders = config.name;
    var classSlider = config.slider;
    var classLinked = config.links;
    var menuWidth = null;
   
    var launch = function() {
       
        var buildSliders = function(){
            jQuery(sliders).append('<span class="'+config.dom.bar+'">'
                   +'<span class="'+config.dom.start+'"><\/span>'
                   +'<span class="'+config.dom.inner+'"><span class="'+config.dom.slider+'"><\/span><\/span>'
                   +'<span class="'+config.dom.end+'"><\/span>'
                   +'<\/span>');
        }();
       
        var setStyles = function() {
            menuWidth = parseInt(jQuery(classLinked)[0].offsetWidth - 15,10);
        }();
   
        jQuery(sliders).each(function(){
            var slider = jQuery(this).find(classSlider);
            var linkedElm = jQuery(this).parent().find(classLinked);
            if (linkedElm[0]) {
                var links = linkedElm.find('a');
                links.click(function(){
                    var left  = this.offsetLeft;
                    var width = this.offsetWidth;
                    jQuery(slider).animate({
                        left  : left,
                        width : width
                        // marginLeft : '-15'
                    });
                });
                jQuery(slider).animate({
                    left  : links[0].offsetLeft,
                    width : links[0].offsetWidth
                    // marginLeft : '-15'
                });
            }
            
            if (this.parentNode.id == 'banners-nav') {
                jQuery(this).parent().children(classLinked).width(jQuery(this).parent().children(classLinked).width());
                jQuery(slider).parents('#banners-nav').find('.inner').width(menuWidth);
                jQuery(slider).parents('#banners-nav').find('.nav-indicator-1').parent().css('width',menuWidth + 6);
            }
            
        });
   
    };
       
    var init = function() {
        if (jQuery(sliders)[0]) {
            launch();
        }
    }();
};


var slidersInterface = {
    callbacks  : function(obj, config) {
        var obj = jQuery(obj.menu);
        var slider = jQuery(obj).find(config.slider);
        var active = obj.find('.active');
        if (active[0]) {
            slider.animate({
                left  : active[0].offsetLeft,
                width : active[0].offsetWidth
            });
        }
    }
};


/* =BUTTONS
------------------------------------------------------------------------------*/
function buttons1() {
    var buttons = w.config.buttons.buttons1.elm;
    var iHeight = w.config.buttons.buttons1.initHeight;
    
    var launch = function() {
        
        var cloneButtons = function(){
            jQuery(buttons).each(function(){
                var btn = jQuery(this).find('h2').clone();
                jQuery(this).append(btn);
                btn.wrap('<div class="clone">');
            });
        }();

        
        function toggleList(that, e, action) {
            e.stopPropagation();
            var button = jQuery(that);
            var form = button.children('form');
            var div  = form.children('div');
            var ul   = form.find('ul');
            var cloneBtn = button.children('.clone');
            
            var formHeight = parseInt(form.css('height') ,10);
            
            if (!form[0].oHeight) {
                var height = parseInt(form[0].offsetHeight + ul[0].offsetHeight ,10);
                form[0].oHeight = height;
            }
            if (action && formHeight == form[0].oHeight) {
                return;
            }
            if (formHeight != form[0].oHeight) {
                button.addClass('animated');
                form.height(form[0].oHeight);
                form.css('margin-top','-' + form[0].oHeight / 2 + 'px');
                form.hide();
                form.fadeIn(200);
                cloneBtn.fadeOut(200);
                setTimeout(function(){
                    button.addClass('active');
                    button.removeClass('animated');
                },0);
            }
            else {
                form.height(iHeight);
                form.css('margin-top',0);
                button.removeClass('active');
            }
        }
        
        function closeAll(that) {
            var btns = jQuery(that);
            btns.each(function(){
                var button = jQuery(this);
                var form = button.children('form');
                var cloneBtn = button.children('.clone');
                button.addClass('animated');
                form.fadeOut(200,function(){
                    form.height(iHeight);
                    form.css('margin-top',0);
                    setTimeout(function(){
                        button.removeClass('active');
                        button.removeClass('animated');
                    },0);
                });
                cloneBtn.fadeIn('fast');
            });
        }
        
        var setEvents = function() {
            var btns = jQuery(buttons);
            btns.each(function(i){
                this.parentId = i;
            });
            
            btns.hover(function(e){
                toggleList(this, e);
            },function(){
                var button = jQuery(this);
                var form = button.children('form');
                var cloneBtn = button.children('.clone');
                button.addClass('animated');
                form.fadeOut(200,function(){
                    form.height(iHeight);
                    form.css('margin-top',0);
                    setTimeout(function(){
                        button.removeClass('active');
                        button.removeClass('animated');
                    },0);
                });
                cloneBtn.fadeIn('fast');
            });
            
        }();
        
        var listItemFocus = function() {
            jQuery('a').focus(function(e){
                if (!jQuery(this).parents(buttons)[0] && jQuery(buttons + '.active')[0]) {
                    closeAll(buttons);
                }
            });
            var items = jQuery(buttons).find('a');
            var tmpItem = null;
            jQuery(items).focus(function(e){
                var current = jQuery(this);
                if (tmpItem && tmpItem != current.parents(buttons)[0].parentId) {
                    closeAll(that);
                }
                tmpItem = current.parents(buttons)[0].parentId;
                var that = current.parents(buttons);
                toggleList(that, e, true);
            });
        }();
        
    };
    
    var init = function() {
        if (jQuery(buttons)[0]) {
            launch();
        }
    }();
}


/*  =LOGOUT
----------------------------------------------------------------------------- */
function logout() {
    var elm   = w.config.logout.elm;
    var label = w.config.logout.label;
    
    var launch = function() {
        
        var setEvents = function() {
            jQuery(label).click(function(){
                jQuery(elm).animate({
                    opacity:'hide'
                });
            });
        }();
        
    };
    
    var init = function() {
        if (jQuery(elm)[0]) {
            launch();
        }
    }();
}


/*  =INTERACTIVE_ELEMENTS
----------------------------------------------------------------------------- */
function interactiveElements() {
    var elm = w.config.interactive.elm;
    var txtPrint = w.config.interactive.txtPrint;
    var txtShare = w.config.interactive.txtShare;

    var launch = function() {
        var zone = jQuery(elm);
        zone.each(function(){
            jQuery(this).append('<ul>'+
                    '<li class="print"><a href="javascript:window.print();"><span><span>'+txtPrint+'</span></span></a>'+
                    '<li class="share"><a href="#"><span><span>'+txtShare+'</span></span></a>'+
                   '</ul>');
            var btShare = jQuery(this).find('.share');
            var btShareLink = btShare.children('a')[0];
            btShareLink.href = 'http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4a6b8c986c3f8bae';
            btShareLink.onmouseover = function(){
                return addthis_open(this, '', '[URL]', '[TITLE]');
            };
            btShareLink.onmouseout = function(){
                addthis_close();
            };
            btShareLink.onclick = function(){
                return addthis_sendto();
            };
        });
        
    };

    var init = function() {
        if (jQuery(elm)[0]) {
            launch();
        }
    }();
}


/*  =SEARCH_FILTERS
----------------------------------------------------------------------------- */
function searchFilters() {
    var elm = w.config.searchs.elm;
    var txtInit  = w.config.searchs.init;
    var txtClose = w.config.searchs.close;
    var button = w.config.searchs.button;
    
    var launch = function() {
        var elms = jQuery(elm);
        elms.append(button);
        elms.find('span').html(txtInit);
        
        var setToggle = function() {
            jQuery(elms).bind('click',function(){
                var current = jQuery(this);
                var field = current.siblings('.search-filters-1');
                if (field.is(':hidden')) {
                    field.show('normal');
                    elms.find('span').html(txtClose);
                }
                else {
                    field.hide('normal');
                    elms.find('span').html(txtInit);
                }
                return false;
            });
        }();
        
        
        
    };
    
    var init = function() {
        if (jQuery(elm)[0]) {
            launch();
        }
    }();
}


/*  =LABEL_FOCUS
----------------------------------------------------------------------------- */
function labelFocus() {
    var elms = 'select, input[type=text]:not([readonly]), input[type=password], input[type=radio], input[type=checkbox], textarea';
    
    var launch = function() {
        jQuery(elms).bind('focus',function(){
            var current = jQuery(this);
            var id = current[0].id;
            if (jQuery('label[for='+id+']')[0]) {
                current.parent().addClass('active-input');
            }
        });
        jQuery(elms).bind('blur',function(){
            var current = jQuery(this);
            var parent = current.parent();
            if (parent.hasClass('active-input')) {
                parent.removeClass('active-input');
            }
        });
    }();
}


/*  =BUBBLES_TOOLTIPS
----------------------------------------------------------------------------- */
function bubblesTooltips() {
    var elm = w.config.bubbles.elm;
    var content = w.config.bubbles.content;
    
    var launch = function() {
        
        var setBubbles = function() {
            var zone = jQuery(elm);
            
            zone.each(function(){
                var oContent = jQuery(this).parent().find(content);
                
                jQuery(this).hover(function(){
                    oContent.addClass('bubble-active');
                },function(){
                    oContent.removeClass('bubble-active');
                });
            });
            
        }();
        
    };
    
    var init = function() {
        if (jQuery(elm).length == jQuery(content).length) {
            launch();
        }
    }();
}


/*  =TABS_CAROUSEL
----------------------------------------------------------------------------- */
/*function tabsCarousel() {
    var elm = w.config.tabs.tabs3.menu;
    var zones = w.config.tabs.tabs3.zones;
    var timer = w.config.tabs.tabs3.timer;
    
    var launch = function() {
        var tabs = jQuery(elm).find('a');
        var length = tabs.length;
        var i = 1;
        sInterval1 = setInterval(function(){
            // log(jQuery(zones))
            // jQuery(zones).fadeOut(function(){
            //     jQuery(tabs[i]).fadeIn('fast');
            // },'fast');
            // log(tabs[i]);

            tabs[i].focus();
            i++;
            
            if (i == length) {
                i = 0;
            }
            
        },timer);
        
    };
    
    var init = function() {
        if (jQuery(elm)[0]) {
            launch();
        }
    }();
    
}*/


/*  =VERTICAL_ALIGN
----------------------------------------------------------------------------- */
function verticalAlignIE6() {
    var elms = w.config.vAlignIE6.elms;
    
    var launch = function() {
        
        jQuery(elms).each(function(){
            this.style.display = 'inline-block';
            var parent  = jQuery(this).parent()[0];
            var pHeight = parent.offsetHeight;
            var iHeight = this.offsetHeight;
            if (iHeight !== 0) {
                var tMargin = parseInt((pHeight-iHeight)/2 ,10) + 'px';
                this.style.marginTop = tMargin;
            }
        });
        
    };
    
    var init = function() {
        if (jQuery(elms)[0]) {
            launch();
        }
    }();
}


/*  =FORM_VALIDATION
----------------------------------------------------------------------------- */
function formValidation() {
    var elms = w.config.formValidation.elms;
    var form = w.config.formValidation.form;
    var intro = jQuery(w.config.formValidation.intro);
    
    var html_error = w.config.formValidation.html.error;
    var html_valid = w.config.formValidation.html.valid;
    var txt_intro  = w.config.formValidation.messages.intro;
    
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    
    var launch = function() {
        var required = jQuery(elms);
        
        var resetMsg = function(input) {
            input.nextAll().remove();
        };

        var setError = function(input, label) {
            resetMsg(input);
            input.nextAll().remove();
            input.after(html_error);
            input.parent().find('.error span').append(w.config.formValidation.messages[label]);
        };
        
        var setValid = function(input) {
            resetMsg(input);
            input.nextAll().remove();
            input.after(html_valid);
        };        
        
        var verify = function() {
            var status = true;
            
            required.each(function(){
                var current = jQuery(this);
                var input   = current.children('input, select, textarea');
                var label   = input.attr('id').split('f-')[1].replace('-','');
                var obj = {current : current, input : input, label : label};

                if (input[0].tagName == 'INPUT' && input.attr('type') == 'text' && label == 'email') {
                    if (!(emailPattern.test(input[0].value))) {
                        setError(input, label);
                        status = false;
                    }
                    else {
                        setValid(input, label);
                    }
                }

                else if ((input[0].tagName == 'INPUT' && input.attr('type') == 'text') 
                || (input[0].tagName == 'INPUT' && input.attr('type') == 'file')
                || (input[0].tagName == 'INPUT' && input.attr('type') == 'password')
                || (input[0].tagName == 'TEXTAREA')) {
                    if (input[0].value == ' ' || input[0].value == '') {
                        setError(input, label);
                        status = false;
                    }
                    else {
                        setValid(input, label);
                    }
                }
                
                else if (input[0].tagName == 'SELECT') {
                    if (input[0].value == 0) {
                        setError(input, label);
                        status = false;
                    }
                    else {
                        setValid(input, label);
                    }
                }
                
            });
            
            return status;
        };
        
        var formSubmit = function() {
            var dForm = jQuery(form);
            dForm.bind('submit', function(event){
                event.preventDefault();
                if (verify()) {
                    this.submit();
                }
                else {
                    dForm.attr("tabindex","-1");
                    dForm.focus();
                    dForm.removeAttr("tabindex");
                    intro.find('.error-2').empty();
                    intro.find('.error-2').append(txt_intro);
                    intro.show();
                }
            });
        }();
        
    };
    
    var init = function() {
        if (jQuery(elms).length > 0) {
            launch();
        }
    }();
}


/* =FORM_REGISTER
----------------------------------------------------------------------------- */
function formRegister() {
    var button = w.config.formRegister.button;
    var form = w.config.formRegister.form;
    
    var launch = function() {
        jQuery(button).bind('click',function(){
            jQuery(form).toggle();
            return false;
        });
    };
    
    var init = function(){
        if (jQuery(button)) {
            launch();
        }
    }();
}


/* =GMAPS
----------------------------------------------------------------------------- */
function setMaps() {
    var elm = w.config.maps.elm;
    var details = w.config.maps.details;
    var cities  = w.config.maps.cities;
    var coords  = w.config.maps.coords;
    
    var mapEvents = null;
    
    var launch = function() {

        var moveDOM = {
            oDetails : jQuery(details),
            show : function() {
                this.oDetails.addClass('accessibility');
                this.oDetails.insertBefore(elm);
            },
            hide : function() {
                this.oDetails.removeClass('accessibility');
                this.oDetails.insertAfter(cities);
            }
        };
        
        var map = null;
        
        var locations = jQuery(details).children('div');

        locations.each(function(iDetails){
                        
            var coordinates = null;
        
            var getCoordinates = function() {
                coordinates = jQuery(details).find(coords)[iDetails].value;
                coordinates = coordinates.split(',');
            }();
            
            var buildMap = function(){
                if (!map) {
                    map = new GMap2(document.getElementById(elm.split('#')[1]));
                    map.setCenter(new GLatLng(coordinates[1],coordinates[0]), 11);
                    map.setUIToDefault();
                }
            }();
            
            var markerInt = {
                
                markerContent : function(marker) {
                    moveDOM.hide();
                    
                    var detailsExtract = jQuery(details).clone().children()[marker.buildIndex];
                    detailsExtract = jQuery(detailsExtract).wrap('<div class="map-details"></div>');
                    detailsExtract = jQuery(detailsExtract).parent()[0];
                    
                    marker.openInfoWindowHtml(detailsExtract,{noCloseOnClick:true});
                    
                    moveDOM.show();
                },
                
                createMarker : function() {
                    var point  = new GLatLng(coordinates[1],coordinates[0], 16);
                    var marker = new GMarker(point);
                    marker.buildIndex = iDetails;
                    
                    GEvent.addListener(marker, 'click', function() {
                        markerInt.markerContent(marker);
                    });
                    
                    if (iDetails == 0) {
                        setTimeout(function(){
                            markerInt.markerContent(marker);
                        },0);
                    }
                    
                    return marker;
                },
                
                init : function() {
                    map.addOverlay(markerInt.createMarker());
                }
                
            };
            markerInt.init();
            
            delete coordinates;
            
        }); // location.each end
        
        var setEvents = function(){
            if (mapEvents) {
                return false;
            }
            mapEvents = true;
            jQuery(cities).find('a').bind('click',function(e){
                e.preventDefault();
                var url = encodeURI(this.href);
                moveDOM.hide();
                var i = 0;
                jQuery(details).load(url+' '+details+' div',function(){
                    launch();
                });
            });
        }();
        
    };
    
    var init = function() {
        if (jQuery(elm)[0] && gMapsKey) {
            launch();
        }
    }();
}


/*  =FORM_CONTROLS
----------------------------------------------------------------------------- */
function formControls() {
    var elm         = window.config.controls.elm;
    var txtLabel    = window.config.controls.txtLabel;
    var txtLinkAll  = window.config.controls.txtLinkAll;
    var txtLinkNone = window.config.controls.txtLinkNone;

    var launch = function() {
        var buildHTML = function() {
            jQuery(elm).append('<strong>'+txtLabel+'</strong> <a href="#" class="'+txtLinkAll+'">'+txtLinkAll+'</a> | <a href="#" class="'+txtLinkNone+'">'+txtLinkNone+'</a>');
        }();
        
        var setEvents = function() {
            jQuery(elm).find('a').click(function(e){
                var checkboxes = jQuery(this).parent().parent().find('input[type=checkbox]');
                if (jQuery(this).hasClass(txtLinkAll)) {
                    checkboxes.attr('checked', true);
                }
                else if (jQuery(this).hasClass(txtLinkNone)) {
                    checkboxes.attr('checked', false);
                }
                e.preventDefault();
            });
        }();
    };

    var init = function() {
        if (jQuery(elm)[0]) {
            launch();
        }
    }();
};


/* =HOVER_PEOPLE_IE6
----------------------------------------------------------------------------- */
function hoverPeopleIE6() {
    var elm = w.config.hoverPeopleIE6.elm;
    
    var launch = function() {
        jQuery(elm).hover(function(){
            jQuery(this).addClass('hover');
        },function(){
            jQuery(this).removeClass('hover');
        });
    };
    
    var init = function() {
        if (jQuery(elm)) {
            launch();
        }
    }();
}





