var isie = (document.all) ? true : false;

Event.observe(window, 'load', function()
{
	
	if(!$('center').hasClassName("active"))
	{
	
		$("center").setOpacity(0);
		
		new Effect.Move('menu', { x: 0, y: 423, mode: 'absolute' });
		
		setTimeout((function()
		{
			new Effect.Move('topmenu', { x: 440, y: 115, mode: 'absolute' });
			
		}).bind(this), 100);
		
		setTimeout((function()
		{
			new Effect.Grow('logoimg', { direction: 'center', duration: 0.8});
			
		}).bind(this), 800);
		
		setTimeout((function()
		{
			Effect.BlindDown('links', { duration: 0.5 });
			
		}).bind(this), 1500);
		
		setTimeout((function()
		{
			$("sublinks").show();
			
		}).bind(this), 1600);
		

		setTimeout((function()
		{
			$("logos").show();
			
		}).bind(this), 1400);
		
		
	}
	
	
    if ($('searchbutton'))
    {
		Event.observe('searchbutton', 'click', function(event) 
	    {
	    	$("searchform").submit();
	    }
	    );	
    }
    
    if ($('payform'))
    {
    	Event.observe('field-gateway', 'change', function(event)
		{
			if($('field-gateway').value == 'invoice')
			{
				$('tr_1a').show();
				
				// plus 1,50 administratie kosten
				w = $('hiddentotalamount').value.replace(',','.');
				w = (w *100) + 150;
				w = w/100;
				w = w.toFixed(2);
				w = '&euro; ' + w.replace('.',',');
				$('totalamount').innerHTML = w;

			}
			else
			{
				$('tr_1a').hide();
				
				w = $('hiddentotalamount').value.replace(',','.');
				w = (w *100);
				w = w/100;
				w = w.toFixed(2);
				w = '&euro; ' + w.replace('.',',');
				$('totalamount').innerHTML = w;
			}
		});
    	
	    Event.observe('payform', 'submit', function(event)
	    //Event.observe('field-gateway', 'change', function(event)
		{
			
			if($('field-gateway').value == 'invoice')
			{
				$('payform').writeAttribute('action', $('pay_url').value);
				$('payaction').name = 'action1';
				
			}
			else
			{
				$('payform').writeAttribute('action', '');
				//$('payform').action.value = '';
				$('payaction').name = 'action';
				
			}
			
			
			return false;
			
		});
		
		
    }
    
//	var flashobject = new SWFObject("/flash/background2.swf", "video", "100%", "100%", "8");
//		flashobject.addParam("quality", "high");
//		flashobject.addParam("wmode", "transparent");
//		// flashobject.addParam("salign", "t");
//		flashobject.write("sfeer");
		
	Event.observe('close_content', 'click', function(event)
	{
		if($("center").getOpacity() == 0)
		{
			$('center').addClassName('active');
			new Effect.Opacity('center', { from: 0.0, to: 1.0, duration: 0.5 });
			return false;			
		}
		else
		{
			
			new Effect.Opacity('center', { from: 1.0, to: 0.0, duration: 0.5 });
			return false;
		}
	});
	
	if(!$('center').hasClassName("active"))
	{
		Event.observe(document.body, 'click', function(event)
		{
			if(!$('center').hasClassName("active"))
			{
				if($("center").getOpacity() == 0)
				{
//					$('center').addClassName('active');
//					new Effect.Opacity('center', { from: 0.0, to: 1.0, duration: 0.5 });
//					return false;
				}
				else
				{
//					new Effect.Opacity('center', { from: 1.0, to: 0.0, duration: 0.5 });
//					return false;
				}
			}
		});
	}
	
	if ($('colorpicker'))
	{
		var flashobject = new SWFObject("/flash/kleur-kiezen3.swf", "video", "187", "187", "8");
			flashobject.addParam("quality", "high");
			flashobject.addParam("wmode", "transparent");
			// flashobject.addParam("salign", "t");
			flashobject.write("colorpicker");
	}
	
	
});

function setColor(color)
{
	var field = document.getElementById('color');
	if (field)
	{
		field.value = color;	
	}
}

function showHideElement(source, target)
{	
	if(document.getElementById(source).checked == 1)
	{
		document.getElementById(target).style.display = 'block';
	}
	else
	{
		document.getElementById(target).style.display = 'none';
	}
}

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 = '';
//   	 	}
//   	 	
//   	 }
//   	 
   	 document.getElementById("quantity").innerHTML = '<br />' + cartcollection.jsonobj.totalquantity + ' items';
   	 document.getElementById("description2").innerHTML = '&euro; ' + cartcollection.jsonobj.totalprice;
}


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 BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
