$(document).ready(function(){
  SetBottom();
  ActiveProductMenu();
  InsertPicturesInstaeadOfSmallTag();	
  $("#language_box").hide();
  $("#language").mouseover(function(){
      $("#language_box").show();
    })
  $("#language").mouseleave(function(){
      //$("#language_box").hide();
  });
  $("#language_box").mouseleave(function(){
      $("#language_box").hide();
  });
});
$(window).resize(function(){
  SetBottom();
});
function SetBottom()
{
  $("#bottom").css("width", $(window).width() + "px");
  $("#bottom").css("left", ($("#content").width() / 2) - ($(window).width()/2) + "px");  
}
function ActiveProductMenu()
{
    $(".small_product").mouseover(function(){
	$("#show_product_title").html($(this).attr("title"));
	$("#show_product_text").html($(this).attr("description"));
	$("#show_product").stop();
	$(this).animate({opacity: 1});
	$("#show_product").animate({opacity: 1});	
    }).mouseout(function(){
	$("#show_product").stop();
	$("#show_product").animate({opacity: 0});
	$(this).animate({opacity: .8});
    });
}
function InsertPicturesInstaeadOfSmallTag()
{
   $(".tooltip small").each(function (i) {
        if($(this).html() != "small")
	{
		if($(this).html().replace(/^\s+|\s+$/g,"") != "")
		{
			var img_url = $(this).html();
			$(this).css("position", "relative");
			$(this).html("<img alt='' src='" + img_url + "' style='position: absolute; left: 0px; top: -46px;' />");
		}
	
		var legend = $(this).parent().parent().get(0);	
		$(legend).children(".control").each(function (i) {
			var control = $(this);
			$(this).css("position", "relative");
			$(this).css("padding-top", "22px");
			$(this).children("input").css("width", "65px").css("left", "234px").css("top", "0px").css("position", "absolute");
        	});

		var header = $(this).parent().parent().parent().get(0);
		$(header).children("legend").each(function (i) {
			var text = $(this).html();
			$(this).parent().append("<div style='position: absolute; left: 40px; top: -25px; white-space: nowrap;'><b>" + text + "</b></div>")
			$(this).css("display", "none");
        	});

		$(legend).children(".fieldLabel").css("width", "301px").css("white-space", "nowrap").css("padding-left", "40px").css("line-height", "20px");
	}
	else
	{
		$(this).html("");
		var legend = $(this).parent().parent().get(0);	
		$(legend).children(".control").each(function (i) {
			var control = $(this);
			$(this).css("position", "relative");
			$(this).children("input").css("width", "65px").css("left", "234px").css("position", "absolute");
        	});
		$(legend).children(".fieldLabel").css("width", "auto").css("white-space", "nowrap").css("padding-left", "0px").css("line-height", "20px");
	}
   });
   $(".Required").each(function (i) {
	if($(this).html() == "disabled")
	{
		var legend = $(this).parent().parent().get(0);	
		$(legend).children(".control").each(function (i) {
			$(this).children("input").removeAttr("style");
			$(this).children("input").attr("style", "width: 65px; left: 234px; top: 0px; position: absolute;");
			$(this).children("input").removeClass("text");
			$(this).children("input").addClass("disabled");
			$(this).children("input").attr("disabled", "disabled");
        	});
	}
	else
	{
		var legend = $(this).parent().parent().get(0);	
		$(legend).children(".control").each(function (i) {			
			$(this).children("input").attr("disabled", "");
        	});
	}
   });
}
