
laagOut = function() {
	if($('laag-a').style.display != "none") { return '-a'; } else { return '-b';  }	
}

laagIn = function() {
	if($('laag-a').style.display != "none") { return '-b'; } else { return '-a';  }	
}

firstTimeLoad = function() {
	// old = http://www.schutte-informatisering.nl/index.php/?P=ajaxmod
	new Ajax.Request('http://www.schutte-informatisering.nl/beheer/addons/ajaxrequest/request.php/', {	
		method: 'get',
		parameters: 'ajax_opt=rand',
		onSuccess: function(resp) {
			var tags = resp.responseText.evalJSON(true);
			var randno = Math.floor ( Math.random() * (tags.length) ); 
			var ret = tags[randno].thid;
			new Ajax.Request('http://www.schutte-informatisering.nl/beheer/addons/ajaxrequest/request.php/', {	
				method: 'get',
				parameters: 'ajax_opt=thema_data&thema_id=' + ret,
				onSuccess: function(resp) {
					tagPlace(ret, laagOut());
					
					var thData = resp.responseText.evalJSON(true);
					
					$('tab_' + ret).setStyle({
						backgroundColor: '#' + thData.color
					});
					
					var aaa = $('tab_' + ret).down(0);
					aaa.setStyle({
						color: '#FFF'
					});
					
					if(thData.image != "") {
						$('image-holder' + laagOut()).update('<img id="' + ret + '" src="' + thData.url + ret + '/' + thData.image + '" onLoad="" >');
					}
					$('tag-holder' + laagOut()).setStyle({
						height: thData.height + 'px', 
						width: thData.width + 'px',
						backgroundImage: 'url(' + thData.url + ret + '/' + thData.bgimage + ')'
					});
				}	
			});			
		}	
	});
} // einde function	

fillTheme = function(th) {
	
	new Ajax.Request('http://www.schutte-informatisering.nl/beheer/addons/ajaxrequest/request.php/', {	
		method: 'get',
		parameters: 'ajax_opt=thema_data&thema_id=' + th,
		onFailure: function(resp) {
			//alert(resp.responseText);
		},
		onSuccess: function(resp) {
		
			tagPlace(th, laagIn());
			
			var thData = resp.responseText.evalJSON(true);
			
			if(thData.image != "") {
				$('image-holder' + laagIn()).update('<img src="' + thData.url + th + '/' + thData.image + '"  onLoad="">');
			}
			
			$('tag-holder' + laagIn()).setStyle({
				height: thData.height + 'px', 
				width: thData.width + 'px',
				backgroundImage: 'url(' + thData.url + th + '/' + thData.bgimage + ')'
			});
			switchLayer(laagOut(), laagIn());
			switchTabs(th, thData.color);
		}	
	});
} // einde function	

switchLayer = function(from, to) {
	
	$('laag' + to).setStyle({ display: '' });
		
	var queue = Effect.Queues.get('laag');
	queue.each( function(effect) { 
		effect.cancel(); 
	});
				
	Effect.Fade($('image-hider' + to), {
		queue: {
			position : 'front',   
			scope: 'laag', 
			limit: 1 
		} , 
		duration:0.2 
	});	
	
	var queue = Effect.Queues.get('tag');
	queue.each( function(effect) { 
		effect.cancel(); 
	});
	Effect.Appear($('tag-holder' + to), {
		queue: {
			position : 'end',   
			scope: 'tag', 
			limit: 1 
		} , 
		duration:0.4 
	});	
	
    $('image-hider' + from).setStyle({ display: '' });
	$('laag' + from).setStyle({ display: 'none' });
	$('tag-holder' + from).setStyle({ display: 'none' });
}

switchTabs = function (thId, thColor) {
	new Ajax.Request('http://www.schutte-informatisering.nl/beheer/addons/ajaxrequest/request.php/', {	
		method: 'get',
		parameters: 'ajax_opt=rand',
		onSuccess: function(resp) {
			var tabs = resp.responseText.evalJSON(true);

			tabs.each( function( data ) {
				
				$('tab_' + data.thid).setStyle({
					backgroundColor: ''
				});
				
				var tab_off = $('tab_' + data.thid).down(0);
				
				tab_off.setStyle({
					color: '#A7A7A7'
				});
			});
			
			$('tab_' + thId).setStyle({
				backgroundColor: '#' + thColor
			});
			
			var tab_select = $('tab_' + thId).down(0);
			
			tab_select.setStyle({
				color: '#FFF'
			});
		}
	});			
}

tagPlace = function(th, laag) {
	
	new Ajax.Request('http://www.schutte-informatisering.nl/beheer/addons/ajaxrequest/request.php/', {	
		method: 'get',
		parameters: 'ajax_opt=tags&active=1&thema_id=' + th,
		onFailure: function(resp) {
			alert(resp.responseText);
		},
		onSuccess: function(resp) {
			if(resp.responseText != false)
			{
				var tags = resp.responseText.evalJSON(true);
				var tags_html = '';
                
				tags.each( function( data ) {					
					tags_html += '<a href="' + data.surl + 'index.php/category/' + data.url + '" style="text-decoration: none;">';
					tags_html += '<div id="tag_' + data.id + '" class="tag" style="font-size:' + data.fsize + 'px;margin:' + data.posy + 'px 0 0 ' + data.posx + 'px;">';
					tags_html += data.title + '</div></a>';
				}); // einde function	
				
				$('tag-holder' + laag).update(tags_html);
				
			}
		}
	});
} // einde function	



switchTheme = function(el)	{
	
}
 
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
} 