function showMedia(id) {
	$("#image-detail").load("/media.php?item_id="+id);
	return id;
}


function showImage(id) {
	$("#overlay-image").load("/overlay.php?item_id="+id);
	$("#layer-artist").show();
}

function hideImage() {
	$("#layer-artist").hide();
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 5000, function() {
            $active.removeClass('active last-active');
        });
}


function showMenu() {
	//$("#layer-menu").fadeTo("slow", 0.99, function () { $("#layer-menu").show(); });
	//if ($("#layer-menu div:visible")) { $("#layer-menu").show(1000); };
	$("#layer-menu").fadeIn(1000); 
	/*
	$("#layer-menu").animate({ 
        width: "1000px",
				opacity: 1
      }, 1000 );
	*/
	//$("#layer-menu").animate({"opacity": "0.90"}, "slow");  
}

function showContact(name) {
	$("#layer-extra").fadeIn().find('.overlay').load("/contact.php?item_id=" + item_id, function() {
							if(name) {
								$('.preview').hide();
								$('.artist-text').html('Artiest:<br />' + name);
							} else {
								$('.preview').attr('src', $('#image-detail img').attr('src').replace('images', 'images/thumb'));
							}
		           $('#contact').ajaxForm(function() { 
                $("#contact").parent().html('Uw bericht is opgestuurd. We beantwoorden uw vraag zo spoedig mogelijk.<br /><br /><a href="javascript:hideMenu()">terug</a>');
            }); 																																																												 
	});	
}

function showRegistreer() {
	$("#layer-extra").fadeIn().find('.overlay').load("/index.php?a=user/add", function() {																																																												           $('#register_form').ajaxForm(function() { 
                $("#register_form").parent().html('Uw account is aangemaakt maar wacht op activatie. In uw mailbox vindt u een e-mail met daarin instructies om uw account te activeren.<br /><br /><a href="javascript:hideMenu()">terug</a>');
            });
	});		
}

function showLogin() {
	$("#layer-extra").fadeIn().find('.overlay').load("/index.php?a=user/loginform", function() {
																																																											 
	});		
}


function hideMenu() {
	//$("#layer-menu").fadeTo("slow", 0, function () { $("#layer-menu").hide(); });
	//$("#layer-menu").hide(1000);
	if($("#layer-menu:visible").length) {
		$("#layer-menu").fadeOut(1000);
	}
	if($("#layer-extra:visible").length) {
		$("#layer-extra").fadeOut(1000);
	}
	/*
	$("#layer-menu").animate({ 
        width: "100px",
				opacity: 0
      }, 1000 );
	*/
}

var last_media_id = 0;
var first_image_html = '';

$(document).ready(function() {
	if($('#image-detail')) {
		first_image_html = $('#image-detail').html();
	}
	
	$('.tipsy-link').tipsy({html: true, gravity: $.fn.tipsy.autoNS, fade: true});
	
	$("#serie #image-thumbs .thumb").bind('click', function(evt) {
		last_media_id = showMedia($(this).attr('id').replace('thumb_', ''));
		$(this).unbind('mouseleave');
		return false;
	});
	
	$("#serie #image-thumbs .thumb").bind('mouseover', function(evt) {
		showMedia($(this).attr('id').replace('thumb_', ''));	
		return false;
	});
	
	$("#serie #image-thumbs").bind('mouseleave', function(evt) {
			if(last_media_id) {
				showMedia(last_media_id);
			} else {
				$("#image-detail").html(first_image_html);
			} 		
	});
	
	$("#navigation .artist a").bind('mouseover', function() {
		$('.short').each(function() {
				if($(this).css('visibility') == 'visible') {
					$(this).css('visibility', 'hidden');		
				}
		});
		

		$(this).parent().find('.short').css('visibility', 'visible');	
		$(this).parent().find('.short').fadeIn('fast');

	});
	
	$('.serie-background').bind('mouseover click', function() {
		$(".serie_info").html($(this).attr('data'));	
		return false;
	});
	
	$('.showMenu').bind('click mouseover', function() { showMenu(); return false; });
	$('.showContact').live('click', function() { showContact(); return false; });
	$('.showRegistreer').bind('click', function() { showRegistreer(); return false; });
	$('.showLogin').bind('click', function() { showLogin(); return false; });
	$('body').bind('click', function() { hideMenu();  });
	$("#layer-extra").bind('click', function(event) { event.stopPropagation(); });
	
	
	/*$('#guestbook_form, #contact_form').validate();*/
	
});
