function startLoading(id) {
	$('#header h1 .loader').show(50);
	$(id).addClass('alpha50');
	//$(id).css('opacity', 0.5);
}

function endLoading(id) {
	$('#header h1 .loader').hide(50);
	//$(id).css('opacity', 1);
	$(id).removeClass('alpha50');
}

function openLookbook() {
	$('#header h1').addClass('relative');
	$('#lookbook').slideDown(400, function() {
		$('#lookbook-container').fadeIn(200);
		$('#lookbook #lookbook-close').fadeIn(200);
	});
}


function closeLookbook() {
	$('#lookbook #lookbook-close').fadeOut(200);
	$('#lookbook-container').fadeOut(200, function() {
		$('#lookbook').slideUp(400, function() {
			$('#header h1').removeClass('relative');
		});
	});
}



$(document).ready(function() {

	var lookbook = $('<div id="lookbook-btn"><div id="lookbook-btn-container"><div class="front face">PROFIL1 Look Book</div><div class="back face"><a class="watch" href="#">Watch</a><a class="download" href="files/profil1-look-book-2011.pdf">Download</a></div></div></div>');
	$('#teaser .column4').append(lookbook);
	
	
	$('#lookbook-close').click(function() {
		if($('#header h1').hasClass('relative')) {
			closeLookbook();
		} 
		return false;
	});
	
	
	$('#lookbook-btn .watch').click(function() {
		if(!$('#header h1').hasClass('relative')) {
			openLookbook();
		}
		return false;
	});
	
	if(!$.browser.webkit) {
		$('#lookbook-btn .back').css('display', 'none');
		
		$('#lookbook-btn').mouseover(function() {
			$('#lookbook-btn .back').fadeIn(400);
		});
		
		$('#lookbook-btn').mouseleave(function() {
			$('#lookbook-btn .back').fadeOut(400);
		});
	}

	$('.slideshow').cycle({
		fx: 'fade'
	});

	$('a:not(#header a)').hover(function() {
  		$(this).addClass('random-hover');
  		$(this).children().addClass('random-hover');
	}, function() {
  		$(this).removeClass('random-hover');
  		$(this).children().removeClass('random-hover');
	});
	
	$('#header h1').append('<img src="layout/website/images/ajax-loader-logo.gif" class="loader" alt="loader" />');
	$('#header h1 .loader').hide();
	
	//$('.active a').addClass('random-hover');
	//$('.active a').children().addClass('random-hover');

	$('#header ul li a span.description').css('height', '0px');
	$('#header ul li a span.description').css('display', 'block');

	$('#header ul li a').mouseover(function() {
	
		$(this).find('span.label').stop().animate({ 'marginTop':'17px'}, 200);
		$(this).find('span.description').stop().animate({ 'height': '20px'}, 100);
	});
	
	$('#header ul li a').mouseout(function() {
		$(this).find('span.label').stop().animate({ 'marginTop':'28px'}, 200);
		$('#header ul li a span.description').stop().animate({ 'height': '0px'}, 100);
		
	});
	
	
	$('a').click(function(){  
	    $(this).blur();
    });
    
    
    $('a[rel=top]').live('click', function(){
    	$.scrollTo(0, { duration: 800 });
    	
    	return false;
    });
    
	
	
	
	$("#team .column1 ul a").each(function() {
	
		
		$(this).click(function(){
			var link = $(this).attr("href");
			var id = link.substr(link.lastIndexOf("=")+1);
			switchTeamMember(id);
			switchTeamMemberDescription(id);
			return false;
		});
	});
	
	
	/*
$('a[rel=backtooverview]').click(function() {
		
		$.scrollTo("#container", 500);
		
		return false;
	});
*/
});


jQuery.easing.def = 'easeOutQuart';

jQuery.fn.sort = function() { 
    return this.pushStack( [].sort.apply( this, arguments ), []); 

}; 


function switchTeamMember(id) {
	$('#flash_wrapper').get(0).selectMember(id);
}


function switchTeamMemberDescription(id) {
	startLoading('#memberReload');
	$("#memberReload").load("index.php?article_id="+id, memberLoaded);
}

function memberLoaded (responseText, textStatus, XMLHttpRequest) {
	endLoading('#memberReload');
	$.scrollTo("#memberReload", 500);
}

