
var FlashSearchEngineClientAgent = function() {
    var self = this;
    self.pluginBox = null;
    self.navigationAnchorBox = null;
    self.doIframeNavigation = false;
    self.historyFrame = null;
    self.stepInFlash = 0;
    self.baseHistoryLength;


    //-----------------------------------------

    this.ChangeHeight = function(value) {
        self.pluginBox.style.height = value + 'px';
        self.pluginBox.Plugin.style.height = self.pluginBox.style.height;
    }

    this.ChangeSearchHash = function(value) {
        var windowStep = self.getWindowSeachStep();
        if (value == 0) { var backLength = history.length - self.baseHistoryLength; history.go(-backLength); return; }
        
        
        if (value < windowStep) { history.go(-2); }
        if (windowStep == value) { return; }
        self.stepInFlash = value;
        self.setWindowSearchStep(value);
    }

    this.GetCurrentSearchStepFromFlash = function() {
        return self.pluginBox.Plugin.GetCurrentSearchStepFromFlash();
    }

    this.ChangeSearchStepInFlash = function(value) {
        self.pluginBox.Plugin.ChangeSearchStepInFlash(value);
    }

    //-----------------------------------------

    self.getWindowSeachStep = function() {
        var windowStep = document.location.hash.replace(/#step/g, '');
        if (windowStep == '') { self.setWindowSearchStep(0); return 0; }
        return parseInt(windowStep);
    }

    self.setWindowSearchStep = function(value) {
        if (!self.doIframeNavigation) { document.location.hash = "step" + value; return; }
        if (!self.pluginBox.historyFrame) { return; }
        var doc = self.pluginBox.historyFrame.contentWindow.document;
        doc.open("javascript:'<html></html>'");
        doc.write("<html><head><scri" + "pt type=\"text/javascript\">window.parent.location.hash = 'step" + value + "';</scri" + "pt></head><body></body></html>");
        doc.close();
    }

    self.transferWindowStepIntoFlash = function() {
        var windowStep = self.getWindowSeachStep()
        if (windowStep && self.getWindowSeachStep() != self.stepInFlash) {
            this.ChangeSearchStepInFlash(windowStep);
            self.stepInFlash = self.GetCurrentSearchStepFromFlash();
        }
        window.setTimeout(function() { self.transferWindowStepIntoFlash(); }, 300);
    }

    self.initialize = function() {
        self.pluginBox = document.getElementById('FlashSearchEngineBox');
        self.pluginBox.Plugin = document.getElementById('FlashSearchEnginePlugin');
        self.pluginBox.historyFrame = document.getElementById('FlashSearchEngineHistoryFrame');
        self.doIframeNavigation = (Browser.Engine.trident && parseInt(navigator.appVersion.substr(navigator.appVersion.toUpperCase().indexOf('MSIE') + 5, 1)) < 8);
        window.setTimeout(function() { self.transferWindowStepIntoFlash(); }, 300);
        self.baseHistoryLength = history.length;
    }
    self.initialize();

    return this;
};

   

    function ResizePlayerHeightFromFlash(value) { window.FlashSearchEngineClientAgent.ChangeHeight(value);}
    function ChangeSearchHashFromFlash(value) { window.FlashSearchEngineClientAgent.ChangeSearchHash(value);}
    function InitializeSearchEngineClientScriptFromFlash() { window.FlashSearchEngineClientAgent = new FlashSearchEngineClientAgent(); }





  