function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

jQuery(document).ready(function($) {

	$("span.add").each(function() {
		var txt = $(this).text();
		switch($(this).text()) {
			case "info (at) balanceinstyle (dot) com":
				$(this).html(createAddress(info));
				break;
			case "amanda (at) balanceinstyle (dot) com":
				$(this).html(createAddress(amanda));
				break;
			case "jill (at) balanceinstyle (dot) com":
				$(this).html(createAddress(jill));
				break;
			case "gisele (at) balanceinstyle (dot) com":
				$(this).html(createAddress(gisele));
				break;
			default:
				$(this).html(createAddress(info, txt));
		}
	});

	if($("#contact-form").length && $("#this-form").length) {
	
		// add the contact-form anchor to the form action
		var form_action = $("#contact-form form").attr("action")
		form_action += "#contact-form";
		$("#contact-form form").attr("action",form_action);
		
		// open #contact-form on #this-form click
		$("#this-form").replaceWith('<a href="#contact-form" tabindex="0" id="this-form">' + $("#this-form").text() + '</a>')
		.attr("title","Click to open the Contact Us Form")
		.live("click", function(){
			$("#contact-form").slideFadeToggle("normal",function(){
				if($(this).is(":hidden")) {
					$("#this-form").attr("title","Click to open the Contact Us form");
					return false;
				} else {
					$("#this-form").attr("title","Click to hide the Contact Us form");
					$.localScroll.hash({reset:false,duration:500});
				}
			});
		}).live("mouseenter", function () {
			$(this).css({"text-decoration":"none","color":"#146481"});
    }).live("mouseleave", function () {
			$(this).css({"text-decoration":"underline","color":"#3c3533"});
    });

		var red_count = 0; // red_count represents error on the form
		$("#si_contact_form div").each(function(){if($(this).css("color")=="red"){red_count+=1}});
		
		var hash = window.location.hash;
		
		if(red_count || hash == "#contact-form"){ 	// if there were errors,
			$("#contact-form").show();								// show the contact form
			$("#this-form").attr("title","Click to hide the Contact Us form");
			$.localScroll.hash({duration:100}) 				// scroll to the contact form
		}
	}
	
});

// slideFadeToggle function
(function($) {
	$.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};
})(jQuery);

var mt=["x6d","x61","x69","108","000116","x6f","00058"];
var amanda=["x61","109","x61","x6e","100","97","64","98","x61","108","x61","x6e","x63","101","x69","110","x73","116","x79","x6c","x65","x2e","99","111","x6d"];
var jill=["x6a","x69","x6c","108","64","98","x61","108","97","110","99","x65","105","110","115","x74","121","x6c","101","x2e","x63","111","109"];
var gisele=["x67","x69","115","101","108","x65","64","x62","x61","108","97","x6e","x63","x65","105","110","x73","116","x79","x6c","101","46","x63","111","x6d"];
var info=["x69","x6e","102","x6f","x40","98","97","x6c","x61","x6e","99","x65","x69","110","x73","116","x79","108","101","x2e","x63","111","109"];

function obscureArr(arr){
	obscureStr = "";
	for (i=0; i<arr.length; i++) obscureStr += '&#'+arr[i]+';';
	return obscureStr;
}

function createAddress(arr, txt){
	var vmt = obscureArr(mt);
	var ea = obscureArr(arr);
	if(typeof(txt) == "undefined"){ txt = ea; } 
	var el = '<a href="' + vmt + ea + '" tabindex="0">' + txt + '</a>';
	return el;
}
