Prototype.Platform = {
    Linux: navigator.userAgent.indexOf('Linux') > -1,
    Windows: navigator.userAgent.indexOf('Windows') > -1
}

function $M(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

function insertFlashMovie(parent, params) { $(parent).update(AC_FL_RunContent(params.toArray().flatten())); }
function flash_player_trace(txt) { log("Flash_Player_trace: " + txt); }

function minSize(wantedSize, minSize) {
    return (wantedSize < minSize) ? minSize : wantedSize;
}

function setCurrentTitle(title) {
    var lines = $A(title.split(/<br\s*\/?>/i), 2).map(function(line) {
        return line.strip();
    });

 //   $M("mainnavigation").setSiteTitle(lines[0], lines[1]);
}

/**
 * TableHighlighter class
 */
var TableHighlighter = Class.create({
    initialize: function(table_id) {
        this.table = $(table_id);
        if (this.table == null) {
            return;
        }

        this.previousRow = null;
        this.table.observe("mousemove", this.onMouseMove.bind(this));
        this.table.observe("mouseout", this.onMouseOut.bind(this));

        this.previousCell = null;
    },

    onMouseOut: function(event) {
        if (this.previousRow != null) {
            this.toggleColumnClassName(this.previousRow, this.previousColumn, "highlight", false);
            this.previousRow.removeClassName("highlight");
        }

        this.previousRow = null;

        if (this.previousCell != null) {
            this.previousCell.removeClassName("current");
            this.previousCell.removeClassName("highlight");
        }
        this.previousCell = null;
    },

    onMouseMove: function(event) {
        var cell = event.element();

        if (cell.hasClassName("current")) {
            return;
        }

        if (cell.nodeName.toLowerCase() != "td") {
            this.onMouseOut(event);
            return;
        }

        if (this.previousCell != null) {
            this.previousCell.removeClassName("current");
            this.previousCell.removeClassName("highlight");
        }

        this.previousCell = cell;
        cell.addClassName("current");

        if (this.previousRow != null) {
            this.previousRow.removeClassName("highlight");
        }

        var row = cell.up();
        var column = row.childElements().indexOf(cell);

        if (this.previousColumn != null && this.previousRow != null && this.previousColumn != column) {
            this.toggleColumnClassName(this.previousRow, this.previousColumn, "highlight", false);
        }

        this.previousRow = row
        this.previousColumn = column;
        this.toggleColumnClassName(this.previousRow, this.previousColumn, "highlight", true);
        this.previousRow.addClassName("highlight");
    },

    toggleColumnClassName: function(row, index, class_name, setClassName) {
        row.previousSiblings().find(function (sibling) {
            var cell = sibling.down(index);
            if (cell != null && cell.nodeName.toLowerCase() == "td") {
                if (setClassName) {
                    cell.addClassName(class_name);
                } else {
                    cell.removeClassName(class_name);
                }
                return false;
            }

            return true;
        });

        row.nextSiblings().find(function (sibling) {
            var cell = sibling.down(index);
            if (cell != null && cell.nodeName.toLowerCase() == "td") {
                if (setClassName) {
                    cell.addClassName(class_name);
                } else {
                    cell.removeClassName(class_name);
                }
                return false;
            }

            return true;
        });
    }
}); // End of TableHighlighter class

/**
 * DaciaApplication class
 */
var DaciaApplication = Class.create({
    initialize : function() {
        this.initialized = false;
        this.flash_interface_loaded = false;
        Event.observe(window, "load", this.initApplication.bind(this));
    },

    /*fromSiteRoot : function (uri) {
        return ("/" + constants.baseUri + uri).gsub(/\/+/, "\/") + "?" + new Date().getTime();
    },*/
	
	fromSiteRoot : function (uri) {
        return ("/" + uri).gsub(/\/+/, "\/") + "?" + new Date().getTime();
    },

    fromLayoutRoot : function (uri) {
        return (constants.baseUri + "system/modules/ro.dacia.website.layout/" + uri).gsub(/\/+/, "\/") + "?" + new Date().getTime();
    },

    initApplication : function() {
      try {
        swfoHeader.write('header_container_flash'); 
        swfoLateral.write('content_left_container');  
        this.flashHeader = $("header_container_flash");
        // contents
        this.content = $("content_container");
        this.content_left = $("content_left_container");
        this.content_data = $("content_center_container");
        this.content_offers = $("content_right_container");

        this.content_extra = $("content_sub_container");

        this.current_content_target = app.content_data;

        // menu divs
        this.content_menu = this.content_left;

        // extra
        this.content_footer = $("footer_container");
        this.popup_content = $("popup_content");

        this.lateral_menu = $("meniulateral");

        this.resetFlashHeader(true);

        Event.observe(window, "resize", this.resetFlashHeader.bind(this, false));

        this.historyService = new Ajax.Service.History("historyElement");
        this.historyDocumentLoad = new DocumentLoad(this);
        this.historyModelLoad = new ModelLoad(this);

        this.historyService.addEventListener("navigateToDoc", this.historyDocumentLoad.receiveUpdateHandle);
        this.historyService.addEventListener("navigateToModel", this.historyModelLoad.receiveUpdateHandle);

        this.initialized = true;
        log("DaciaApplication initialized: " + this.flash_interface());
        if ( window.location.hash != '' ) {
            document.observe("application:initialized", function(event) {
                if ( window.location.hash.match(/modele-si-preturi/) ) {
                  this.historyService.dispatchEvent("navigateToModel", [ window.location.hash, {}]);
                } else {
                  this.historyService.dispatchEvent("navigateToDoc", [ window.location.hash, {}]);
                }
            }.bind(this));
        }

       } catch ( e ) {
        alert("ex: " + e.name + " mess: " + e.message + " obj: " + obj);
       }
    },

    flash_interface : function() {
        if ( this.flashUiObject == null ) {
            this.flashUiObject = $("mainnavigation");
        }

        return this.flashUiObject;
    },

    resetFlashHeader : function(makeVisible) {
        return; 
        log("ResetFlashHeader: " + makeVisible);

        if ( this.flashHeader == null )
            return;

        var htmlHeaderPosition = $("header_container").cumulativeOffset();

        this.flashHeader.setStyle({
            top: 0,
            left: 0 // '' + htmlHeaderPosition[0] + 'px' REMOVED: Because it's a hack and shouldn't be put like that; the issue has been fixed with CSS in `winter/template.css` and should be moved from there to the global stylesheet
        });

        if (makeVisible) {
            this.flashHeader.removeClassName("hidden");
            this.flashHeader.show();
        }
    },

    resizeFlashHeader : function(size, isModelsMenu) {
        log("Flash UI resizing(" + size + ", " + isModelsMenu + ')');

        if ( typeof isModelsMenu == "undefined" ) {
            isModelsMenu = true;
            log("Value adjusted to true ");
        }

        this.flashHeader.setStyle( { height: '' + size + 'px'} );

        if (isModelsMenu) {
            this.hideHtmlContent();
        } else {
            this.showHtmlContent();
        }

        if ( ! this.flash_interface_loaded ) {
            this.flash_interface_loaded = true;
            document.fire("application:initialized");
        }
    },

    resizeLeftMenu : function(size) {
        size = minSize(size, 300);
        if ( this.content_menu.hasClassName("hidden") )
            return;

        this.content_menu.setStyle({ height: "" + size + "px" });
    },
	
  /*==========================================================================
   HTML CONTENT
   ============================================================================
   */

    showHtmlContent : function(force) {
        log("Showing html content .. current style: " + this.content.classNames());

        // if the html content is already visible ( either the center or the bottom part of it we will ignore it ).
        if ( ! force && this.content.hasClassName("visible") && (this.content_extra.hasClassName("visible") || this.content_data.hasClassName("visible"))) {
            log("Some parts of html content is already visible!");
            return;
        }        

        this.content.removeClassName('hidden');
        this.content.addClassName('visible');
        this.content.setStyle({height: ''});

        if ( this.content_menu.hasClassName("hidden") ) {
            this.content_menu.removeClassName("hidden");
            this.content_menu.setStyle({height: '', visibility: 'visible'});
        }
        this.content_extra.setStyle({height: '0px', visibility: 'visible'});
        this.content_extra.update("&nbsp;");
        this.content_data.setStyle({height: ''});
        this.content_offers.setStyle({height: '', visibility: 'visible'});
        
        jQuery('a.lightbox').lightBox({
            imageLoading: '/system/modules/ro.dacia.website.layout/resources/images/lightbox/lightbox-ico-loading.gif',
            imageBtnClose: '/system/modules/ro.dacia.website.layout/resources/images/lightbox/lightbox-btn-close.gif',
            imageBtnPrev: '/system/modules/ro.dacia.website.layout/resources/images/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/system/modules/ro.dacia.website.layout/resources/images/lightbox/lightbox-btn-next.gif'
        }); 
    },

    showExtraHtmlContent: function() {
        this.content.removeClassName('hidden');
        this.content.addClassName('visible');
        this.content.setStyle({height: ''});

        this.content_menu.addClassName("hidden");
        this.content_menu.setStyle( { height : '0px', visibility: 'hidden' });

        this.content_data.setStyle( { height: '0px', visibility : 'hidden' });
        this.content_data.update("&nbsp;");
        this.content_offers.setStyle( { height: '0px', visibility : 'hidden' });
        this.content_offers.update("&nbsp;");

        this.content_extra.setStyle( { height: '', visibility : 'visible' });
        this.content_extra.addClassName("visible");
    },

    hideHtmlContent : function () {
        log("Hiding html content ... current style: " + this.content.classNames());

        this.content_offers.setStyle({height: '0px'});
        this.content_menu.addClassName("hidden");
        this.content_menu.setStyle({height: '0px'});
        this.content_data.setStyle({height: '0px'});
        this.content_data.update("&nbsp;");

        this.content.removeClassName('visible');
        this.content.addClassName('hidden');
        this.content.setStyle({height: '' + (this.flashHeader.getHeight() - $("header_container").getHeight() - $("header_container").cumulativeOffset()[1]) + 'px'});
        this.content_extra.setStyle( { height: '0px', visibility: 'hidden' } );
        this.content_extra.update("&nbsp;");
    },
	
	/*==========================================================================
   Date Tehnice
   ============================================================================
   */

    showTechnicalData : function(modelKey, dataId) {
        log("Loading technical data for: " + modelKey + " " + dataId) ;
        var uri = constants.baseUri + "/modele-si-preturi/" +  modelKey + "/model-technical-data.php";

        var application = this;
        new Ajax.Request(uri, {
            requestHeaders: {
                'X-Requested-With' : 'XMLHttpRequest',
                'X-Prototype-Version' : '1.6.0.2'
            },

            onSuccess: function(transport) {
                application.popup_content.update(transport.responseText);
                application.popup_content.setStyle( {
                    left : '' + ((document.viewport.getDimensions().width - application.popup_content.getWidth()) / 2) + 'px',
                visibility: 'visible'
                })
                application.popup_content.show();
                application.showTransparentLayer();
                application.trackUriRequest("/dynamicRequests/tehnicalData/" + modelKey + "/" + dataId);
            },

            onFailure: function(transport) {
                application.popup_content.update("<h1>Documentul nu a fost gasit pe server</h1>");
                application.popup_content.show();
            },

            parameters: {
                'table': dataId
            }
        });
    },

    hideTechnicalData: function(modelKey) {
        this.popup_content.hide();
        this.popup_content.update("&nbsp;");
        this.hideTransparentLayer();
    },
	
   /*==========================================================================
   Version
   ============================================================================
   */

    showVersionDetail: function(modelId, versionId) {
        var uri = this.fromLayoutRoot("renderers/versionDetail.php");

        var application = this;
        new Ajax.Request(uri, {
            requestHeaders: {
                'X-Requested-With' : 'XMLHttpRequest',
                'X-Prototype-Version' : '1.6.0.2'
            },

            onSuccess: function(transport) {
                application.popup_content.update(transport.responseText);
                application.popup_content.setStyle( {
                    left : '' + ((document.viewport.getDimensions().width - application.popup_content.getWidth()) / 2) + 'px',
                    visibility: 'visible'
                })
                application.popup_content.show();
                application.showTransparentLayer();
                application.trackUriRequest("/dynamicRequests/versionDetail/" + versionId);
            },

            onFailure: function(transport) {
                application.hideTransparentLayer();
            },

            parameters: {
                'id': versionId
            }
        });
    },
   
    showTwoVersionsDetail: function(modelId, firstVersionId, secondVersionId) {
        var uri = this.fromLayoutRoot("renderers/versionDetail.php");

        var application = this;
        new Ajax.Request(uri, {
            requestHeaders: {
                'X-Requested-With' : 'XMLHttpRequest',
                'X-Prototype-Version' : '1.6.0.2'
            },

            onSuccess: function(transport) {
                application.popup_content.update(transport.responseText);
                application.popup_content.setStyle( {
                    left : '' + ((document.viewport.getDimensions().width - application.popup_content.getWidth()) / 2) + 'px',
                    visibility: 'visible'
                })
                application.popup_content.show();
                application.showTransparentLayer();
                application.trackUriRequest("/dynamicRequests/versionDetail/" + firstVersionId);
            },

            onFailure: function(transport) {
                application.hideTransparentLayer();
            },

            parameters: {
                'id': firstVersionId,
                'compare_id': secondVersionId
            }
        });
    },

    hideVersionDetail: function() {
        this.popup_content.setStyle({visibility : 'hidden'});
        var app = this;
        setTimeout(function() { app.popup_content.update("&nbsp;"); }, 500);
        this.hideTransparentLayer();
    },
   /*==========================================================================
   Gallery
   ============================================================================
   */
    showAccessoryGallery : function(model, accessory) {
        this.showGalleryFromUri(this.fromLayoutRoot("renderers/modelAccessoriesGallery.php") + "&" + $H({model : model, accessoryId : accessory}).toQueryString());
        this.trackUriRequest("/dynamicRequests/accessoryGallery/" + model + "/" + accessory);
    },

    showPopupGallery : function(model, page) { 
        this.showGalleryFromUri( constants.baseUri + "modele-si-preturi/" + model + "/image-gallery-" + page + ".xml?" + new Date().getTime());
        this.trackUriRequest( constants.baseUri + "modele-si-preturi/" + model + "/image-gallery-" + page + ".xml");
    },

    hidePopupGallery : function() {
         $("popup_gallery_container").setStyle({ height: '0px' });
        var app = this;
        setTimeout(function() { $("popup_gallery_container").update("&nbsp;"); }, 500);
        this.hideTransparentLayer();
    },

    showGalleryFromUri: function(uri, initialImageId, fullSizeVideo) {
//        if ( navigator.userAgent.match(/MSIE 6/ ) ) {
//           $("popup_gallery_container").setStyle({ visibility: '' });
//        }
    
	
	
        uri = uri.replace(new RegExp("^https?://www\\.dacia\\.md"), ''); 
         
		// uri = uri.replace(new RegExp("^https?://localhost/"), ''); 
		
        $("popup_gallery_container").setStyle({
            top: '0px',
            left : '' + ((document.viewport.getDimensions().width - 950) / 2) + 'px',
            width: '950px',
            height: '700px',
            visibility: 'visible', 
            zIndex: 1000
        });

        window.scrollTo(0, 0); 

        var swfoGallery = new SWFObject(constants.baseUri + 'system/modules/ro.dacia.website.layout/resources/swf/photogallery/photogallery.swf', 'photogallery', '950', '100%', '8', '#ffffff'); 
        swfoGallery.addParam("wmode", "transparent"); 
        swfoGallery.addParam("salign", "tl"); 
        swfoGallery.addParam("scale", "noScale"); 
        swfoGallery.addParam("base",constants.baseUri + "system/modules/ro.dacia.website.layout/resources/swf/photogallery/"); 
        swfoGallery.addParam("allowScriptAccess", "sameDomain"); 
        if (initialImageId != undefined) swfoGallery.addVariable("initialImageId", initialImageId); 
        if (fullSizeVideo != undefined) swfoGallery.addVariable("fullSize", fullSizeVideo); 
		try {
        swfoGallery.write('popup_gallery_container'); 
		} catch (e) {
			 log("vvvex: " + e.name + " mess: " + e.message + " obj: " + obj);
		}
        log(uri);
        try {
            log("A: " + uri);
            var obj = $("photogallery");
            obj.setImagesLocation(uri);
            log("B: " + uri);
        } catch (e) {
            log("ex: " + e.name + " mess: " + e.message + " obj: " + obj);
            setTimeout(function() {
                try {
                   log("C: " + uri);
                   var obj = $("photogallery");
                   obj.setImagesLocation(uri);
                log("D: " + uri);
                } catch(e) {
                   log("ex: " + e.name + " mess: " + e.message + " obj: " + obj);
                }
            }, 1000);
        }

        this.showTransparentLayer();
    },
   /*==========================================================================
   Transparent layer
   ============================================================================
   */
    hideTransparentLayer : function() {
        $("transparent_layer").hide();
		$("top").show();

        if ( Prototype.Platform.Linux ) {
            this.flashHeader.setStyle({ visibility: 'visible'});
        }

        if ( $("meniulateral") != null ) {
            $($("meniulateral")).setStyle( { visibility: 'visible' } );
        }

        $$(".sIFR-replaced").each(function(node) {
            node.setStyle({display: ""});
        });
    },

    showTransparentLayer : function() {
        var transparent = $("transparent_layer");
		$("top").hide();

        if ( Prototype.Platform.Linux ) {
            this.flashHeader.setStyle({ visibility: 'hidden' });
        }

        transparent.absolutize();
        transparent.setStyle({ top: '0', left : '0', width: '' + document.documentElement.offsetWidth + 'px', height: '' + document.documentElement.scrollHeight + 'px', zIndex: 999 });
        transparent.show();

        if ( $("meniulateral") != null ) {
            $($("meniulateral")).setStyle( { visibility: 'visible' } );
        }

        $$(".sIFR-replaced").each(function(node) {
            node.setStyle({display: "none"});
        });
    },

   /*==========================================================================
     Preluader
   ============================================================================
   */
    showPreloader : function(node) {
        node.update("<div id=\"preloader_content\" class=\"preloader\" style=\"display: none;\">&nbsp;</div>");
        $('preloader_content').show();

    },
	
	
  /*==========================================================================
     Navigation
   ============================================================================
   */
   RrecordDescription : function(txt) {
	 log(txt);  
   },
	   
	   
   navigationEntrySelected : function(uri, params, addToHistory) {

        if ( uri && uri.match(new RegExp("^https?://"))) {
            window.open(uri, '_new');
            return;
        }
		
		if ( uri && uri.match(new RegExp("langro"))) {
            document.location="/rom/";
            return;
        }
		
		if ( uri && uri.match(new RegExp("langru"))) {
            document.location="/rus/";
            return;
        }

        if ( uri ) {

            uri = uri.replace( /\/sites\/default\/dacia.ro/g, '');
			//uri = uri.replace( /^\/(rom|rus)\//g, '');

            if ( uri.match(/avi$/) ) {
                window.open( "/export/sites/default/dacia.ro" + uri, "_new" );
                return;
            }

            this.updateSectionNavigation(uri);

            if ( uri.match( /harta-dealer/ ) ) {
               this.load_content_extra(this.fromSiteRoot(uri), params, addToHistory);
            } else {
               this.load_content(this.fromSiteRoot(uri), params, addToHistory);
            }

            this.updateMainNavigation(uri);
        }
    },
	

    modelNavigationUriSelected : function(uri) {
        this.updateMainNavigation(uri);
    },

    menuEntrySelected: function(uri) {
        this.navigationEntrySelected(uri); 
    },

    updateSectionNavigation : function(uri) {
        if ($("meniulateral").setCurrentUri == null) {
            swfoLateral.write('content_left_container'); 
        }
        (function tryLater() {
            if ($("meniulateral").setCurrentUri == null) return setTimeout(tryLater, 500); 
            $("meniulateral").setCurrentUri(uri);
        })(); 
    },
	

    updateMainNavigation: function(uri) {
        try {
            this.flash_interface().setCurrentUri(uri);
        } catch (e) {
            setTimeout(function() {
                try { 
                    this.flash_interface().setCurrentUri(uri);
                } catch (ex) {
                    log("No flash interface is visible");
                }
            }, 500);
        }
    },

    recordModelPageNavigation: function(key, page) {
        if ( typeof page == "undefined" ) {
            page = "";
        }
        if(page == 'interior' || page == 'exterior'){
		   //document.location= '/' +  "/modele-si-preturi/" + key + "/" + page;	
		  // return;
		}
		
        log("Received NAV event:" + key  + " / " + page);
        this.historyService.registerRequest("navigateToModel", ['#' + "/modele-si-preturi/" + key + "/" + page, {}]);
        this.trackUriRequest("/modele-si-preturi/" + key + "/" + page);
       // this.loadFooterData("modele-si-preturi");
    },
	
   /*==========================================================================
     Submit forms
   ============================================================================
   */
    submitForm: function(form) {
        log("form: " + form + " action: " + form.action + " form: " + form.inspect());
        log("Id:" + form.id);

        this.updateSectionNavigation(form.action);
        this.updateMainNavigation(form.action);
        this.load_content(form.action, Form.serialize(form), false);
    },

    submitSearchForm : function(query) {
        this.updateSectionNavigation("/search");
        this.updateMainNavigation("/search");
        this.load_content("/search", { query: query} );
    },
   /*==========================================================================
     trackUriRequest
   ============================================================================
   */
    trackUriRequest: function(uri) {
        uri = uri.replace(/\?[^\?]+/, '');
       // if ( pageTracker && (typeof pageTracker._trackPageview != "undefined") ) {
        //   pageTracker._trackPageview( uri );
        //} //vital
    },
   /*==========================================================================
     Ajax
   ============================================================================
   */
    loadFooterData: function(section) {
        this.load_ajax_content(constants.baseUri + section + "/footer.php", {}, false, function(transport) { this.content_footer.update(transport.responseText) }.bind(this), function(transport) {} );
    },

    load_content_extra: function(uri, parameters, updateHistory) {
        this.load_ajax_content(uri, parameters, updateHistory, function(transport) {
            this.current_content_target = this.content_extra;
            this.showExtraHtmlContent();
            this.content_extra.setStyle( { visibility : 'hidden' } );
            this.content_extra.update(transport.responseText);
        }.bind(this))
    },

    load_content: function(absoluteUri, parameters, updateHistory) {

        this.showPreloader(this.content_data);

        this.load_ajax_content(
            absoluteUri, 
            parameters, 
            updateHistory, 
            function(transport) {
                this.current_content_target = this.content_data;
                this.showHtmlContent(true);
                this.content_data.setStyle( { visibility: 'hidden' } );
                this.content_data.update(transport.responseText);
            }.bind(this),
            function(transport) {
                this.content_data.update("<h1>Documentul nu a fost gasit pe server</h1>");
                this.showHtmlContent();
            }.bind(this)
        );
    },

    load_ajax_content: function(uri, params, updateHistory, onSuccess, onFailure) {
        log("Loading content from uri: " + uri);

        if ( typeof updateHistory == "undefined") {
            updateHistory = true;
        }

         new Ajax.Request(uri, {
            requestHeaders: {
                'X-Requested-With' : 'XMLHttpRequest'
            },

            onSuccess: function(transport) {
              try {
                  if ( updateHistory ) {
                      this.historyService.registerRequest("navigateToDoc", ['#' + uri.replace(/\?.*$/, ""), params]);
                  }

                  onSuccess(transport);
                  this.resetFlashHeader(false);
                  this.trackUriRequest(uri);
              } catch (ex ) {
                  log("ex: " + ex.name + ", " + ex.message + ", ex: " + ex);
             }
            }.bind(this),

            onFailure: function(transport) { onFailure(transport); },
            asynchronous : false,
            parameters: params
        });
    }
}); // End of DaciaApplication class

var app = new DaciaApplication();

/*** Wouldn't have hurt to say in docs: "Called only from Flash." and maybe move it to another file. */
function flash_player_trace(txt) { 

log("Flash_Player_trace: " + txt); 

if(txt == "CLEANUP"){//if(txt.match(new RegExp("CLEANUP"))){
	//document.location.reload();
}

}

/*** Naming failure. */
function minSize(wantedSize, minSize) {
    return (wantedSize < minSize) ? minSize : wantedSize;
}

function setCurrentTitle(title) {
    var lines = $A(title.split(/<br\s*\/?>/i), 2).map(function(line) {
        return line.strip();
    });
    $("mainnavigation").setSiteTitle(lines[0], lines[1]);
}

function resizeFlashContainer(container, size) {
    log("Resize flash container called for: " + container + " with desired size: " + size);
    $(container).setStyle( { height: '' + size + 'px' });
    $(container).down().setStyle( { height: '' + size + 'px' });
}

function doSifrTextReplacement() {
    sIFR.replaceElement("h1", named({sFlashSrc: constants.dacia_light_swf, sSize : "30", sColor: "#666666", sHoverColor: "#003291", sWmode: "opaque"}));
    sIFR.replaceElement("div.subtitle", named({sFlashSrc: constants.dacia_regular_swf, sSize : "18", sColor: "#666666", sHoverColor: "#003291", sWmode: "opaque"}));
    if ( app.content_data != null ) {
        app.content_data.setStyle({ visibility: 'visible' });
    }
}

function doShowPriceList(model) {
     app.navigationEntrySelected( constants.baseUri + "/modele-si-preturi/lista-de-preturi.php", { model: model } );
}

function updateArticleOffers() {
    var content_holder = $("right_content_holder");
    if (content_holder != null) {
        $("content_right_container").update(content_holder.innerHTML);
        content_holder.update("&nbsp;");
    }
}

function updateSectionOffers() {
    var content_holder = $("footer_container_holder");
    if (content_holder != null) {
        $("footer_container").update(content_holder.innerHTML);
        content_holder.update("&nbsp;");
    }
}

function setPageTitle(title) {
    document.title = "Dacia.md: " + title.replace(/<[^>]*>/g, '');
}

var openHomePage = function() {
    app.trackUriRequest("/");
    app.modelNavigationUriSelected("/");
   // app.loadFooterData("modele-si-preturi");
    window.location.href = '#/'; 
    app.historyService.registerRequest("navigateToModel", ['#' + "/", {}]);
    setCurrentTitle(lang=='ro' ? "Bine aţi venit pe dacia.md" : "Добро пожаловать на dacia.md" );
}

function selectTestDrive( model_id, version_id ) {
    setTimeout(function() {
        app.hideVersionDetail();
        app.navigationEntrySelected("/reteaua-dacia/test-drive")
    }, 100);
}

function configureModelWithVersion( model_id, version_id ) {
    setTimeout(function() {
        app.hideVersionDetail();
        app.modelNavigationUriSelected("/modele-si-preturi/" + model_id + "/configurator/" + version_id);
    }, 100);
}

var doOpenExtraPage = app.navigationEntrySelected.bind(app);

var doOpenPage = function (uri) {
    if (uri.match(/^\/modele-si-preturi\//) && !uri.match(/\/modele-si-preturi\/lista-de-preturi\.php/)) {
        app.modelNavigationUriSelected(uri); 
    } else {
        app.navigationEntrySelected(uri); 
    }
};

var doSearch = app.submitSearchForm.bind(app);
var doFormSubmit = app.submitForm.bind(app);

var doShowVersionDetail = app.showVersionDetail.bind(app);
var doShowTwoVersionsDetail = app.showTwoVersionsDetail.bind(app);
var doHideVersionDetail = app.hideVersionDetail.bind(app);

var doShowTehnicalData = app.showTechnicalData.bind(app);
var doHideTehnicalData = app.hideTechnicalData.bind(app);

var doPopupGallery = app.showPopupGallery.bind(app);
var doHideGallery = app.hidePopupGallery.bind(app);
var doShowGalleryFromUri = app.showGalleryFromUri.bind(app); 

var doShowAccessory = app.showAccessoryGallery.bind(app);

var recordModelPageSelected = app.recordModelPageNavigation.bind(app);
var resizeFlashMovieContainer = app.resizeFlashHeader.bind(app);
var resizeSectionMenu = app.resizeLeftMenu.bind(app);

var navigationEntrySelected = app.navigationEntrySelected.bind(app);
var menuClicked = app.menuEntrySelected.bind(app);
var sideBarEntryClick = app.navigationEntrySelected.bind(app);

var recordDescription = app.RrecordDescription.bind(app);