Event.observe(window, 'load', function()
{
	if ($('flash'))
	{
//		 swf object schrijven
//		var flashobject = new SWFObject("/video/kruiswijk.swf", "video", "400", "266", "8");
//		flashobject.addParam("quality", "high");
//		flashobject.addParam("wmode", "transparent");		
//		flashobject.write("flash");

		// global object
		videoplayer		= new VideoPlayer();

		videoplayer.play('/video/VTS_01_1.flv', 'flash', 510, 287, '/video/duck1.jpg');

	}
	
	newNavigator = new NavigatorCollection();
	newNavigator.getNavigator(
	{
		'id'				: "mainmenu",
		'submenu'			: "downblind",
		'effect'			: "none"
	});

	imageScrollCollection = new ImageScrollCollection();
	imageScrollCollection.addImageScroll('scrolldiv_h','lr','big_image',false,true,true,true);
	
	if ($('nieuwsbrief'))
	{
		inputDisabler = new InputDisabler();
		inputDisabler.setCheckbox('InfoBulletin');
		inputDisabler.setInputs(new Array('Telefoon', 'Straat', 'Huisnummer', 'Postcode', 'Plaats'));
	}
	
	
	var newFAQ = new Faq();
});

var VideoPlayer = Class.create(
{
	initialize: function()
	{
		
	},
	play: function(source, target, width, height, prerollimage)
	{
		
		var flashvars = {
			flvpFolderLocation: "/flvplayer/",
			flvpAutoStartMovie: false,
			flvpPreRollImage: prerollimage,
			flvpVideoSource: source,
			flvpWidth: width,
			flvpHeight: height,
			flvpTurnOnCorners: false,
			flvpShowbInfo: false,
			flvpShowbCc: false,
			flvpShowbMenu: false,
			flvpInterfaceDisplay : "autohide",
			flvpBackButtonRollOverColor: "0x546472",
			flvpPlayButtonRollOverColor: "0x546472",
			flvpPauseButtonRollOverColor: "0x546472",
			flvpStopButtonRollOverColor: "0x546472",
			flvpForwardButtonRollOverColor: "0x546472",
			flvpInfoButtonRollOverColor: "0x546472",
			flvpCCButtonRollOverColor: "0x546472",
			flvpFullscreenButtonRollOverColor: "0x546472",
			flvpMenuButtonRollOverColor: "0x546472",
			flvpCloseMenuButtonRollOverColor: "0x546472",
			flvpScrubBarDragRollOverColor: "0x546472",
			flvpVolumeButtonOnRollOverColor: "0x546472",
			flvpVolumeButtonOffRollOverColor: "0x546472",
			flvpVolumeDragRollOverColor: "0x546472",
			flvpScrubBarFrontColor : "0x546472",
			flvpVolumeFrontColor : "0x546472"
		};
		
		var params = {
			wmode: "transparent",
			menu: "true", 
			allowfullscreen: "true"
		};
		
		swfobject.embedSWF("/video/flvplayer.swf", target, width, height, "9.0.0", "/flash/expressInstall.swf", flashvars, params);
	}
});

function var_dump(obj, recursive)
{	
	//var recursive = recursive||true;
	var s = var_dump_noprint(obj, 0, recursive);
	
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/g, '&gt;');
	debugwin = window.open('', 'debugwin', 'left=20,top=20,width=400,height=800,toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
	debugwin.document.write('<html><body style="cursor:pointer;" onClick="self.close()"><pre>' + s + '</pre></body></html>');
	debugwin.document.close();
}

/**
* voor debuggen, wordt gebruikt door var_dump hierboven
* ook los te gebruiken: alert(var_dump_noprint(obj));
*/
function var_dump_noprint(obj, indent_level, recursive)
{

	var LINEFEED = '\n';	
	var INDENT   = '\t';
	var indent_level = indent_level||0;
	var indent_str = '';
	var j;
	for(j=0; j<indent_level; j++) {
		indent_str += INDENT;
	}
	var s = '';
	if(typeof obj == 'undefined' || obj==null) {
		s += 'undefined' + LINEFEED;
	} else if(typeof obj == 'array' || typeof obj == 'object') {
		s += typeof obj + ' (' + LINEFEED;
		if(recursive || indent_level==0) {
			var i;
			for(i in obj) {
				s += indent_str + INDENT + '[' + i + '] => ' /*+ INDENT*/ + var_dump_noprint(obj[i], (indent_level+1), recursive);
			}
		}
		s += indent_str + ')' + LINEFEED;
	} else if(typeof obj == 'function') {
		s += 'function' + LINEFEED;
	} else {
		s += '(' + typeof obj + ') ' /*+ INDENT*/ + obj + LINEFEED;
	}
	return s;
}
function SwapImage(element)
{
	this.active = element;
}

SwapImage.prototype.swap = function(element, id, src)
{
	if (this.active.id != element.id)
	{
		element.className = 'active';
		
		document.getElementById(id).src = src;
		
		this.active.className = '';
		this.active = element;
	}
}

var isie = (document.all) ? true : false;

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5 && version < 7.0) && (document.body.filters)) 
	{
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{

				img.style.display = 'block';
				
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<div " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></div>" 
				img.outerHTML = strNewHTML
				
				i = i-1
			}
		}
	}
	
	for (var i=0; i<document.images.length; i++)
	{
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		{
			//img.style.display = 'block';
		}
	}
}

function showHideElement(source, target)
{	
	if(document.getElementById(source).checked == 1)
	{
		document.getElementById(target).style.display = 'block';
	}
	else
	{
		document.getElementById(target).style.display = 'none';
	}
}

function changeQuantity(objectinstanceid, count, udcsizeitemid, udccoloritemid)
{
	new Ajax.Request('/_ctrl/shop/cart/add/'+objectinstanceid+'/'+count+'/'+ udcsizeitemid +'/'+ udccoloritemid +'', {
			onSuccess: function(transport) 
			{
				document.location.href='/_ctrl/shop/cart/list';
			}
		});
}



function updateCart(cartcollection)
{
	 var totalamount = cartcollection.jsonobj.totalcleanprice;

   	 if (cartcollection.jsonobj.shippingcosts == 0)
   	 {
     	document.getElementById('tr_1a').style.display = 'none';
   	 }
   	 else
   	 {
   	 	
   	 	if (isie)
   	 	{
   	 		document.getElementById('tr_1a').style.display = 'block';
   	 	}
   	 	else
   	 	{
   	 		document.getElementById('tr_1a').style.display = 'table-row';
   	 	}
   	 	
   	 }
   	 
   	 document.getElementById("quantity").innerHTML = cartcollection.jsonobj.totalquantity;
   	 document.getElementById("description2").innerHTML = cartcollection.jsonobj.totalprice;
}

window.onload = function ()
{
	// png's voor IE6 aanpassen
	correctPNG();
	
}

function AddArticle (objectinstanceid, path)
{
	document.getElementById('add_'+objectinstanceid).href = path + '/_ctrl/shop/cart/add/'+objectinstanceid+'/'+ 1 +'/';
}


function addCard(nr, totalcard)
{
	
	nr = Number(cardcount);
	
	var html = 
		Builder.node
			('tr', {},
					[
					 
					 Builder.node ('td', {style:'width:140px'}, 
							 [
							  	
							  ]
					 ),
					 Builder.node ('td', {style:'width:115px'}, 
							 [
							  	Builder.node('input', { id: 'artcode_'+nr, className:'artcode', type: 'text', name: 'artcode[]'})
							  ]
					 ),
					 Builder.node ('td', {style:'width:45px'}, 
							 [
							  	Builder.node('input', {id: 'cardcount_'+nr ,className:'aantal', type: 'text', name: 'cardcount[]'})
							  ]
					 ),
					 Builder.node ('td', {}, 
							 [
							  
							  ]
					 ),
					 
					 ]
			);
	
	var desc = $('cardcol').descendants();
	
	desc[0].appendChild(html);
	
	$('artcode_'+nr).className = 'artcode';
	$('cardcount_'+nr).className = 'aantal';
	
	cardcount++;
}

var InputDisabler = Class.create(
{
	initialize: function()
	{
		this.checkbox 	= null;
		this.inputs		= null;
	},
	
	setCheckbox: function(checkboxid)
	{
		this.checkbox 	= $(checkboxid);
		this.disabled	= ($(checkboxid).getValue() == 1) ? true : false;
		
		Event.observe(this.checkbox, 'click', function(event)
		{
			this.doItInputs();
		}.bind(this));
	},
	
	setInputs: function(inputs)
	{
		this.inputs = inputs;
		
		this.doItInputs();
	},
	
	doItInputs: function()
	{
		if (this.disabled)
		{
			this.inputs.each(function(s)
			{
				$(s).enable();
				$(s).removeClassName('disabled');
			});
		}
		else
		{
			this.inputs.each(function(s)
			{
				$(s).addClassName('disabled');
				$(s).disable();
			});
		}
		this.disabled = !this.disabled;
	}
});

var AnimationCollection = Class.create(
{
	initialize: function(id)
	{
		this.items 	= new Array();
		this.ul		= $(id);
		
		this.ul.childElements().each(function(child)
		{
			if(child.nodeName.toUpperCase() == "LI")
			{
				Event.observe(child, 'mouseover', function(event)
				{
					$(child).addClassName('hover');
				}.bind(this));
				Event.observe(child, 'mouseout', function(event)
				{
					$(child).removeClassName('hover');
				}.bind(this));
			}
		}.bind(this));
	}
});

var AnimationItem = Class.create(
{
	initialize: function()
	{
		Event.observe(childitem.id, 'mouseover', function(event)
		{
			
			childitem.mouseover = true;
			//$('debug').innerHTML = $('debug').innerHTML + childitem.id + childitem.mouseover + '<br/>';
			childitem.mouseout	= false;
			
		}.bind(this));
	}
});

var Animation = Class.create(
{
	slideshow: function(start,last,interval,target)
	{
		var frame = start;   
		var nextframe = start+1;   
		
		Effect.Appear(target+'1',{duration:.5,from:0.0,to:1.0});   
		
		setInterval(function()
		{   
			Effect.Fade(target+frame,
					{	duration:.5,
						from:1.0,
						to:0.0,
						afterFinish:function()
						{
							$(target+frame).hide();
							
						    frame = nextframe;
						    nextframe = (frame == last) ? start : nextframe+1;
						},
						beforeStart:function()
						{
						    Effect.Appear(target + nextframe,{duration:.5,from:0.0,to:1.0});
						}
					});
		}, interval);   
		return; 
	}
});



var Faq = Class.create(
{
	initialize: function() 
	{
		this.attachEvents();
	},
	attachEvents: function()
	{
		$$('.question').each(function(item, index)
		{
			Event.observe(item.id, 'click', this.click.bindAsEventListener(this, item));
			Event.observe(item.id, 'mouseout', this.mouseout.bindAsEventListener(this, item));
			Event.observe(item.id, 'mouseover', this.mouseover.bindAsEventListener(this, item));
		}.bind(this));
	},
	mouseover: function(event, elm)
	{
		elm.addClassName('bold');
	},
	mouseout: function(event, elm)
	{
		elm.removeClassName('bold');
	},
	click: function(event, elm)
	{
		var exploded 	= elm.id.split('_');
		var id 			= parseInt(exploded[1]);
		var answer		= $('answer_' + id);
		
		if (answer.visible())
		{
			answer.hide();
		}
		else
		{
			answer.show();
		}
	}
});

