﻿var jsReady = false;
var playerVersion;
function isReady() {
    return jsReady;
}
//
function getFlashMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    var isOpera = navigator.userAgent.indexOf("Opera") != -1;
//il. this will cause the page to reload - not required for this operation
//    if (isOpera) {
//        window.location.reload();
//    }
    //    return (isIE || isOpera) ? document.getElementById(movieName) : document[movieName];
//Note: document in Opera = IE
    return (isIE) ? document.getElementById(movieName) : document[movieName];
}

//
function processFlashRequest(flash, str) {
    getFlashMovie(flash).myFunction(str);
}
//
//
function sendRequestToFlash(flash, strRequest, strJsonValue) {
    var s = hfFlashVars.Get("jResult");
    var myJSONObject = eval("(" + s + ')');
    //alert(myJSONObject);
    getFlashMovie(flash).ProcessRequest(strRequest, strJsonValue, myJSONObject);
}
//
function processRequest(strRequest, strRequestType, extObject) {

//    alert(extObject["ReqType"]);
//    alert(extObject["ReqObject"]["FTitle"]);
    var reqObject = null;
    if (extObject!= null) {
//        alert(extObject["ReqType"]);
//        alert(extObject["ReqObject"]["FTitle"]);
        extObject["ReqObject"]["FTitle"] = "title has changes";
        reqObject = extObject;
//        try {
//            reqObject = eval("(" + extObject["ReqObject"] + ')');
//        }
//        catch (e) {
//            alert('An error has occurred: ' + e.message)
//        }
//        finally {
//            if (reqObject != null) {
//                alert(reqObject["FTitle"]);
//            }
//        }
//    
    }

    
    
    switch (strRequest) {
        case "show.map":
            puMap();
            cbp.PerformCallback();

            //hfFlashVars.PerformCallback();
//            var s = hfFlashVars.Get("jResult");
//            var myJSONObject = eval("(" + s + ')');
//            alert(myJSONObject);
//            //            return myJSONObject;
            //            return reqObject;
            break;
        case "show.custom.display":
            var s = hfFlashVars.Get("jVar");
            var myJSONObject = eval("(" + s + ')');
            return myJSONObject;
            break;
        default:
    
    }
}
//
function popup(w, h, p) {
    var left = (screen.availWidth / 2) - (w / 2);
    var top = (screen.availHeight / 2) - (h / 2);
    window.open(p, 'Insert', 'width=' + w + ',height=' + h + ',scrollbars=1,status=0,left=' + left + ', top=' + top)
}
function puMap() {
    //popup(380, 340, 'MapIt.aspx');
    var popupWidth, popupHeight;
    pu.SetContentUrl('http://maps.google.com/maps?f=q&q=33.808125,-117.919104');
    popupWidth = 500; //pu.document.body.offsetWidth - ieWidthPad
    popupHeight = 500; //pu.document.documentElement.clientHeight -ieHeightPad
    //pu.SetSize(parent.screen.width * (parent.screen.width/80), parent.screen.height*(parent.screen.height/80));
    pu.SetSize(popupWidth, popupHeight);
    parent.pu.Show();
    //parent.pu.focus();
}


function puWindow(e,s) {
    parent.pu.Show();
}
function getDefaultFlashVars() {
    var myJSONObjectTest = {
        "tnWidth": "100",
        "tnHeight": "100",
        "mcThumbsWidth": "300",
        "mcThumbsHeight": "300"
    };
    return myJSONObjectTest;
}

function getUserFlashVars() {
        //check if hfFlashVars exists
    var s = hfFlashVars.Get("UserFlashVars");
    var myJSONObject = eval("(" + s + ')');
        return myJSONObject;


}
    function setFlashVersion() {
        playerVersion = swfobject.getFlashPlayerVersion();
        alert("You have Flash player " + playerVersion.major + "." + playerVersion.minor + "." + playerVersion.release
        + "." + playerVersion.built + " installed"); 
    }
function LoadGallery(e, s) {
//    if (playerVersion.major >= 10) {
//        parent.pu.Show();
    //    }
//    setFlashVersion();
    var flashvars = getUserFlashVars();
    var attributes = {};
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    var isOpera = navigator.userAgent.indexOf("Opera") != -1;
        if (isIE) {
            var params = {
                "wmode": "opaque",
                "menu": "false",
                "allowFullScreen": "true",
                "movie": "OtnmInfoGallery.swf",
                "name": "OtnmInfoGallery",
                "allowScriptAccess": "always"
            };
            swfobject.embedSWF("OtnmInfoGallery.swf", "OtnmInfoGallery", "100%", "100%", "9.0.0", "", flashvars, params, attributes);
        }
        else
        //{
            if (isOpera) {
                var params = {
                };
                params.wmode="window";
                params.menu= "false";
                params.allowFullScreen="true";
                params.allowScriptAccess="always";
//                params.scale="showall";
//                params.salign = "t";
                swfobject.embedSWF("OtnmInfoGallery.swf", "OtnmInfoGallery", "100%", "100%", "9.0.0", "", flashvars, params, attributes);
            }
            else 
            {
                var params = {
                    "wmode": "opaque",
                    "menu": "false",
                    "allowFullScreen": "true",
                    "movie": "OtnmInfoGallery.swf",
                    "name": "OtnmInfoGallery",
                    "allowScriptAccess": "always"
                };

                swfobject.embedSWF("OtnmInfoGallery.swf", "OtnmInfoGallery", "100%", "100%", "9.0.0", "", flashvars, params, attributes);
                //alert('is opera');
                //window.location.reload();
                

            }
        //}
            
//            AC_FL_RunContent(
//		        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
//		        'width', '100%',
//		        'height', '100%',
//		        'src', 'OtnmInfoGallery',
//		        'quality', 'high',
//		        'pluginspage', 'http://www.adobe.com/go/getflashplayer',
//		        'align', 'middle',
//		        'play', 'true',
//		        'loop', 'true',
//		        'scale', 'noscale',
//		        'wmode', 'window',
//		        'devicefont', 'false',
//		        'id', 'OtnmInfoGallery',
//		        'bgcolor', '#000000',
//		        'name', 'OtnmInfoGallery',
//		        'menu', 'false',
//		        'allowFullScreen', 'true',
//		        'allowScriptAccess', 'sameDomain',
//		        'movie', 'OtnmInfoGallery',
//		        'salign', ''
//		        ); //end AC code

        
}


//function setFlashCanPlay() {
//    var MM_contentVersion = 10;
//    var MM_FlashCanPlay = false;
//    var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
//    if (plugin) {
//        var words = navigator.plugins["Shockwave Flash"].description.split(" ");
//        for (var i = 0; i < words.length; ++i) {
//            if (isNaN(parseInt(words[i])))
//                continue;
//            var MM_PluginVersion = words[i];
//        }
//        MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
//    }
//    else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0
//   && (navigator.appVersion.indexOf("Win") != -1)) {
//        MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)));
//    }
//    if (MM_FlashCanPlay) {
//        hfFlashVars.Set("flashCanPlay", "1");
//    } else {
//    hfFlashVars.Set("flashCanPlay", "2");
//    }
//}
