﻿// JavaScript Document

$(document).ready(function(){

});

// When text focus
function PromptClear(field,Word){
	if ( $(field).val()==Word ){
		if ( Word=="http://" ){
			$(field).val("http://");
			if(navigator.userAgent.indexOf("MSIE")>0) {
				var range = field.createTextRange();   
				range.collapse(true);   
				range.moveStart('character', 7);   
				range.select();
			}
		}
		else { $(field).val(""); }
	    $(field).removeClass("thingray");
	}
}

// When text blur
function PromptCheck(field,Word){
    if ( $(field).val()=="" || $(field).val()==Word ){
	    $(field).val(Word);
		$(field).addClass("thingray");
	}
	if ( $(field).val()=="http://" ){
	    $(field).val(Word);
		$(field).addClass("thingray");
	}
}

(function($){ 
    
$.fn.LoadImage=function(options){
	return this.each(function(){
  
		var defaults = { 
			width: 100,
			height: 100,
			loading:"loading.gif"
		};
		var opts = $.extend(defaults, options);
		
		var t=$(this);
		var src=$(this).attr("src")
		var img=new Image();
		img.src=src;

		var autoScaling=function(){
			if(img.width>0 && img.height>0){ 
				if(img.width/img.height>=opts.width/opts.height){ 
					if(img.width>opts.width){ 
						t.width(opts.width); 
						t.height((img.height*opts.width)/img.width); 
					}else{ 
						t.width(img.width); 
						t.height(img.height); 
					} 
				} 
				else{ 
					if(img.height>opts.height){ 
						t.height(opts.height); 
						t.width((img.width*opts.height)/img.height); 
					}else{ 
						t.width(img.width); 
						t.height(img.height); 
					} 
				} 
			}
		}
		
		t.hide();
		
		if(img.complete){
			autoScaling();
			t.show();
		    return;
		}
		
		$(this).attr("src","");
		var loading=$("<img alt=\"Loading ...\" title=\"Photo Loading ...\" src=\"images/"+opts.loading+"\" class=\"loadpic\" />");
		t.after(loading);
		loading.show();
		
		$(img).load(function(){
			autoScaling();
			loading.remove();
			t.attr("src",this.src);
			t.fadeIn();
		});
		
	});
}

})(jQuery);

