function Accueil() {
    this.citiesCombo = $("#ville_choix");
    this.selectgamme;

    this.loadRssItems = function LoadRssItems() {
        $.post(mazedia.url.rRequestGetRssItems,
                {
                },
                function (results) {
                    mazedia.ui.accueil.loadRssItemsCallBack(results);
                },
                "json"
        );
    };

    this.loadRssItemsCallBack = function LoadRssItemsCallBack(data) {
        if (data.State == "OK") {
            $(".articles").html("");

            var html = "";
            for (var i = 0; i < data.Items.length; i++) {
                html += "<div class='article'>";

                html += "<h3 title='" + data.Items[i].Title + "'>";
                html += data.Items[i].Title;
                html += "</h3>";
                html += "<p title='" + data.Items[i].Content + "'>";
                html += data.Items[i].SmallContent;
                html += "<a href='" + data.Items[i].Link + "' target='_blank'>[+]</a>";
                html += "</p>";

                html += "</div>";
            }
            $(".articles").html(html);

            $("#blog_loading").hide();
        } else {
            $(".articles").html("<i>Aucune news disponible ...</i>");
        }
    };

    this.applyRoundedMenu = function ApplyRoundedMenu(cssClass) {
        $(cssClass).prepend('<div class="tl"></div><div class="tr"></div>');
    };

    this.getPrix = function CalculePrixAccueil(nbJour, gamme, formule, controlIn) {
        // Formule
        var formule = $("#modes a.current").attr("rel");
        var gamme = $("#listeGamme").val();

        if (nbJour == "0") { nbJour = "1"; }
        if (nbJour == "1") { nbJour = "2"; }
        $.post(mazedia.url.rRequestCalculateur,
                                                { jour: nbJour,
                                                    formule: formule,
                                                    gamme: gamme
                                                },
                                                function(results) {
                                                    controlIn.html(results.RETOUR + " &euro;");
                                                }, "json"
              );
    };

    this.getEndDate = function GetEndDate() {
        var endDate = new Date($('#datepickLast').dpGetSelected());

        if (endDate == 'NaN')
            endDate = new Date($('#datepickLast').dpGetSelected()[0]);

        return endDate;
    };

    this.getBeginDate = function GetBeginDate() {
        var beginDate = new Date($('#datepickFirst').dpGetSelected());

        if (beginDate == 'NaN')
            beginDate = new Date($('#datepickFirst').dpGetSelected()[0]);

        return beginDate;
    };

    this.setBtReservationGoToReserverWithSelectedChoices = function GoToReserverWithSelectedChoices() {
        $("#reservation").click(function() {
            var idGamme = $("#listeGamme").val();
            var url = '/reserver?g=' + idGamme +
                               "&db=" + mazedia.ui.accueil.getBeginDate().asString() +
                               "&de=" + mazedia.ui.accueil.getEndDate().asString();
            window.location = url;
        });
    };

    this.setDefaultTypeFamille = function SetDefaultTypeFamille(selectID) {
        $("#vhl" + selectID).addClass("current");
        $(".resa_vehicule .field_line").each(function() {
            $(this).hide();
        });
        $("#vhl" + selectID).next().show();
    };

    this.setOnClickToH3CategorieVehicule = function SetOnClickToH3CategorieVehicule(specificID) {
        $(".resa_vehicule h3").click(function() {
            $(".resa_vehicule h3").each(function() {
                if(! $(this).attr("class").indexOf("current") >=0) {
                    var id = $(this).attr("id").replace("vhl", "");
                     $(this).next().find("#choixVehicule" + id).val("");  
                } 
            });
            
            $(".resa_vehicule h3").each(function() {
                $(this).removeClass("current");
            });

            $(".resa_vehicule .field_line").each(function() {
                $(this).hide();
            });

            $(this).addClass("current");
            $(this).next().show();

            if ($(this).attr("id") == "vhl" + specificID) // 00, EB, 03/06/2010, Actuellement le specific ID correspond aux motos
                $("#resaAgenceRetour").hide();
            else
                $("#resaAgenceRetour").show();
        });
    };

    this.setformatkilometrage = function Setformatkilometrage() {
        $(".resa_etape .inpt_field").change(function() {
            var km = $(this).val();
			if ($(this).val().indexOf("Km") == -1)
            	$(this).val(km + " Km");
        });
    };

    this.setOnClickEtape2AgenceRetour = function SetOnClickEtape2AgenceRetour() {
        $(".resa_nav_etapes a.more").click(function() {
            $("#agenceRetVisible").val("true");
            $("#resaLienAgenceRetour").hide();
            $("#resaModifAgenceRetour").show();
            return false;
        });
    };

    this.setPromoAccueil = function SetPromoAccueil() {
        $("div.scrollable").scrollable({
            vertical: true,
            size: 2
        });
    };

    this.masqueResaRapide = function MasqueResaRapide() {
        //00, 12/05/2010 : EB, nothing to do here
    };

    this.setImageActuAccueil = function SetImageActuAccueil() {
        $(".resa_vehicule select").change(function() {
            this.selectgamme = $(this).attr('value');

            if (this.selectgamme != "") {
                $("#une .article").hide();
                $("#une").block({ message: $('#divLoading'), 
                                  css: { width: '200px' } 
                                });

                $.post(mazedia.url.rRequestGetSelectedGamme,
                                                { gammeUrl: this.selectgamme
                                                },
                                                function(results) {
                                                    if (results.Retour == "OK") {
                                                        $("#une .gamme").show();
                                                        
                                                        var htmlGamme = "<h1 class='hidden'>A la Une</h1>" +
                                                                        "<h2>" + results.SelectGamme.GAM_TITRE + "</h2>" +
                                                                        "<p>" + results.SelectGamme.GAM_ACCROCHE + "</p>" +
                                                                        "<p>" + (results.SelectGamme.GAM_EXEMPLE != null ? results.SelectGamme.GAM_EXEMPLE : "")  + "</p>" +
                                                                                results.SelectGamme.GAM_VISUEL;
                                                        
                                                        $("#une .gamme").html(htmlGamme);
                                                    }
                                                    else {
                                                        $("#une .article").show();
                                                        $("#une .gamme").hide();
                                                    }
                                                    $("#une").unblock();
                                                }, "json"
              );
            } else {
                $("#une .article").show();
                $("#une .gamme").hide();
            }
        });

    };
    
    this.setSelecteurMenu = function setSelecteurMenu() {
        $("#menu .roundedTop").click(function() {
            $("#menu .roundedTop").each(function() {
                $(this).removeClass("current");
            });

            $(this).addClass("current");
        });
    };
    
    this.getOptionWithSelectedValue = function GetOptionWithSelectedValue(isSelected) {
        var optionHtml = '<option ';
        
        if(isSelected)
            optionHtml += 'selected="selected"';
        optionHtml += '></option>';
        
        return optionHtml;
    };

    this.addDefaultTextToSelectVehicules = function addDefaultTextToSelectVehicules(id, text, defaultIsSelected) {
        var option = $(this.getOptionWithSelectedValue(defaultIsSelected)).val("").html(text);
        option.insertBefore($("#choixVehicule" + id + " option:first"));
        if(defaultIsSelected)
            $("#choixVehicule" + id).val("");
    };

    this.addDefaultTextToSelectAgencies = function addDefaultTextToSelectAgencies(text, defaultIsSelected, selectItem, selectedItemRetour) {
        var option = $(this.getOptionWithSelectedValue(defaultIsSelected)).val("").html(text);
        var optionBis = $(this.getOptionWithSelectedValue(defaultIsSelected)).val("").html(text);

        $("#choixVilles_Departure").prepend(option);
        if (defaultIsSelected)
            $("#choixVilles_Departure").val("");
        else
            $("#choixVilles_Departure").val(selectItem);
        if (selectedItemRetour == "") {
            $("#choixVilles_Arrival").prepend(optionBis);
            if (defaultIsSelected)
                $("#choixVilles_Arrival").val("");
            else
                $("#choixVilles_Arrival").val(selectItem);
        } else {
            $("#choixVilles_Arrival").prepend(optionBis);
            if (defaultIsSelected)
                $("#choixVilles_Arrival").val("");
            else
                $("#choixVilles_Arrival").val(selectedItemRetour);
        }
    };

    this.addOnClickGoToSeeGammes = function AddOnClickGoToSeeGammes(parentCss) {
        $(parentCss + "a.info").click(function() {
            var url = $(this).prev().val();
            
            url = $(this).attr('href') + "/" + url;
            window.open(url, '_blank');

            return false;
        });
    };

    this.addOnClickPictureAgency = function AddOnClickPictureAgency() {
        $("#lnkGoToAgency").click(function() {
            var url = $("#choixVilles_Departure").val();

            url = $(this).attr('href') + "/" + url;
            window.open(url, '_blank');

            return false;
        });
    };

    this.setDatePicker = function SetDatePicker() {
        $('#dateResaDebut').change(function() {
            $('#dateResaRetour').val((Date.fromString($(this).val(), $('input[name=date_format]').val())).addDays(1).asString($('input[name=date_format]').val()));
        });
    };

    this.setOnClickComputePrice = function setOnClickComputePrice(alertVehicule,
                                                                  alertAgenceAller,
                                                                  alertAgenceRetour,
                                                                  alertKms,
																  alert_GammeInvalid,
																  alert_DateDepartInvalid,
																  alert_DateRetourInvalid,
                                                                  validKmsSettings) {

        $(".resa_calcul").click(function() {
            $(this).css("background", "url(/Content/medias/europcar-ajax-loader.gif) no-repeat scroll center center transparent");
            $("#textResaWait").show();
            mazedia.calculateur.alert_Vehicule = alertVehicule;
            mazedia.calculateur.alert_agenceAller = alertAgenceAller;
            mazedia.calculateur.alert_agenceRetour = alertAgenceRetour;
            mazedia.calculateur.alert_KmEnvisages = alertKms;
            mazedia.calculateur.alert_GammeInvalid = alert_GammeInvalid;
            mazedia.calculateur.alert_DateDepartInvalid = alert_DateDepartInvalid;
            mazedia.calculateur.alert_DateRetourInvalid = alert_DateRetourInvalid;

            var idVehicule = $(".resa_vehicule h3.current").next().find("select").val();
            var idAgenceDepart = $("#choixVilles_Departure").val();
            var idAgenceArrivee = $("#choixVilles_Arrival").val();
            var nbKms = $("#km_envisage").val();
            var dateDepart = $('#dateResaDebut').val();
            var dateArrivee = $('#dateResaRetour').val();
            var formResa = $("#etapes_reservation");

            mazedia.calculateur.isValidKmsSettings = (validKmsSettings == "True");
            return mazedia.calculateur.checkParamsBeforeGoToDevisPage(idVehicule, idAgenceDepart,
                                                                      idAgenceArrivee, nbKms,
																	  dateDepart, dateArrivee, formResa);
        });
    };

    this.initSelectBoxAgences = function initSelectBoxAgences(txtHoraires, txtAcces) {

        $("#choixVilles_Departure").selectbox(
            {
                onChangeCallback: mazedia.ui.accueil.changeSelectedFirstAgency
            }
        );

        $("#choixVilles_Arrival").selectbox(
            {
            }
        );
        
        $("#choixVilles_Departure_container li").mouseover(function() {
            if ($(this).attr('rel') != '') {
                mazedia.ui.accueil.showAgencyDetail(agences[$(this).attr('rel')], "resaAgenceDetailDeparture", txtHoraires, txtAcces);
            }
            else {
                $("#resaAgenceDetailDeparture").hide();
            }
        }).mouseout(function() {
            $("#resaAgenceDetailDeparture").hide();
        });

        $("#choixVilles_Arrival_container li").mouseover(function() {
            if ($(this).attr('rel') != '') {
                mazedia.ui.accueil.showAgencyDetail(agences[$(this).attr('rel')], "resaAgenceDetailArrival", txtHoraires, txtAcces);
            }
            else {
                $("#resaAgenceDetailArrival").hide();
            }
        }).mouseout(function() {
            $("#resaAgenceDetailArrival").hide();
        });

    };

    this.changeSelectedFirstAgency = function changeSelectedFirstAgency(args) {
        $("#choixVilles_Arrival").selectbox.setSelected(args.selectedVal);
    };
    
    this.showAgencyDetail = function showAgencyDetail(agence, container, txtHoraires, txtAcces) {
         
         var horaires = '';
         if (agence.horaires != '') {
            horaires = "<h3>" + txtHoraires + "</h3>" +
                        "<p><span>" + agence.horaires + "</span></p>";
         }
         
         var acces = '';
         if (agence.acces != '') {
            acces = "<h3>" + txtAcces + "</h3>" +
                    "<p><span>" + agence.acces + "</span></p>";
         }
         
         $("#" + container).html(
            "<h2>" + agence.nom + "</h2>" +
            "<p>" +
                "<span>" + agence.adresse1 + "</span>" + 
                "<span>" + agence.adresse2 + "</span>" +
                "<span>" + agence.cp + "&nbsp;" + agence.ville + "</span>" +   
                "<span>Tél. : " + agence.telephone + "</span>" + 
                "<span>Fax : " + agence.fax + "</span>" +
            "</p>" +
            horaires +
            acces
        ).show();
    };

    this.setDatesAndHoursToDatePickerAndSliders = function SetDatesAndHoursToDatePickerAndSliders(patternDate, defaultDateBegin, defaultDateEnd) {
    $('#dateResaDebut').datepicker({ dateFormat: patternDate, defaultDate: +1, numberOfMonths: 2 });
    $('#dateResaRetour').datepicker({ dateFormat: patternDate, defaultDate: +2, numberOfMonths: 2 });
    };
}

