// define global properties
facebookAppId = '169187446489962';
yhst = "mex-grocer";
domainurl = "http://www.mexgrocer.com"; // example "http://www.allvintagegames.com"
facebookpage = "http://www.mexgrocer.com/facebook-items.html" // facebook page url on site.
storename = "MexGrocer"; // Store name
viewcarturl = "http://order.store.yahoo.net/"+yhst+"/cgi-bin/wg-order?" + yhst;
cssLocation = "//lib.store.yahoo.net/lib/"+yhst+"/facebook-styles-yahoo.css";
privacyLink = "http://www.mexgrocer.com/privacy-policy.html";
copyrightId = ".credits";
badgesId = "";
contentsIdentity = ".sectcontents";
hasYMiniCart = false;
hasSCMiniCart = true; // will only clone item #'s and order total area.
shoppingcartHtml = ""; // use if hasYMiniCart = false;
contentsTableId = "#contents-table";
contentsTableImgTdId = ".imgCell"
contentsTableInfoTdId = ".infoCell";

haspaging = true;
pagingTableId = "#scpContents table ";
pagingTableImgTd = ".scpimgcell"
pagingTableInfoTd = ".scpinfocell";


// define shell properties
logoimage = "//lib.store.yahoo.net/lib/"+yhst+"/fblogo.jpg"; // use //www. to call the image NOT http://
headHTML = '<ul class="fbtopnav"><li><a href="http://www.mexgrocer.com/catagories.html">Mexican Food</a></li><li><a href="http://www.mexgrocer.com/catagories-gourmet-food.html">Gourmet</a></li><li><a href="http://www.mexgrocer.com/mexican-recipes.html">Recipes</a></li><li><a href="http://www.mexgrocer.com/catagories-mexican-candy.html">Candy</a></li><li><a href="http://www.mexgrocer.com/mexican-party-ideas.html">Party Ideas</a></li><li><a href="http://www.mexgrocer.com/catagories-cooking-utensils.html">Cooking Utensils</a></li></ul><ul class="fbbotnav"><li><a href="http://www.mexgrocer.com/gift-packages.html">Gifts and Packages</a></li><li><a href="http://www.mexgrocer.com/hot-specials.html">Hot Specials</a></li><li><a href="http://www.mexgrocer.com/best-sellers.html">Best Sellers</a></li><li><a href="http://www.mexgrocer.com/new-products.html">New Products</a></li></ul>'; // use for open html area in the head (phone number, etc).

// define homepage properties
captionheader = ""; // caption description header (item page).
categoriesheader = "<img src='//lib.store.yahoo.net/lib/"+yhst+"/fbcatsheader.jpg' alt='featured categories' style='display:block' />"; // categories header (home page).
itemheader = "<img src='//lib.store.yahoo.net/lib/"+yhst+"/fbitemsheader.jpg' alt='featured items' style='display:block' />";

// define section properties
sectionCaptionId = "#bottom-caption"; // .sectinfo on yahoo, .sectioncontain on scec
sectionPageHeadId = ".pagename"; // section page header id

// define item page properties
itemdescheader = "";
crosssellheader = "You May Also Like";
productTableId = ".iteminfo";
imageAreaId = "#scMainImage";
itemNameId = ".pagename"; // if name is part of the PIT, leave blank.

//info page properties
infoPageId = "#info-div";

// define cart properties
cartId = "#ys_pageBody";

pageType = -1;


/* 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
*/

jQuery.jScale={
	getnewSize:function(side, nvalue){
		var otherside=(side=="w")? "h" : "w"
		if (typeof nvalue=="undefined" || nvalue==null) //if this side has no explicit size set, scale it
			var newSize=this.ndimensions[otherside] * this.odimensions[side] / this.odimensions[otherside]
		else
			var newSize=(/%/.test(nvalue))? parseInt(nvalue)/100 * this.odimensions[side] : parseInt(nvalue)
		this.ndimensions[side]=Math.round(newSize)
	},
	getnewDimensions:function($, imgref, setting, callback){
 		//create temporary floating image to get original image's true dimensions (in case width/height attr set)
		var $tempimg=$('<img src="'+imgref.src+'" style="position:absolute; top:0; left:0; visibility:hidden" />').prependTo('body')
		this.odimensions={w:$tempimg.width(), h:$tempimg.height()} //get image dimensions
		var sortbysize=(this.odimensions.w>this.odimensions.h)? ["w","h"] : ["h","w"] //array to determine [largerside, shorterside]
		this.ndimensions={}
		if (typeof setting.ls!="undefined"){ //if setting.ls defined
			setting[sortbysize[0]]=setting.ls //set the correct side to the longest side's value setting
			setting[sortbysize[1]]=null
		}
		var sortbyavail=(setting.w)? ["w","h"] : (setting.h)? ["h","w"] : [] //check which side to work on based on availibility (which property is set by user)
		if (sortbyavail.length>0){
			this.getnewSize(sortbyavail[0], setting[sortbyavail[0]]) //work on side with property that's defined for sure first
			this.getnewSize(sortbyavail[1], setting[sortbyavail[1]]) //work on side with property that may or may not be defined last
			var callbackfunc=callback || function(){}
			if (setting.speed>0)
				$(imgref).animate({width:this.ndimensions.w+'px', height:this.ndimensions.h+'px'}, setting.speed, callbackfunc)
			else{
				$(imgref).css({width:this.ndimensions.w+'px', height:this.ndimensions.h+'px'})
				callbackfunc.call(imgref)
			}
		}
		$tempimg.remove()
	}
};

jQuery.fn.jScale=function(setting, callback){
	return this.each(function(){ //return jQuery obj
		var imgref=this
		if (typeof setting=="undefined" || imgref.tagName!="IMG")
			return true //skip to next matched element
		if (imgref.complete){ //account for IE not firing image.onload
			jQuery.jScale.getnewDimensions(jQuery, imgref, setting, callback)
		}
		else{
			$(this).bind('load', function(){
				jQuery.jScale.getnewDimensions(jQuery, imgref, setting, callback)
			})
		}
	})
};
// Write stylesheet if inside of facebook
if (window.parent!==window.self && self.name.indexOf("app_runner_")==0 || typeof(fbtesting) !== "undefined"){
	var headID = document.getElementsByTagName("head")[0];         
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = cssLocation;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
}

function winPop(){
	return false;	
}

function changePagingProps() {
	if(window.scPaging!=undefined){
		scPaging.addEvent("onInit",function() {
			scPaging.itemsPerPageText="all";	
			scPaging.calculateItemsPerPage();
			scPaging.calculateTotalPages();
		});
	}
}

// if paging 2.0 is detected.
if (window.parent!==window.self && self.name.indexOf("app_runner_")==0 || typeof(fbtesting) !== "undefined"){
	changePagingProps();
}

function writeContentsTable(tableId,appendTo,tablename,isPaging){
	if(isPaging){
		$imgCellTd = $(tableId + " td" + pagingTableImgTd);
		//custom infoCellTd = $(tableId + " td" + pagingTableInfoTd).get();
		infoCellTd = $(tableId + "tr.scpInfoGridRow td").get();
	} else {
		$imgCellTd = $(tableId + " td" + contentsTableImgTdId);
		infoCellTd = $(tableId + " td" + contentsTableInfoTdId).get();
	}
	
	$contentsrow = "";
	$inforow = "";

	$contents = "<table id='contents-table' class='"+tablename+"' width='100%'></table>"
	$(appendTo).append($contents);
	
	$imgCellTd.each(function(i){
		$i = i;
		$lencount = $i % 3;
		
		$imgCell = $(this).html();
		$infoCell = $(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){
			$("."+tablename).append("<tr>"+$contentsrow+"</tr>");
			$("."+tablename).append("<tr>"+$inforow+"</tr><tr><td class='horizontalSpacer' colspan='10'>&nbsp;</td></tr>");
			$contentsrow = "";
			$inforow = "";
		}
	})
	
	if($contentsrow != ""){
		$("."+tablename).append("<tr>"+$contentsrow+"</tr>");
		$("."+tablename).append("<tr>"+$inforow+"</tr>");
	}

	$("."+tablename).append("</table>");
}

// mailing list html code (copy from store) -- replace this.value with this.value = \'\'
mailinglisthtml = '<div class="bottomphone"><b>1.877.463.9476</b> <br><br>4060 Morena Blvd. <br>Suite C <br>San Diego, CA 92117</div><div class="btmlogo"><a href="http://www.mexgrocer.com/" target="_blank"><img src="//lib.store.yahoo.net/lib/'+yhst+'/fblogo2.jpg" border="0" alt="Go to Mexgrocer.com" /></a></div><form onsubmit="return (!(UPTvalidateform(document.UPTml64949)));" name="UPTml64949" method="post" target="_parent" action="http://www.elabs7.com/functions/mailing_list.html"><input type="hidden" value="3" name="submitaction"><input type="hidden" value="64949" name="mlid"><input type="hidden" value="1324658325" name="siteid"><input type="hidden" value="q2" name="tagtype"><input type="hidden" value="-1" name="demographics"><input type="hidden" value="http://www.mexgrocer.com/thank-you.html" name="redirection"><input type="hidden" value="http://" name="uredirection"><input type="hidden" value="on" name="welcome"><input type="hidden" value="on" name="double_optin"><input type="hidden" value="" name="append"><input type="hidden" value="on" name="update"><input type="hidden" value="submit" name="activity"><input type="text" onfocus="if(this.value == this.defaultValue){this.value=\'\'; this.style.color=\'#7C7C7C\';}" onblur="if(this.value == \'\'){this.value= this.defaultValue; this.style.color=\'#7C7C7C\';}" id="newsletter-email" value="Email Address" name="email"><input type="image" name="subscribe" src="//lib.store.yahoo.net/lib/mex-grocer/mailing-go.gif" id="newsletter-go" value="Go!"></form><div class="newsdesc">Join Our Mailing List to Get Special Offers and Discounts by Email</div>';

//shell header
facebookheader = '<div id="fb-root">';
	// shell start
	facebookheader += '<div id="page">';
		// header area start
		facebookheader += '<div id="fbheader">';
			facebookheader += '<div class="fbheadhtml">'+headHTML+'</div>';
			facebookheader += '<a href="'+facebookpage+'" id="logolink">';
				// logo image
				facebookheader += '<img src="'+logoimage+'" alt="'+storename+'" title="'+storename+'" border="0" />';
			facebookheader += '</a>';
			// cart container
			if(hasYMiniCart){
				facebookheader += '<div class="fbcart"></div>';
				
			} else {
				facebookheader += '<div class="fbcart">'+shoppingcartHtml+'</div>';
			}
			   
			  // custom
				facebookheader += '<div class="fbviewcart"><a href="'+viewcarturl+'"><img border="0" alt="view cart" src="//lib.store.yahoo.net/lib/mex-grocer/fbviewcart.jpg" /></a></div>'; 
			
			// header links
			facebookheader += '<div id="fbheader-links">';
				facebookheader += '<ul>';
					facebookheader += '<li><a href="'+facebookpage+'">Home</a></li>';
					facebookheader += '<li><a href="about.html">About Us</a></li>';
					facebookheader += '<li><a href="order-ship-info.html">Shipping</a></li>';
					facebookheader += '<li><a href="contact.html">Contact Us</a></li>';
					facebookheader += '<li><a href="help.html">Help</a></li>';
					facebookheader += '<li><a href="'+domainurl+'" target="_blank" class="fbviewsite">Visit Our Site</a></li>';
					
				facebookheader += '</ul>';
			facebookheader += '</div>';
		facebookheader += '</div>';
		// header area end
		facebookheader += '<div id="fbcontent">';

// shell footer
		facebookfooter = '</div>';
		facebookfooter += '<div id="fbfooter">';
			facebookfooter += mailinglisthtml;
			facebookfooter += '<a href="'+privacyLink+'" id="fb-privacy">Privacy Policy</a>';
			facebookfooter += '<div id="fbfooter-links">';
				facebookfooter += '<ul>';
					facebookfooter += '<li><a href="'+facebookpage+'">Home</a></li>';
					facebookfooter += '<li><a href="about.html">About Us</a></li>';
					facebookfooter += '<li><a href="order-ship-info.html">Shipping</a></li>';
					facebookfooter += '<li><a href="contact.html">Contact Us</a></li>';
					facebookfooter += '<li><a href="help.html">Help</a></li>';
					facebookfooter += '<li><a href="'+domainurl+'" target="_blank">Visit Our Site</a></li>';
					facebookfooter += '<li><a href="'+viewcarturl+'">Shopping Cart</a></li>';
				facebookfooter += '</ul>';
			facebookfooter += '</div>';
			//copyright container
			facebookfooter += '<div class="fbcopyright"></div>';
			facebookfooter += '<div class="fbbadges"></div>';

			/* End Custom Area */
			
		facebookfooter += '</div>';
	facebookfooter += '</div>';
facebookfooter += '</div>';

// home/section page body
facebookhomehtml ='<div id="fbcont-int">';
	// banner area
	facebookhomehtml +='<div class="fbbanner pagebanner">';
	facebookhomehtml +='</div>';
	facebookhomehtml +='<div id="fbmessage">';
		facebookhomehtml +='<div class="fbheader">';
			facebookhomehtml += captionheader;
		facebookhomehtml += '</div>';
		// caption container
		facebookhomehtml +='<div id="facebookcaption"></div>';
	facebookhomehtml +='</div>';
	facebookhomehtml +='<div class="fbcats">';
		// categories header
		facebookhomehtml +='<div class="fbheader">';
			facebookhomehtml += categoriesheader;
		facebookhomehtml += '</div>';
		// categories container
		facebookhomehtml +='<div class="fbcategories"></div>';	
	facebookhomehtml += '</div>';
	facebookhomehtml +='<div class="fbprods">';
	  facebookhomehtml +='<div class="fbheader">';
		  facebookhomehtml +=itemheader;
	  facebookhomehtml +='</div>';
	  facebookhomehtml +='<div id="facebookcontent"></div>';
	facebookhomehtml +='</div>';
facebookhomehtml +='</div>';
facebookhomehtml +='<div id="fbiteminfocontain" style="display:none;"></div>';
facebookhomehtml +='<div id="fbbottomcaption" style=""></div>';
facebookhtml = facebookheader + facebookhomehtml + facebookfooter;

// item page html
facebookitemhtml ='<div id="fbcont-int">';
  if(itemNameId != ""){
  	facebookitemhtml += '<div class="fbitemname"></div>';
  }
  facebookitemhtml +='<div class="fbitemcontain">';
      facebookitemhtml +='<div class="fbleft"></div>';
      facebookitemhtml +='<div class="fbright"></div>';
  facebookitemhtml +='</div>';
  facebookitemhtml +='<div class="fbitemdesc clear">';
      facebookitemhtml +='<div class="fbheader">'+itemdescheader+'</div>';
      facebookitemhtml +='<div class="fbitemdesctxt"></div>';
  facebookitemhtml +='</div>';
  facebookitemhtml +='<div class="fbcrossell">';
      facebookitemhtml +='<div class="fbheader">'+crosssellheader+'</div>';
      facebookitemhtml +='<div id="fbcsitems"></div>';
  facebookitemhtml +='</div>';
  /*facebookitemhtml +='<div class="fbrelated">';
      facebookitemhtml +='<div class="fbheader">'+relatedcatsheader+'</div>';
      facebookitemhtml +='<div id="fbrelatedcats"></div>';
  facebookitemhtml +='</div>';
  */
facebookitemhtml +='</div>';
facebookitem = facebookheader + facebookitemhtml + facebookfooter;

// cart body html
facebookhtmlcart = facebookheader + '<div id="fbcont-int"></div>' + facebookfooter;				

$(document).ready(function(){		   
	if (window.parent!==window.self && self.name.indexOf("app_runner_")==0 || typeof(fbtesting) !== "undefined"){
		// determine what type of page it is and run correct code.
		// 0 = home, 1 = section, 2 = item, 3 = cart, info = 4
		
		//remove snapshop init class
		$(".popImg-0036").attr("class","");
		
		if(location.href == facebookpage || typeof(fbtesting) !== "undefined"){pageType = 0;}
		
		if($(infoPageId).length > 0){pageType = 4;}
		
		if($("#articleinfocont").length > 0){pageType = 6;}
		if($("#recipe").length > 0){pageType = 7;}
		if($("#bottom-caption").length > 0){pageType = 8;}
		if($("#contactForm").length > 0){pageType = 9;}
		
		if(location.href != facebookpage && $(productTableId).length < 1 && $(contentsIdentity).length > 0){pageType = 1;}
		if($(productTableId).length > 0){pageType = 2;}
		if($(cartId).length > 0){pageType = 3;}
		if($(pagingTableId).length > 0){pageType = 5;}
		//alert(pageType);
	
	    var page_name="";
	
		// homepage
		if(pageType == 0){
			// append the home html
			$('body').append(facebookhtml);
			
			// grab the text
			if($(sectionCaptionId).length > 0){ 
				$captiondiv = $(sectionCaptionId).clone(true);
				$("#facebookcaption").html($captiondiv.html());
			} else {
				$("#fbmessage").hide();	
			}
			// find items and categories
			if($(".products").length > 0){ writeContentsTable(".products","#facebookcontent","fbprodtable",false) } else {$(".fbprods").hide();}
			if($(".categories").length > 0){ writeContentsTable(".categories",".fbcategories","fbcatstable",false)}	else {$(".fbcats").hide();}
			
			// banner image
			prodImage =  $(".homebanner").clone(true);
			$('.fbbanner').prepend(prodImage);
			
			page_name="Home Page";
		}
		
		// section page
		if(pageType == 1 || pageType == 5){
			$('body').append(facebookhtml);


			// Custom
			if($("#viewmore").length > 0){			
				$("#viewmore").click();
			}
			
			
			
			// end custom
			
			subhead = $("h1[itemprop='name']").clone(true);
			$('#fbcont-int').prepend(subhead);
			
			if($(sectionCaptionId).length > 0){ 
				$captiondiv = $(sectionCaptionId).clone(true);
				$("#fbbottomcaption").html($captiondiv.html());
			} else {
				$("#fbmessage").hide();	
			}
			
			// hide items that don't belong
			$(".fbbanner").hide();
			$("#fbmessage img").hide();
			$(".fbdescheader").hide();
			$(".fbheader").hide();
			
			
			// start custom
			var capcont = $("#facebookcaption #sectinfocont-inner");
			if (capcont.get(0)) {
				var captext = capcont.get(0).innerHTML;
				var captlen = captext.length;
				if(captlen>390){
					var captslice = captext.slice(0,390) + "... </b></p><span id='viewmore'> view more</span>";
					capcont.html(captslice);
				}
				$("#facebookcaption #viewmore").click(function(){
				
					var old=$("#facebookcaption #sectinfocont-inner")[0];
				
					$(old).before("<div id='sectinfocont-inner'>"+captext+"</div>");
					
					$(old).remove();
				
					//$("#sectinfocont-inner").html(captext);
					//$("#sectinfocont-inner").children().replaceWith(captext)
					});
			}
			
			// end custom
			
			// find items and categories
			if($(contentsTableId).length > 0){
				writeContentsTable(contentsTableId,"#facebookcontent","fbsectiontable",false);
			} else if($(pagingTableId).length > 0) {
				writeContentsTable(pagingTableId,"#facebookcontent","fbsectiontable",true);
				$(".scpimg a").attr("style","display:block;");
			} else {
				$(".fbprods").hide();
			}	
			page_name="Default/Cart Page";
		}
		
		// item page
		if(pageType == 2){
			
			$('body').append(facebookitem);
			
			prodImage = $(imageAreaId).clone(true);
			$('.fbleft').prepend(prodImage);
			//$(".fbleft img#scMainImgId").jScale({w: '180px'});
			$(".fbleft img#scMainImgId").jScale({w: '180px'});
			$(".fbleft img#scMainImgId").jScale({h: '200px'});
			
			
			infoTable = $(productTableId).clone(true);
			$('.fbright').append(infoTable);
			
			if(itemNameId != ""){
			  itemnametxt = $(itemNameId+":first").text();
			  $('.fbitemname').text(itemnametxt);
			}
			
			hasTabbedInfo = true;

			if(hasTabbedInfo){
				itemDesc = $(".tabinfomain").clone(true);
				$(".fbitemdesctxt").append(itemDesc);
				$(".tabinfomain").tabbedInfo({firetab:0});
				$(".fbitemdesctxt .tabinfo:first").attr("style","");
				$(".fbitemdesctxt .tabbtns:first").click();
				$(".fbitemdesctxt .tabbtn:first").click();
				$(".tabbtns div").each(function(){
					if($(this).text() == "Reviews" || $(this).text() == "Build Your Own"){
						$(this).hide();	
					}
				});
			
			} else {
				// item description
				$(".fbitemdesctxt").text($(".description").text());
			}

			// cross sell
			if($(".upsell-panel").length > 0){
				relitems = $(".upsell-panel").clone(true);
				$('#fbcsitems').append(relitems);
			} else {
				$(".fbcrossell").hide();	
			}
			
			$("#scMainImage").click(function(){
				FB.Canvas.scrollTo(0,0);							 
			});
			
			
			$(".bottom-info tr:last").hide();
			
			$(productTableId + " form").attr("target","");
			
			page_name="Item Page";
		}
		
		// cart
		if(pageType == 3){
			$myelement = $(cartId).clone(true);
			
			$('body').append(facebookhtmlcart);
			$("#fbcont-int").html($myelement);
			$("#fbcont-int").css("padding","0");
			
			$("a[href='http://store.yahoo.com/"+yhst+"/index.html']").attr("href",facebookpage);
			$(".fbcart,.fbviewcart").hide();
			page_name="Cart Page";
		}
		
		if(pageType == 4){
			$('body').append(facebookhtmlcart);
			
			$infoHtml = $(infoPageId).clone(true);
			$("#fbcont-int").html($infoHtml);
			$("table").attr("style","width:520px;");
		}
		
		// recipe page.
		if(pageType == 6){
			$('body').append(facebookhtmlcart);
			
			$infoHtml = $("#articleinfocont").clone(true);
			$("#fbcont-int").html($infoHtml);
			$("table").attr("style","width:520px;");
			
			page_name="Recipe Page";
		}
		
		if(pageType == 7){
			$('body').append(facebookhtmlcart);
			
			$infoHtml = $("#recipe").html();
			$("#fbcont-int").html("<div class='recipe'>"+$infoHtml+"</div>");
			$("table").attr("style","width:520px;");
		}
		
		if(pageType == 8){
			$('body').append(facebookhtmlcart);
			
			$infoHtml = $("#bottom-caption").html();
			$("#fbcont-int").html($infoHtml);
			
			if($(".pagename-sub").length > 0){
			  itemnametxt = $(".pagename-sub").clone(true);
			  $("#fbcont-int").prepend(itemnametxt);
			}
			$("table").attr("style","width:520px;");
		}
		
		if(pageType == 9){
			$('body').append(facebookhtmlcart);
			
			$infoHtml = $(".yui-g").html();
			$("#fbcont-int").html($infoHtml);
$("table").attr("style","width:520px;");
			
		}		
		
		var trackerName="~0";
        if (window._gat && window._gat._getTrackerByName(trackerName) && window._gat._getTrackerByName(trackerName)._trackEvent) {
	        window._gat._getTrackerByName(trackerName)._setCustomVar(1,"Face Book Store", page_name, 3);
	        window._gat._getTrackerByName(trackerName)._trackEvent("FaceBook Store","Open", page_name,0);
        }
		
		
		//default pageType
		if(pageType == -1){
			
			
			if($("#sectinfocont-inner").length > 0){
				// info page
				$('body').append(facebookhtml);
				subhead = $("h1[itemprop='name']").clone(true);
				$('#fbcont-int').prepend(subhead);
				
				infocapt = $("#sectinfocont-inner").clone(true);
				$("#facebookcaption").html(infocapt);
			} else {
				
				$('body').append(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);		
			}
			
			
		}
		
		if(pageType != 0){
			// previous page
			$('#fbcont-int').prepend("<a href='javascript:history.go(-1)' class='prevPage'><- Previous Page</a>");	
		}
		
		// info page
		
		// clean up headers that do not have information incase styles were applied
		$(".fbheader").each(function(){
			if($(this).text() == "" && $(this).html() == ""){
				$(this).hide();	
			}
		});
		
		//clone default items
		 $("embed, object, iframe").attr("width","490");
		 $("#info-div:first").remove();
		 
		// badges
		if(badgesId != ""){
			badgehtml = $(badgesId).html();
			$(".fbbadges").html(badgehtml);
		}
		// copy right
		if(copyrightId != ""){
			copyhtml = $(copyrightId).html();
			$(".fbcopyright").html(copyhtml);
		}
		
		// floating cart
		if(hasYMiniCart || hasSCMiniCart){
			window.checkIntervalId=window.setInterval(function() {
				if ($("#toggLink-0061").length > 0) {
					cartpage = $("#minCart-0061").clone(true);
					$('.fbcart').html(cartpage);
					//$('.fbcart').click(function(){window.location = viewcarturl;});
					window.clearInterval(window.checkIntervalId);
				}
				
				// yMiniCart
				if ($("#yfc_mini").html()!="") {
					cartpage = $("#yfc_mini").clone(true);
					$('.fbcart').append(cartpage);
					$('.fbcart').click(function(){window.location = viewcarturl;});
					window.clearInterval(window.checkIntervalId);
				}	
			}, 500);
		}
		
		/* ------------------------------------------------------------ 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);
		}());	
	}
});

/*
Mini cart fix...

<script type='text/javascript'>


if (window.parent!==window.self && self.name.indexOf("app_runner_")==0) {
	SC.inFrame=function() {

		return false;	

	};
}

</script>
*/


