// by ntkr.com © 2005-2010
// please keep this header intact
//----------------------------------------------------------------------------
// global variables
var elementId = "varegruppe";
var items = new Array();
var root = new Menu(0, "root", "0", "", 0,0);
var activeMenuId = -1;
var activeParser = new Parser("0");
var butik = 0;
//----------------------------------------------------------------------------
// constructors for objects
function Parser(path){
this.path = path;
this.position = 0;
this.hasMore = hasMore;
this.next = next;
}
function Menu(id, name, path, indent, noOfElements,butik){
this.id = id;
this.name = name;
this.path = path;
this.indent = indent;
this.parser = new Parser(path);
this.subItems = new Array();
this.butik = butik;
}
//----------------------------------------------------------------------------
// functions belonging to constructors (Objects [Menu, Parser])
function hasMore(){
return this.path.length > this.position;
}
function next(){
var retVal = "";
var tmpCharacter = "";
while (this.position < this.path.length){
tmpCharacter = this.path.charAt(this.position);
if (tmpCharacter != ","){
retVal += tmpCharacter;
}
else{
break;
}
this.position++;
}
//this.position = ++this.position;
this.position++;
return retVal;
}
//----------------------------------------------------------------------------
// methods for instantiating and re-organizing the menu objects correct!
function addItem(item){
item.parser.position = 0;
if (item.parser.hasMore()){
if (item.parser.next() == "0"){
item.parser = new Parser(item.id);
root.subItems[root.subItems.length] = item;
}
else{
item.parser.position = 0;
var owner = resolveItem(root, item);
item.parser = new Parser(item.path + "," + item.id);
item.path = item.path + "," + item.id;
owner.subItems[owner.subItems.length] = item;
}
}
}
function resolveItem(item, fItem){
var id = -1;
if (fItem.parser.hasMore()){
id = fItem.parser.next();
}
if (id == -1){
item.parser.position = 0;
return item;
}
else{
var i = 0;
while (item.subItems.length > i){
tmpItem = item.subItems[i];
if (tmpItem.id == id){
break;
}
i++;
}
item.parser.position = 0;
return resolveItem(tmpItem, fItem);
}
}
function init(elementId, parsePath,butik){
this.elementId = elementId;
this.butik = butik;
if(root.subItems.length == 0){
addItem(new Menu(56, "Action", "0", "", 1314, 1));
addItem(new Menu(64, "Animation", "0", "", 636, 1));
addItem(new Menu(135, "Anime", "0", "", 29, 1));
addItem(new Menu(171, "Asiatiske", "0", "", 43, 1));
addItem(new Menu(140, "Børnefilm", "0", "", 566, 1));
addItem(new Menu(62, "Danske film", "0", "", 712, 1));
addItem(new Menu(66, "Dokumentar", "0", "", 258, 1));
addItem(new Menu(57, "Drama", "0", "", 1420, 1));
addItem(new Menu(65, "Erotik", "0", "", 14388, 1));
addItem(new Menu(146, "Eventyr", "0", "", 178, 1));
addItem(new Menu(165, "Familie", "0", "", 146, 1));
addItem(new Menu(173, "Filmbokse", "0", "", 74, 1));
addItem(new Menu(59, "Gyser", "0", "", 376, 1));
addItem(new Menu(60, "Komedie", "0", "", 1506, 1));
addItem(new Menu(147, "Krigsfilm", "0", "", 143, 1));
addItem(new Menu(195, "Krimi / Mystery", "0", "", 15, 1));
addItem(new Menu(163, "Musical", "0", "", 62, 1));
addItem(new Menu(63, "Musik", "0", "", 73, 1));
addItem(new Menu(61, "Sci-fi / Fantasy", "0", "", 254, 1));
addItem(new Menu(58, "Thriller", "0", "", 710, 1));
addItem(new Menu(141, "Tv-Serier", "0", "", 992, 1));
addItem(new Menu(194, "Undervisning", "0", "", 23, 1));
addItem(new Menu(161, "Ungdomsfilm", "0", "", 75, 1));
addItem(new Menu(177, "Usorterede titler", "0", "", 7418, 1));
addItem(new Menu(79, "Western", "0", "", 118, 1));
addItem(new Menu(67, "GameCube", "0", "", 0, 2));
addItem(new Menu(78, "Hardware / tilbehør", "67", " ", 2, 2));
addItem(new Menu(190, "Spil", "67", " ", 49, 2));
addItem(new Menu(68, "Playstation 2", "0", "", 0, 2));
addItem(new Menu(136, "Hardware / tilbehør", "68", " ", 3, 2));
addItem(new Menu(181, "Spil", "68", " ", 1145, 2));
addItem(new Menu(69, "Nintendo DS", "0", "", 0, 2));
addItem(new Menu(130, "Hardware / tilbehør", "69", " ", 1, 2));
addItem(new Menu(187, "Spil", "69", " ", 920, 2));
addItem(new Menu(71, "Gameboy Advance", "0", "", 0, 2));
addItem(new Menu(189, "Spil", "71", " ", 172, 2));
addItem(new Menu(72, "PSP", "0", "", 0, 2));
addItem(new Menu(139, "Hardware / tilbehør", "72", " ", 3, 2));
addItem(new Menu(191, "Spil", "72", " ", 428, 2));
addItem(new Menu(73, "Xbox", "0", "", 0, 2));
addItem(new Menu(192, "Spil", "73", " ", 39, 2));
addItem(new Menu(74, "Xbox 360", "0", "", 0, 2));
addItem(new Menu(138, "Hardware", "74", " ", 2, 2));
addItem(new Menu(180, "Spil", "74", " ", 863, 2));
addItem(new Menu(182, "Tilbehør", "74", " ", 0, 2));
addItem(new Menu(81, "PC", "0", "", 0, 2));
addItem(new Menu(188, "Spil", "81", " ", 1923, 2));
addItem(new Menu(166, "Filmplakater", "0", "", 48, 5));
addItem(new Menu(167, "Fotografier", "0", "", 30, 5));
addItem(new Menu(170, "Fotosæt", "0", "", 6, 5));
addItem(new Menu(168, "Merchandise", "0", "", 5, 5));
addItem(new Menu(169, "Plakater - diverse", "0", "", 24, 5));
addItem(new Menu(172, "Soundtracks", "0", "", 6, 5));
addItem(new Menu(183, "Playstation 3", "0", "", 0, 2));
addItem(new Menu(184, "Hardware", "183", " ", 1, 2));
addItem(new Menu(185, "Spil", "183", " ", 714, 2));
addItem(new Menu(186, "Tilbehør", "183", " ", 2, 2));
addItem(new Menu(174, "Wii", "0", "", 0, 2));
addItem(new Menu(178, "Hardware", "174", " ", 1, 2));
addItem(new Menu(179, "Spil", "174", " ", 837, 2));
addItem(new Menu(176, "Tilbehør", "174", " ", 4, 2));
}
showMenu(parsePath);
}
//----------------------------------------------------------------------------
// methods for showing the menu
function showMenu(parsePath){
var lastId = getLastId(parsePath);
if (activeMenuId == lastId){
parsePath = trimLastId(parsePath);
activeMenuId = -1;
}
else{
activeMenuId = lastId;
}
this.activeParser = new Parser(parsePath);
document.getElementById(elementId).innerHTML = "";
writeMenu(root);
}
function writeMenu(menuItem){
var tmpItem = null;
var nextId = -1;
if (activeParser.hasMore()){
nextId = activeParser.next();
}
var i = 0;
while (menuItem.subItems.length > i){
tmpItem = menuItem.subItems[i];
if (tmpItem.butik == butik){
if (tmpItem.subItems.length > 0){
document.getElementById(elementId).innerHTML += "" + tmpItem.indent + "" + tmpItem.name + "
";
}
else{
document.getElementById(elementId).innerHTML += "" + tmpItem.indent + "" + tmpItem.name + "
";
}
if (tmpItem.id == nextId){
writeMenu(tmpItem);
}
}
i++;
}
}
//----------------------------------------------------------------------------
// additional methods used when showing the menu!
function getLastId(parsePath){
var retVal = "";
var i = parsePath.length;
while (i > -1){
if (parsePath.charAt(i) != ","){
retVal += parsePath.charAt(i);
}
else{
break;
}
i--;
}
return reverse(retVal);
}
function trimLastId(parsePath){
var i = parsePath.length;
while (i > -1){
if (parsePath.charAt(i) == ","){
break;
}
i--;
}
return parsePath.substring(0, i);
}
function reverse(str){
var retVal = "";
var i = str.length - 1;
while (i > -1){
retVal += str.charAt(i);
i--;
}
return retVal;
}