// Current page location at the load time
var currentLocation = window.location + "";
// sIFR initialization code
var cooperBlack = { src: basePath + 'includes/swf/saraLeesIFR.swf' };
sIFR.activate(cooperBlack);
// Markup for the active indicattor arrow used at the bottom navigation
var activeIndMarkup = '<div class="activeIndicator"></div>';
// Markup for loading message
var loadingMarkup = '<p class="ajax-msg ajax-loading">Loading...</p>';
// Markup for ajax error message
var ajaxErrorMarkup = '<p class="ajax-msg ajax-error">Error loading the info</p>';
/** Function that allows fade in/fade out with the toggle functionality */
jQuery.fn.fadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle'}, speed, easing, callback);
};
function popup(url) {
	var newWindow = window.open(url,'name','height=600,width=800,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
} 
//Adds new uniqueArr values to temp array
function uniqueArr(a) {
 temp = new Array();
 for(i=0; i < a.length; i++){
  if(!contains(temp, a[i])){
   temp.length += 1;
   temp[temp.length-1] = a[i];
  }
 }
 return temp;
}
 //Will check for the Uniqueness in an array
function contains(a, e) {
 for(j=0; j < a.length; j++)
 	if(a[j] == e)
		return true;
 return false;
}
/** jQuery code start */
$(document).ready(function(){
	// Default text
	autoFill($(".topSearchBox"), "Search");
	autoFill($(".topUsernameBox"), "Username");
	// This set the active tab based on page loaded
	if(typeof(sectionName) != 'undefined'){
		switch(sectionName){
			case "recipes":
				$("#main-menu ul li a.recipes").parent().addClass("activeTab");
				break;
			case "products":
				$("#main-menu ul li a.products").parent().addClass("activeTab");
				break;
			case "offers":
				$("#main-menu ul li a.offers").parent().addClass("activeTab");
				break;
			case "advertising":
				$("#main-menu ul li a.advertising").parent().addClass("activeTab");
				break;
			case "mamas-kitchen":
				$("#main-menu ul li a.mamas-kitchen").parent().addClass("activeTab");
				break;
			default:
				break;
		}
	}
	if(!isAuthenticated) {
		// Sign Up popup functionality
		$(".signUpRef").live("click",function(){
			var urlPopUp = basePath + "ajax/users/register.aspx?ReturnUrl=" + currentLocation;
			$("#userAccessWrapper").modal();
			$("#optInIframe").attr("src",urlPopUp);
			return false;
		});
		// Sign In popup functionality
		$(".signInRef").live("click",function(){
			var urlPopUp = basePath + "ajax/users/login.aspx";
			$("#userAccessWrapper").modal();
			$("#optInIframe").attr("src",urlPopUp);
			return false;
		});
		// Sign In Coupon popup functionality
		$(".signInRefCoupon").live("click",function(){
			var urlPopUp = basePath + "ajax/users/login.aspx?coupon=1";
			$("#userAccessWrapper").modal();
			$("#optInIframe").attr("src",urlPopUp);
			return false;
		});
		// Password recovery popup functionality
		$(".passRecoveryRef").click(function(){
			var urlPopUp = basePath + "ajax/users/forgottenPassword.aspx";
			$("#userAccessWrapper").modal();
			$("#optInIframe").attr("src",urlPopUp);
			return false;
		});
	}
});
// This functions adjusts the size of the iframe on the popups
function adjustPopupSize() {
	var x = 0, y = 0, windowWidth = $(window).width(), windowHeight = $(window).height();
	$("#modalPopUpContainer a.modalCloseImg").css({'top' : '5px'});
	if ($("#optInIframe").contents().find(".creatingUser").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'550px','height':'530px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 550) / 2,'top':(windowHeight - 505) / 2});
	} else if ($("#optInIframe").contents().find(".userCreated").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'380px','height':'80px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 380) / 2,'top':(windowHeight - 80) / 2});
		/*setTimeout(function() {
			if (currentLocation.indexOf("logout.aspx") >= 0)
					window.location = basePath;
			else
					window.location = currentLocation;
		},3000);*/
	} else if ($("#optInIframe").contents().find(".passRecovery").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'350px','height':'150px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 350) / 2,'top':(windowHeight - 150) / 2});
	} else if ($("#optInIframe").contents().find(".passSent").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'350px','height':'92px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 350) / 2,'top':(windowHeight - 92) / 2});
	} else if ($("#optInIframe").contents().find(".signInModalCoupon").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'340px','height':'350px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 340) / 2,'top':(windowHeight - 350) / 2});
	} else if ($("#optInIframe").contents().find(".signInModal").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'340px','height':'250px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 340) / 2,'top':(windowHeight - 250) / 2});
	} else if ($("#optInIframe").contents().find(".invalidCredentials").length > 0) {
		$("#optInIframe, #modalPopUpContainer").css({'width':'340px','height':'100px'});
		$("#modalPopUpContainer").css({'left':(windowWidth - 340) / 2,'top':(windowHeight - 100) / 2});
	}
}
// Autofill function
function autoFill(id, v){
	$(id).attr({ value:v })
	.focus(function(){
			if($(this).val() == v){
				$(this).val("");
			}
	})
	.blur(function(){
		if($.trim($(this).val()) == ""){
			$(this).val(v);
		}
	});
}// end autoFill()
/** This reinitialize the Add This buttons */
function reinitializeAddThis(){
	$(".addthis_button").each(function(){
		$(".addthis_button").click(function(){
			addthis_sendto();
			return false;
		});
		$(this).attr("onMouseOver", "return addthis_open(this, '', '"+window.location+"', '"+document.title+"');");
	});
	
}// end reinitializeAddThis()
/** sIFR replacing code */
// Apply sIFR replacing
function applyHomesIFR (){
	sIFR.replace(cooperBlack, {
		selector: '.leftColumn h3.red-hdr, .productHeadline h1.red-hdr'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.leftColumn h3.green-hdr, .productHeadline h1.green-hdr'
		,css: '.sIFR-root {color:#005944; font-weight:bold;}'
		,wmode: 'transparent'
	});
}
// Apply sIFR replacing for products and recipes titles
/*function itemTitleReplace(){
	sIFR.replace(cooperBlack, {
		selector: '.itemInfo .title a'
		,css: '.sIFR-root {color:#005944; font-weight:bold; cursor:pointer;}'
		,wmode: 'transparent'
	});
}*/
// Apply sIFR replacing for offers pages
function applyOfferIFR (){
	sIFR.replace(cooperBlack, {
		selector: '.offers-title h1'
		,css: '.sIFR-root {color:#005944; font-weight:bold; }'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.offers-title2 h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold; float:left; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '.offers-title3 h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '.offers-title4 h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '.offers-title5 h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '.left-offer-info h2'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.offer-container-steveharvey h2'
		,css: '.sIFR-root {color:#005944; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	
	sIFR.replace(cooperBlack, {
		selector: '.offer-container-helpme_hillshirefarm h2'
		,css: '.sIFR-root {color:#005944; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge h2'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge h3'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge h1'
		,css: '.sIFR-root {color:#ff0000; font-weight:normal; }'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge h4'
		,css: '.sIFR-root {color:#126d3c; font-weight:normal; }'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge h5'
		,css: '.sIFR-root {color:#666666; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge-couponview h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge-couponview h2'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge-couponview h3'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge-giftcard h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '#offer-container-freshtastechallenge-giftcard h2'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '.offer-container-delilah h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
	
	sIFR.replace(cooperBlack, {
		selector: '.offer-container-delilah h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});

	sIFR.replace(cooperBlack, {
		selector: '.offer-container-DeliSelectLunchmeat h2'
		,css: '.sIFR-root {color:#b52e18; font-weight:normal; }'
		,wmode: 'transparent'
	});
}
// sIFR replacing for logged in copy
sIFR.replace(cooperBlack, {
	selector: '.signIn table tr td span.welcome'
	,css: '.sIFR-root {color:#ffffff;} .sIFR-root a {color:#ffffff;} .sIFR-root a:hover {color:#ffffff; text-decoration:underline;}'
	,wmode: 'transparent'
});
// sIFR replacing for left side titles
sIFR.replace(cooperBlack, {
	selector: '.leftControls h2'
	,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
	,wmode: 'transparent'
});
sIFR.replace(cooperBlack, {
	selector: '.leftControls h3'
	,css: '.sIFR-root {color:#005944; font-weight:bold;}'
	,wmode: 'transparent'
});
sIFR.replace(cooperBlack, {
	selector: '.sitemapContainer h1'
	,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
	,wmode: 'transparent'
});
sIFR.replace(cooperBlack, {
	selector: '.userContainer h1'
	,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
	,wmode: 'transparent'
});
// sIFR replacing for adverstising titles function
function applyAdvertisingIFR (){
	sIFR.replace(cooperBlack, {
		selector: '.tv-filter .descrip'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.tv-filter .video-title'
		,css: '.sIFR-root {color:#005944; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.tv-filter .video-time'
		,css: '.sIFR-root {color:#999999; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.tv-filter .descrip-radio'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.print-filter .descrip-print'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.print-filter .print-title'
		,css: '.sIFR-root {color:#005944; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.print-filter .print-time'
		,css: '.sIFR-root {color:#999999; font-weight:bold;}'
		,wmode: 'transparent'
	});
	sIFR.replace(cooperBlack, {
		selector: '.print-filter h2'
		,css: '.sIFR-root {color:#bb2128; font-weight:bold;}'
		,wmode: 'transparent'
	});
}

/*Funtion for products nutritional popup*/

function applyProductPopUpIFR(){    
    sIFR.replace(cooperBlack, {
        selector: '.nutritionLeft .nutritionTitle'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    });

}

/*Funtion for print recipes popup*/

function applyReciperPrintPopUpIFR(){       
    sIFR.replace(cooperBlack, {
        selector: '.printContainer .title .subjectcontainer'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    });

}

//itemTitleReplace();
applyOfferIFR();
applyAdvertisingIFR();
applyProductPopUpIFR();
applyReciperVideoPopUpIFR();
applyRSSIFR();
applyForgotPasswordIFR();
applyPasswordEmailedIFR();
applyLogOutIFR();
applyPrintProductIFR();

// Singin/Registration replacing
sIFR.replace(cooperBlack, {
		selector: '.loginContainer h1'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
		,wmode: 'transparent'     
});
// Messages replace
sIFR.replace(cooperBlack, {
		selector: '.messageContainer h1 span'
		,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
		,wmode: 'transparent'     
});
sIFR.replace(cooperBlack, {
		selector: '.messageContainer h1 div p'
		,css: '.sIFR-root {color:#005944; font-weight:bold;}'
		,wmode: 'transparent'     
});
/*Funtion for video recipes*/ 
function applyReciperVideoPopUpIFR(){
    sIFR.replace(cooperBlack, {
        selector: '.videoContainer .bottom .name'
        ,css: '.sIFR-root {color:#005944; font-weight:bold;}'
        ,wmode: 'transparent'     
    });
        
    sIFR.replace(cooperBlack, {
        selector: '.videoContainer .title-video .title'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    });
}

/*Funtion for video recipes*/ 
function applyBioHarveyPopUpIFR(){
    sIFR.replace(cooperBlack, {
        selector: '.biographyPopUp .right-section h2'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    });   
    
     sIFR.replace(cooperBlack, {
        selector: '.biographyPopUp .all-section h3'
        ,css: '.sIFR-root {color:#005944; font-weight:bold;}'
        ,wmode: 'transparent'     
    });    
    
     sIFR.replace(cooperBlack, {
        selector: '.biographyPopUp h4'
        ,css: '.sIFR-root {color:#005944; font-weight:bold;}'
        ,wmode: 'transparent'     
    });      
}

/*Funtion for video RSS*/ 
function applyRSSIFR(){
    sIFR.replace(cooperBlack, {
        selector: '.rightSide h2'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    });           
}
/*Funtion for video ForgotPassword*/ 
function applyForgotPasswordIFR(){
     sIFR.replace(cooperBlack, {
        selector: '.CommonFormArea .CommonFormDescription'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    }); 
}
/*Funtion for video ForgotPassword*/ 
function applyPasswordEmailedIFR(){
     sIFR.replace(cooperBlack, {
        selector: '.messageWrong .title'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    }); 
}

/*Funtion for logout*/ 
function applyLogOutIFR(){
     sIFR.replace(cooperBlack, {
        selector: '.CommonMessageContent h3'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    }); 
}

/*print products*/ 
function applyPrintProductIFR(){
     sIFR.replace(cooperBlack, {
        selector: '.printContainer .title'
        ,css: '.sIFR-root {color:#b52e18; font-weight:bold;}'
        ,wmode: 'transparent'     
    }); 
}

function spotlightTagging_share() {
	var axel = Math.random() + "";
	var a = axel * 10000000000000;
	var spotpix = new Image();
	spotpix.src = "http://ad.doubleclick.net/activity;src=1419543;type=hills544;cat=email800;ord=1;num="+ a + "?";
}