$(document).ready(function(){
	

	$("input#search").click(function(){
		$(this).select();
	});
	
	$("div.piece").hover(function(){
			$(this).find("div.piece_stats").fadeIn(500);
			//$(this).css("border","1px solid gray");
			//$(this).animate({border : "1px solid gray"}, 1000);
		},function(){
			$("div.piece_stats:visible").fadeOut('fast');
			//$(this).css("border","1px solid #f1f1f1");
			//$(this).animate({border : "1px solid #f1f1f1"}, 500);
		});
	
		
	
	$("div.piece").click(function(){
		var link = $(this).find('a').attr('href');
		window.location = link;

	});


     	$("form.contactform textarea").keyup(function(){
			var countem = $(this).val().length;
			if(countem > 300) {
				$("span#charnum").css({"color":"red","background":"none"});
			} else if(countem < 301) {
				$("span#charnum").css({"color":"#000","background":"none"});
			}
			$("span#charnum").text(countem);
			
		});	
	

	
		var image = $("form.contactform select[name='artwork']").val();
	
		$.ajax({
			
					type: "GET",
					url: "ajax.php",
					data: "artwork=" + image,
					success: function(txt){
						  if(txt != '')
							$("td#imgpreview img").attr('src','art/thumbs/t_'+txt);  
					}
		});


	
	$("form.contactform select[name='artwork']").change(function(){
		var image = $(this).val();
		//$("td#imgpreview img").attr('src',image);
	
		$.ajax({
			
					type: "GET",
					url: "ajax.php",
					data: "artwork=" + image,
					success: function(txt){
						  if(txt != '')
							$("td#imgpreview img").attr('src','art/thumbs/t_'+txt);  
					}
		});
	});
	
	
	$("div#showHideComments").click(function(){
		if($(this).text() == 'Show Comments') {
			$(this).text('Hide');
			$('div#comments p').slideDown();
			$('div#viewer_nav ul li a').each(function(){
				var link = $(this).attr('href');
				link = link.replace("c=hide","c=show");
				$(this).attr('href',link);
			});
			
			var plink = $('a#prevLink').attr('href');
			plink = plink.replace("c=hide","c=show");
			$('a#prevLink').attr('href',plink);
			
			var nlink = $('a#nextLink').attr('href');
			nlink = nlink.replace("c=hide","c=show");
			$('a#nextLink').attr('href',nlink);
		
		} else {
		
			$(this).text('Show Comments');
			$('div#comments p').slideUp();
			$('div#viewer_nav ul li a').each(function(){
				var link = $(this).attr('href');
				link = link.replace("c=show","c=hide");
				$(this).attr('href',link);
			});
			
			var plink = $('a#prevLink').attr('href');
			plink = plink.replace("c=show","c=hide");
			$('a#prevLink').attr('href',plink);
			
			var nlink = $('a#nextLink').attr('href');
			nlink = nlink.replace("c=show","c=hide");
			$('a#nextLink').attr('href',nlink);
		}
	});
	
	
});


var myimages=new Array()
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}


function disp_confirm(formID)
{
	if (confirm("Are you sure you want to delete this?"))
		{
		document.getElementById(formID).action.value = 'delete';
		document.getElementById(formID).submit();
		}
	else
		{
		return false;
		}
}


function changeStyle(id,newstyle) {

if (document.getElementById)
   {
   var nodeObj = document.getElementById(id)
   nodeObj.style.display = newstyle;
   }
}
