//$Id: common-large.js 1343 2008-05-21 12:34:44Z ingvig $
//(c) Siminn.dk

function generateFlash (category, number) {
  var prt = location.protocol.indexOf('https')>-1?'https://':'http://';
  var flashFile = prt+'static.siminn.is/siminn-dk/f/'+category+'/';
  if(number >= 0)
    flashFile += number+'.swf';
  else {
    //Fetch file count for the selected category
    switch (category)
    {
    case 'c1': //Forside
      fileCount = 1;
      break
    case 'c2': //Telefoni
      fileCount = 1;
      break
    case 'c3': //Omstillingsanlæg
      fileCount = 1;
      break
    case 'c4': //Internet
      fileCount = 1;
      break
    case 'c5': //Hosting services
      fileCount = 1;
      break
    case 'c6': //Kundeservice
      fileCount = 1;
      break
    case 'c7': //Om os
      fileCount = 1;
      break
    case 'c8': //CDrator
      fileCount = 1;
      break
    }
    flashFile += Math.floor(Math.random()*fileCount)+'.swf';
  }
  //var fo = new FlashObject(flashFile, "walker", "940", "320", 6, "#ffffff");
var fo;
if (category == 'c1' || category == 'c9' ) {
  fo = new FlashObject(flashFile, "walker", "940", "280", 6, "#ffffff");
} else {
  fo = new FlashObject(flashFile, "walker", "940", "120", 6, "#ffffff");
}
  fo.write("branding");
}

var FlashObject = function(swf, id, w, h, ver, c) {
            this.swf = swf;
            this.id = id;
            this.width = w;
            this.height = h;
            this.version = ver;
            this.align = "middle";

            this.params = new Object();
            this.variables = new Object();
            this.redirect = "";
            this.sq = document.location.search.split("?")[1] || "";
            this.bypassTxt = "<p>Ert Ë›Ë™ meï£¿ Macromedia Flash viï£¿bÃ›tina uppsetta fyrir vafrann Ë›inn? <a href='?detectflash=false&"+ this.sq +"'>Smelltu hÃˆr ef Ë›Ë™ er meï£¿ Flash viï£¿bÃ›t nË™mer "+ this.version +" uppsetta</a>.</p>";

            if (c) this.color = this.addParam('bgcolor', c);
            this.addParam('quality', 'high'); // default to high
            this.doDetect = getQueryParamValue('detectflash');
}
var FOP = FlashObject.prototype;

FOP.addParam = function(name, value) { this.params[name] = value; }
FOP.getParams = function() { return this.params; }
FOP.getParam = function(name) { return this.params[name]; }
FOP.addVariable = function(name, value) { this.variables[name] = value; }
FOP.getVariable = function(name) { return this.variables[name]; }
FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" allowScriptAccess="always" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" /><param name="allowScriptAccess" value="always" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }

        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;       
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
            variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId) {
            if(detectFlash(this.version) || this.doDetect=='false') {
                        if (elementId) {
                                    document.getElementById(elementId).innerHTML = this.getHTML();
                        } else {
                                    document.write(this.getHTML());
                        }
            } else {
                        if (this.redirect != "") {
                                    document.location.replace(this.redirect);
                        } else if (this.altTxt) {
                                    if (elementId) {
                                                document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
                                    } else {
                                                document.write(this.altTxt +""+ this.bypassTxt);
                                    }
                        }
            }                       
}

 
/* ---- detection functions ---- */
function getFlashVersion() {
            var flashversion = 0;
            if (navigator.plugins && navigator.mimeTypes.length) {
                        var x = navigator.plugins["Shockwave Flash"];
                        if(x && x.description) {
                                    var y = x.description;
                                    flashversion = y.substring(y.indexOf('.')-2, y.indexOf('.')).trim();
                        }
            } else {
                        result = false;
                for(var i = 15; i >= 3 && result != true; i--){
                                    execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
                                    flashversion = i;
                        }
            }
            return flashversion;
}

function detectFlash(ver) {           return (getFlashVersion() >= ver) ? true:false; }


// get value of query string param

function getQueryParamValue(param) {

            var q = document.location.search || document.location.href.split("#")[1];
            if (q) {
                        var detectIndex = q.indexOf(param +"=");
                        var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
                        if (q.length > 1 && detectIndex > -1) {
                                    return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
                        } else {
                                    return "";
                        }
            }
}

 
/* add Array.push if needed */
if(Array.prototype.push == null){
            Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}