// 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 FacebookStores(facebookAppId, storeid, domainUrl, options) {

    this.facebookAppId = facebookAppId;
    this.mid = storeid;
    this.domainurl = domainUrl;

    var defaultOptions={
	// global variables
        facebookpage:this.domainurl + "/facebook-items.aspx", // Facebook Item Page Url
        privacyPolicyPage:"privacy-policy.aspx", // Privacy Policy Url
        copyrightText:"Copyright &copy; 2011 Esslinger and Company All Rights Reserved. ", // Copy Write Text
      	searchButton : "/facebook/store/images/fb-search-go.jpg",
		mailButton : "",
		// Home page properties
		captionheader : "", // caption description header for the homepage 
        categoriesheader : "Featured Categories", // categories header (home page).
        itemheader : "Featured Items", // item header (home page).
		homebanner : "<img src='/facebook/store/images/fb-main-banner.jpg' alt='Gift Guide - Find the perfect gift for the person who does it all... - 20%-40% Off selected items' />",
		homebannerlink: "http://www.esslinger.com/2011giftguide.aspx",

    // define section properties
        sectionCaptionId : ".page-html-content", // .sectinfo on yahoo, .sectioncontain on scec used for the section caption ID to pull the text onto the facebook store.
        sectionPageHeadId : ".section-header", // section page header/pagename id
		sectionCategoryId: ".category-list",
		sectionProductId: ".product-list",

    // define item page properties
        itemdescheader : "Product Description",  // item description header (can be HTML).
        crosssellheader : "You May Also Like", // Cross sell header
        productTableId : "#product-detail-div", // PIT table clone, should be cloned before <form> element.
        itemNameId : ".item-header", // if name is part of the PIT, leave blank. Item Page name
        hasTabbedInfo : false, // Newest version of Tabbed Information. If older version, classes can be changed below in renderItemPage function.
		
		/* Default Prod Info Table Selectors */
		priceSelector: ".prod-detail-cost-value",
		salePriceSelector: ".sale",
		reducedSelector: ".reduced",
		optionsSelector: ".option",
		youSaveSelector: ".saved",
		skuSelector: ".prod-detail-part-value",
		writeAddtoCart: true,

        //info page properties
        infoPageId : ".infopage", // info Page container DIV.

        // define cart properties
        cartId : "#ctl00_pageContent_checkoutPanel" // 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.cssLocation = "/facebook/store/css-js/facebook-styles-custom.css";
    
    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() {
        return window.parent!==window.self && self.name.indexOf("app_runner_")==0;
    }
	
	function isFacebookTest() {
        return window.parent!==window.self && self.name.indexOf("iframe_canvas")==0;
    }
	
	if(isFacebook()|| isFacebookTest()){
		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);
	}


    this.determinePageType=function () {
        var p=-1;
        
	    if(location.href != this.config.facebookpage && $(this.config.productTableId).length < 1 && $(".category-list-item").length > 0 || $(".product-list-item-container").length > 0 || $(".search-result-text").length > 0)
	        p = 1; // section
			
		if($(this.config.sectionPageHeadId).length > 0){
			p = 1;
		}
	    if($(this.config.productTableId).length > 0) // item
	        p = 2;
	    if($(this.config.cartId).length > 0) // cart
	        return 3;
			
	    if($(this.config.infoPageId).length > 0) {
	        p = 4;
	    }
	 	if($(".cart-container").length > 0) {
		       p = 7;
	    }
		if((location.href == this.config.facebookpage) || (location.href == this.config.facebookpage+"?fb=1"))
            return 0; // home

	    return p;
    }

    this.initHTML=function() {
        //shell header
        var facebookheader = '<div id="fb-root">'+
	        '<div id="page">'+
	            '<div id="fbheader">'+
					'<div onkeypress="javascript:return WebForm_FireDefaultButton(event, \'ctl00_ctl02_go\')" class="custom-search" id="ctl00_ctl02_searchBox">'+
						'<input type="text" class="textbox fbsearchbox" id="ctl00_ctl02_search" maxlength="100" name="ctl00$ctl02$search" onfocus="if(this.value == this.defaultValue){this.value=\'\';}" onblur="if(this.value == \'\'){this.value= this.defaultValue;}" value="">'+	
	  					'<input type="image" class="fbsearchgo" style="border-width:0px;" alt="Go" src="'+this.config.searchButton+'" id="ctl00_ctl02_go" name="ctl00$ctl02$go">'+
					'</div>'+
			        '<div class="fbcart"></div>' +
					'<div id="fbheader-links">'+
				        '<ul>'+
					        '<li><a href="'+this.config.facebookpage+'">Home</a></li>'+
							'<li><a href="checkout.aspx">View Cart</a></li>'+
							'<li><a target="_blank" href="http://www.esslinger.com">Visit Our Site</a></li>'+
							'<li><a href="http://www.esslinger.com/learningcenter.aspx">Learning Center</a></li>'+							
				        '</ul>'+
			        '</div>'+
		        '</div>'+
		        '<div id="fbcontent">';

        // shell footer
		        var facebookfooter = '</div>'+
				'<div id="fbfooter">'+
			        '<div id="fbfooter-links">'+
				        '<ul>'+
					        '<li><a href="'+this.config.facebookpage+'">Home</a></li>'+
							'<li><a target="_blank" href="http://www.esslinger.com">Visit Our Site</a></li>'+
							'<li><a href="http://www.esslinger.com/privacy-policy.aspx">Privacy Policy</a></li>'+							
					        '<li><a href="checkout.aspx">Shopping Cart</a></li>'+
				        '</ul>'+
			        '</div>'+
			        '<div class="fbcopyright">'+this.config.copyrightText+'<a href="http://yahoo.solidcactus.com/facebook-store">Facebook Store</a> by <a href="http://www.solidcactus.com/">Solid Cactus</a></div>'+
    		        '</div>'+
	                '</div>'+
                 '</div>';

        // home/section page body
        var facebookhomehtml ='<div id="fbcont-int">'+
	        '<div class="fbbanner pagebanner">'+
	        '</div>'+
	        '<div id="fbmessage">'+
		        '<div class="fbheaderimg">'+
			        this.config.captionheader+
		        '</div>'+
		        '<div id="facebookcaption"></div>'+
	        '</div>'+
	        '<div class="fbcats">'+
			  '<div class="fbheaderimg">'+
		          this.config.categoriesheader+
	          '</div>'+
		        '<div class="fbcategories results-grid"></div>'+
	        '</div>'+
	        '<div class="fbprods">'+
	          '<div class="fbheaderimg">'+
		          this.config.itemheader+
	          '</div>'+
	          '<div id="facebookcontent" class="results-grid"></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>'+
          '<div class="fbitemcontain">' +
              '<div class="fbleft"></div>' +
              '<div class="fbright"></div>' +
          '</div>' +
          '<div class="fbitemdesc clear">' +
              '<div class="fbheaderimg">'+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" class=""></div>' + facebookfooter;	
    }

     this.renderHomePage=function() {
         $('#aspnetForm').append(this.facebookhtml);
	    
		$("#fbmessage").hide();
		/*
		// grab the text
	    if($(this.config.sectionCaptionId).length > 0){
	         var $captiondiv = $(this.config.sectionCaptionId).clone(true);
		    $("#facebookcaption").html($captiondiv.html());
	    } else {
		    $("#fbmessage").hide();	
	    }
	    */
		
		// paging functionality.
	    if($(".product-list-results-header").length > 0){ 
			homeitems = $(".product-list-results-header").clone(true);
			$("#facebookcontent").append(homeitems);
		}
		
		// find items and categories
	    if($(this.config.sectionProductId).length > 0){ 
			homeitems = $(this.config.sectionProductId).clone(true);
			$("#facebookcontent").append(homeitems);
			//$(".product-list-img").jScale({w: '130px'});
		}
		
	    if($(this.config.sectionCategoryId).length > 0){ 
			homecategories = $(this.config.sectionCategoryId).clone(true);
			$(".fbcategories").append(homecategories);
			$(".product-list-img").jScale({w: '130px'});
			//$(".fbcategories img").jScale({w: '120px'});
		}
			
		
	    // banner image
	   	if(this.config.homebanner != ""){
			if(this.config.homebannerlink != ""){
				homeBannerHtml = "<a href='"+this.config.homebannerlink+"'>"+this.config.homebanner+"</a>";
			} else {
				homeBannerHtml = this.config.homebanner;
			}
			$('.fbbanner').prepend(homeBannerHtml);
		} else {
			$('.fbbanner').hide();	
		}
		
		 $("#wrapper select").remove();
		 
		 $(".product-list-control input").attr("src", "/facebook/store/images/fb-atc.jpg");
		 $(".product-list-control input").css("display", "block");
		 $(".product-list-control input").css("margin", "0 auto");
		 $(".product-list-control a img").attr("src", "/facebook/store/images/fb-view-details-btn.jpg");
		 $(".product-list-control a img").css("margin-top", "5px");
    }

    this.renderSectionPage = function () {
        $('#aspnetForm').append(this.facebookhtml);
		$('#fbcont-int').addClass("sect-page");
		
		// grab the text
	    if($(this.config.sectionCaptionId).length > 0){
	         var $captiondiv = $(this.config.sectionCaptionId).clone(true);
		    $("#facebookcaption").html($captiondiv.html());
	    }

	    
		// paging functionality.
	    if($(".product-list-results-header").length > 0){ 
			homeitems = $(".product-list-results-header").clone(true);
			$("#facebookcontent").append(homeitems);
		}
		
		// find items and categories
	    if($(this.config.sectionProductId).length > 0){ 
			homeitems = $(this.config.sectionProductId).clone(true);
			$("#facebookcontent").append(homeitems);
			//$(".product-list-img").jScale({w: '125px'});
		}
		
	    if($(this.config.sectionCategoryId).length > 0){ 
			homecategories = $(this.config.sectionCategoryId).clone(true);
			$(".fbcategories").append(homecategories);
			$("div.category-list-item-body img").jScale({w: '115px'});
		} else {
				
		}
		
		if($(this.config.sectionPageHeadId).length > 0){
			var subhead = $(this.config.sectionPageHeadId).clone(true);
        	$('.fbheaderimg:first').text(subhead.text()).show();
		}
		
        // hide items that don't belong
        $(".fbbanner").hide();
        $("#fbmessage img").hide();
        $(".fbdescheader").hide();
        $('.fbheaderimg').hide();
		if(!$(".search-result-text").length > 0){
		$('.fbheaderimg:first').text(subhead.text()).show().addClass("fbheader");
		}
		$("#wrapper select").remove();
		
		
		// search results caption
		if($(".search-result-text").length > 0){
			$('.pagebanner:first').text("Search Results").show().addClass("fbheader");
			var $captiondiv = $(".search-result-text").clone(true);
		    $("#facebookcaption").html($captiondiv).show();
			
			if($(".search-categories").length > 0){
				var catresults = $(".search-categories").clone(true);
				$("#facebookcaption").append(catresults);
			}
			
			if($(".search-filters").length > 0){
				var searchfilters = $(".search-filters").clone(true);
				$("#facebookcaption").append(searchfilters);
			}
		}
		
		$(".product-list-control input").attr("src", "/facebook/store/images/fb-atc.jpg");
		$(".product-list-control input").css("display", "block");
		$(".product-list-control input").css("margin", "0 auto");
		$(".product-list-control a img").attr("src", "/facebook/store/images/fb-view-details-btn.jpg");
		$(".product-list-control a img").css("margin-top", "5px");
    }
    
    this.renderItemPage=function() {
        $('#aspnetForm').append(this.facebookitem);		
		$('#fbcont-int').addClass("item-page");
		
    	var prodImage=null;
    			
	    if($(".MagicZoomPlus").length > 0){
		    prodImage = $(".MagicZoomPlus").clone(true);
			$('.fbleft').prepend(prodImage);
	    } 
		
	    //$(".MagicZoomPlus img").jScale({w: '200px'});
	    //$(".pretty_photo_image img").jScale({h: '200px'});
		
	    //var infoTable = $(this.config.productTableId).clone(true);
	    
		// build info table
		var prodTable = "<table class='fbdetails' cellpadding='0' cellspacing='0' width='100%'>"+
						(this.config.skuSelector != "" && $(this.config.productTableId + " " + this.config.skuSelector).length > 0 ? "<tr><th>Sku:</th><td class='sku'>"+$(this.config.productTableId + " " + this.config.skuSelector).text()+"</td></tr>" : "");
						
						if(this.config.priceSelector != "" && $(this.config.productTableId + " " + this.config.priceSelector).length > 0 && !$(this.config.productTableId + " " + this.config.reducedSelector).length > 0){
							prodTable += "<tr><th>Price:</th><td class='price'>"+$(this.config.productTableId + " " + this.config.priceSelector).text()+"</td></tr>";
						}
						
						if(this.config.reducedSelector != "" && $(this.config.productTableId + " " + this.config.reducedSelector).length > 0){
							prodTable += "<tr><th>Price:</th><td class='reduced'>"+$(this.config.productTableId + " " + this.config.reducedSelector).text()+"</td></tr>";
						}
						
						if(this.config.salePriceSelector != "" && $(this.config.productTableId + " " + this.config.salePriceSelector).length > 0){
							prodTable += "<tr><th>Sale Price:</th><td class='sale'>"+$(this.config.productTableId + " " + this.config.salePriceSelector).text();
							
							if(this.config.youSaveSelector != "" && $(this.config.productTableId + " " + this.config.youSaveSelector).length > 0){
							prodTable += "<span class='saved'>"+$(this.config.productTableId + " " + this.config.youSaveSelector).text()+"</span>";
						}	
							
							prodTable +="</td></tr>";
						}
						
						
						$(this.config.optionsSelector).each(function(i){
							currentoption = $(this);
							prodTable += "<tr><td colspan='2' class='option'>"+currentoption.html()+"</td></tr>";
						})
						
						if(this.config.writeAddtoCart){
							prodTable += "<tr><td colspan='2' class='fbatc'><span class='fbqty'>Qty: <input type='text' name='quantity' size='2' value='1' /></span><input type='submit' name='addtocart' class='fbatcbutton' value='Add to Cart' /></td></tr>";		
						}
						
						prodTable += "</table>";							
		//$('.fbright').append(prodTable);
		
		var blah = $(".prod-detail-rt").clone(true);
		$(".fbright").append(blah);
		$("#wrapper select, #wrapper input").remove();
		
		
		// append hidden inputs to build form.
		formpid = $("input[name='pid']").attr("value");
		formmid = $("input[name='mid']").attr("value");
		
		$(".newfbform").append("<input name='pid' type='hidden' value = '"+formpid+"' /><input name='mid' type='hidden' value = '"+formmid+"' />");
		
	    if(this.config.itemNameId != ""){
	      var itemnametxt = $(this.config.itemNameId+":first").text();
	      $('.fbitemname').text(itemnametxt);
	    }
		
	    // item description
	    if(this.config.hasTabbedInfo){
		    var itemDesc = $(".tabinfomain").clone(true);
		    $(".fbitemdesctxt").append(itemDesc);
		    $(".tabinfomain").tabbedInfo({firetab:0});
		    $(".fbitemdesctxt .tabinfo:first").attr("style","");
		    $(".fbitemdesctxt .tabbtns:first").click();
		    $(".tabbtns:contains('build your own')").hide();
		    $(".tabbtns:contains('reviews')").hide();
		    $(".tabinfo embed, .tabinfo object").attr("width","490");
		
	    } else {
		    // item description
		    $(".fbitemdesctxt").html($(".prod-detail-desc").text());
	    }
		
	    // cross sell
	    if($("#ctl00_pageContent_ctl111_productList").length > 0){
			homecategories = $("#ctl00_pageContent_ctl111_productList").clone(true);
			$("#fbcsitems").append(homecategories);		
	    } else {
		    $(".fbcrossell").hide();	
	    }
		
    }

    this.renderCartPage=function() {
        var $myelement = $(this.config.cartId).clone(true);
        $('#aspnetForm').append(this.facebookhtmlcart);
		$('#fbcont-int').addClass("cart-page");
		
	    $("#fbcont-int").append($myelement);
	    $("#fbcont-int").css("padding", "0");
	    $("#wrapper select,#wrapper input,#wrapper textarea").remove();
		//$(".cart-item-image a img").jScale({w: '25px'});
    }
    
    this.renderInfoPage=function() {
        $('#aspnetForm').append(this.facebookhtmlcart);
		
		var $infoHtml = $(this.config.infoPageId).clone(true);
		$("#fbcont-int").html($infoHtml);	
    }
	
	this.renderCartFirstPage=function() {
        var $myelement = $(".cart-container").clone(true);
        $('#aspnetForm').append(this.facebookhtmlcart);
		$('#fbcont-int').addClass("cart-page");
		
	    $("#fbcont-int").append($myelement);
	    $("#fbcont-int").css("padding", "0");
	    $("#wrapper select,#wrapper input,#wrapper textarea").remove();
		//$(".cart-item-image a img").jScale({w: '25px'});
    }
    

    this.renderDefaultPage=function() {
        $('#aspnetForm').append(this.facebookhtmlcart);
	    $("#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() {
        // 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 7:
                this.renderCartFirstPage();
                break;   
            default:
                this.renderDefaultPage();
                break;          
        }
        
        // clean up headers that do not have information incase styles were applied
		$(".fbheader").each(function(){
		    if($(this).text() == "" && $(this).html() == ""){
			    $(this).hide();	
		    }
	    });
		
		// clone the floating cart
		if($("#newshopcart").length > 0){
			$viewcartbuttons = $("#newshopcart").clone();
			$(".fbcart").html($viewcartbuttons);
			$viewcartbuttons = $(".itemtlt").clone();
			$(".fbcart").append($viewcartbuttons);
			//$(".fbcart").append("<a href='checkout.aspx'>Checkout</a>");
		}
		
		
		if($(".cart-continue a").length > 0){
			$(".cart-continue a").attr("href",this.config.facebookpage);	
		}
		
		// resize all images by width in a contents table
		//$(".product-thumb img").jScale({w: '125px'});
    }
	
	

    $(function(){
	    if (isFacebook() || isFacebookTest()){
		    
		    if (facebookStores!=null) {	        
		        facebookStores.init(); 
				//if ($.browser.msie ) {
					//$('#aspnetForm').attr("target", "_blank");
					//$("a[href*=\"cart.aspx\"],a[href*=\"checkout.aspx\"] ").attr("target", "_blank");
				//}
		    }
    	   	    		
		    
    		
		    /* ------------------------------------------------------------ Custom ------------------------------------------------ */
		    // 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 facebookStores = new FacebookStores("266418390082751","","http://www.esslinger.com",{});

// add section header class
