var ashlea_penfold = new Class({

	initialize: function() {
	
		this.initialized = true;
		this.scroller = null;
		this.imgDomPath = 'img.portfolio_img';
		this.images = [];
		this.initExternalLinks();
		this.initGallery();
		this.loadImages();
		this.suppressRightClick();
	},
	
	initGallery: function() {
		$$('div.image_wrapper img').each(function(el) {
			el.setStyle('opacity', '0.001');
		});
		
		this.scroller = new Scrollbar(
			$('portfolio_wrapper'), 
			'#portfolio_scroll_content', 
			'#portfolio_scrollbar', 
			'#portfolio_scroll_handle', 
			{	mode: 'horizontal'	}
		);
	},
	
	loadImages: function(i) {
   	if(i == null) {
   		i = 0;
			ashlea_images.each(function(image) {
				this.images.push(image.src);
			}.bind(this));
		}

		
		preload_img = new Asset.image(this.images[i], {
			id: this.images[i],
			onload: function() {
				if(i <= (this.images.length-1)) {
					var placeholder = $('image_'+(i+1));
					placeholder.setProperty('src', preload_img.src);
					placeholder.set('tween', {duration: '1200'});
					placeholder.fade(1.0);
					this.loadImages(i+1);
					
				} 
			}.bind(this)
		}); 
		

	},
	
	initExternalLinks: function() {
		if (!document.getElementsByTagName) return;
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
				anchor.target = "_blank";
			}
		}
	},
	
	suppressRightClick: function(el) {
		
		var imgs = $$(this.imgDomPath);
		imgs.each(function(el) {
			el.addEvent('contextmenu', function(e){
				var e = new Event(e).stop();
			});
		});
	}
	

	
});




//////////////////////////////////////////////////////////////


var ap_obj;
window.addEvent('domready', function() {
	ap_obj = new ashlea_penfold();
});
