/*
 *  Wsnav Compass Tool
 *  Korem inc.
 */


function Compass(wsnav, lang){
    this.wsnav = wsnav;
    this.wsnav.addEventListener(this);
    this.lang = lang;
    this.posX = 0;
    this.posY = 0;
    this.compassHeight = 68;
    this.compassWidth = 68;
    this.toolSelected = "undefine";
}


Compass.prototype.panningMove=function(direction){
    if(!this.wsnav.isLoading){
        this.wsnav.loadingAction(true);
        var oldCenterX = this.wsnav.xmin+(this.wsnav.xmax - this.wsnav.xmin)/2;
        var oldCenterY = this.wsnav.ymin+(this.wsnav.ymax - this.wsnav.ymin)/2;
        var newCenterX = 0;
        var newCenterY = 0;
        if (direction ==1){//nord ouest
            newCenterX = this.wsnav.xmin;
            newCenterY = this.wsnav.ymax;
            this.wsnav.modifyImage((this.wsnav.mapWidth/2), (this.wsnav.mapHeight/2), this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==2){//nord
            newCenterX = oldCenterX;
            newCenterY = this.wsnav.ymax;
            this.wsnav.modifyImage(0, (this.wsnav.mapHeight/2), this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==3){//nord est
            newCenterX = this.wsnav.xmax;
            newCenterY = this.wsnav.ymax;
            this.wsnav.modifyImage((this.wsnav.mapWidth/2)*-1, (this.wsnav.mapHeight/2), this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==4){//ouest
            newCenterX = this.wsnav.xmin;
            newCenterY = oldCenterY;
            this.wsnav.modifyImage((this.wsnav.mapWidth/2), 0, this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==5){//est
            newCenterX = this.wsnav.xmax;
            newCenterY = oldCenterY;
            this.wsnav.modifyImage((this.wsnav.mapWidth/2)*-1, 0, this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==6){//sud ouest
            newCenterX = this.wsnav.xmin;
            newCenterY = this.wsnav.ymin;
            this.wsnav.modifyImage((this.wsnav.mapWidth/2), (this.wsnav.mapHeight/2)*-1, this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==7){//sud
            newCenterX = oldCenterX;
            newCenterY = this.wsnav.ymin;
            this.wsnav.modifyImage(0, (this.wsnav.mapHeight/2)*-1, this.wsnav.mapWidth, this.wsnav.mapHeight);
        }else if (direction ==8){//sud est
            newCenterX = this.wsnav.xmax;
            newCenterY = this.wsnav.ymin;
            this.wsnav.modifyImage((this.wsnav.mapWidth/2)*-1, (this.wsnav.mapHeight/2)*-1, this.wsnav.mapWidth, this.wsnav.mapHeight);         
        }
        this.wsnav.setCenter(newCenterX,newCenterY);
        this.wsnav.refreshMap();
    }
}

Compass.prototype.areaOnMouseOver=function(direction){
    var compass = document.getElementById('divCompass');

    if(direction == 'center'){
        compass.style.cursor='default';
        compass.className = 'divCompass_' + this.lang;
    }
    else{
        compass.style.cursor='pointer';
        compass.className = 'divCompass_' + direction + '_' + this.lang;
    }

    for(z in wsnav.tools){
        /*if(wsnav.tools[z].selected){
            this.toolSelected = wsnav.tools[z].id;
            break;
        }*/
    }
    //this.wsnav.clearselect();
}

Compass.prototype.areaOnMouseOut=function(){
    if(this.toolSelected == "undefine"){
        /*for(z in wsnav.tools){
            if(wsnav.tools[z].selected){
                this.toolSelected = wsnav.tools[z].id;
                break;
            }
        }*/
    }
    //this.wsnav.select(this.toolSelected);

    var compass = document.getElementById('divCompass');
    compass.style.cursor=document.getElementById('divMap').style.cursor;
    compass.className = 'divCompass_' + this.lang;
}


Compass.prototype.init=function(){
    var compass = document.getElementById("divCompass");
/*
    if (parseFloat(navigator.appVersion.split("MSIE")[1]) >= 5.5 && parseFloat(navigator.appVersion.split("MSIE")[1]) < 7) {
        compass.className="divCompass_"+this.lang+ "_IE";
    } else {
        compass.className="divCompass_"+this.lang;
        var imgCompass = document.getElementById("imgCompass");
        imgCompass.style.height = this.compassHeight + "px";
        imgCompass.style.width = this.compassWidth + "px";
    }
*/    
    compass.className="divCompass_"+this.lang;
    var imgCompass = document.getElementById("imgCompass");
    imgCompass.style.height = this.compassHeight + "px";
    imgCompass.style.width = this.compassWidth + "px";

    /*compass.style.height = this.compassHeight + "px";
    compass.style.width = this.compassWidth + "px";
    compass.style.top = this.posY + "px";
    compass.style.left = this.posX + "px";*/


}


Compass.prototype.mapevent=function(name){
    if(name=="map_init_end"){
        this.init();
    }
}
