﻿//Netxion.Util.debug = true;
Netxion.Util.include("Netxion.Ui.js");
Netxion.Util.include("Netxion.Ui.Controls.Menu.js");
Netxion.Util.include("Netxion.Ui.Devices.Screen.js");
Netxion.Util.include("Netxion.Ui.Controls.Form.js");

window.onload = function()
{
	this.imageShiftTimeout = 3000;
	this.loadedImages  = [];
	this.imageIndex    = Math.floor(Math.random() * 4);
	this.loadedSources = [];
	void this.setTimeout("window.loadImages()", 400);
	Netxion.Ui.HtmlLoader.load();

	window["frmMovie"] = new Netxion.Ui.Controls.Form("width=480;height=320;status=0;title=1;center=1;resize=0;move=0;");


	window["frmMovie"].element.style.background = "#FFFFFF";
	window["frmMovie"].element.style.border     = "solid #000000 1px";

	window["imgGallery"] = new Netxion.Ui.Controls.ImageGallery();
	window["imgGallery"].element.style.visibility = "hidden";
	window["imgGallery"].element.style.position   = "absolute";
	Netxion.Ui.Util.centerElement(window["imgGallery"].element);
	window.document.body.appendChild(window["imgGallery"].element);

	window["imgGallery"].onload = window["imgGallery"].onchange = function()
	{
		Netxion.Ui.Util.centerElement(this.element);
	}

	window["imgGallery"].onshow = function()
	{
		var zindex = Netxion.Ui.Devices.Screen.getMaxZIndex();
		this.element.style.zIndex = zindex + 2;
		Netxion.Ui.Devices.Screen.lock("#FFFFFF", 80, zindex + 1);
	}
	
	window["imgGallery"].onhide = function()
	{
		Netxion.Ui.Devices.Screen.unlock();
	}

	window["frmMovie"].onclose = function(){this.hide(); return true;}
	window["frmMovie"].onshowcomplete = function()
	{
		var zindex = Netxion.Ui.Devices.Screen.getMaxZIndex();
		this.element.style.zIndex = zindex +2;
		Netxion.Ui.Devices.Screen.lock("#FFFFFF", 80, zindex+1);
	}

	window["frmMovie"].onhide = function()
	{
		setTimeout("window[\"frmMovie\"].content.element.innerHTML = '';",100);
		Netxion.Ui.Devices.Screen.unlock();
	}
};

window.loadImages = function()
{
	var arrImages = document.getElementById("divImages").innerHTML.split(",");

	for(var i=0; i<4; i++)
	{
		var index = Math.floor(Math.random() * arrImages.length);
		var image = document.getElementById("divHeadImages").appendChild(document.createElement("img"));
		image.width = image.height = 64;
		image.src = "/incoming/page1/tblImage/" + arrImages[index];
		window.loadedImages.push(image);
		window.loadedSources[i] = image.src;
		arrImages.splice(index, 1);
	}
	window.shiftImage();
};

window.shiftImage = function()
{
	window.imageIndex++;
	if(window.imageIndex > 3){window.imageIndex = 0;}

	for(var i=0; i<4; i++)
		window.loadedImages[(i + window.imageIndex) % 4].src = window.loadedSources[i];

	window.loadedImages[window.imageIndex].src = "/gfx/void.gif";
	window.setTimeout("window.shiftImage()", window.imageShiftTimeout);
};

window.showMovie = function(sMovie)
{
	window["frmMovie"].content.element.innerHTML = '<embed width="480" height="320" id="single" flashvars="file=' + sMovie + '&autostart=true&allowfullscreen=false" src="/flvplayer.swf" type="application/x-shockwave-flash" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'
	window["frmMovie"].show();
};

window.showGallery = function(sFiles)
{
	window["imgGallery"].load(sFiles);
	window["imgGallery"].show();	
};

/**
* 
* @constructor
*/
Netxion.Ui.Controls.ImageGallery = function()
{
	this._ptr    = Netxion.Util.objects.push(this)-1;
	this.element = document.createElement("table");
	this.images  = [];
	this.cursor  = 0;
	
	this.next = function()
	{
		var strOldImage = this.images[this.cursor];
		this.cursor++;
		if(this.cursor >= this.images.length){this.cursor=0;}
		this.display.src = this.images[this.cursor];
		if(this.display.src != strOldImage){this.onchange();}
	};

	this.previous = function()
	{
		var strOldImage = this.images[this.cursor];
		this.cursor--;
		if(this.cursor < 0){this.cursor = this.images.length-1;}
		this.display.src = this.images[this.cursor];
		if(this.display.src != strOldImage){this.onchange();}
	};

	this.hide = function()
	{
		this.element.style.visibility = "hidden";
		this.onhide();
	};

	this.show = function()
	{
		this.element.style.visibility = "visible";
		this.onshow();
	};

	this.load = function(v)
	{
		if(!v){return;}
		var strOldImage = this.images[this.cursor];
		this.images.splice(0, this.images.length);
		this.cursor = 0;
		if(typeof v == "object" || typeof v == "array"){for(e in v){this.images.push(v[e]);}}
		if(typeof v == "string"){var arr = v.split(","); for(e in arr){this.images.push(arr[e]);}}
		this.display.src = this.images[this.cursor];
		if(this.images[this.cursor] != strOldImage){this.onchange()};
	};

	this.onload   = function(){};
	this.onchange = function(){};
	this.onhide   = function(){};
	this.onshow   = function(){};

	this.main = function(arguments)
	{
		this.element.tableLayout      = "fixed";
		this.element.cellSpacing = this.element.cellPadding = 0
		this.element.className        = "ImageGallery";
		this.element.style.background = "#FFFFFF";
		this.element.appendChild(document.createElement("tbody"));
		this.element.childNodes[0].appendChild(document.createElement("tr"));
		this.element.childNodes[0].appendChild(document.createElement("tr"));

		this.element.childNodes[0].childNodes[0].appendChild(document.createElement("td")).className = "Title";
		this.spPrevious = this.element.childNodes[0].childNodes[0].childNodes[0].appendChild(document.createElement("span"));
		this.spClose    = this.element.childNodes[0].childNodes[0].childNodes[0].appendChild(document.createElement("span"));
		this.spNext     = this.element.childNodes[0].childNodes[0].childNodes[0].appendChild(document.createElement("span"));

		this.element.childNodes[0].childNodes[1].appendChild(document.createElement("td"));
		this.display = this.element.childNodes[0].childNodes[1].childNodes[0].appendChild(document.createElement("img"));
		this.display.onload = new Function("e", "Netxion.Util.objects[" + this._ptr.toString() + "].onload();");

		this.spClose.style.textAlign  = this.spPrevious.style.textAlign  = this.spNext.style.textAlign  = "center";
		this.spClose.style.padding    = this.spPrevious.style.padding    = this.spNext.style.padding    = "3px";
	//	this.spClose.style.fontFamily = this.spPrevious.style.fontFamily = this.spNext.style.fontFamily = "Courier";

		this.spPrevious.innerHTML   = "vorige";
		this.spNext.innerHTML       = "volgende";
		this.spClose.innerHTML      = "sluiten";

		this.spPrevious.onclick = new Function("e", "Netxion.Util.objects[" + this._ptr + "].previous();");
		this.spNext.onclick     = new Function("e", "Netxion.Util.objects[" + this._ptr + "].next();");
		this.spClose.onclick    = new Function("e", "Netxion.Util.objects[" + this._ptr + "].hide();");
		
		this.load(arguments[0]);
	}; this.main(arguments);
};