$(document).ready(function() {
	$(function() {
		$('.submenu').slideToggle(0);
	    });


	$('.art').click(function() {
		$('.submenu:eq(0)').slideToggle(1000);
	    });				 

	$('.artist').click(function() {
		$('.submenu:eq(1)').slideToggle(1000);
	    });

	$('.resource').click(function() {
		$('.submenu:eq(2)').slideToggle(1000);
	    });

	$('.news').click(function() {
		$('.submenu:eq(3)').slideToggle(1000);
	    });

	$('.commish').click(function() {
		$('.submenu:eq(4)').slideToggle(1000);
	    });

	$('img.placeholder').load(placeHolderLoaded);

	$('#charartthumb a').click(function(event) {
		event.preventDefault();
		var image =  $(this).attr('href');
		var description = $(this).attr('title');
		$(this).effect("transfer", { to: '.placeholder' }, 1000, function() {
			$('p.desc').fadeOut(500);
			$('img.placeholder').fadeOut(500, function() {
				$('p.desc').empty();
				$('p.desc').append(description);
				$('#load').fadeIn(500, function() {
					fadeInDone();
				    });
				$('img.placeholder').attr('src', image);
			    });
		    });
	    });



	$('#portraitart a').click(function(event) {
		event.preventDefault();
	});

	$(function() {
		$('#portraitart img').animate({opacity: .5}, 0);
	    });

	$('#portraitart img').hover(
	function(over) {
		$(this).animate({opacity: 1}, 500);
	},
	function(out) {
		$(this).animate({opacity: .5}, 500);
		});
  	});

var fadeInFlag;
var placeholderFlag;

function fadeInDone() {
    fadeInFlag = true;
    checkForFadeInAndPlaceHolder();
}

function placeHolderLoaded() {
    placeholderFlag = true;
    checkForFadeInAndPlaceHolder();
}

function checkForFadeInAndPlaceHolder() {
    if (fadeInFlag && placeholderFlag) {
	fadeInFlag = placeholderFlag = false;
	$('#load').fadeOut(500, function() {
		$('img.placeholder').fadeIn(500);
		$('p.desc').fadeIn(500);
	    });   
    }
}




this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 10;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Loading...' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});

