function doImageLoadPortfolio(data)
{
	if(data.large)
	{
		jQuery('#inner-content').css('background-image', 'none');
		jQuery('#container').css('background-image', 'url(' + data.url + ')');
	}
	else
	{
		jQuery('#container').css('background-image', 'none');
		jQuery('#inner-content').css('background-image', 'url(' + data.url + ')');
	}
	jQuery('#loading').css('background-image', 'none');
	if (data.format) {
		jQuery('#portfolio-info').addClass(data.format);
	}
	jQuery('#loading').fadeOut(500, function() {
		jQuery('#loading').css('background-image', 'url(' + wpTplDir + '/images/spinner.gif)');
	});
}

function doImageLoadCulture(data)
{
	jQuery('#inner-content .content').css('display', 'none');
	jQuery('#inner-content').css('background-image', 'url(' + data.url + ')');
	jQuery('#loading').css('background-image', 'none');
	jQuery('#loading').fadeOut(500, function() {
		jQuery('#loading').css('background-image', 'url(' + wpTplDir + '/images/spinner.gif)');
	});
}

jQuery(document).ready(function(){ 

	// Initialize hover menu
	jQuery("ul.sf-menu").superfish({
		animation:	{height: 'show'},
		speed:		'fast',
		autoArrows:	false,
		delay:		300,
		dropShadows:false,
		onBeforeShow: 
			function(){
				jQuery('.title_indicator').fadeOut(1);
			},
		onHide:
			function(){
				if (jQuery('ul.sf-menu li.sfHover').length == 0) {
					jQuery('.title_indicator').fadeIn(400);
				}
			}
	});
	jQuery("#playIntro").fancybox({
		type: 'iframe',
		width: 450,
		height: 305
	});

	// Portfolio image loader
	jQuery('#project-thumbs a').click(function(){
	
		jQuery('#portfolio-info').removeClass();
		jQuery('#loading').show();
		
		jQuery.ajax({
			timeout: 	5000,
			dataType:	'json',
			url:		wpTplDir + '/ws_attachment.php',
			data:		'attid=' + jQuery(this).attr('id') + '&size=full',
			success:	function(data){
				if (data.success) {
					var image = new Image();
					jQuery(image).load(function(){ doImageLoadPortfolio(data); }).attr("src", data.url);
				}
			}
		});
		return false;
	});


	// Culture image loader
	jQuery('.culture #sidebar-inner a').click(function(){
	
		jQuery('#video').remove();
											   
		jQuery('#loading').show();
		
		jQuery.ajax({
			timeout: 	5000,
			dataType:	'json',
			url:		wpTplDir + '/ws_attachment.php',
			data:		'attid=' + jQuery(this).attr('id') + '&size=culture-photo',
			success:	function(data){
				if (data.success) {
					try
					{
						var image = new Image();
						jQuery(image).load(function(){ doImageLoadCulture(data); }).attr("src", data.url);
					}
					catch(exc)
					{
					}
				}
			},
			error:		function(a,b,c) {
			}
		});
		return false;
	});
	
	jQuery('#flash-intro').click(showSite);
	
	jQuery('#hide').click(hideSidebar);
	jQuery('#show').click(showSidebar);
	jQuery('#skip-intro').click(skipIntro);
	
	jQuery('#animateRepairTool').click(function(){
		animateHome();
	});
	
	jQuery('#view-details').click(function(){
		jQuery('#details-extended').slideToggle();								   
	});

});

function showSite() {
	jQuery('#flash-container').css('left', '-5000px');
	animateHome();
}

function musicFinished() {
	jQuery('#flash-container').remove();
}

function skipIntro() {
	jQuery('#flash-container').fadeOut(function(){
		animateHome();
		jQuery(this).remove();
	});
}

/* Animating the repair tool - test */
function animateHome() {
	jQuery('#home-photo').animate({
		left: '+=647px'
	}, 1500, 'easeOutBounce', function(){
		showSidebar();
	});
}

/* Sidebar show / hide */
function showSidebar() {
	jQuery('#show').slideUp(function(){		
		jQuery('#sidebar').slideDown();		
	});
};
function hideSidebar() {
	jQuery('#sidebar').slideUp(function(){
		jQuery('#show').slideDown();
	});
};

