function RandomNumber(max)
{
	return Math.floor(Math.random() * (max + 1));
}

/**
* Takes care of blending images in/out for the image id 'image_rotator'
* The array imagesToBlend holds paths to images to blend
* For now each blend a random images is picked
*/
//configuration for the image blending at the top
var blendtime = 2.5;  // time in seconds
var pausetime = 3000; // time in milliseconds
var advance   = (blendtime * 1000) + pausetime;
var start     = 5000; //milliseconds after load to start the rotating
function Blend(imagesToBlend)
{
	//alert('Blend(' + imagesToBlend + ')');
	var random_number = RandomNumber(imagesToBlend.length - 1);
	
	//is blending supported?
	if(document.all)
	{
		document.getElementById('image_rotator').style.filter = 'blendTrans(duration=' + blendtime + ')';
		document.getElementById('image_rotator').filters.blendTrans.Apply();   
	}
	
	//alert('next image to blend is : ' + random_number + ' => ' + imagesToBlend[random_number]);
	document.getElementById('image_rotator').src = imagesToBlend[random_number];
	
	if(document.all)
		document.getElementById('image_rotator').filters.blendTrans.Play();

	//window.status = random_number;
	setTimeout(function () { Blend(imagesToBlend) }, advance);
	
}

function CreatePopupWindow(img,width,height)
{
	window.open(img,'_new','width='+width+',height='+height+',status=no,scrollbars=no,toolbar=no,location=no,menubar=no,directories=no,resizable=yes');
	return;
}

function popupImage(ImageString)
{
	var url = '/content/image/images/original/'+ImageString;
	CreatePopupWindow(url,800,600);
}

function ShowHide(object_id)
{
	//alert(object_id);
	if(document.getElementById(object_id).style.display == 'none')
		HideElement(object_id);
	else
		ShowElement(object_id);

}

function HideElement(object_id)
{
	if(document.getElementById(object_id))
		document.getElementById(object_id).style.display = 'none';
}

function ShowElement(object_id)
{
	//alert('ShowElement('+object_id+')');
	if(document.getElementById(object_id))
		document.getElementById(object_id).style.display = 'block';
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
	  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function changeToVoorkant()
{
	document.getElementById('chang_side_to').value = "Voorkant";
	document.getElementById('studio_form').submit();
}

function changeToAchterkant()
{
	document.getElementById('chang_side_to').value = "Achterkant";
	document.getElementById('studio_form').submit();
}


function changeImage( imagename )
{
	document.getElementById('illustratie_image').value = imagename;
	document.getElementById('studio_form').submit();
}


function PagerBack( pagerID, count )
{
	if( pagerID > 0 )
	{
		document.getElementById('pagerID').value = pagerID -1;
		document.getElementById('studio_form').submit();
	}
}

function PagerNext( pagerID, count )
{
	if( pagerID < count -5 )
	{
		document.getElementById('pagerID').value = pagerID +1;
		document.getElementById('studio_form').submit();
	}
	else
	{
		document.getElementById('pagerID').value = 0;
		document.getElementById('studio_form').submit();
	}
}

// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if (!window.SI) { var SI = {}; };
SI.Files =
{
	htmlClass : 'SI-FILES-STYLIZED',
	fileClass : 'file',
	wrapClass : 'cabinet',
	
	fini : false,
	able : false,
	init : function()
	{
		this.fini = true;
		
		var ie = 0 //@cc_on + @_jscript_version
		if (window.opera || (ie && ie < 5.5) || !document.getElementsByTagName) { return; } // no support for opacity or the DOM
		this.able = true;
		
		var html = document.getElementsByTagName('html')[0];
		html.className += (html.className != '' ? ' ' : '') + this.htmlClass;
	},
	
	stylize : function(elem)
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };
		
		elem.parentNode.file = elem;
		elem.parentNode.onmousemove = function(e)
		{
			if (typeof e == 'undefined') e = window.event;
			if (typeof e.pageY == 'undefined' &&  typeof e.clientX == 'number' && document.documentElement)
			{
				e.pageX = e.clientX + document.documentElement.scrollLeft;
				e.pageY = e.clientY + document.documentElement.scrollTop;
			};
			
			var ox = oy = 0;
			var elem = this;
			if (elem.offsetParent)
			{
				ox = elem.offsetLeft;
				oy = elem.offsetTop;
				while (elem = elem.offsetParent)
				{
					ox += elem.offsetLeft;
					oy += elem.offsetTop;
				};
			};
			
			var x = e.pageX - ox;
			var y = e.pageY - oy;
			var w = this.file.offsetWidth;
			var h = this.file.offsetHeight;
			
			this.file.style.top = y - (h / 2)  + 'px';
			this.file.style.left = x - (w - 30) + 'px';
		};
	},
	
	stylizeById : function(id)
	{
		this.stylize(document.getElementById(id));
	},
	
	stylizeAll : function()
	{
		if (!this.fini) { this.init(); };
		if (!this.able) { return; };
		
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++)
		{
			var input = inputs[i];
			if (input.type == 'file' && input.className.indexOf(this.fileClass) != -1 && input.parentNode.className.indexOf(this.wrapClass) != -1)
			{
				this.stylize(input);
			};
		};
	}
}; 

function SubmitOnEnter(e,form)
{
	var key=e.keyCode || e.which;
//	if (key==13){
	if (window.event && window.event.keyCode == 13)
		form.submit();
	else
		return true;
	
}

