  $(document).ready(function() {

	var ie = false;
	if ($.browser.msie) {
		ie = true;
	}

	setBar();
	$(window).resize(function() {
		setBar();
	});
	
   $("a#login-link").click(function(e){
	   $("#heckle").submit();
	   e.preventDefault();
   });
   
   var arVersion = navigator.appVersion.split("MSIE");
   var version = parseFloat(arVersion[1]);
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   } 
	 
	var resetSearch = true
	$("#design-search input").focus(function() {
	  if (resetSearch) {
		  $(this).val("");
			resetSearch = false;
		}
	});
	
	var resetEmail = true
	$("#email-capture-container input").focus(function() {
	  if (resetEmail) {
		  $(this).val("");
			resetEmail = false;
		}
	});
	
	/* Create button active state for IE */
	var activeClass = "";
	$("input:submit").mousedown(function() {
		activeClass = $(this).attr("id") + "-active";
		if (ie) {
			$(this).addClass(activeClass);
		}
	}).mouseup(function() {
		if (ie) {
			$(this).removeClass(activeClass);
		}
	});
	
	$("#email-submit").click(function() {
	  $("#email-capture-window").css({"top":$(this).offset().top+40,"left":$(this).offset().left-180}).slideDown();
	});
	
	$("#email-capture-enter, #email-window-close").click(function() {
	  $("#email-capture-window").slideUp();
	});
	
	$("#email-window-close").mouseover(function() {
	  $(this).css("cursor","pointer");
	});

	$(".window-print").click(function(e) {
	  window.print();
	  e.preventDefault();
	});
	
	$(".custom-select").each(function() {
	  $(this).before('<span class="select"></span>');
		var selectOverLay = $(this).prev(".select");
		selectOverLay.append('<span class="select-down"></span>');
		var displayText = $(this).find(":selected").text();
		var thisWidth = parseInt($(this).css("width"));
		selectOverLay.css("width",thisWidth+13).append('<div class="select-text">'+displayText+'</div>');
		selectOverLay.after('<ul class="select-options"></ul>');
		var optionsBox = selectOverLay.next("ul.select-options");
		optionsBox.css({"min-width":thisWidth+3});
		var options = $(this).find("option");
		$.each(options, function(i) {
		  if ($(this).is(":selected")) {
			optionsBox.append('<li class="opt-active">'+$(this).text()+'</li>');
		  } else {
			optionsBox.append('<li>'+$(this).text()+'</li>');
		  }
		});
	});
	
	$(".select").click(function() {
	  $("ul.select-options").not($(this).next()).slideUp(100);
	  $(this).next("ul.select-options").css({"top":$(this).offset().top+32,"left":$(this).offset().left+3}).toggle(100);		
	});
	
	$(document).bind("click",function(e) {
	  var target = $(e.target);
		if (!target.parents().hasClass("select")) {
	    $("ul.select-options").slideUp(100);
		}
	});
	
	$("ul.select-options li").click(function() {
		$(this).siblings("li").removeClass("opt-active");
		$(this).addClass("opt-active");
	    var nthSelect = $("ul.select-options").index($(this).parent());
		//alert(nthSelect);
		var selectIndex = $("ul.select-options:eq("+nthSelect+") li").index(this);
		var selectObj = $(this).parent().next();
		selectObj.find("option:eq("+selectIndex+")").attr("selected",true);
		$("ul.select-options").slideUp(100);
		var displayText = selectObj.find("option:selected").text();
		//alert(displayText);
		$(".select-text:eq("+nthSelect+")").text(displayText);
		selectObj.change();
	});
	
	$("select").focus(function() {
		$(this).prev().prev(".select").addClass("select-focus");
		$(this).prev().prev(".select").find(".select-down").addClass("select-down-focus");
	});
	
	$("select").blur(function() {
		$(this).prev().prev(".select").removeClass("select-focus");
		$(this).prev().prev(".select").find(".select-down").removeClass("select-down-focus");
	});
	
	$(".close-button").click(function(e) {
	  cancelPopup();
	  e.preventDefault();
	});
	
	$("#footer-promo-content a").click(function(e) {
		e.preventDefault();
	});
		
  });
	
	window.onload = function() {
		setBar();
	}
	
	function lightBox() {
		$("body").append('<div id="lightbox-bg"></div>');
		$("#lightbox-bg").css({"width":$(document).width(),"height":$(document).height(),"top":"0","left":"0"}).show();	
	}
	
	function resetLightBox() {
		if ($("#lightbox-bg").length > 0) {
			$("#lightbox-bg").css({"width":$(document).width(),"height":$(document).height(),"top":"0","left":"0"}).show();
		}
	}
	
	function closeLightBox() {
		$("#lightbox-bg").remove();
	}
	
	function setBar() {
		$("#body-wrapper").height($(document).height()-10);	
	}
	
	function updateSelect(what) {
		var overlayObj = what.prev();
		var objSelectedIndex = what.attr("selectedIndex");
		var overlayObjSelected = $(overlayObj).find("li").eq(objSelectedIndex);
		$(overlayObj).find("li").removeClass("opt-active");
		overlayObjSelected.addClass("opt-active");
		overlayObj.prev().find(".select-text").text(overlayObjSelected.text());
	}
	
	// For SFV
	var params = {wmode: "opaque"};
	
	function face(templateId) {
		 return eval("face"+templateId);
	}
	
	function closeRelatedLightBox() {
		 parent.closeSFDWin();
	     var newUrl = parent.location.href;
	     parent.location = newUrl;
	}
	
	function closeSFV() {
		 closeLightBox();
		 $("#sfv-window").fadeOut();
	}
	
	function cancelPopup() {
		closeLightBox();
		$("iframe.pop-window-body").attr("src","/sfd/plain.html");
		$(".pop-window-body").html("");
		$(".med-pop-window, .dyn-pop-window").hide();
		$("#acct-ae-window").hide();
	}
	
	function waitIcon() {
	  lightBox();
	  $("body").append('<div class="wait-icon"></div>');
	  $(".wait-icon").css({"top":$(window).height()/2+$(document).scrollTop()-16,"left":$(document).width()/2-16});
	}
	
	function closeWaitIcon() {
		closeLightBox();
		$(".wait-icon").remove();
	}
