jQuery.noConflict();
var imageCount;
var imagesReady=0;

jQuery(function() {
	imageCount = jQuery('img').length;
	
	jQuery('img').each(function(){
		jQuery(this).load(function(){
			imagesReady++;
				setNewHeight();
		});
	});
	
	setArtVars();
	setNewHeight();
	jQuery(window).resize(
		function() {
			setNewHeight();
		}
	);
	if (document.artistcount > 0)
		initSlider();

	jQuery('.artist_name').hover(
		function() {
			showArtist(this);
		}
		,
		function() {
			initSlider();
		}
	);
	jQuery('.artist_name.foldable>a').click(
		function(){
			if(jQuery(this).parent().find('.photo_strip:visible').length){
				jQuery(this).parent().find('.photo_strip').hide(600);
				jQuery(this).parent().css('box-shadow','none');
			}else if(jQuery(this).parent().find('.photo_strip').length){
				jQuery('.photo_strip').hide(600);
				jQuery('.artist_name').css('box-shadow','none');
				jQuery(this).parent().find('.photo_strip').show(600);
				jQuery(this).parent().css({'box-shadow':'0px 0px 5px #666'});
			}
			return false;
		}
	);
});


function setNewHeight() {
	jQuery('html, body, #main').height(Math.max(jQuery('#height_wrapper').height()- 30, jQuery(window).height() - 60) + 'px');
	//jQuery('#impressum').top(Math.max(jQuery('#height_wrapper').height()- 40, jQuery(window).height() - 70) + 'px');
}

function setArtVars() {
	document.artistcount = jQuery('.artist_portrait').length;
	document.art_id = Math.round((document.artistcount - 1) * Math.random());
}

function showArtist(object) {
	if (typeof document.slideInterval != 'undefined')
		window.clearInterval(document.slideInterval);
	var currentname = jQuery(object).find('a span').attr('class');
	
	fadeArtist(jQuery('.artist_portrait img[alt="' + currentname + '"]').parent());
}

function initSlider() {
	if (typeof document.slideInterval != 'undefined')
		window.clearInterval(document.slideInterval); 
		
	document.slideInterval = window.setInterval('slideArtists()', 2500);
}

function slideArtists() {
	if (typeof document.art_id == 'undefined' || typeof document.artistcount == 'undefined')
		return;
	fadeArtist(jQuery('.artist_portrait:eq(' + document.art_id + ')'));
	if (document.art_id >= (document.artistcount - 1))
		document.art_id = 0;
	else
		document.art_id++;
}

function fadeArtist(jQObject) {
	if (jQObject.length < 1 || jQObject.hasClass('active'))
		return;
	var currentname = jQObject.find('img').attr('alt');
	jQuery('.artist_name a span').removeClass('active');
	jQuery('.artist_name a span.' + currentname).addClass('active');
	//alert();
	jQuery('.artist_portrait').removeClass('active').fadeOut(750);
	jQObject.addClass('active').fadeIn(750);
}
