

$(document).ready(function(){

// !hello world

/*
	Shadowbox.init({
			overlayColor:'#000'
		,	overlayOpacity:1
		, skipSetup: true
	});
*/


// hey - is that a homepage? wow!

	if ( $('.home').length > 0 ) {



/* 		console.log('hey giz'); */
		$('div.home').innerfade({
				speed: 'slow',
				timeout: 5000,
				type: 'sequence',
				containerheight: '300px'
			});
			
			
			$('.innerfade').children('p').children('img').each(function(){
				$(this).css({


					'z-index':1
				});
			});
			
			

			
			
			$('.innerfade').height(			$('.innerfade').children('p:first').children('img').height()	);
			$('.innerfade').width(			$('.innerfade').children('p:first').children('img').width()		);
			
			$('.innerfade').css({
					'position':		'absolute'
				,	'top':			($(window).height()-$('.innerfade').height())/2
				,	'left':			($(window).width()-$('.innerfade').width())/2
			});
	
		
	$(".postWrapper").css({
							'z-index':50
							});
	$("#top_menu_container").css({
							'position':'absolute',
							'top':20,
							'left':20,
							'z-index': 100
							});
/* console.log('zindex changed'); */
	
	}
	

// silently load the content of the pages in the menu
	incremented=0;
	if ($('#top_menu_container').length > 0) {
	
		$('ul#nav li a').each(function(){
				var url = $(this).attr('href');
				incremented = incremented + 1;
				$('#top_menu_container').append('<div id="imgs_'+incremented+'" class="slideshow" url="'+url+'" style="display:none;"></div>');
		});
		
		$("div.slideshow").each(function(){
			url_slideshow = $(this).attr('url');
			$(this).load(url_slideshow + " #primaryContent * img:first");
		});		
	
	}


// margin for the CONTENT block
/* 	var margin_left_content = parseInt($('#canvas').css('margin-left')); */  // margin: auto is a killer; it wont return the size in px; better to redo the calculation in javascript
	var margin_left_content = parseInt($(window).width()-$('#canvas').width())/2;
/* 	console.log(margin_left_content); */
	
	var window_width = parseInt($(window).width());
	$('.portfolio').css({'margin-left':margin_left_content*-1, 'width':window_width-10});

// setup color for NAV
	$('#nav li a').each(function(){
		$(this).css({'color':'#333333'});
	});
	
// setup colour behaviour for NAV

var color_1 = $('#canvas').attr('color_1');
$('.current_page_item a, .current_page_parent a').css({'border-bottom':'1px solid '+color_1});


	$('#nav li a').hover(
		function() {
			var color_1 = $('#canvas').attr('color_1');
			$(this).css({'color':color_1});
			index_of_menu_hovered = $('#nav li a').index($(this));
			$('div#imgs_'+(index_of_menu_hovered+1)).show();
			
		},
		function() {
			$(this).css({'color':'#333333'});
			index_of_menu_hovered = $('#nav li a').index($(this));
			$('div#imgs_'+(index_of_menu_hovered+1)).hide();

		}
	);
	
// images behaviour
	$('div.portfolio p a').click(
		function(){
			return false;
		});
	
	$('div.portfolio a').hover(
		function(){
			var the_title = $(this).attr('title');
/* 			console.log(the_title); */
						var color_2 = $('#canvas').attr('color_2');
			$('#the_title').html(the_title).stop().fadeTo('fast', 1).css({'color':color_2});
			$('div.portfolio * img.size-medium').each(function(){
				$(this).stop().fadeTo('fast', '0.35')
			});
			$(this).stop().fadeTo(0, '1');
		},
		function(){
			$('#the_title').stop().fadeTo(0, '0').html('');
		}
	);
	
	$('div.portfolio').hover(function(){},
		function(){
			$('div.portfolio * img.size-medium').each(function(){
				$(this).stop().fadeTo('fast', '1'); //.css({'color':color_2});
			});
		}
	);

});
