window.onresize = function() { onResizeHelper(); }
var mapPositioned;
var canOpen = 'yes';
function onResizeHelper()
{
    if ( $('mapZoomedDiv') )
    {
        if (navigator.appVersion.indexOf("MSIE")!=-1)
        {
            temp = navigator.appVersion.split("MSIE");
            version = parseFloat(temp[1]);
            
            if (version>=7)
            {
                var pos = findPosition(233, 20, $('body')); 
                $('mapZoomedDiv').style.position = 'absolute';
                $('mapZoomedDiv').style.left = pos[0] + 'px';
                $('mapZoomedDiv').style.top = pos[1] + 'px';
                mapPositioned = true;
            }
            else
            {
                var pos = findPosition(233, 20, $('body')); 
                $('mapZoomedDiv').style.position = 'absolute';
                $('mapZoomedDiv').style.left = pos[0] + 'px';
                $('mapZoomedDiv').style.top = pos[1] + 'px';
                mapPositioned = true;
            }
        }
        else
        {
            var pos = findPosition(234, 21, $('body')); 
            $('mapZoomedDiv').style.position = 'absolute';
            $('mapZoomedDiv').style.left = pos[0] + 'px';
            $('mapZoomedDiv').style.top = pos[1] + 'px';
            mapPositioned = true;
        }
    }
    
    /*var pos = findPosition(765, 56, $('ctl00_ContentPlaceHolder1_imgMap'));
    $('ctl00_ContentPlaceHolder1_TextBox1').style.position = 'absolute';
    $('ctl00_ContentPlaceHolder1_TextBox1').style.left = pos[0] + 'px';
    $('ctl00_ContentPlaceHolder1_TextBox1').style.top = pos[1] + 'px';
    
    var pos = findPosition(795, 80, $('ctl00_ContentPlaceHolder1_imgMap'));
    $('ctl00_ContentPlaceHolder1_TextBox2').style.position = 'absolute';
    $('ctl00_ContentPlaceHolder1_TextBox2').style.left = pos[0] + 'px';
    $('ctl00_ContentPlaceHolder1_TextBox2').style.top = pos[1] + 'px';  
    
    var pos = findPosition(789, 176, $('ctl00_ContentPlaceHolder1_imgMap'));
    $('ctl00_ContentPlaceHolder1_TextBox3').style.position = 'absolute';
    $('ctl00_ContentPlaceHolder1_TextBox3').style.left = pos[0] + 'px';
    $('ctl00_ContentPlaceHolder1_TextBox3').style.top = pos[1] + 'px';
    
    var pos = findPosition(765, 105, $('ctl00_ContentPlaceHolder1_imgMap'));
    $('ctl00_ContentPlaceHolder1_Button1').style.position = 'absolute';
    $('ctl00_ContentPlaceHolder1_Button1').style.left = pos[0] + 'px';
    $('ctl00_ContentPlaceHolder1_Button1').style.top = pos[1] + 'px';

    var pos = findPosition(765, 202, $('ctl00_ContentPlaceHolder1_imgMap'));
    $('ctl00_ContentPlaceHolder1_Button2').style.position = 'absolute';
    $('ctl00_ContentPlaceHolder1_Button2').style.left = pos[0] + 'px';
    $('ctl00_ContentPlaceHolder1_Button2').style.top = pos[1] + 'px';*/

    $("contentWrapper").style.minHeight = $("leftDivI").offsetHeight + $("mainFormI").offsetHeight + "px";
    var parsedCW = parseInt($("contentWrapper").style.minHeight);
    var dummyOT = $("dummy").offsetTop;
    var heightCW;
    if ( navigator.appVersion.indexOf("MSIE") != -1 )
    {
            if (dummyOT - 87 > parsedCW)
                heightCW = dummyOT - 87 + "px";
            else
                heightCW = parsedCW  + "px";
    }
    else
    {
            if (dummyOT - 110 > parsedCW)
                heightCW = dummyOT - 94 + "px";
            else
                heightCW = parsedCW + 25 + "px";
    }
    $("contentWrapper").style.height = heightCW;
}

function onResizeHelperCIS()
{
    window.onresize = function() { onResizeHelperCIS(); }
    
    $("contentWrapper").style.minHeight = $("leftDivI").offsetHeight + $("mainFormI").offsetHeight + "px";
    var parsedCW = parseInt($("contentWrapper").style.minHeight);
    var dummyOT = $("dummy").offsetTop;
    var heightCW;
    if ( navigator.appVersion.indexOf("MSIE") != -1 )
    {
        if (dummyOT - 87 > parsedCW)
            heightCW = dummyOT - 70 + "px";
        else
            heightCW = parsedCW  + "px";
    }
    else
    {
        if (dummyOT - 110 > parsedCW)
            heightCW = dummyOT - 94 + "px";
        else
            heightCW = parsedCW + 25 + "px";
    }
    $("contentWrapper").style.height = heightCW;
}

function onLoadHelper()
{
    onResizeHelper();
    
    if ( $('mapZoomedDiv') ) 
    { 
        // Preload zoom hover image for close button
        var hoverImg = new Image(); 
        hoverImg.src = '/App_Themes/Default/Images/sw-map-zoom-hover.png'; 
        
        // Fix IE dumb PNG issues
        /*if ( navigator.appVersion.indexOf('MSIE') != -1 )
        {           
            
            //$('ctl00_ContentPlaceHolder1_imgMapZoomed').src = '/App_Themes/Default/Images/sw-map-hover-ie.gif';
            //$('ctl00_ContentPlaceHolder1_imgMapZoomedClose').src = '/App_Themes/Default/Images/sw-map-hover-ie-hover.gif';
            $('ctl00_ContentPlaceHolder1_imgMapZoomed').style.position = 'relative';
            $('ctl00_ContentPlaceHolder1_imgMapZoomedClose').style.position = 'relative';
            $('ctl00_ContentPlaceHolder1_imgMapZoomed').style.left = '0px';
            $('ctl00_ContentPlaceHolder1_imgMapZoomedClose').style.left = '-5px';
            $('ctl00_ContentPlaceHolder1_imgMapZoomed').style.top = '0px';
            $('ctl00_ContentPlaceHolder1_imgMapZoomedClose').style.top = '-2px';
        }*/
    }
}

function findPosition(x, y, imgMap )
{
    if (imgMap == null)
        return [x,y];
    var curleft = curtop = 0;
    if (imgMap.offsetParent)
    {
        curleft = imgMap.offsetLeft;
        curtop = imgMap.offsetTop;
        while (imgMap = imgMap.offsetParent)
        {
            curleft += imgMap.offsetLeft;
            curtop += imgMap.offsetTop;
        }
    }
    return [curleft + x,curtop + y];
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(var i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(var i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

function hideAfterFade(id, opacStart, opacEnd, millisec)
{
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd)
    { 
        for(var i = opacStart; i >= opacEnd; i--)
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 
        setTimeout( "$('mapZoomedDiv').style.visibility = 'hidden'; canOpen = 'yes';", (timer * speed) );
    }
    else if(opacStart < opacEnd)
    { 
        for(var i = opacStart; i <= opacEnd; i++) 
        { 
            if( i == 0)
            {
                $('mapZoomedDiv').style.visibility = 'hidden';
            }
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++;
        } 
    } 
}

function $(ctrl)
{
    if ( typeof ctrl == 'string' )
        return document.getElementById( ctrl );
    else if ( typeof ctrl=== 'object' )
        return ctrl;
    
    return null;
}
