function Property(name, address, latlng, country, sector) {
    this.name = name;
    this.address = address;
    this.latlng = latlng;
    this.country = country;
    this.sector = sector || noSector;
}

Property.prototype.getMarker = function(map) {
    var marker = new google.maps.Marker({
        position: this.latlng,
        map: map,
        title: this.name
    });
    if(this.sector.hasImage()) {
        marker.setIcon(this.sector.getImage());
    }
    return marker;
};

Property.prototype.getInformation = function() {
    var result = "<div class='property-information'>";
    if(this.name != null) {
        result += "<h4>";
        if(this.sector.hasImage()) {
            result += "<img src='" + this.sector.getImage() + "'> ";
        }
        result += this.name + "</h4>";
    }
    result += "<div" +  (this.sector.hasImage() ? " class='with-sector'>" : ">")+ this.address + "</div>";
    result += "</div>";
    return result;
};

function Sector(name, image) {
    this.name = name;
    this.image = image || null;
}

Sector.prototype.hasImage = function() {
    return this.image != null;
};

Sector.prototype.getImage = function() {
    return this.image
};

var retail = new Sector("Retail", "img/markers/retail.png");
var offices = new Sector("Offices", "img/markers/offices.png");
var logistics = new Sector("Logistics", "img/markers/logistics.png");
var noSector = new Sector("");

var properties = [
    new Property("Le Forum, Montreux",
            "Shopping Center Le Forum<br/>Place du March&#233; 6B<br/>1820 Montreux<br/><a class='info' href='properties/switzerland/LeForum.html'>Read more...</a>", new google.maps.LatLng(46.432075, 6.909971), "Switzerland", retail),
    new Property("Uster", "Winterthurerstr. 18,<br/>8610 Uster", new google.maps.LatLng(47.354597, 8.713703), "Switzerland", retail),
    new Property("Wiggis Park", "Wiggis-Park<br/>Molliserstrasse 41<br/>8754 Netstal<br/><a class='info' href='properties/switzerland/Wiggis-Park.html'>Read more...</a>", new google.maps.LatLng(47.067681, 9.058592), "Switzerland", retail),
    new Property("EKZ Volkestwil", "Im Zentrum 18<br/>8604 Volketswil<br/><a class='info' href='properties/switzerland/Zanti.html'>Read more...</a>", new google.maps.LatLng(47.388660, 8.680615), "Switzerland", retail),
    new Property("T&#228;gipark", "T&#228;gipark<br/>Jurastrasse 42<br/>5430 Wettingen", new google.maps.LatLng(47.458563, 8.328989), "Switzerland", retail),
    new Property("Thalwil", "Florastrasse 1<br/>8800 Thalwil", new google.maps.LatLng(47.296957, 8.562169), "Switzerland", retail),
    new Property("LGC A", "Rte de la Longeraie 9<br/>1110 Morges, VD<br/><a class='info' href='properties/switzerland/LakeGeneva.html'>Read more...</a>", new google.maps.LatLng(46.506220, 6.482127), "Switzerland", offices),
    new Property("LGC B", "Rte de la Longeraie 7<br/>1110 Morges, VD<br/><a class='info' href='properties/switzerland/LakeGeneva.html'>Read more...</a>", new google.maps.LatLng(46.506338, 6.482234), "Switzerland", offices),
    new Property("Tolochenaz", "Rte du Molliau 30<br/>1131 Tolochenaz, VD", new google.maps.LatLng(46.501317, 6.480711), "Switzerland", logistics),
    new Property("St. Gallen", "Bohl 9<br/>9000 St. Gallen", new google.maps.LatLng(47.426955, 9.376917), "Switzerland", retail),
    new Property("Proven Center", "Avenue de Provence 82<br/>1007 Lausanne, VD", new google.maps.LatLng(46.524678, 6.602912), "Switzerland", offices),
    new Property("N&#233;spresso, Lutry", "Rue de Remparts 2<br/>1095 Lutry", new google.maps.LatLng(46.503012, 6.683384), "Switzerland", offices),
    new Property("Spreitenbach", "Fegistrasse 9<br/>Spreitenbach", new google.maps.LatLng(47.431107, 8.365209), "Switzerland", logistics),
    new Property("Biop&#244;le", "Biop&#244;le - Rte de la Corniche 2<br/>Epalinges Case postale 7690<br/>1002 Lausanne<br/><a class='info' href='properties/switzerland/Biopole.html'>Read more...</a>",
            new google.maps.LatLng(46.584586, 6.636086), "Switzerland", offices),
    new Property("Saturn, Volketswil", "Industriestrasse 15<br/>8604 Volketswil<br/><a class='info' href='properties/switzerland/Volketswil.html'>Read more...</a>", new google.maps.LatLng(47.381701, 8.674414), "Switzerland", retail),

    new Property("", "4 Rue de Ventadour,<br/>75001 Paris<br/><a class='info' href='properties/france/Ventadour.html'>Read more...</a>", new google.maps.LatLng(48.866832, 2.334337), "France"),
    new Property("", "90 Avenue de Flandre, <br/>75019 Paris<br/><a class='info' href='properties/france/Flandre.html'>Read more...</a>", new google.maps.LatLng(48.890540, 2.376523), "France"),
    new Property("", "14 Chauss&#233;e Jules C&#233;sar,<br/>95520 Osny<br/><a class='info' href='properties/france/Osny.html'>Read more...</a>", new google.maps.LatLng(49.051314, 2.070172), "France"),
    new Property("", "74, Rue Georges Bonnac<br/>33000 Bordeaux", new google.maps.LatLng(44.840260, -0.585773), "France"),
    new Property("", "Espace Technologique, <br/>91190 Saint-Aubin", new google.maps.LatLng(48.709654, 2.153041), "France"),
    new Property("", "70 Rue Mollien, <br/>62100 Calais", new google.maps.LatLng(50.956034, 1.864135), "France"),
    new Property("", "8 Avenue Yves Brunaud,<br/>31770 Colomiers", new google.maps.LatLng(43.616038, 1.345310), "France"),
    new Property("", "1 Rue Claude Chappe, <br/>57070 Metz", new google.maps.LatLng(48.622995, 2.413280), "France"),
    new Property("", "8 Rue Maryse BastiŽ, <br/>91430 Igny", new google.maps.LatLng(48.732049, 2.234902), "France"),
    new Property("", "Rue Jean Mermoz, <br/>91080 Courcouronnes", new google.maps.LatLng(48.622995, 2.413280), "France"),
    new Property("", "Rue George Enesco, <br/>94000 Cr&#233;teil<br/><a class='info' href='properties/france/Creteil.html'>Read more...</a>", new google.maps.LatLng(48.797352, 2.447087), "France"),
    new Property("", "8 Boulevard Dubreuil, <br/>91400 Orsay", new google.maps.LatLng(48.697015, 2.180609), "France")

];

function loadPropertyMarkers(country, latlng, zoom) {
    var myOptions = {
        zoom: zoom,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"), myOptions);
    var infowindow = new google.maps.InfoWindow({content: 'hello'});
    $.each(properties, function() {
        var property = this;
        if (property.country === country) {
            var marker = property.getMarker(map);
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.setContent(property.getInformation());
                infowindow.open(map, marker);
            });
        }

    });
    $("a.info").live("click", function() {
        $(this).fancybox({
            overlayOpacity: 0.7,
            overlayColor: "#000",
            frameWidth: 820,
            frameHeight: 400,
            hideOnContentClick: false
        });
        return false;
    });
}

var caseStudies = [
    ["Le Forum, Montreux", "Switzerland", "img/properties/DSC_0787-2.jpg", "properties/switzerland/LeForum.html"],
    ["Wiggis-Park, Netstal (Glarus)", "Switzerland", "img/properties/DSC_1031_hdr.jpg", "properties/switzerland/Wiggis-Park.html"],
//    ["Shopping Center - Z&#228;nti Volketswil", "Switzerland", "img/properties/DSC_0935_hdr.jpg", "properties/switzerland/Zanti.html"],
    ["Lake Gen&#233;ve Centers A & B", "Switzerland", "img/properties/LGC-Morges-081005-15-32_hdr.jpg", "properties/switzerland/LakeGeneva.html"],
    ["Lake Gen&#233;ve Centers A & B", "Switzerland", "img/properties/LGC-Morges-081005-15-30_hdr.jpg", "properties/switzerland/LakeGeneva.html"],
    ["Lake Gen&#233;ve Centers A & B", "Switzerland", "img/properties/LGC-Morges-081005-15-67_hdr.jpg", "properties/switzerland/LakeGeneva.html"],
//    ["Tolochenaz (Vaud)", "Switzerland", "img/properties/header.jpg", "properties/switzerland/Tolochenaz.html"],
    ["Biopole", "Switzerland", "img/properties/k-cche-bio-020_bis_hdr.jpg", "properties/switzerland/Biopole.html"],
    ["Biopole", "Switzerland", "img/properties/k-cche-bio-018_bis_hdr.jpg", "properties/switzerland/Biopole.html"],

    ["Lausanne", "Switzerland", "img/properties/Lausanne_0705_1.jpg", null],

    //    ["Volketswil - Saturn Center", "Switzerland", "img/properties/header.jpg", "properties/switzerland/Volketswil.html"],

    ["Osny Le Pr&#233;sident", "France", "img/properties/osny-2-hdr.jpg", "properties/france/Osny.html"],
    ["Ventadour", "France", "img/properties/ventadour_hdr.jpg", "properties/france/Ventadour.html"],
    ["Paris Avenue de Flandre", "France", "img/properties/flandre-3-hdr.jpg", "properties/france/Flandre.html"],
    ["Orsay", "France", "img/properties/orsay_hdr.jpg", null],
    ["Metz", "France", "img/properties/Sans-titre-8_hdr.jpg", null]
];

function loadHeader() {
    var carousel = $("#carousel");

    $.each(caseStudies, function() {
//        carousel.append("<div><img src='"+this[2]+"'/><a href="+this[3]+"'><p>"+this[0]+" <span>"+this[1]+"</span></p></a></div>");
        var txt = "<div class='header-property'><img src='"+this[2]+"'/>";
        if(null != this[3]) {
            txt += "<a href='" + this[3] + "'>";
        }
        txt += "<p>"+this[0]+" <span>"+this[1]+"</span></p>";
        if(null != this[3]) {
            txt += "</a>";
        }
        txt += "</div>";
        carousel.append(txt);
    });

    $("#carousel a").fancybox({
            overlayOpacity: 0.7,
            overlayColor: "#000",
            frameWidth: 820,
            frameHeight: 400,
            hideOnContentClick: false
        });

    $("#carousel").shuffle().cycle({
        fx: 'fade'
    });

}