iid='';
function sh(id){
	if($(id))$(id).setStyle('display',(($(id).getStyle('display')=='none')?'block':'none'));
}
function hrm(id){
	$$('.val').each(function(itm){itm.setStyle('display', 'none');});
	if(id!=iid){$(id).setStyle('display','block');iid=id}else{iid=''};
}
function si(tp,dr,fn){
	$('iw').set('html','<img src="/content/'+tp+'/i_'+dr+'/'+fn+'" id="zi">');
	$('pp').setStyle('display','block');$('pp').setStyle('top','0');
	$('pp').addEvents({
		'mouseup':function(e){sp(e);},'mousemove':function(e){sp(e);},
		'click':function(e){$('pp').removeEvents();$('pp').setStyle('display','none');}
	});
}
function sp(e){
	w=$('pp').getStyle('width').toInt();h=$('pp').getStyle('height').toInt();if(w==100){gs();}
	var iw=$('zi').getStyle('width').toInt();var ih=$('zi').getStyle('height').toInt();
	if(iw){
		$('iw').setStyle('left',((iw>w)?((e.client.x/w)*(w-iw)):((w-iw)/2)));
		$('iw').setStyle('top',((ih>h)?((e.client.y/h)*(h-ih)):((h-ih)/2)));
	}
}
function sq(s){
	$('q').set('html','<input type="text" name="qry" value="'+s+'" onfocus="this.value=\'\';this.onfocus=\'\'">');
}
function gs() {
	// IE patch
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    w = window.innerWidth;
    h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
 return Array(w, h);
}
function hl(){
	if($('txt')){$$('div.b').each(function(e,i){e.setStyle('display', 'none');})}else{sl(0);}
}
function sl(n){
	if (n<0)n=0;
	nn=n;
	//sd();
	$$('div.t').each(function(e,i){e.setStyle('border-bottom', '2px solid '+((i==n)?'#0071BC':'#fff'));});
	//$$('div.b').each(function(e,i){e.fade(((i<n&&(n<ids.length))?'out':'show'));e.setStyle('display', ((i<n&&(n<ids.length))?'none':'block'));});
	$$('div.b').each(function(e,i){e.setStyle('display', ((i<n&&(n<ids.length))?'none':'block'));});
	
	if (n==ids.length){hl();}
}
function sd(){
	pd = gs();
	if($('big')){
		$$('.im').each(function(e){
			ps=$('big').getSize();pr=ps.x/ps.y;
			sc=e.get('sc').toInt();
			r=e.get('width').toInt()/e.get('height').toInt();
			if (ims=e.getElement('img')){
				ims.setStyles({width:((r>pr)?sc+'%':'auto'),height: ((r>pr)?'auto':sc+'%')});
			}
			
		});
	}
}
function u_d(items){
	if (items.length){
		items.each(function(e) {
			var fx = new Fx.Tween(e, {wait:false});
			e.getParent().setStyle('cursor', 'pointer');
			e.t = ((e.getStyle('top') == 'auto')? 80 : e.getStyle('top').toInt());
			e.getParent().addEvent('mouseenter', function(){fx.start('top', e.t-40);});
			e.getParent().addEvent('mouseleave', function(){fx.start('top', e.t);});
			e.getParent().addEvent('click', function(){document.location.href = e.getElement('a');});
		});
	}
}
function ini_big(){
		if (lms=$$('.im')){
		ims = new Array();ids = new Array();
		lms.each(function(e){ims.push (e.getChildren('input').get('value'));ids.push (e.get('id'));});
		nn = 0;
		pd = gs();
		var loader = new Asset.images(ims, {
			onProgress: function(c,index) {
				ps=$('big').getSize();pr=ps.x/ps.y;
				e = $(ids[c]);sc=e.get('sc').toInt();e.fade('hide');e.fade('in');e.setStyle('background', '#fff');
				r=e.get('width').toInt()/e.get('height').toInt();
				new Element('img',{ src:ims[c], style:'width:'+((r>pr)?sc+'%':'auto')+';height:'+((r>pr)?'auto': sc+'%') }).inject(e);
			}
		});
		$$('div.b').each(function(e,i){e.addEvent('click', function(e){sl(((e.page.x<(pd[0]/2))?nn-1:nn+1))});});
	}	
}

function c_m(){
	if ($('c_m')){
		var c_m = '<p style="padding:15px;"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/nl/"><img alt="Creative Commons License" style="border-width:0" src="/gfx/cc.png" /></a><br /><br />Op dit werk is een <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/nl/">Creative Commons Licentie</a> van toepassing.</p>';
$$('.b').addEvents({
   		'contextmenu' : function(e) {
   			$('c_m').setStyles({ 'display' : 'inline', 'position': 'absolute', 'top': (e.page.y-120),'left': (e.page.x-380),'background-color' : '#FFF','width' : '200px','font-size' :'10px','text-align' :'left','font-weight' : 'bold' ,'text-align': 'center','z-index': '2000'});
			$('c_m').set('html', c_m);
   			//e.stop();	
   		},
		'click' : function() { $('c_m').setStyle('display', 'none');}
    });
$(document).addEvent('click', function() {$('c_m').setStyle('display', 'none');});
	}

}

window.addEvent('domready', function() {
	if($('big')){ini_big();c_m();}else{u_d($$('div.lb'));}
});

window.onresize = function(){
	if ($('big')) {sd();};
}
