$(document).ready(function(){

		// IMAGE
		$("div#ListImage div#Preview a").click(function() {
			return false;
		});
		
		$("div#ListImage div#Thumbnail a.aImg").click(function() {
			$(".PreVDO").hide();
			$(".PreImg").show();
			$("div#ListImage div#Thumbnail a.VImg").css( {opacity: 0.5} );
			return false;
		});

		$("div#ListImage div#Thumbnail a.aImg").not(".delete").each(function() {
			$(this).css({opacity: 0.5});
			/*$(this).mouseover(function() {
				if ( $(this).attr("href").length > 0 ) {
					$(this).not(".active").animate( {opacity: 1 }, "fast" );
					$(this).click();
				}
			});
			$(this).mouseout(function() {
				if ( $(this).attr("href").length > 0 ) {
					$(this).not(".active").animate( {opacity: .5 }, "fast" );
				}
			});*/

			$(this).click(function(e) {
				e.preventDefault();
				if ( $(this).attr("href").length > 0 ) {
					
					$("div#ListImage div#Thumbnail a.aImg").removeClass("active");
					$("div#ListImage div#Thumbnail a.aImg").css( {opacity: 0.5} );
					$(this).addClass("active");
					$(this).css( {opacity: 1} );

					if ( $("div#ListImage div#ImgDesc").length == 0 ) {
						$('<div id="ImgDesc"></div>').insertAfter("div#ListImage div#Preview")
					}
					$("div#ListImage div#ImgDesc").empty();
					$("div#ListImage div#ImgDesc").hide();
					$("div#ListImage div#ImgDesc").css( {opacity: 0.7} );

					$("div#ListImage div#Preview img").hide();
					var img = new Image();
					$(img).hide();
					$(img).load(function() {
						
						$("div#ListImage div#Preview img").attr("src", $(this).attr("src"));
						//$("div#ListImage div#Preview a").css("background", "url('"+$(this).attr("src")+"') no-repeat center center");
						// fade our image in to create a nice effect

						if ($("div#ListImage div#ImgDesc").length > 0 && $(this).attr("title").length > 0 ) {
							$("div#ListImage div#ImgDesc").html( $(this).attr("title") );
							$("div#ListImage div#ImgDesc").fadeIn();
							//alert("Show")
							$("div#ListImage div#Preview img").fadeIn("normal", function() {$("div#ListImage div#ImgDesc").fadeIn();} );
						} else {
							$("div#ListImage div#Preview img").fadeIn();
						}
						//$("div#ListImage div#Preview a").lightbox( {} );
					});
					//$(img).attr("title", $(this).attr("title"));
					$(img).attr("src", $(this).attr("href"));
					if( $(this).attr("title").length > 0 ){
						$("div#ListImage div#Preview a").attr("href", $(this).attr("title"));
						$("div.Enlarge a#imgLink").attr("href", $(this).attr("title"));
						$("div.Enlarge a#coverImgLink1").attr("href", $(this).attr("title"));
						$("div.Enlarge").show();
					}
					else{
						$("div.Enlarge").hide();
					}
				}
				return false;
			});
		});
		if ( $("div#ListImage div#Thumbnail a.aImg").length > 0 ) { // Active Attachment
			$("div#ListImage div#Thumbnail a.aImg:first").click();
		}

});

$('a').click(function(){ $(this).blur(); })

function validateField(field) {
	var error = false;

	// remove whitespace
	$(field).val( jQuery.trim( $(field).val() ) );

	// required fields
	if ($(field).attr("class").indexOf("required") != -1) {
		if (!$(field).val().length)
			error = true;
	}
	// numeric fields
	if ($(field).val().length && $(field).attr("class").indexOf("numeric") != -1) {
		if (!/^[0-9]*$/.test($(field).val()))
			error = true;
	}
	// float fields
	if ($(field).val().length && $(field).attr("class").indexOf("float") != -1) {
		$(field).val( formatCurrency( $(field).val() ) );
		if (!/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/.test($(field).val()))
			error = true;
	}
	// emails
	if ($(field).val().length && $(field).attr("class").indexOf("email") != -1) {
		if (!/^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/.test($(field).val()))
			error = true;
	}
	// url
	if ($(field).val().length && $(field).attr("class").indexOf("url") != -1) {
		if (!/^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i.test($(field).val()))
			error = true;
	}

	if (error) {
		$(field).addClass("focus");
	} else {
		$(field).removeClass("focus");
	}

	return !error;
}

