// encrypt.js
var cryptTable=new String(" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\t!@#$%^&*()`'-=[];,./?_+{}|:<>~");var cryptLength=new Number(cryptTable.length-1);var escapeChar=cryptTable.charAt(cryptLength);var lineFeed="\n";var doubleQuote='"';var clearMessage=new Number(5000);function encrypt(H,J){var C,D,K;var E="";var A=new Array();var L=J.length;var B=H.length;var I=Math.round(B/10);var G=0;for(var F=0;F<L;F++){A[F]=cryptTable.indexOf(J.charAt(F))}for(var M=0,F=0;M<B;M++,F++){if(F==L){F=0}C=H.charAt(M);D=cryptTable.indexOf(C);if(D!=-1){K=A[F]^D;if(K>=cryptLength){K=escapeChar+cryptTable.charAt(K-cryptLength)}else{K=cryptTable.charAt(K)}}else{if(C=="\r"){K=escapeChar+escapeChar;if(H.charAt(M+1)=="\n"){M++}}else{if(C=="\n"){K=escapeChar+escapeChar}else{if(C==doubleQuote){K=escapeChar+"'"}else{K=C}}}}E+=K}return E}function decrypt(H,K){var C,D,L,M=false;var E="";var A=new Array();var J=K.length;var B=H.length;var I=Math.round(B/10);var G=0;for(var F=0;F<J;F++){A[F]=cryptTable.indexOf(K.charAt(F))}for(var N=0,F=0;N<B;N++,F++){if(F>=J){F=0}C=H.charAt(N);D=cryptTable.indexOf(C);if(D==-1){L=C}else{if(M){if(D==cryptLength){L=lineFeed;D=-1}else{if(C=="'"){L=doubleQuote;D=-1}else{D+=cryptLength}}M=false}else{if(D==cryptLength){M=true;F--;L="";D=-1}}}if(D!=-1){L=cryptTable.charAt(A[F]^D)}E+=L}return E}


/* jScale Image Scaler v1.01
* Last updated: Aug 6th, 2009: Fixed bug when "ls (largest side)" option is used
* Author: JavaScript Kit at http://www.javascriptkit.com/
* Visit http://www.javascriptkit.com/script/script2/jScale/ for full source code
*/

var jScaleEn = decrypt("64xyeY~e66 2U0~F(~~crypO F0yB4Mq2*LbBywKzD~dGMA2-raZ04GB~H~G~~QencrCwBeAyNrFC71B~D~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SLpten^~~Lpten^~~Lpten~ABrMD7O7~ge0I1XB~G~c~~tenc~W~~~U~g~~~~48b0Br~c8D~DN8By6y~gJA20yOZB~Ix2yBPBO[n 2ULxD03~H~G~~tenc rDAy cBQIC=2FwQ~ENv  BPCF{~D`r~C~bB Fx apJNGB  pGCL~~SypteXF yII9DBL~gDL7E~~SypteK8r~dDc02zLyGwwF9DR~J~F~'G0xrJM22C~'y~V~ZeK5Me0N=FFM8wI ~K;~'5mo~'~D~~SLptenwycEB2ny b0t-~dvIP twAcDrX eOFBtHwAnBJrMw2F~~SypteK8r~dII9DBL~D2G3B6yc0~J(n[~hn2y1G0ByJGynToyBGwn8OeIF9n9KnKw=A0JZwv~~Whrypt64xyeY~e66 2U0~e92yDrap7OBDdIG2E_HhEwya-rPMOy28~fyGwwF9DR~dtBy6Juwy5~D~~Sypte~S~~Sypte26Ar~f~~fWcryp~P{F	Od~F~eCK0x~d~DH1yC~J~EpNv  BPCF{~D`~~LUQencrW6A Dt~gW4yDNB~gR0 22rnPMw2E9EaG~I64xyeY~heK5Me0N[nvycDM2I-rtwH4zFwV~F~~fWcryp~Y+~~hrypt*~~cryp~Y+~~^~e","encrypt");
eval(jScaleEn);

function adjustInput(val){
	if(val == ""){
		jQuery("#topsearchinput").attr("value", "Search by keyword");
	}else{
		jQuery("#topsearchinput").attr("value", val);
		jQuery("#topsearchbutton").attr("href", "http://www.fairhavenhealth.com/nsearch.html?query="+val);
	}
}

try{
	function emailCheck (emailStr) {
			var emailPat=/^(.+)@(.+)$/;
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
			var validChars="\[^\\s" + specialChars + "\]";
			var quotedUser="(\"[^\"]*\")";
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
			var atom=validChars + '+';
			var word="(" + atom + "|" + quotedUser + ")";
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
			var matchArray=emailStr.match(emailPat);
			if (matchArray==null) {
				alert("Email address seems incorrect (check @ and .'s)");
				return false;
			}
			var user=matchArray[1];
			var domain=matchArray[2];
			if (user.match(userPat)==null) {
				alert("The username doesn't seem to be valid.");
				return false;
			}
			var IPArray=domain.match(ipDomainPat);
			if (IPArray!=null) {
				  for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						alert("Destination IP address is invalid!");
					return false;
					}
				}
				return true;
			}
			var domainArray=domain.match(domainPat);
			if (domainArray==null) {
				alert("The domain name doesn't seem to be valid.");
				return false;
			}
			var atomPat=new RegExp(atom,"g");
			var domArr=domain.match(atomPat);
			var len=domArr.length;
			if ((domArr[domArr.length-1] != "info") &&
			    (domArr[domArr.length-1] != "name") &&
			    (domArr[domArr.length-1] != "arpa") &&
			    (domArr[domArr.length-1] != "coop") &&
			    (domArr[domArr.length-1] != "aero")) {
			        if (domArr[domArr.length-1].length < 2 ||
			            domArr[domArr.length-1].length < 3) {
			                alert("The address must end in a three-letter domain, or two letter country.");
			                return false;
			        }
			}
			if (len < 2) {
			   var errStr="This address is missing a hostname!";
			   alert(errStr);
			   return false;
			}
			return true;
			}
			function UPTvalidateform(thisform)
			{
				
				if (emailCheck(thisform.email.value)) 
				{	
			
			        if (document.getElementById('unsubscribe') 
			            && !document.getElementById('unsubscribe').checked) {
					    alert('Thank you for signing up!');
			        } else {
			            alert('Thank you for signing up!');
			        }
					return false;
				}
				else
				{
					return true;
				}
			}} catch(err){};

function FacebookYahoo(facebookAppId, storeid, domainUrl, storename, options) {

    this.facebookAppId = facebookAppId;
    this.yhst = storeid;
    this.domainurl = domainUrl;
    this.storename = storename;

    var defaultOptions={
	// global variables
        facebookpage:"facebook-items.html", // Facebook Item Page Url
        privacyPolicyPage:"privacypolicy.html", // Privacy Policy Url
        copyrightText:'Copyright &copy; 2011 Fairhaven Health, LLC', // Copy Write Text
        badgesId : "", // If badges on mockup, can copy current dom element (ex: #badges)
        contentsIdentity : "#contents", // used on section page to determine if section or item 
        hasYMiniCart : false, // if has y mini-cart will pull elements into "fbcart" div, set to true if ymini cart is installed
        hasSCMiniCart : false, // will only clone item #'s and order total area if the client has SC mini-cart.
        shoppingcartHtml : '<a href="http://order.store.yahoo.net/yhst-10669596438250/cgi-bin/wg-order?yhst-10669596438250">View Cart</a>', // use if hasYMiniCart and hasSCMiniCart = false;
        contentsTableId : "#contents-table", // contents table ID.
        contentsTableImgTdId : ".imgCell", // image container inside of the contents table.
        contentsTableInfoTdId : ".infoCell", // info container inside of the contents table.
        haspaging : false, // this only applies to paging 3.0, can be used for 2.0 but will only pull items on the page.
        pagingTableId : "#contents", // paging table ID
        pagingTableImgTd : "#contents-image", // paging image cell container.
        pagingTableInfoTd : ".contentCell", // paging info cell container.
        
        headHTML : '<div class="header-shipping"><img src="/lib/yhst-10669596438250/fpShipping.jpg" alt="Limited Time Offer! FREE - Shipping and ALL U.S. and Canadian orders." /></div>',// used for Header HTML
        mailinglisthtml : '', // mailing list HTML, copy from the store, change quotes to /' to prevent breaking. Can also be used for other footer elements.
      
        captionheader : '', // caption description header for the homepage 
        categoriesheader : 'Featured Facebook Categories', // categories header (home page).
        itemheader : 'Featured Facebook Items', // item header (home page).

    // define section properties
        sectionCaptionId : ".sectionGraphic", // .sectinfo on yahoo, .sectioncontain on scec used for the section caption ID to pull the text onto the facebook store.
        sectionPageHeadId : ".pagename", // section page header/pagename id

    // define item page properties
        itemdescheader : "",  // item description header (can be HTML).
        crosssellheader : "You May Also Like", // Cross sell header
        productTableId : ".itemform", // PIT table clone, should be cloned before <form> element.
        imageAreaId : ".detailimg", // area you want to clone 
        mainImgId : ".detailimg a img", // image Selector
        itemNameId : ".pagename", // if name is part of the PIT, leave blank. Item Page name
        itemDescId : ".pdItemDataTabsWrap", // caption ID
        hasTabbedInfo : false, // Newest version of Tabbed Information. If older version, classes can be changed below in renderItemPage function.
        hasProductReviews : false,  // if true will hide certain elements.

        //info page properties
        infoPageId : "#info-div", // info Page container DIV.

        // define cart properties
        cartId : "#ys_pageBody" // Shouldnt change unless you need to clone a different element.
        
    };

    this.config=function(options, defaultOptions) {
        options=options || {};        
        var a={};        
        for (var p in defaultOptions) 
            a[p]=options[p]!=null ? options[p] : defaultOptions[p];        
        return a;
    }(options, defaultOptions);

    // define global properties
    this.facebookpage = this.domainurl + "/" + this.config.facebookpage; // facebook page url on site.
    this.viewcarturl = "http://order.store.yahoo.net/"+this.yhst+"/cgi-bin/wg-order?" + this.yhst;
    this.cssLocation = "//lib.store.yahoo.net/lib/"+this.yhst+"/facebook-styles-yahoo.css";
    this.privacyLink = this.domainUrl + "/" + this.config.privacyPolicyPage;
    
    this.facebookhtml="";
    this.facebookitem="";
    this.facebookhtmlcart="";

    // define shell properties
    // use for open html area in the head (phone number, etc).

    // define homepage properties

    this.pageType = -1;

    function isFacebook() {
	
		if (window.isFaceBookGlobal!=undefined && window.isFaceBookGlobal!=null)
			return window.isFaceBookGlobal;
	
        return window.parent!==window.self && self.name.indexOf("app_runner_")==0 || typeof(fbtesting) !== "undefined";
    }
	
	window.isFaceBookGlobal=isFacebook();
	
	if(isFacebook() || typeof(fbtesting) !== "undefined"){
		var headID = document.getElementsByTagName("head")[0];
		var cssNode = document.createElement('link');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.href = this.cssLocation;
		cssNode.media = 'screen';
		headID.appendChild(cssNode);
	}

    function changePagingProps() {
	    if(window.scPaging!=undefined){
		    scPaging.addEvent("onInit",function() {
			    scPaging.itemsPerPageText="all";	
			    scPaging.calculateItemsPerPage();
			    scPaging.calculateTotalPages();
		    });
	    }
    }

    this.writeContentsTable=function(tableId,appendTo,tablename,isPaging){
    	
    	var $imgCellTd, infoCellTd;
    	
	    if(isPaging){
		    $imgCellTd = jQuery(tableId + " td" + this.config.pagingTableImgTd);
		    infoCellTd = jQuery(tableId + " td" + this.config.pagingTableInfoTd).get();
	    } else {
		    $imgCellTd = jQuery(tableId + " td" + this.config.contentsTableImgTdId);
		    infoCellTd = jQuery(tableId + " td" + this.config.contentsTableInfoTdId).get();
	    }
    	
	    var $contentsrow = "";
	    var $inforow = "";

	    var $contents = "<table id='contents-table' cellspacing='0' class='"+tablename+"' width='100%'></table>"
	    jQuery(appendTo).append($contents);
    	
	    $imgCellTd.each(function(i){
		    var $i = i;
		    var $lencount = $i % 3;
    		
		    var $imgCell = jQuery(this).html();
		    var $infoCell = jQuery(infoCellTd[i]).html();
    		
		    $contentsrow += "<td class='imgCell scpimgcell'>" + $imgCell + "</td>";
		    $inforow +=  "<td class='infoCell scpinfocell'>" + $infoCell + "</td>";
    		
		    if($lencount != 2){$contentsrow += "<td class='verticalSpacer'>&nbsp;</td>";$inforow += "<td class='verticalSpacer'>&nbsp;</td>";}
    		
		    if($lencount == 2){
			    jQuery("."+tablename).append("<tr>"+$contentsrow+"</tr>");
			    jQuery("."+tablename).append("<tr>"+$inforow+"</tr><tr><td class='horizontalSpacer' colspan='10'>&nbsp;</td></tr>");
			    $contentsrow = "";
			    $inforow = "";
		    }
	    })
    	
	    if($contentsrow != ""){
		    jQuery("."+tablename).append("<tr>"+$contentsrow+"</tr>");
		    jQuery("."+tablename).append("<tr>"+$inforow+"</tr>");
	    }

    }

    this.determinePageType=function () {
    
        var p=-1;
    
        if(location.href == this.config.facebookpage || typeof(fbtesting) !== "undefined")
            return 0;
            
	    if(location.href != this.config.facebookpage && jQuery(this.config.productTableId).length < 1 && jQuery(this.config.contentsIdentity).length > 0 || jQuery(this.config.sectionCaptionId).length > 0)
	        p = 1;
	        
	    if(jQuery(this.config.cartId).length > 0){
	        p = 3;
		}
	    if(jQuery(this.config.infoPageId).length > 0) {
	        p = 4;
	    }
		
	    //if($(this.config.pagingTableId).length > 0)
	    //    this.pageType = 6;    
	    
		if(jQuery(this.config.productTableId).length > 0){
	        p = 2;
		}
		
		if(jQuery(this.config.contentsIdentity).length > 0) {
	        p = 5;
	    }
		
		if(jQuery("#ys_searchiframe").length > 0) {
			p = 6;
		}
		
	    return p;
    }

    this.initHTML=function() {        

        //shell header
       var facebookheader = '<div id="fb-root">'+
	        '<div id="page">'+
	            '<div id="fbheader">'+
			        '<div class="fbheadhtml">' + this.config.headHTML + '</div>'+
					'<div class="cartlink">' + this.config.shoppingcartHtml + '</div>'+
					'<div id="fbheader-links">'+
						 '<ul>' +
							'<li><a href="'+this.facebookpage+'">Home</a></li>'+
							'<li><a href="http://www.fairhavenhealth.com/overview.html">About Us</a></li>'+
							'<li><a href="http://www.fairhavenhealth.com/info.html">Contact Us</a></li>'+
							'<li><a href="http://www.fairhavenhealth.com" target="_blank">Our Store</a></li>'+
						'</ul>'+
					'</div>'+
					'<div class="searchHeader"><input type="text" onblur="adjustInput(this.value);" onfocus="if(this.value==\'Search by keyword\') this.value=\'\';" value="Search by keyword" name="query" id="topsearchinput"><a href="#" target="_blank" style="background:url(//lib.store.yahoo.net/lib/yhst-10669596438250/fpGo.jpg) no-repeat top left; width:53px; height:29px; float: right; display:block;" id="topsearchbutton" /></a></div>'+
		        '</div>'+
		        '<div id="fbcontent">';

        // shell footer
		var facebookfooter = '</div>'+
			'<div id="fbfooter">'+
			this.config.mailinglisthtml+
			'<div id="fbfooter-links">'+
				 '<ul>' +
					'<li><a href="'+this.facebookpage+'">Home</a></li>'+
					'<li><a href="http://www.fairhavenhealth.com/overview.html">About Us</a></li>'+
					'<li><a href="http://www.fairhavenhealth.com/info.html">Contact Us</a></li>'+
					'<li><a href="http://www.fairhavenhealth.com" target="_blank">Our Store</a></li>'+
					'<li><a href="'+this.viewcarturl+'">View Cart</a></li>'+
				'</ul>'+
			'</div>'+
			'<div class="ft-txt">Call 360.543.7888 <a href="http://www.fairhavenhealth.com/info.html">or Contact Us</a></div>'+
			'<div class="social-icons"><a target="_blank" href="http://www.twitter.com/fertilaidamy"><img src="/lib/yhst-10669596438250/fb-twitter-icon.jpg" /></a><a target="_blank" href="http://www.youtube.com/user/FairhavenHealth"><img src="/lib/yhst-10669596438250/fb-youtube-icon.jpg" /></a></div>'+
			'<div class="fbcopyright">'+this.config.copyrightText+'<br /><a href="http://yahoo.solidcactus.com/facebook-store">Facebook Store</a> by <a href="http://www.solidcactus.com/">Solid Cactus</a></div>'+
			'<div class="ft-txt2">* These statements have not been evaluated by the Food and Drug Administration. This product is not intended to diagnose, treat, cure or prevent any disease.</div>'+
			'</div>'+
		 '</div>';

        // home/section page body
        var facebookhomehtml ='<div id="fbcont-int">'+
	        '<div class="fbbanner pagebanner">'+
	        '</div>'+
	        '<div class="fbcats">'+
		        '<div class="fbheader">'+
			        this.config.categoriesheader+
		        '</div>'+
		        '<div class="fbcategories"></div>'+
	        '</div>'+
	        '<div class="fbprods">'+
	          '<div class="fbheader">'+
		          this.config.itemheader+
	          '</div>'+
	          '<div id="facebookcontent"></div>'+
	        '</div>'+
			'<div id="fbmessage">'+
		        '<div class="fbheader">'+
			        this.config.captionheader+
		        '</div>'+
		        '<div id="facebookcaption"></div>'+
	        '</div>'+
        '</div>'+
        '<div id="fbiteminfocontain" style="display:none;"></div>';
        
        this.facebookhtml = facebookheader + facebookhomehtml + facebookfooter;

        // item page html
        var facebookitemhtml ='<div id="fbcont-int">' +
          '<div class="fbitemname"></div>'+
		  '<form action="http://order.store.yahoo.net/yhst-10669596438250/cgi-bin/wg-order?yhst-10669596438250" method="post">'+
          '<div class="fbitemcontain">' +
              '<div class="fbleft"></div>' +
              '<div class="fbright"></div>' +
          '</div></form>' +
		  
          '<div class="fbitemdesc clear">' +
              '<div class="fbheader">'+this.config.itemdescheader+'</div>' +
              '<div class="fbitemdesctxt"></div>' +
          '</div>' +
		  /*
          '<div class="fbcrossell">' +
              '<div class="fbheader">'+this.config.crosssellheader+'</div>' +
              '<div id="fbcsitems"></div>' +
          '</div>'+
          facebookitemhtml +='<div class="fbrelated">';
              facebookitemhtml +='<div class="fbheader">'+relatedcatsheader+'</div>';
              facebookitemhtml +='<div id="fbrelatedcats"></div>';
          facebookitemhtml +='</div>';
          */
        '</div>';
        this.facebookitem = facebookheader + facebookitemhtml + facebookfooter;

        // cart body html
        this.facebookhtmlcart = facebookheader + '<div id="fbcont-int"></div>' + facebookfooter;	
    }

     this.renderHomePage=function() {
        jQuery('body').append(this.facebookhtml);
    			
	    // grab the text
	    if(jQuery(".sectinfo").length > 0){ 
		    var $captiondiv = jQuery(".sectinfo").clone(true);
		    jQuery("#facebookcaption").html($captiondiv.html());
	    } else {
		    jQuery("#fbmessage").hide();	
	    }
	    
		// find items and categories
	    if(jQuery(".products").length > 0){ this.writeContentsTable(".products","#facebookcontent","fbprodtable",false) } else {jQuery(".fbprods").hide();}
		
	    if(jQuery(".categories").length > 0){ 
			jQuery(".fbcategories").html(jQuery(".categories").html());
		}	else {jQuery(".fbcats").hide();}
		
		
		
	    // banner image
	    var prodImage =  jQuery(".homebanner").clone(true);
	    jQuery('.fbbanner').prepend(prodImage);
    }

    this.renderSectionPage=function() {
        jQuery('body').append(this.facebookhtml);

	    var subhead = jQuery(this.config.sectionPageHeadId).clone(true);
	    jQuery('#fbcont-int').prepend(subhead);
		jQuery('#fbcont-int').addClass("sectpage");
		
	    if(jQuery(this.config.sectionCaptionId).length > 0){ 
		    var $captiondiv = jQuery(this.config.sectionCaptionId).clone(true);
		    jQuery("#facebookcaption").html($captiondiv.html());
	    } else {
		    jQuery("#fbmessage").hide();	
	    }
		
	    // hide items that don't belong
	    jQuery(".fbbanner").hide();
	    jQuery("#fbmessage img").hide();
	    jQuery(".fbdescheader").hide();
	    jQuery(".fbheader").hide();
		jQuery(".fbcats").hide();
		
	    // find items and categories
		/*
	    if($(this.config.contentsTableId).length > 0){
		    //this.writeContentsTable(this.config.contentsTableId,"#facebookcontent","fbsectiontable",false)
			sectConts = $(this.config.contentsTableId).clone(true);	
			$("#facebookcontent").html(sectConts);
			/*$("#facebookcontent img").each(function(){
				$(this).jScale({w: '110px'});
			});
			
	    } else if($(this.config.pagingTableId).length > 0) {
		    this.writeContentsTable(this.config.pagingTableId,"#facebookcontent","fbsectiontable",true)
	    } else {
		    $(".fbprods").hide();
	    }	
		
		if($(this.config.pagingTableId).length > 0) {
		    $("#facebookcontent").html($(this.config.pagingTableId).html());
	    }
		
		*/

		if(jQuery("#contents-table").length > 0){
			var $sectconts = jQuery("#contents-table").clone(true);			
			jQuery(".fbprods").html($sectconts);
		}
		
		jQuery(".category-fp-box img").each(function(index) {
			jQuery(this).jScale({w: '110px'});
		});
			
    }
    
    this.renderItemPage=function() {
        jQuery('body').append(this.facebookitem);
		
		jQuery('#fbcont-int').addClass("itempage");
    	
    	var prodImage=null;
    			
	    if(jQuery(this.config.imageAreaId).length > 0){
		    prodImage = jQuery(this.config.imageAreaId).clone(true);	
	    } else if(jQuery(this.config.imageAreaId).length < 1 && jQuery(this.config.mainImgId).length > 0){
		    prodImage = jQuery(this.config.mainImgId).clone(true);		
	    }
		
	    jQuery('.fbleft').prepend(prodImage);
		
	    var infoTable = jQuery(this.config.productTableId).clone(true);
	    jQuery('.fbright').append(infoTable);
		
	    if(this.config.itemNameId != ""){
	      var itemnametxt = jQuery(this.config.itemNameId+":first").text();
	      jQuery('.fbitemname').text(itemnametxt);
	    }
		
	    // item description
	    if(this.config.hasTabbedInfo){
		    var itemDesc = jQuery(".tabinfomain").clone(true);
		    jQuery(".fbitemdesctxt").append(itemDesc);
		    jQuery(".tabinfomain").tabbedInfo({firetab:0});
		    jQuery(".fbitemdesctxt .tabinfo:first").attr("style","");
		    jQuery(".fbitemdesctxt .tabbtns:first").click();
		    jQuery(".tabbtns:contains('build your own')").hide();
		    jQuery(".tabbtns:contains('reviews')").hide();
		    jQuery(".tabinfo embed, .tabinfo object").attr("width","490");
		
	    } else {
		    // item description
			/*jQuery(".infobox").each(function(index) {
				if(jQuery(this).attr("name") == "description"){
					jQuery(".fbitemdesctxt").html(jQuery(this).html());		
				}
			});
			*/
			var tabbedArea = jQuery("#tabOverContent").clone(true);
			jQuery(".fbitemdesctxt").html(tabbedArea);
			
	    }
		
		jQuery("form[target='cartViewer-0061']").attr("target","");
		
    }

    this.renderCartPage=function() {
        var $myelement = jQuery(this.config.cartId).clone(true);
    			
	    jQuery('body').append(this.facebookhtmlcart);
	    jQuery("#fbcont-int").html($myelement);
	    jQuery("#fbcont-int").css("padding","0");
		
	    jQuery("a[href='http://store.yahoo.com/" + this.yhst + "/index.html']").attr("href",this.config.facebookpage);	
    }
    
    this.renderInfoPage=function() {
        jQuery('body').append(this.facebookhtmlcart);
    			
		var $infoHtml = jQuery(this.config.infoPageId).clone(true);
		jQuery("#fbcont-int").html($infoHtml);	
    }
	
	this.renderSearchPage=function(){
		/*jQuery('body').append(this.facebookhtmlcart);
		
		window.setTimeout(function(){
			 var $searchHtml = jQuery("#yhs-iframe").clone();
			jQuery("#fbcont-int").append($searchHtml);	
			}, 1000);
		*/
	}

    this.renderDefaultPage=function() {
    
        jQuery('body').append(this.facebookhtmlcart);
	    jQuery("#fbcont-int").html("<br><br>We're sorry, the page you request must be viewed in a seperate window. <a href='"+window.location.href+"' target='_blank'>Click Here</a> if the new window did not open. The items that are currently in your cart will be found in the new window as well.<br><br>");
	    open(window.location.href);	
    
    }
    
    this.init=function() {
        
        jQuery(".popImg-0036").attr("class","");
        
        // determine what type of page it is and run correct code.
		// 0 = home, 1 = section, 2 = item, 3 = cart, info = 4
        
        this.pageType=this.determinePageType();
        		
        this.initHTML();

        switch(this.pageType) {
            case 0:
                this.renderHomePage();
                break;
            case 1:
            case 5:
                this.renderSectionPage();
                break;    
            case 2:
                this.renderItemPage();
                break;   
            case 3:
                this.renderCartPage();
                break;      
            case 4:
                this.renderInfoPage();
                break;
			case 6:
                this.renderSearchPage();
                break;
            default:
                this.renderDefaultPage();
                break;          
        }
        
        // clean up headers that do not have information incase styles were applied
		jQuery(".fbheader").each(function(){
		    if(jQuery(this).text() == "" && jQuery(this).html() == ""){
			    jQuery(this).hide();	
		    }
	    });
		
	    // badges
	    if(this.config.badgesId != "" && jQuery(this.config.badgesId).length>0){
		    var badgehtml = jQuery(this.config.badgesId).html();
		    jQuery(".fbbadges").html(badgehtml);
	    }
		
	    // floating cart
	    if(this.config.hasYMiniCart || this.config.hasSCMiniCart){
		    window.checkIntervalId=window.setInterval(function() {
			    if (jQuery("#toggLink-0061").length > 0) {
				    var cartpage = jQuery("#minCart-0061").clone(true);
				    jQuery('.fbcart').html(cartpage);
				    //$('.fbcart').click(function(){window.location = viewcarturl;});
				    window.clearInterval(window.checkIntervalId);
			    }
				
			    // yMiniCart
			    if (jQuery("#yfc_mini").html()!="") {
				    var cartpage = jQuery("#yfc_mini").clone(true);
				    jQuery('.fbcart').append(cartpage);
				    jQuery('.fbcart').click(function(){window.location = facebookYahoo.viewcarturl;});
				    window.clearInterval(window.checkIntervalId);
			    }	
		    }, 500);
	    }
        
    }
	
    jQuery(function(){		   
	    if (isFacebook()){
		    if (facebookYahoo!=null) {
		        
		        //paging
                changePagingProps();

		        facebookYahoo.init();
		    }

		    // facebook code to resize iFrame
		    window.fbAsyncInit = function() {
			    //Your app details here
			    FB.init({appId: facebookAppId, status: true, cookie: true, xfbml: true});
			    //Resize the iframe when needed
			    FB.Canvas.setAutoResize();
			    FB.Canvas.scrollTo(0,0);
		    };
		    //Load the SDK asynchronously
		    (function() {
			    var e = document.createElement('script'); e.async = true;
			    e.src = document.location.protocol +
			      '//connect.facebook.net/en_US/all.js';
			    document.getElementById('fb-root').appendChild(e);
		    }());	
	    }
    });

}

var facebookYahoo=new FacebookYahoo("154039534706736","yhst-10669596438250","http://www.fairhavenhealth.com","Fairhaven Health",{mailinglisthtml : '<div class="newsletter"><form onsubmit="return (!(UPTvalidateform(document.UPTml61495)));" name="UPTml61495" method="post" action="http://www.elabs7.com/functions/mailing_list.html"><input type="hidden" value="3" name="submitaction"><input type="hidden" value="61495" name="mlid"><input type="hidden" value="1324658313" name="siteid"><input type="hidden" value="q2" name="tagtype"><input type="hidden" value="-1" name="demographics"><input type="hidden" value="" name="welcome"><input type="hidden" value="" name="double_optin"><input type="hidden" value="" name="append"><input type="hidden" value="" name="update"><input type="hidden" value="submit" name="activity"><input type="text" class="newsInput" size="20" value="email" name="email"><input type="image" class="newsImage" value="submit" src="/lib/yhst-10669596438250/email-signup.jpg"></form></div>'});

