/*

the history manager is in the mootools js.

*/

		// image rollovers
	function rolloverupdate() {
		
		$$('.thumb img').each(function(c) {
				c.addEvents({
				   'mouseover': function() {c.fade(0.5)},
				   'mouseout': function() {c.fade(1);}
				});   
				   
		});
		
	}


//to minimize menu --------------------------------------------

function min_menu() {
	var v = h.getCurrentLocation();
if (v == 'home.html' || v === '' || v == 'about.html' || v == 'hire.html' || v == 'contact.html') {return false;}
		$('header').morph('.header_hidden');
	//$('header').fade(0.4);
	$('header-back').fade(0.5);
	$('header').addEvent('mouseenter', max_menu);
	$('header').removeEvent('mouseleave', max_menu);
	$('menu-title').setStyle('visibility', 'visible');
	$('name').setStyle('visibility', 'visible');
	
}
function max_menu() {
	$('menu-title').setStyle('visibility', 'hidden');
	$('name').setStyle('visibility', 'hidden');
	$('header').morph('.header_show');
	$('header').fade(1);
	$('header-back').fade(1);
	$('header').removeEvent('mouseenter', max_menu);
	$('header').addEvent('mouseleave', min_menu);

}


// resolve what page to load -------------------------------------------------------
function resolvepage() {
hash = h.getCurrentLocation();
if (hash === ''  || hash == 'home.html') {http = 'home.html';}
menulink(hash);

}
// end resolvepage()----------------------------------------------------------------



//ajax load  -----------------------------------------------
function menulink(http) {

	$('gallery-holder').set('load', {onComplete: function() {
		//$('gallery-holder').erase('load');
		Slimbox.scanPage();
		h.addState(http);
		if (http == 'images.php?album=Design') {$('design-info').fade(1);}
		else {$('design-info').fade('hide');}
		
		
		if ($$('.thumb') != '') {	
			//rolloverupdate();
			var images = $$('.thumb');
			var pathes = [];
			images.each(function(image){
			pathes.push(image.getProperty('src'));
			
			});
			var preloadedImages = new Asset.images(pathes,{onComplete: function() { $('fadebox').fade(0);}}); 
		}
		else {$('fadebox').fade(0); }
			
		min_menu();
		
	}});
	
//$('fadebox').set('tween', {onComplete: function() { }});

$('fadebox').fade(1);
$('gallery-holder').load(http);

}


function loadnohistory() {
hash = h.getCurrentLocation();
if (hash === '' || hash == 'home.html') {
	hash = 'home.html';
	
	$('gallery-holder').set('load', {onComplete: function() {
		
		//$('gallery-holder').erase('load');
	
		Slimbox.scanPage();
		max_menu();
		
		
		if ($$('.thumb') != "") {
			rolloverupdate();
			var images = $$('.thumb');
			var pathes = [];
			images.each(function(image){
			pathes.push(image.getProperty('src'));
			
			});
			var preloadedImages = new Asset.images(pathes,{onComplete: function() { $('fadebox').fade(0);}}); 
			
		}
		else {$('fadebox').fade(0); }
		
	}});
	
	$('fadebox').fade(1);
	$('gallery-holder').load(hash);
	
} 
else {resolvepage();}

	
}



window.addEvent('domready', function() {
//$('fadebox').setStyle('opacity', 0);
//$('fadebox').set('fade', {link: 'chain'});							  
menuitem = null;
h = new HistoryManager();
hash = null;
http = null;

loadnohistory();

// add history event ----------------------------------------------------
h.addEvent('onHistoryChange', loadnohistory);

// animate menu -----------------------------------------------------------------
max_menu();

// menu selections etc. ------------------------------------------------------------------------
	
	
	$$('ul li a, menulink').each(function(el) {
				//el.set('morph', {duration: 200});
				//el.set('tween', {duration: 1000});
				el.addEvents({
				 //'mouseover': function() {el.set('tween', {duration: 300});el.tween('color', '#d80');},
				 //'mouseout': function() {el.set('tween', {duration: 2000});el.tween('color', '#666663');},
				'mouseover': function() {el.set('morph', {duration: 300});el.morph('.mouseover');},
				'mouseout': function() {el.set('morph', {duration: 2000});el.morph('.normal');},
				'click': function(){
					// removes all white 'selected' classes
					$$('ul li a, menulink').removeClass('selected');
					// sets the class for the 'selected' css
					el.addClass('selected'); 
					menuitem = el;
					if (el.get('rel') !== null) {
					menulink(el.get('rel'), el.get('id')); 
					}
					min_menu();
				}
				});
	});
	
	
// end menu -----------------------------------------------------------------------------------



});


