/*
Funkcja używana do generwoania komunikatów przy załadowaniu mapy.

Przyjmowane argumenty:
     message - string HTML będący treścią komunikatu
     handler - funkcja wykonująca się po kliknieciu przycisku 'Kontynuuj'
     cookieNumber - numer ciastka blokującego wyświetlanie komunikatu
                    każdy komunikat musi mieć unikalną ta wartość
                    wartość zero ma szczególne znaczenie, ciastko nie jest ustawiane i może posiadać ją wiele komunikatów

Funkcja zwraca funkcję kompatybilną z Google MAPAPI (kontrolka)
albo handler jeśli komunikat ma się nie pojawić.

Przygotowane do tej pory komunikaty znajdują się w pliku WelcomeMessages.js
*/

Wiking.widgets.WelcomeMessage = function(message, handler, cookieNumber){
    if(document.cookie.indexOf("wm" + cookieNumber+ "=3B34")!=-1)
        return handler;

    function Control(){
        Wiking.getMap().addControl(this);
        Wiking.widgets.BlackScreen.draw();
    }
    Control.prototype=new GControl();
    Control.prototype.selectable = function(){return false;}
    Control.prototype.printable = function(){return true;}
    Control.prototype.initialize = function(map){
        var ie = Prototype.Browser.IE ? 10 : 0;
        var html =     '<div style="float:left;font-size:1px;width:8px;height:8px;background:url(\'wimg/clefttop.png\')"></div>'+
                       '<div style="float:left;font-size:1px;background:url(\'wimg/ctop.png\');height:8px;width:'+(311-16)+'px"></div>'+
                       '<div style="float:left;font-size:1px;width:8px;height:8px;background:url(\'wimg/crighttop.png\')"></div>'+
                     '<div style="float:left;clear:left;">'+
                       '<div style="float:left;width:8px;background:url(\'wimg/cleft.png\');height:'+(210-16+ie)+'px"></div>'+
                       '<div style="float:left;background:#fff;height:'+(210-16+ie)+'px;width:'+(311-16)+'px">'+
                        //TREŚĆ
                           '<div style="padding:10px;">'+
                                message +
                                '<div style="height:1px;border-bottom:1px solid #ccc;margin:10px 0 0 0;font-size:1px;"></div>'+
                                '<div style="text-align:center;"><button id="continueNIE" style="padding:4px 10px;margin-top:10px;cursor:pointer;">Kontynuuj</button></div>'+     
                           '</div>'+
                       '</div>'+
                       '<div style="float:left;font-size:1px;width:8px;background:url(\'wimg/cright.png\');height:'+(210-16+ie)+'px"></div>'+
                     '</div>'+ 
                     '<div style="float:left;clear:left;">'+  
                        //font size ie fix
                       '<div style="float:left;font-size:1px;width:8px;height:8px;background:url(\'wimg/cleftbottom.png\')"></div>'+
                       '<div style="float:left;font-size:1px;background:url(\'wimg/cbottom.png\');height:8px;width:'+(311-16)+'px"></div>'+
                       '<div style="float:left;font-size:1px;width:8px;height:8px;background:url(\'wimg/crightbottom.png\')"></div>'+
                     '</div>';
        var div = document.createElement('div');
        div.innerHTML=html;
        div.style.zIndex="300";
        map.getContainer().appendChild(div);
        GEvent.bindDom(document.getElementById('continueNIE'),'click',this,this.continue_);
        return div;
    }
    Control.prototype.continue_ = function(){
        if(cookieNumber!=0)
            // ustawienie ciastka potwierdzającego akceptację treści komunikatu
            document.cookie="wm" + cookieNumber + "=3B34;expires=Thu, 18 Feb 2510 10:10:45 GMT"
        this.clear_();
        handler();
    }
    Control.prototype.clear_ = function(){
        Wiking.getMap().removeControl(this);
    }
    Control.prototype.getDefaultPosition = function(){
        var size = Wiking.getMap().getSize();
        return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(size.width/2-167,size.height/2-105));
    }; 
    return Control;
};


