﻿function ExMarker() {
    this.x;
    this.y;
    this.txt_title;
    this.txt_tease;
    this.txt_id;
    this.dateArr;
    this.tagArr;
    this.txt_link;

    //methods
    this.initExMarker = initExMarker;
    this.paintMarker = paintMarker;
    this.getGPoint = getGPoint;
    this.removeMarker = removeMarker;
    this.setDateArr = setDateArr;
    this.setTagArr = setTagArr;
    this.toggleMarker = toggleMarker;

    //extended for dtrail
    this.setImage = setImage;
    this.getImage = getImage;
    this.setFullDescription = setFullDescription;
    this.getFullDescription = getFullDescription;
    this.removeClickListener = removeClickListener;

    function initExMarker(x, y, txt_title, txt_tease, txt_id, txt_link,image_link) {
        this.x = x;
        this.y = y;
        this.txt_title = txt_title;
        this.txt_tease = txt_tease;
        this.txt_id = txt_id;
        this.txt_link = txt_link;
        this.image_link = image_link;

        this.gpoint = new GPoint(this.y, this.x);
        //create the marker
        var blueIcon = new GIcon(G_DEFAULT_ICON);
        blueIcon.image = this.image_link;
        blueIcon.iconSize = new GSize(32, 32);
        markerOptions = { icon: blueIcon };

        this.marker = new GMarker(this.gpoint, markerOptions);
        var marker = this.marker;

        var notes = this.txt_tease + "<br/><div style='float:right;padding-bottom:28px;'><a href=\'"+txt_link+ "\'><img src='images/btnmore.jpg'></img></a></div>";
        //alert(notes);
        
        this.clicklistener = GEvent.bind(marker,"click",this,
        
		  function() {
		      //marker.openInfoWindowHtml(notes);
		      marker.openInfoWindowHtml("<table width='200' cellpadding='0' cellspacing='0' border='0'><tr><td>"+notes+"</td></tr></table>");
		  }
		);

    }

    function removeClickListener() {
        GEvent.removeListener(this.clicklistener);
    }

    function setImage(imagelink) {
        this.bigpix = imagelink;
    }

    function getImage() {
        return this.bigpix;
    }

    function setFullDescription(fullDesc) {
        this.fullDesc = fullDesc;
    }

    function getFullDescription() {
        return this.fullDesc;
    }

    function setDateArr(textcmt) {
        this.dateArr = new Array(35);
        var dateelem = textcmt.split(",");
        for (var i = 0; i < 35; i++) {
            if (dateelem[i] == "0") {
                this.dateArr[i] = false;
            } else {
                this.dateArr[i] = true;
            }
        }

    }

    function setTagArr(tagarr) {
        this.tagArr = tagarr;
    }

    function toggleMarker(calarr,tagarr) {
        if (typeof this.dateArr == 'undefined') {
        } else {
            var counter = 0;
            var temparr = this.dateArr;
            var thistagarr = this.tagArr;
            var marker = this.marker;
            var comparr = new Array(35);
            //flatten the matrix
            var ctc = 0;
            for (var row = 0; row < 5; row++) {
                for (var col = 0; col < 7; col++) {
                    if (calarr[row][col] == "1") {
                        comparr[ctc] = true;
                    } else {
                        comparr[ctc] = false;
                    }
                    ctc++;
                }
            }
            //alert(comparr+"\n"+temparr);
            for (var tmpctc = 0; tmpctc < comparr.length; tmpctc++) {
                if (temparr[tmpctc]&& comparr[tmpctc]) {
                    var map = thismap();
                    map.addOverlay(marker);
                    return;
                
                }
            }

            for (var x = 0; x < tagarr.length; x++) {
                if (tagarr[x] == "1" && thistagarr[x]=="Yes") {
                    var map = thismap();
                    map.addOverlay(marker);
                    return;
                }
            }           

        }
    }


    function getGPoint() {
        return this.gpoint;
    }

    function removeMarker() {
        var map = thismap();
        map.removeOverlay(this.marker);
    }

    function paintMarker() {
        var map = thismap();
        map.addOverlay(this.marker);
    }

}

