$(document).ready( function() {
	$("#txtSearch").click(function(){ 
		$(this).attr({ value: '' }); 
	});
	
	$("#txtSearch").blur(function(){
		if($(this).val() == '') {
			$(this).attr({ value: 'Typ hier uw zoekwoorden...' });
		}
	});
	
	$('div#HomeLeftBar div.NewsItemWrapper').bind('click', function() {
		document.location = $(this).find('h2 a').attr('href');
	});
	
	$('div#Wrapper div.Tr div.Column div.Content div.NieuwsItem').bind('click', function() {
		document.location = $(this).find('h2 a').attr('href');
	});
	
	$('div#HomeRightBar div#LightBoxTitle').bind('click', function() {
		document.location = $(this).find('h2 a').attr('href');
	});
	
	$('div.Menu ul.Menu>li').each(function() {
		var iWidth = $(this).children('a').width();
		$(this).find('div.SubMenuWrapper div.Stretch').width(iWidth+22);
		$(this).find('div.SubMenuWrapper div.Fill').width(159 - iWidth - 24);
	});
	
	$('.Expandable').click(function() {
		
		if ( $(this).attr('state') == 'opened') {
			// sluiten
			

			$(this).next().removeClass('Expanded').addClass('Collapsed');
			$(this).attr('state', 'closed').removeClass('Expanded').addClass('Collapsed');
		} else {
			// openen

			
			$(this).next().removeClass('Collapsed').addClass('Expanded');
			$(this).attr('state', 'opened').removeClass('Collapsed').addClass('Expanded');
		}
	}).each(function() {
		var tag = $(this).tagName();
		if ( $(this).attr('state') == undefined && $(this).hasClass('Collapsed')) {
			$(this).attr('state', 'closed');
			$(this).nextAll().each(function() {
				if ( $(this).tagName() != tag ) {
					$(this).removeClass('Expanded');
					$(this).addClass('Collapsed');
				} else {
					return false;
				}
			});
		} else if ( $(this).attr('state') == undefined && ($(this).hasClass('Expanded') || !$(this).hasClass('Collapsed')) ) {
			$(this).attr('state', 'opened');
			$(this).nextAll().each(function() {
				if ( $(this).tagName() != tag ) {
					$(this).removeClass('Collapsed');
					$(this).addClass('Expanded');
				} else {
					return false;
				}
			});			
		} // else: state was already set
		
	});
});

var sCurImg = 'One';

function addListener(element, type, expression, bubbling) {
	  bubbling = bubbling || false;
	  if(window.addEventListener)	{ // Standard
	    element.addEventListener(type, expression, bubbling);
	    return true;
	  } else if(window.attachEvent) { // IE
	    element.attachEvent('on' + type, expression);
	    return true;
	  } else return false;
	}

var ImageLoader = function(url){
	  this.url = url;
	  this.image = null;
	  this.element = null;
	  this.loadEvent = null;
};

ImageLoader.prototype = {
	  load:function(image){
		this.image = image;
	    var url = this.url;
	    var image = this.image;
	    var loadEvent = this.loadEvent;
	    var element = this.element;
	    addListener(this.image, 'load', function(e){
	      if(loadEvent != null){
	        loadEvent(url, image, element);
	      }
	    }, false);
	    this.image.src = this.url;
	  },
	  getImage:function(){
	    return this.image;
	  }
};

function getCaption (AI, ID, PI) {
	$.ajax({
		   type: "POST",
		   url: AbsPath + "includes/Components/Lightbox/Ajax.php",
		   data: "albumId=" + AI + "&pictureId=" + PI,
		   success: function(msg){
				aNewImg = msg.split('**');
				
				$('#bigLightboxPic').attr( 'newSource', AbsPath + 'upload/Fotogallerij/Home/' + aNewImg[1] ).attr( 'ImgID', 'bigLightboxPic' ).fadeOut( 'slow', function() {
				 var loader = new ImageLoader( $(this).attr( 'newSource' ) );
				 loader.element = $(this);
				 loader.loadEvent = function( url, image, element ) {
						 element.fadeIn( 'slow' );
				 }
				 loader.load( document.getElementById( $(this).attr( 'ImgID' ) ) );
				 } );
	
		   			$('#'+ sCurImg).removeClass('Active');
		   			$('#'+ sCurImg).addClass('Inactive');
		   			$('#'+ ID).removeClass('Inactive');
		   			$('#'+ ID).addClass('Active');
		   				sCurImg = ID;
		   				
		   			$('div#HomeRightBar div#LightBoxTitle span.Date').html('' + aNewImg[3] + ' - ');
		   			$('div#HomeRightBar div#LightBoxTitle span.Caption').html('' + aNewImg[ 2]);
		   			$('#PicHeader').html('' + aNewImg[0]);
		   }
	});
}

function redir (Location) {
	window.location = AbsPath + Location;
}
