var bgsleight	= function() {
	
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}
	
	function fnLoadPngs() {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
		for (var i = document.all.length - 1, obj = null; (obj = document.all[i]); i--) {
			if (itsAllGood && obj.currentStyle.backgroundImage.match(/\.png/i) != null) {
				fnFixPng(obj);
				obj.attachEvent("onpropertychange", fnPropertyChanged);
			}
		}
	}

	function fnPropertyChanged() {
		if (window.event.propertyName == "style.backgroundImage") {
			var el = window.event.srcElement;
			if (!el.currentStyle.backgroundImage.match(/images\/empty\.gif/i)) {
				var bg	= el.currentStyle.backgroundImage;
				var src = bg.substring(5,bg.length-2);
				el.filters.item(0).src = src;
				el.style.backgroundImage = "url(images/empty.gif)";
			}
		}
	}

	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		obj.style.backgroundImage = "url(images/empty.gif)";
	}
	
	
	
	
	return {
		
		init: function() {
			
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.search('MSIE 6') && window.attachEvent) {
				addLoadEvent(fnLoadPngs);
			}
			
		}
	}
	
}();


bgsleight.init();



Behaviour.register({
	
	'div.bol_uit': function (el) {
		Event.observe(el, 'click', function() {
				
			if ($(el).hasClassName('bol_aan')) {
				$(el).removeClassName('bol_aan');
			} else {
				$(el).addClassName('bol_aan');
			}
				
			$(el).nextSiblings().each( function(sib) {
				sib.removeClassName('bol_aan');
				});	
			$(el).previousSiblings().each( function(sib) {
				sib.addClassName('bol_aan');
				});	
		
		});
	},
	'div.ok_button': function (el) {
		Event.observe(el, 'click', function() {
			//var stars=$(el).parentNode.getElementsByClassName('bol_aan');
			var stars = $$(".bol_aan");	
			//alert(stars.length);
			stars = stars.length;
			//alert('Je koos '+stars+' bolletjes');
			
			_a.call('/game/vote', '', {gid:el.id,vote:stars}, function(r, text, status) {
				//alert(text);
				if (text) {
					document.getElementById('votingbooth').style.display = 'none';
					document.getElementById('exitpoll').style.display = 'block';
					var data = text.split(':');
					document.getElementById('Rating').innerHTML = data[0];
					document.getElementById('Rates').innerHTML = data[1];
				} else {
					alert('Er ging iets mis\n'+status);
				}

			});
			
		});
	},
	'div.kies': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'kies_over';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'kies';
		});
	},
	'span.play': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'play_over';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'play';
		});
	},
	'span.edit': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'edit_over';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'edit';
		});
	},

	'div.start_button_gamekid': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'start_button_over_gamekid';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'start_button_gamekid';
		});
	},
	
	'span.start_button': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'start_button_over';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'start_button';
		});
	},
	'div.tips_n_tricks': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'tips_n_tricks_over';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'tips_n_tricks';
		});
	},
	'div.game_speel': function (el) {
		Event.observe(el, 'mouseover', function() {
			$(el).className = 'game_speel_over';
		});
		Event.observe(el, 'mouseout', function() {
			$(el).className = 'game_speel';
		});
	},

	'a.delgame': function(el) {
		el.onclick = function() {
			if (confirm('Weet je zeker dat je dit spel wilt verwijderen?')){
				_a.call(el.href, '', {}, function(r, text, status) {
					//alert('Hi');
					if (text= 'none') {
						//alert(text);
						//Try.these(function() {
							$(el).up('.contentParent').style.display=text;
						//},
						//function() {
						//	el.parentNode.update(text);
						//});
					} else {
						alert(text);
					}
	
				});
				return false;
			}
			else {true
				return false;
			}
		};
	},



	'a.dologin': function(el) {
		el.onclick = function() {
			if (document.getElementById('logindiv')){
				loginshade = document.getElementById('loginshade');
				loginshade.style.display = 'block';
				logindiv = document.getElementById('logindiv');
				logindiv.style.display = 'block';
			}
			else {
				alert('Error: no logindiv');
			}
			return false;
		};
	},

	'a.nologin': function(el) {
		el.onclick = function() {
			if (document.getElementById('logindiv')){
				loginshade = document.getElementById('loginshade');
				loginshade.style.display = 'none';
				logindiv = document.getElementById('logindiv');
				logindiv.style.display = 'none';
			}
			else {
				alert('Error: no logindiv');
			}
			return false;
		};
	},

	'input.cancel_login': function(el) {
		el.onclick = function() {
			loginshade = document.getElementById('loginshade');
			loginshade.style.display = 'none';
			logindiv = document.getElementById('logindiv');
			logindiv.style.display = 'none';
			return false;
		};
	},

	'a.dogamekit': function(el) {
		el.onclick = function() {
			gamekit = window.open(el.href, 'kit','width=970,height=690px,resizable=yes');
			gamekit.focus();
			return false;
		};
	},
	
	'a.addfav': function(el) {
		el.onclick = function() {
			_a.call(el.href, '', {}, function(r, text, status) {
				if (text) {
					alert('Dit spel staat nu bij jouw favorieten in My GameStudio');

				} else {
					alert('Er ging iets mis:\n'+text);
				}

			});
			return false;
		};
	}

});



function frame() {
        var gk = document.getElementById('GameKit');
        var fr = document.getElementById('TipsFrame');
        new Effect.Move('GameKitDiv', {x:0, y:-650, mode:'absolute'});
        fr.style.overflow = 'auto';
}

function deframe() {
        var gk = document.getElementById('GameKit');
        var fr = document.getElementById('TipsFrame');
        new Effect.Move('GameKitDiv', {x:0, y:0, mode:'absolute'});
        fr.style.overflow = 'hidden';
}

function doOver (img) {
	img.setAttribute("src",img.getAttribute("src").replace(/.gif/g,"_o.gif"));
}
function doOut (img) {
	img.setAttribute("src",img.getAttribute("src").replace(/_[od]\./g,"."));
}


function popupColofon(el, type) {
//testing
//el.href="/algemeen/aanmelden/bevestiging_aanmelding.html";
        var breedte = 531;
        var hoogte = 500;

//      //gebrek aan scrollbar-correctie op NN4
//      if (browser.nn4 && (type=="reactie"))
//              if (browser.mac) breedte -= 15;
//              else breedte -= 16;

        if (screen && screen.width && screen.height) {
                var wt = (screen.height - 500)/2;
                var wl = (screen.width - breedte)/2;
        } else {
                var wt = 100;
                var wl = 120;
        }
        var w = window.open(el.href, "popup", "top=" + wt + ",left=" + wl + ",scrollbars=yes,width=" + breedte + ",height=" + hoogte);
        w.focus();
        return false;
}
