var resizeFirst = true;
var resizeRatio = {hProp:0,wProp:0};
var resizeMax = {x:0,y:0};

$(function() {
	$("ul").hide();
	$(".size_list").hover(
		function() {
			$("#size").slideDown();
		}, function() {
			$("#size").slideUp();
		}
	)
	$(".color_list").hover(
		function() {
			$("#color").slideDown();
		}, function() {
			$("#color").slideUp();
		}
	)
	
	$(window).resize(function() {
		$(".resize").resizeProp();
	});
	$(".resize").resizeProp();
	
	$('#input_service').keyup(function(e) {
		if(e.keyCode == 13) window.location = "./"+$("#service").val()+"/"+$("#input_service").val()
	});
	$('#input_url').keyup(function(e) {
		if(e.keyCode == 13) window.location = "./"+$("#input_url").val()
	});

})

NS4 = (document.layers) ? true : false;
function checkEnter(event, service) {     
    var code = 0;
	if (NS4) {
		code = event.which;
	} else {
		code = event.keyCode;
	}
	if(code == 13) window.location = "./"+service+document.getElementById('p').value
}

(function($){  
	$.fn.extend({    
		resizeProp: function(options) {  
			var defaults = {  
				marginWidth: 50,
				marginHeight: 50,
				minimum: 100
			};  
			var options = $.extend(defaults, options);  

			return this.each(function() { 
				if(resizeFirst) {
					resizeRatio.wProp = $(this).attr("width")/$(this).attr("height");
					resizeRatio.hProp = $(this).attr("height")/$(this).attr("width");
					resizeMax.w = $(this).attr("width");
					resizeMax.h = $(this).attr("height");
					resizeFirst = false;
				}  
				var sWidth = Math.max($(window).width() - options.marginWidth, options.minimum);
				var sHeight = Math.max($(window).height() - options.marginHeight, options.minimum);
				
				if(sHeight >= sWidth) {
					if(resizeRatio.hProp <= (sHeight/sWidth)) {
						$(this).attr("width",sWidth)
						$(this).attr("height",$(this).attr("width") / resizeRatio.wProp)
					} else {
						$(this).attr("height",sHeight)
						$(this).attr("width",$(this).attr("height") / resizeRatio.hProp)
					}
				} else {
					if(resizeRatio.wProp <= (sWidth/sHeight)) {
						$(this).attr("height",sHeight)
						$(this).attr("width",$(this).attr("height") / resizeRatio.hProp)
					} else {
						$(this).attr("width",sWidth)
						$(this).attr("height",$(this).attr("width") / resizeRatio.wProp)
					}
				}
				
				$(this).attr("width",Math.min($(this).attr("width"), resizeMax.w))
				$(this).attr("height",Math.min($(this).attr("height"), resizeMax.h))	
				if($(this).find("embed")) {
					$(this).find("embed").attr("width",$(this).attr("width"))
					$(this).find("embed").attr("height",$(this).attr("height"))
				}		
				
				$("#spacer").attr("width", $(this).attr("width"))
				$("#spacer").attr("height", $(this).attr("height"))
				$("#spacer").css('marginLeft', -$(this).attr("width"))
				$("#loading").css("display", "none");
				
			});  
		}  
	});  
})(jQuery);
