$(document).ready(function() { 
     $('.nav-tabs ul').superfish({
        hoverClass: 'sfHover',
        delay:      1500, 
        animation:  {height:'show'},
        speed:      'fast', 
        autoArrows: false,
        pathClass:  'current'
     });   
    $('#lid-search input, #flavorfinder input').clearonfocus();
    $('.ro').hover(function() {
        var newImage = $(this).attr('src').replace(/^(.*?)(\.(?:gif|jpg|png))$/, "$1_o$2");
        $(this).attr('src', newImage);
    },
    function() {
        var newImage = $(this).attr('src').replace('_o.', '.');
        $(this).attr('src', newImage);
    });
    $('#site-switcher').change(function(){
        var newSite = $(this).val();
        if (newSite !== 'default') {
            window.open(newSite);
        }
    });
    
     $("div#shoponline:contains('Sandwiches')").css("display", "none").add("#global-landing-left #flavorfinder").css("border", "none");
     $("div#shoponline:contains('Uncrustables')").css("display", "none").add("#global-landing-left #flavorfinder").css("border", "none");
     
     
});

//Flavor Finder
function FlavorFinder() {
    var w = window.open('http://productlocator.infores.com/productlocator/resources/13/SMCK/sm_default.htm', 'pop', 'width=530,height=530,menubar=no,resizable=yes,scrollbars=yes');
}

function FlavorFinderSearch(upc, zip) {
    if (upc.toString().length <= 0 || zip.toString().length != 5) {
        FlavorFinder();
    }
    else{
        var loc = "http://productlocator.infores.com/productlocator/servlet/ProductLocator?productid=" + upc + "&zip=" + zip + "&searchradius=5&image.x=22&image.y=9&productfamilyid=SMCK&template=smuckers.xsl&clientid=13&stores=1&storespagenum=1&storesperpage=5&etailers=0&etailerspagenum=1&producttype=upc";
        var w = window.open(loc, 'pop', 'width=530,height=530,menubar=no,resizable=yes,scrollbars=yes');
    }
}

//Pop Up
function popup(url, width, height, moreAttributes) {

    if (typeof width == "undefined") {
        width = "400";
    }
    if (typeof height == "undefined") {
        height = "350";
    }
    if (typeof moreAttributes == "undefined")
    {
        moreAttributes = "menubar=no,resizable=yes,scrollbars=no";
    }

    var attributes = "width=" + width + ",height=" + height + "," + moreAttributes;

    var w = window.open(url, 'pop', attributes);
    w.focus();
}


//Stars on Ice scripts

$(document).ready(function() { 
	$("a.soipopwinlink").click(function(){
		var mylinkurl = $(this).attr("href");
		var mypopwidth = 168; // UPC code size defaults
		var mypopheight = 129;
		var mywindowname = "whereupc" // UPC code defaults
		
		if ($(this).hasClass("soiofferdetails")) {
			mypopwidth = 413;
			mypopheight = 245;
			mywindowname = "offerdetails";
		}
		var mymoreAttributes = "menubar=no,resizable=yes,scrollbars=no,left=50,top=50";
		var myattributes = "width=" + mypopwidth + ",height=" + mypopheight + "," + mymoreAttributes;
		var w = window.open(mylinkurl, mywindowname, myattributes);
		w.focus();
		return false;
	});
	
	$("input#soiupcbutton").click(function() {
		var myUpcCodes = $("input#soiupc").val();
		var myUpcCodesSafe = escape(myUpcCodes);
		var mylinkurl = "/promotions/stars_on_ice/ValidateUPC.aspx?upccodes=" + myUpcCodesSafe;
		var mypopwidth = 413;
		var mypopheight = 430;
		var mymoreAttributes = "menubar=no,resizable=yes,scrollbars=no,left=50,top=50";
		var myattributes = "width=" + mypopwidth + ",height=" + mypopheight + "," + mymoreAttributes;
		var w = window.open(mylinkurl, 'pop', myattributes);
		w.focus();
		return false;
	});
});

function getNumberOfWords(inputText)
{   
    var count = 0;

    inputText = inputText.replace(/^\s*|\s*$/g,'');
  
    if(inputText) 
    {
        count = inputText.split(/\s+/).length;
    }
    
    return count;
}

//Social Birthdays callouts - official rules link
function openBirthdayRules() {
    window.open("/SocialBirthdayRules.aspx", "SocialBirthdayRules", "status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1,width=600,height=700");
}
