﻿////////outbound tracking//////////
	function outboundTrack(){		 
		if (document.getElementsByTagName) {
			var ahrefs = document.getElementsByTagName('a');
			var len = ahrefs.length;
			for(var i=0; i < len; i++ ){
				
				//track when user clicks on external link
				if (ahrefs[i].href.indexOf('http://www.heinz.com') == -1 && !ahrefs[i].onclick && ahrefs[i].href.indexOf('http://heinz.com') == -1 && ahrefs[i].href.indexOf('http://164.109.45.99') == -1) {
					ahrefs[i].onclick = function () {
						pageTracker._trackPageview("/outbound-links/" + this.href.substring(7));
					} 
				
				}
			}
		}	
	}



/////////////Trivia Section////////////////
function correctTriviaAnswer(currObj){
    $('.triviaQuestion > .triviaAnswer').removeClass("correct").removeClass("incorrect").css('display','none');
    var parentObj = $(currObj.parentNode.parentNode.parentNode);
    $(parentObj).find(".triviaAnswer").prepend("<div class='answerTitle'>Correct!</div>").slideDown("slow").attr( "class", "correct" );

}

function incorrectTriviaAnswer(currObj){ 
    $('.triviaQuestion > .triviaAnswer').css('display','none');
    var parentObj = $(currObj.parentNode.parentNode.parentNode);
    $(parentObj).find(".triviaAnswer").prepend("<div class='answerTitle'>Incorrect.</div>").slideDown("slow").attr( "class", "incorrect" );
}

///////////////DropDown List Handler///////////
function onDropDownChange(dropdown)
{
    var myindex  = dropdown.selectedIndex;
    var SelValue = dropdown.options[myindex].value; 
    top.location.href = SelValue;
    return true;
}

//////////////Recipe//////////////////
function setRecipeBg(divName, recipePath){
    var bgDiv = document.getElementById(divName);
    bgDiv.style.background = "url("+ recipePath + ")";
    bgDiv.style.backgroundRepeat = "no-repeat";
}

/////////////Product Carousel/////////////
//generate the product carousel on load
function productCarouselInit(){
        //var CarouselScript=document.createElement('carouselscript') 
        //CarouselScript.src="/scripts/jquery.jcarousel.pack.js" 
        //document.body.appendChild(CarouselScript); 

        var mycarousel_itemList = [
            {url: 'http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg', title: 'Flower1'},
            {url: 'http://static.flickr.com/75/199481072_b4a0d09597_s.jpg', title: 'Flower2'},
            {url: 'http://static.flickr.com/57/199481087_33ae73a8de_s.jpg', title: 'Flower3'},
            {url: 'http://static.flickr.com/77/199481108_4359e6b971_s.jpg', title: 'Flower4'},
            {url: 'http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg', title: 'Flower5'},
            {url: 'http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg', title: 'Flower6'},
            {url: 'http://static.flickr.com/58/199481218_264ce20da0_s.jpg', title: 'Flower7'},
            {url: 'http://static.flickr.com/69/199481255_fdfe885f87_s.jpg', title: 'Flower8'},
            {url: 'http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg', title: 'Flower9'},
            {url: 'http://static.flickr.com/70/229228324_08223b70fa_s.jpg', title: 'Flower10'}
        ];

        function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
        {
            // The index() method calculates the index from a
            // given index who is out of the actual item range.
            var idx = carousel.index(i, mycarousel_itemList.length);
            carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
        };

        function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
        {
            carousel.remove(i);
        };

        /**
         * Item html creation helper.
         */
        function mycarousel_getItemHTML(item)
        {
            return '<img src="' + item.url + '" width="75" height="75" alt="' + item.title + '" />';
        };

        jQuery(document).ready(function() {
            jQuery('#mycarousel').jcarousel({
                wrap: 'circular',
                itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
                itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
            });
        });
}
////////////////Date and Time Functions//////////////////
    //-- returns the current date in mm.dd.yyyy format as a string :
function todayStr()
{ 
    var today=new Date();
    return (today.getYear())+(today.getMonth()+1)+today.getDate();
}
////////////////GET QUERY in JavaScript Function///////////
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
} 