function center_div()
{
	var winH = $(window).height();
	var posY = (winH - $('#enquire_window').height()) / 2 + $(window).scrollTop();
	$('#enquire_window').stop().animate({'top':posY}, 100); 
}
function close_mask()
{
	$('#mask').fadeTo(500, 0, function(){$('#mask').hide();});	
	$('#enquire_window').fadeTo(500, 0, function()
		{
			$('#enquire_window').hide();
			$('#enquire_window').html('');
		}
	);	
}
function exhibition_info()
{
	$(".artist_bio").click(function()
			{
				$('#artwork_canvas_thumb').css('display', 'none'); 				
				var id  = $(this).attr('id').replace('artist_', '');
				$('#exhibition_details').html('');
				$('#exhibition_details').load('/exhibition/artist_bio.php?id='+id);
				$('#exhibition_details').css('display', 'block'); 
				return false;
			}
		);
	$(".press_release").click(function()
			{
				$('#artwork_canvas_thumb').css('display', 'none'); 				
				var id  = $(this).attr('id').replace('press_release_', '');
				$('#exhibition_details').html('');
				$('#exhibition_details').load('/exhibition/press_release.php?id='+id);
				$('#exhibition_details').css('display', 'block'); 
				return false;
			}
		);
	$(".curator").click(function()
			{
				$('#artwork_canvas_thumb').css('display', 'none'); 				
				var id  = $(this).attr('id').replace('curator_', '');
				$('#exhibition_details').html('');
				$('#exhibition_details').load('/exhibition/curator.php?id='+id);
				$('#exhibition_details').css('display', 'block'); 
				return false;
			}
		);
		
		
	$(".artwork_info").click(function()
			{
				$('#exhibition_details').css('display', 'none'); 
				$('#artwork_canvas_thumb').css('display', 'block'); 
				return false;
			}
		);
	$(".canvas_large").click(function()
			{
				var id  = $(this).attr('id').replace('canvas_large_', '');
				$('#artwork_fullscreen').html('');
				$('#artwork_fullscreen').load('/exhibition/artwork.php?id='+id, function() 
						{
							$('#exhibition_container').hide();
							$('#artwork_fullscreen').show();
							$(window).scrollTop(0);
						}
					);
				return false;
			}
		);
	$(".full_screen").click(function()
			{
				var id  = $(this).attr('id').replace('full_screen_', '');
				$('#artwork_fullscreen').html('');
				$('#artwork_fullscreen').load('/exhibition/artwork.php?id='+id, function() 
						{
							$('#exhibition_container').hide();
							$('#artwork_fullscreen').show();
							$(window).scrollTop(0);
						}
					);
				return false;				
			}
		);
	enquire();
	close_full_view();	
}
function close_full_view()
{
	$(".close_full_view").click(function()
		{
			$('#artwork_fullscreen').hide();
			$('#exhibition_container').show();
			return false;				
		}
	);
}
function enquire()
{
	$(".enquire").click(function(e) {
		var id  = $(this).attr('id').replace('enquire_', '');
		e.preventDefault();
		
		$('#enquire_window').html('');
		$('#enquire_window').load('/contact/enquiry.php');
		$('#enquire_window').css('height', '550px');
		
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').fadeTo(500, 0.5);	
		$('#mask').show();
		//Get the window height and width
		
		var winH = $(window).height();
		var posY = (winH - $('#enquire_window').height()) / 2 + $(window).scrollTop();
		var winW = $(window).width();
		$('#enquire_window').css('top',  posY+'px');
		$('#enquire_window').css('left', winW/2-$('#enquire_window').width()/2);
		$('#enquire_window').fadeTo(500, 1);	
		$('#enquire_window').show(); 	
		return false;
		
	});
	$('#mask').click(function ()
	{
		close_mask();
	});	
	$(window).scroll(function(){ 
		center_div();
	});
}
function collection_thumbs()
{	 
	$(".artwork_view").click(function()
		{	
			
			var id  = $(this).attr('id').replace('canvas_large_', '');
			$('#artwork_fullscreen').html('');
			$('#artwork_fullscreen').load('/exhibition/artwork.php?id='+id, function() 
					{
						$('#exhibition_container').hide();
						$('#artwork_fullscreen').show();
						$(window).scrollTop(0);
					}
				);
			return false;			
		}
	);
}
function menu_hover()
{
	$("#menu_link").hover(function()
	{ 
		$("#main_menu").css('display', 'block'); 
 	});
 	$("#menu_link").mouseout(function() 
		{ 
      	t = setTimeout(function()
      		{  
					$("#main_menu").css('display', 'none'); 
            }, 500); // adjust your time here 
    });
    $("#main_menu").mouseover(function()
    	{ 
	    	clearTimeout(t);
			$("#main_menu").css('display', 'block'); 
    	});	
	
    $("#main_menu").mouseout(function() 
		{ 
      	t = setTimeout(function()
      		{
					$("#main_menu").css('display', 'none'); 
            }, 500); // adjust your time here 
    }); 
    
}
function footer_signup()
{
	$('#signup_link').click(function()
		{
			close_box();
			return false;
		}
	)
	$('#btnClose').click(function()
		{
			close_box();
		}
	)		
	$('#signup_fname').focus(function()
		{
			if ($('#signup_fname').hasClass('comm'))
			{
				$('#signup_fname').removeClass("comm");
				$('#signup_fname').addClass("comm_selected");
				$('#signup_fname').val('');	
			}			
		}
	)	
	$('#signup_email').focus(function()
		{
			if ($('#signup_email').hasClass('comm'))
			{
				$('#signup_email').removeClass("comm");
				$('#signup_email').addClass("comm_selected");	
				$('#signup_email').val('');
			}			
		}
	)	
	$('#btnSubmit').click(function()
		{
			signup();
		}
	)
}
function signup()
{
	var post_data = encodeURI("fname="+$('#signup_fname').val()+"&email="+$('#signup_email').val());
	var data;
	$.ajax({
		type: "POST",
		url: "/signup/",
		data: post_data,
		success: function(msg)
			{
				parseMsg(msg);     		
		   }
		}
	);
}
function parseMsg(msg)
{
	var data = $.parseJSON(msg);
	if (data.error == 1)
	{
		$('#msg').html('<p class="err_comm">'+data.error_msg+'</p>');
	}
	else if (data.error == 0)
	{
		$('#msg').html('<p class="succ">You have been successfully added to our mailing list.</p>');
		reset_signup_box()
	}
}
function close_box()
{
	if ($('#signup_box').css('display') == 'block')
	{
		$('#signup_box').css('display', 'none');
		reset_signup_box();
	}
	else
	{
		$('#signup_box').css('display', 'block');
	}
}
function reset_signup_box()
{
	$('#signup_fname').removeClass("comm_selected");
	$('#signup_fname').addClass("comm");
	$('#signup_fname').val('enter your name here');	
	
	$('#signup_email').removeClass("comm_selected");
	$('#signup_email').addClass("comm");	
	$('#signup_email').val('enter your email address here');
}
