// JavaScript Document
window.addEvent('domready', function() {
	var szNormal = 130, szSmall = 115, szFull = 325;
	 
	var menuItems = $$("#menu .menuItem");
	var menuFX = new Fx.Elements(menuItems, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeInOut});
	
	menuItems.each(function(menu, menuIndex) {
							
			menu.addEvent("mouseenter", function(event) {
			
			var o = {};
			o[menuIndex] = {width: [menu.getStyle("width").toInt(), szFull]}
			
			menuItems.each(function(otherMenu, otherMenuIndex) {
				if(menuIndex != otherMenuIndex) {
					var w = otherMenu.getStyle("width").toInt();
					if(w != szSmall) o[otherMenuIndex] = {width: [w, szSmall]};
				}
			});
			
			menuFX.start(o);
		});
	});
	 
	$("menu").addEvent("mouseleave", function(event) {
		var o = {};
		
		menuItems.each(function(menu, menuIndex) {
			o[menuIndex] = {width: [menu.getStyle("width").toInt(), szNormal]}
		});
		
		menuFX.start(o);
	});
	
	var subHeaderTitleSlide = false;
	
	// alert(document.location.href);
	
	if (document.location.href.contains('portfolio'))
	{
		subHeaderTitleSlide = new Fx.Slide('subHeaderTitle', {mode: 'horizontal'});
		subHeaderTitleSlide.hide();
		
		$$('.portfolioItem').each(function(element,index) {
			
			var child = element.getChildren('.portfolioDetails');
			
			var childSlide = new Fx.Slide(child[0], {wait: false, mode: 'vertical'});
			childSlide.hide();
			
			element.addEvent("mouseenter", function(event) {  
				event = new Event(event);												
				childSlide.slideIn();
				event.stop();
			});
			
			element.addEvent("mouseleave", function(event) {
				event = new Event(event);
				childSlide.slideOut();
				event.stop();
			});
		});
	}
	else if (document.location.href.contains('projects'))
	{
		subHeaderTitleSlide = new Fx.Slide('subHeaderTitle', {wait: false, mode: 'horizontal'});
		subHeaderTitleSlide.hide();
	}
	else if (document.location.href.contains('shop'))
	{
		subHeaderTitleSlide = new Fx.Slide('subHeaderTitle', {wait: false, mode: 'horizontal'});
		subHeaderTitleSlide.hide();
	}
	else if (document.location.href.contains('blog'))
	{
		subHeaderTitleSlide = new Fx.Slide('subHeaderTitle', {wait: false, mode: 'horizontal'});
		subHeaderTitleSlide.hide();
		
		var childSlide = new Fx.Slide('blogMenuShade', {mode: 'vertical'});
		childSlide.hide();
		
		$('topShowHide').addEvent('click', function(event) {
			event = new Event(event);			
			childSlide.toggle();
			
			if (!childSlide.open)
			{
				$('topShowHide').value = "Hide Posts Menu";
			}
			else
			{
				$('topShowHide').value = "Show Posts Menu";
			}
			
			event.stop();
		});
													
	}
	else if (document.location.href.contains('about'))
	{
		subHeaderTitleSlide = new Fx.Slide('subHeaderTitle', {wait: false, mode: 'horizontal'});
		subHeaderTitleSlide.hide();
	}
	else if (document.location.href.contains('project/incognito'))
	{
		$$("a").filter(function(el) {
			return el.href && !el.href.indexOf("http://www.flickr.com/photos/") && el.firstChild && el.firstChild.src;
		}).slimbox({}, function(el) {
			return [el.firstChild.src.replace(/_[mts]\.(\w+)$/, "_b.$1"),	(el.title || el.firstChild.alt) + '<br /><a href="' + el.href + '">Flickr page</a> | <a href="' + el.firstChild.src.replace(/_[mtsb]\.(\w+)$/, "_o.$1") + '">Download Original</a>'];
		});
	}
	else
	{
			$$('#projectChanger').each(function(element,index) {
			
			var child = element.getChildren('.projectDetails');
			
			var childSlide = new Fx.Slide(child[0], {wait: false, mode: 'vertical'});
			childSlide.hide();
			
			element.addEvent("mouseenter", function(event) {  
				event = new Event(event);												
				childSlide.slideIn();
				event.stop();
			});
			
			element.addEvent("mouseleave", function(event) {
				event = new Event(event);
				childSlide.slideOut();
				event.stop();
			});
		});
	}

	$$('.toolTip').each(function(element,index) {  
		var content = element.get('title').split('::');  
		element.store('tip:title', content[0]);  
		element.store('tip:text', content[1]);  
	});  
	
	var toolTips = new Tips($$('.toolTip'), {
		onShow: function(tip) {
			tip.fade('in');
		},
		onHide: function(tip) {
			tip.fade('out');
		}
	});
	
	toolTips.tip.set('tween', {duration: 300});

	$$('.hide').each(function(el) {
		el.removeClass('hide');
	});
		
	if (subHeaderTitleSlide)
	{
		subHeaderTitleSlide.hide().slideIn();
		subHeaderTitleSlide.show();
	}	
});