
//firebugX
if (!("console" in window) || !("firebug" in console))
{
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    window.console = {};
    for (var i = 0; i < names.length; ++i)
        window.console[names[i]] = function() {}
}


var lastThumbId = '';
window.addEvent('domready', function() {
	$$('li.project').each(function(el){
		$(el).addEvent('mouseover',function(){
			if($('t_'+el.id)){$('t_'+el.id).tween('opacity',1);}
		});
		
		$(el).addEvent('mouseout',function(){
			if($('t_'+el.id)){$('t_'+el.id).tween('opacity',0);}
		});
	})
	
	
	$$('.thumb').each(function(el){
		$(el).setOpacity(0);
	});

	
	var cols = false;
	$$('.page').each(function(el,i){
		$(el).fade('hide');
		cols = true;
	});
	
});


window.addEvent('load', function() {
	
	//reps
	var cols = false;
	$$('.page').each(function(el,i){
		cols = true;
	});
	if(cols){
		goPage(0);
	}

});


var lastPage = '';
var lastLink = '';
function goPage(p){
	//each not good
	$$('.page').each(function(el,i){
		if(p == i){
			$(el).fade('in');
			if (lastPage!='' && lastPage != el){
				$(lastPage).fade('out');
			}
			lastPage = el;
		}
	})
	
	$$('#pageMenu a').each(function(el,i){	
		if(p == i){
			$(el).addClass('current');
			if (lastLink!='' && lastLink != el){
				$(lastLink).removeClass('current');
			}
			lastLink = el;
		}	
	})
}


window.addEvent('domready', function() {
	
	if($chk($("ss"))){
		console.info("ss: SlideShow div found, loading images");
		
		//array of images to swap between
		ims = new Array('_i/_splash/1.jpg','_i/_splash/2.jpg','_i/_splash/3.jpg','_i/_splash/4.jpg','_i/_splash/5.jpg','_i/_splash/6.jpg','_i/_splash/7.jpg','_i/_splash/8.jpg');
		
		var loaded = -1;
		var currentImage = -1;
		var total = ims.length;
		
		var ssImages = new Asset.images(ims,
											{
												
												onProgress:function(i){
													var el = new Element('img', { src: ims[i], 'class': 'ss'})
													
													el.set('opacity',0.0);
													el.set('tween', {duration: 'long'});
													
													el.inject($('ss'));
													loaded = i;
													
													console.info("ss: loaded : " + i + ",");
												},
												onComplete:function(){
													console.info("ss: loaded all slideshow images");
												}
												
											}
											);
											
		
		
		var updateSS = function()
		{
			//show the next image
			if(loaded == -1)
			{
				//none loaded, check again, quickly
				updateSS.delay(100);
				return;
			}
			
			if(currentImage == loaded && loaded < total - 1){
				//not enough loaded
				updateSS.delay(100);
				return;
			}
			
			var fr   = $('ss').getChildren("img")[ currentImage % total];
			var to   = $('ss').getChildren("img")[(currentImage+1) % total];
			
			currentImage = (currentImage + 1) % total;
			
			
			if(fr){
				fr.set('z-index',100);
				fr.tween('opacity',0);
			}
			
			to.set('s-index',101);
			to.tween('opacity',1);
			
			
			updateSS.delay(5000);
			
			
		}
		
		
		//start the slideshow
		updateSS();
		
	}
	
});//domready