
function Colorator(ccLink, mode, model, exterior, interior, wheels, top, modelyr) {
    this.coloratorModes = new EnumColoratorModes();
    fbLog('modelyr (PS5-Parameter): ' + modelyr);
    this.modelyear = (modelyr != '' ? modelyr : '2009');
    fbLog('modelyear: ' + this.modelyear);
    this.openCCFromColorator = openCCFromColorator;
    this.doColorConfigLink = doColorConfigLink;
    this.Pool = "";
    this.Language = "";
    this.m_currentLink = null;
    this.m_model = model;
    this.m_selectedExterior = exterior;
    this.m_selectedInterior = interior;
    this.m_selectedWheels = wheels;
    this.m_top = top;
    this.m_ccLink = ccLink;

    this.getFlashLanguage = function() {
        switch (this.Pool) {
            case "usa":
                return "bbk";
                break;
            case "germany":
                return "bbk";
                break;
            default:
                return "bbk";
        }
    }
    /// internal function parseMode:
    // wird benutzt um den gelieferten Mode-Textparameter 
    // in eine Enumaration zu parsen.
    this.parseMode = function(modeString) {
        switch (modeString) {
            case 'interior':
                return this.coloratorModes.Interieur;
                break;
            case 'exterior':
                return this.coloratorModes.Exterieur;
                break;
            case 'wheels':
                return this.coloratorModes.Wheels;
                break;
            default:
                fbLog('modeString: ' + modeString);
                return coloratorModes.Exterieur;
        }
    }
    fbLog('mode (parameter): ' + mode);
    this.Mode = (mode == undefined || mode == '')
                    ? ColoratorModes.Exterieur
                    : this.parseMode(mode);
    fbLog('this.Mode: ' + this.Mode);

    this.initFlash = function() {
        //initVisualizerFlash(model, this.Mode, exterior, interior, wheels);
        fbLog('model: ' + model);
        fbLog('modelyear: ' + this.modelyear);
        fbLog('language: ' + this.getFlashLanguage());
        fbLog('exterior: ' + exterior);
        fbLog('interior: ' + interior);
        fbLog('wheels: ' + wheels);
        fbLog('top: ' + top);

        doCall('text_' + this.getFlashLanguage());
        if (model != '') doCall(model + '_load');
        if (this.modelyear != '') doCall('my_' + this.modelyear);
        if (exterior != '') doCall(exterior + '_on');
        if (interior != '') doCall(interior + '_on');
        if (wheels != '') doCall(wheels + '_on');
        if (top != '') doCall(top + '_on');

        if (this.Mode != this.coloratorModes.Exterieur) {
            doCall('in_on');
        }

        doCall('background_on');
    }

    this.changeActivation = function(newElemId, oldElemId) {
        var newElem = document.getElementById('link' + newElemId);
        var oldElem = document.getElementById('link' + oldElemId);

        if (newElem != null && oldElem != null) {
            oldElem.className = "colorselect";
            newElem.className = "colorselectselected selected";
        }
    }

    this.changeImage = function(model, _mode, id) {
        doCall(id + '_on');
        var mode = this.parseMode(_mode);
        switch (mode) {
            //case "interior":   
            case this.coloratorModes.Interieur:
                this.changeActivation(id, this.m_selectedInterior);
                this.m_selectedInterior = id;
                break;

            //case "exterior":  
            case this.coloratorModes.Exterieur:
                this.changeActivation(id, this.m_selectedExterior);
                this.m_selectedExterior = id;
                break;


            //case "wheels":        
            case this.coloratorModes.Wheels:
                this.changeActivation(id, this.m_selectedWheels);
                this.m_selectedWheels = id;
                break;
        }
    }
}



function EnumColoratorModes() {
    this.Exterieur = 0;
    this.Interieur = 1;
    this.Wheels = 2;
}


function openCCFromColorator()
{
  /* Inner size is important, but gotoUrlNewWinSizeByName() calcs outer size */
  var sWidth = 980;
  var sHeight = 680;
  sWidth -= g_is_ie ? 15 : 20;
  sHeight -= 25;
  ccLink = this.m_ccLink;
  if(ccLink.indexOf('?') > -1)ccLink += "&"
  else ccLink += "?"
  
  // RT Parameter dazu gekommen.
  ccLink +=     'RT=' + new Date().getTime() + 
                '&ORDERTYPE=' + this.m_model + 
                '&option1=' + this.m_selectedInterior + 
                '&option2=' + this.m_selectedExterior + 
                '&option3=' + this.m_selectedWheels
                
  if (getScreenXYUrlParam())
    ccLink += getScreenXYUrlParam(); // default.js (BU -- 23.06.08 
  
  //alert(ccLink);
  gotoUrlNewWinSizeByName(ccLink, sWidth, sHeight, "PVA");
}

function doColorConfigLink(link)
{
  link = link + 'int=' + this.m_selectedInterior + '&ext=' + this.m_selectedExterior + '&whl=' + this.m_selectedWheels
  document.location.href = link;
}



//RTT ab hier
function RunFlashOld() {
    var prefix = "/all/visualizer-flash/";
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" WIDTH="680" HEIGHT="329" id="flash">');
    document.write('    <param NAME="base" VALUE="' + prefix + '" />');
    document.write('    <param NAME="movie" VALUE="' + prefix + 'trigger.swf" />');
    document.write('    <param NAME="quality" VALUE="high" />');
    document.write('    <param name="menu" value="false" /> ');
    document.write('    <param NAME="bgcolor" VALUE="#FFFFFF" />');
    document.write('    <embed base="' + prefix + '" src="' + prefix + 'trigger.swf" quality="high" menu="false" bgcolor="#FFFFFF"  WIDTH="680" HEIGHT="329" NAME="flash" swLiveConnect="true" TYPE="application/x-shockwave-flash" PLUGINSPAGE="//www.macromedia.com/go/getflashplayer"></embed>');
    document.write('</object>');
}

function RunFlash() {
    var prefix = "/all/visualizer-flash/";
    var params = {  base: prefix                  
                  , quality: 'high'
                  , menu: 'false'
                  , bgcolor: '#FFFFFF'
                  , wmode: 'transparent'
                  , name: 'flash'
                  , id: 'flash'
                  };
    var flashvars = {};
    var attributes = {};

    swfobject.embedSWF(prefix + 'plugin/trigger.swf', 'flash', 680, 329, "8", "", flashvars, params, attributes);

}

function RunZoomFlash() {
    var prefix = "/all/visualizer-flash/";
    var params = {  base: prefix                  
                  , quality: 'high'                  
                  , wmode: 'transparent'                  
                  };
    var flashvars = {};
    var attributes = {};
    
	swfobject.embedSWF(prefix + "plugin/zoom.swf", "zoomflashdiv", "924", "404", "8","", flashvars, params, attributes);

}


function doCall(value) {
    if (typeof (value) == 'undefined' || value == '') return;
    fbLog("doCall : " + value);
    //document.getElementById('flash').SetVariable('nobject.nvariable', value);
    //window.document.flash.SetVariable('nobject.nvariable', value);
    var obj = document.getElementById('flash');
    obj.SetVariable('nobject.nvariable', value);

}

function controller_start() {
    newWindow = window.open('/all/visualizer-flash/flash.html', 'thewin', 'height=270,width=207,toolbar=no');
    newWindow.focus();
    alert("controller_start");
}

function controller_stop() {
    newWindow.close();
}

function focusWindow() {
    if (newWindow.closed) {
        controller_start();
    } else {
        newWindow.focus();
    }
}

function sprache() {
    doCall('pfad_xml/');
    colorator.initFlash();
}

function requirements() {
}

function model() {
    fbLog('model(): Modell geladen');
}

function loaded_ex() {
    fbLog('loaded_ex(): Exterior geladen');
}

function loaded_in() {
    fbLog('loaded_in(): Interior geladen');
}
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function flash_DoFSCommand(command, args) {
    fbLog("flash_doFSCommand - args: " + args);
    //var flashObj = InternetExplorer ? flash : document.flash;
    var flashObj = document.getElementById("flash");
    if (args == "sprache") {
        sprache();
    }
    if (args == "model") {
        model();
    }
    if (args == "Loaded_Ex") {
        loaded_ex();
    }
    if (args == "Loaded_In") {
        loaded_in();
    }
}

function visualizerSetCursor(obj, selected, isMouseOver) {
    if (selected == 'selected' || obj.className == 'colorselectselected selected') return;
    if (isMouseOver) {
        obj.className = 'colorselectselected';
        obj.style.cursor = 'pointer';
    }
    else {
        obj.className = 'colorselect';
        obj.style.cursor = 'default';
    }
}


function zoom_view() {
    fbLog('zoom_view geklickt!');
	
	var footer = document.getElementById('footer');
	var parent = footer.parentNode;
	
	var middletop = document.clientHeight;
	var middleleft = document.clientWidth;
  
	var zoomdiv = document.createElement('div');
    zoomdiv.setAttribute('id', 'zoomdiv');
	//zoomdiv.setAttribute('style', 'position:absolute;border:1px solid #808080;z-index:1250;top:108px;left:70px;width:924px;height:404px;background-color:white;');	
	zoomdiv.style.cssText = "position:absolute;border:1px solid #808080;z-index:3000;top:108px;left:70px;width:924px;height:404px;background-color:white;";
	parent.appendChild(zoomdiv);
	
	var zoomflashdiv = document.createElement('div');
    zoomflashdiv.setAttribute('id', 'zoomflashdiv');
	//zoomflashdiv.setAttribute('style', 'position:relative;z-index:1260;width:924px;height:404px;');
	zoomflashdiv.style.cssText = "position:relative;z-index:1260;width:924px;height:404px;";
	zoomdiv.appendChild(zoomflashdiv);
	
	//var flashscript = document.createElement('script');
	//flashscript.setAttribute('type', 'text/javascript');	
	//zoomdiv.appendChild(flashscript);
	
	//var scripttext = document.createTextNode('var params = {base: "/all/visualizer-flash/", wmode: "transparent"}; var flashvars = {}; var attributes = {}; swfobject.embedSWF("/all/visualizer-flash/plugin/zoom.swf", "zoomflashdiv", "924", "404", "9.0.0","expressInstall.swf", flashvars, params, attributes);');
    //flashscript.appendChild(scripttext);
	
	var backdiv = document.createElement('div');
    backdiv.setAttribute('id', 'backdiv');
	//backdiv.setAttribute('style', 'position:absolute;background-color:white;z-index:1249;top:0px;left:0px;width:100%;height:100%;opacity:0.75;filter: Alpha(opacity=75, finishopacity=75, style=2);');	
	backdiv.style.cssText = "position:absolute;background-color:white;z-index:2999;top:0px;left:0px;width:1064px;height:100%;opacity:0.75;filter: Alpha(opacity=75, finishopacity=75, style=2);";
	parent.appendChild(backdiv);
	
	var close = document.createElement('div');
	close.setAttribute('id', 'close');
	//close.setAttribute('style', 'position:absolute;top:6px;left:902px;z-index:1300');
	close.style.cssText = "position:absolute;top:6px;left:902px;z-index:1300";
	zoomdiv.appendChild(close);
	
	var closebutton = document.createElement('img');
	//closebutton.setAttribute('style', 'cursor:pointer');
	closebutton.style.cssText = "cursor:pointer";
	//closebutton.setAttribute('onclick', 'javascript:closeZoomdiv();');
	closebutton.onclick = closeZoomdiv;
	closebutton.setAttribute('src', '/images/close-button.gif');
	close.appendChild(closebutton);	
	
	RunZoomFlash();
	
    //myleft = 20;
    //mytop = 20;
    //settings = "width=924,height=404,top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,dependent=no";
    //win = window.open("/all/visualizer-flash/zoom.html", "zoom", settings);
    //win.focus();    
}

function closeZoomdiv()
{
	var footer = document.getElementById('footer');
	var parent = footer.parentNode;
	var zoomdiv = document.getElementById('zoomdiv');
	var backdiv = document.getElementById('backdiv');
	
	parent.removeChild(zoomdiv);
	parent.removeChild(backdiv);	
}

function fbLog(msg) {
    try {
        console.log(msg);
    }
    catch (e) {        
    } 
}
