/*  VARIABLES */

	var url;
	var section;
	var page;
	
	var json;
	var timelineNum = 0;
	var timelineImg = null; //this is used in the query string when visiting directly
	var imageNum = -1;
	
	var $w;
	
	var $domain = 'creamofwheat.com';
	var $siteURL = 'http://'+$domain+'/';

$(document).ready(init);

function init()
{	

	
	url = $.url()
	
	section = url.segment()
	
	
	
	for ( var i = 0; i < section.length; i++ )
	{
		if ( section[ i ] == 'about' ) { loadJSON( feed, timelineLoaded ); page = 'about'; }
		else if ( section[ i ] == 'products' ) {loadJSON( feed, productsLoaded ); page = 'products'; }
		else if ( section[ i ] == 'healthy-living' ) {loadJSON( feed, productsLoaded ); initHL();  page = 'healthy-living'; }
		else if ( section[ i ] == 'locate' ) { initLocate(); page = 'locate'; }
		else if ( section[ i ] == 'recipes' ) { initRecipes(); page = 'recipes'; }
		
	}
	$('#nav .navitem, #nav .subitem').hover( navover, navout )
	$('#nav .navitemwsub').hover( showSub, hideSub )
	$('#footer .navitem').hover( ftover, ftout )
	$('#features .featureitem').hover( fiover, fiout )
	
	addExternalTracking();
	
	$w = $(window)
}

/********* JSON Loader ************/

function loadJSON( $feed, $success )
{	
	
	$.ajax({ type: "GET", url:$feed, dataType: "jsonp", success:$success });		
}


/****** BTNS ********/

function navover()
{
	$(this).stop(true, true).animate( { 'color':'#c2020f' }, 1500, 'easeOutQuint'  )
}

function navout()
{
	$(this).stop(true, true).animate( { 'color':'#1f499d' }, 500, 'easeOutQuint'  )
}

function showSub()
{
		$(this).find( '#link' ).stop(true, true).animate( { 'color':'#c2020f' }, 1500, 'easeOutQuint'  )
        //Following events are applied to the subnav itself (moving subnav up and down)  
        $(this).parent().find("ul.subnav").stop( true, true ).slideDown('fast').show(); //Drop down the subnav on click  
  
        $(this).parent().hover(function() {  
        }, function(){  
            $(this).parent().find("ul.subnav").stop( true, true ).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up  
        });  
  
       
}

function hideSub()
{
	$(this).find( '#link' ).stop(true, true).animate( { 'color':'#1f499d' }, 500, 'easeOutQuint'  )
}

function fiover()
{
	$(this).find( '.featuredImg' ).stop(true, true).css( { 'top':'0%', 'left':'0%', 'height':'100%', 'width':'100%' } )
	
}

function fiout()
{
	$(this).find( '.featuredImg' ).css( { 'top':'2%', 'left':'2%', 'height':'96%', 'width':'96%' } )
}

function ftover()
{
	$(this).stop(true, true).animate( { 'color':'#c2020f' }, 1500, 'easeOutQuint'  )
}

function ftout()
{
	$(this).stop(true, true).animate( { 'color':'#4d2e1a' }, 500, 'easeOutQuint'  )
}

function arrowover()
{
	$(this).stop(true, true).animate( { 'opacity':'.5' }, 1000, 'easeOutQuint'  )
}

function arrowout()
{
	$(this).stop(true, true).animate( { 'opacity':'1' }, 500, 'easeOutQuint'  )
}

function resizer()
{
	resizeLB()
	$w.resize( resizeLB )
	$w.bind('scroll', resizeLB );
}


/*** POP UP USED ON FACEBOOK ****/



function popup(url) {
	newwindow=window.open(url,'name','height=430,width=570,scrollbars=no, resizable=0');
	if (window.focus) {newwindow.focus()}
	return false;
}




/******* TIME LINE **********/

function nextArrowClick()
{
	timelineNum++
	$( '#timelineContainer' ).stop(true, false).animate( { 'left':timelineNum * -184 + 'px' }, 1000, 'easeInOutQuint' )
	setTimelineNav()
}

function prevArrowClick()
{
	timelineNum--	
	$( '#timelineContainer' ).stop(true, false).animate( { 'left':timelineNum * -184 + 'px' }, 1000, 'easeInOutQuint' )
	setTimelineNav()
}

function thumbOver()
{
	$( this ).find( 'h3' ).stop(true, true).animate( {'color':'#c2020f', 'font-size':'25'}, 500, 'easeOutQuint' )
}

function thumbOut()
{
	$( this ).find( 'h3' ).stop(true, true).animate( {'color':'#4d2e1a', 'font-size':'17'}, 250, 'easeOutQuint' )
}

function thumbClick()
{
	
	$( '.lightBox' ).css( 'display', 'block' ) 
	$( '.lightBox #bkg' ).css( { 'opacity':'0' } ).animate( { 'opacity':'.5' }, 1000, 'easeInOutExpo' )
	
	
	if(timelineImg != null){
		for ( var i = 0; i < json.length; i++ )
		{
			if(json[i].id == timelineImg) imageNum = i
		}	
	}
	else imageNum = $( this ).attr( 'id' ).substr( 8 )
	
	timelineImg = null 
	
	emailabout('about',json[ imageNum ].id, json[ imageNum ].artist, json[ imageNum ].year, json[ imageNum ].thumb);
	
	var shareurl = $siteURL +'about/share/index.php?id='+ json[ imageNum ].id
	
	$( '.lightImg' ).css( 'left', '0px' )
	$( '.lightImg' ).append( '<div class="lightImgBkg"><div id="close">CLOSE X</div><img src="' + path + json[ imageNum ].image + '" class="detailImg"/><div class="lbText"><h3>Artist: ' + json[ imageNum ].artist + ' - ' + json[ imageNum ].year + '</h3><p>' + json[ imageNum ].blurb + '</p></div><div class="lbShare"><a class="download downloadbtn" href="' + path + json[ imageNum ].full + '" target="_blank"></a><a class="emailbtn sendtoafriend"></a><div class="clear"></div><a id="fb" class="fbbtn float-left" href="http://www.facebook.com/sharer/sharer.php?u='+shareurl+'" onclick="return popup(\'http://www.facebook.com/sharer/sharer.php?u='+shareurl+'\')"></a><div id="twitter" class="left"><a href="http://twitter.com/share" class="twitter-share-button" data-url="'+ $siteURL +'share/about-share.php?id='+ json[ imageNum ].id +'" data-text="Classic art from the Cream of Wheat™ Memory Gallery" data-count="true">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div></div><div class="clear"></div>' )  
	
	
	$( '.lightBox #close' ).hover( ftover, ftout )
	$( '.lightBox #close' ).click( function(event){closeImage(); closeemail();} )
	$('.detailImg').load( showImage )
	$( '.lightImg' ).css( { 'visibility':'hidden' } )
	
	$('.eclose').click(closeemail)
	$('.emailbtn').click(openemail)
	
	$( '.lightBox #bkg' ).click( function(event){closeImage(); closeemail();} )
	

	
}




function getUrlVars(){
	
	
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	
	for(var i = 0; i < hashes.length; i++)
    {
	    hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
		
		if( hash[1] != undefined){ 
			timelineImg = hash[1];
			thumbClick()
		
		}
    }
}



function showImage()
{
	resizeLB();
	$( '.lightImgBkg' ).css( { 'width':$( '.detailImg' ).width() + 40 + 'px' } );
	$( '.lightImgColorBkg' ).css( { 'width': 790 + 'px', 'height':580 + 'px' } );
	var $bkg;
	if ( page == 'about' ) $bkg = $( '.lightImgBkg' )
	else $bkg = $( '.lightImgColorBkg' )
	
	$( '.lightImg' ).stop( true, false ).css( { 'visibility':'visible', 'left':-$bkg.width() } ).delay( 500 ).animate( { 'left':$w.width() * .5 + $bkg.width() * -.5 + $w.scrollLeft() }, 1500, 'easeInOutExpo' );
	
	
	
}

function closeImage()
{
	//console.log('closeimg')
	
	$( '.lightImg' ).stop( true, false ).delay( 100 ).animate( { 'left':$w.width() }, 250, 'easeInQuint' )
	$( '.lightBox #bkg' ).animate( { 'opacity': '0' }, 250, 'linear' )
	setTimeout( function(){ $( '.lightBox' ).css( 'display', 'none' );$( '.lightImgBkg' ).remove() } , 350 )	
	
}

function timelineLoaded( $data )
{
	resizer()	
	
	json = $data.feed;
	
	
	$( '#timelineContainer' ).css( { width:json.length * 195 } )
	
	var $str = '<div></div>';
	
	for ( var i = 0; i < json.length; i++ )
	{
		if ( json[i].type == 'image' ) $str += '<div class="timelineImg float-left" id="timeline'+ i +'" ><img src="'+ path + json[i].thumb +'" class="thumb"><br><h3 class="center" style="padding-top:10px; padding-right:15px;">' + json[ i ].year + '</h3></div>' ;	
		else if ( json[i].type == 'fact' ) $str +=  '<div class="timelineFact float-left" ><div style="height:191px"><h3>FACT:</h3><p>' + json[i].blurb + '</p></div><h3 class="center" style="padding-top:10px; padding-right:15px;">' + json[ i ].year + '</h3></div>' ;	
	}
	
	$( '#timelineContainer' ).html ( $str )
	
	$( '#nextArrow' ).hover( arrowover, arrowout )
	$( '#prevArrow' ).hover( arrowover, arrowout )
	
	$( '#nextArrow' ).click( nextArrowClick )
	$( '#prevArrow' ).click( prevArrowClick )
	
	$( '.timelineImg' ).hover( thumbOver, thumbOut )
	$( '.timelineImg' ).click( thumbClick )	
	
	setTimelineNav()	
	
	getUrlVars()	//look to see if there's a direct url to an image
}

function setTimelineNav()
{
	if ( timelineNum == 0 )
	{
		$( '#nextArrow' ).css( { 'visibility':'visible' } )
		$( '#prevArrow' ).css( { 'visibility':'hidden' } )
	}
	else if ( timelineNum == json.length - 5 )
	{
		$( '#nextArrow' ).css( { 'visibility':'hidden' } )
		$( '#prevArrow' ).css( { 'visibility':'visible' } )
	}
	else 
	{
		$( '#nextArrow' ).css( { 'visibility':'visible' } )
		$( '#prevArrow' ).css( { 'visibility':'visible' } )
	}
}

function resizeLB()
{	
	$( '.lightBox' ).css( { 'width':$w.width() + $w.scrollLeft(), 'height':$w.height() + $w.scrollTop() } )	
	var $bkg;
	if ( page == 'about' ) $bkg = $( '.lightImgBkg' )
	else $bkg = $( '.lightImgColorBkg' )
	
	if ( page == 'about') $( '.lightImg' ).css( { 'left':$w.width() * .5 + $bkg.width() * -.5 + $w.scrollLeft(), 'top':200} )
	else	$( '.lightImg' ).css( { 'left':$w.width() * .5 + $bkg.width() * -.5 + $w.scrollLeft(), 'top':( $w.height() * .5 ) + ($bkg.height() * -.5 ) + $w.scrollTop()} )
	
	if ( page == 'about' || page == 'recipes' ){
		
		var center = ( ($w.width() - $('#emailbox').width() )/2+ $w.scrollLeft() )
		var tcenter = ( ($w.height() - $('#emailbox').height())/2 + $w.scrollTop() )
		
		$( '#emailbox' ).css( {'left':center, 'top':tcenter });
		
	}
	
	if(page =='products' && subPage =='cinnabon'){
		
		var center = ( ($w.width() - $('#video').width() )/2+ $w.scrollLeft() )
		var tcenter = ( ($w.height() - $('#video').height())/2 + $w.scrollTop() )
		
		$( '#video' ).css( {'left':center, 'top':tcenter });
	}
	
}


/******* PRODUCTS **********/

var featuredProducts = [ 'chocolate', 'cinnabon', 'variety', 'healthy-grain', 'original', 'cream-of-rice' ]





function productsLoaded( $data )
{
	resizer()
	
	json = $data.feed;	
	
	
	$( '.product' ).hover( productOver, productOut )
	$( '.product' ).click( productClick )	
	
	$( '.smallbtn, .largebtn' ).hover( productBtnOver, productBtnOut )
	$( '#nutritionInfo' ).click( nutritionClick )	
	$( '#recipes' ).click( function(){ window.location = path + 'recipes/' } )	
	
	$( '.nextitem, .previtem' ).hover( productBtnOver, productBtnOut )
	$( '.nextitem' ).click( nextClick )
	$( '.previtem' ).click( prevClick )
	
}

function productOver()
{
	$( this ).find( '.moreinfo' ).stop(true, true).animate( {'color':'#c2020f'}, 1000, 'easeOutQuint' )
	$( this ).find( '.productdescrip' ).stop(true, true).animate( {'color':'#c2020f'}, 1000, 'easeOutQuint' )
}

function productOut()
{
	$( this ).find( '.moreinfo' ).stop(true, true).animate( {'color':'#1f499d'}, 250, 'easeOutQuint' )
	$( this ).find( '.productdescrip' ).stop(true, true).animate( {'color':'#4d2e1a'}, 250, 'easeOutQuint' )
}

function productClick()
{
	var i = $( this ).attr( 'id' ).charAt( 7 ) 
	var j = $( this ).attr( 'id' ).substr( 9 ) 
	
	appendLBContent( i, j )	
}

function nutritionClick()
{
	 if ( subPage == 'chocolate' ) { var i = 1; j = 1 }
	if ( subPage == 'cinnabon' ) { var i = 1; j = 3 }
	if ( subPage == 'original' ) { var i = 0; j = 1 } 
	if ( subPage == 'healthy-grain' ) { var i = 2; j = 1 } 
	if ( subPage == 'cream-of-rice' ) { var i = 3; j = 0 } 
	if ( subPage == 'variety' ) { var i = 2; j = 0 } 
	
	appendLBContent( i, j )		
}

function appendLBContent( i , j )
{
		$( '.lightBox' ).css( 'display', 'block' ) 
	$( '.lightBox #bkg' ).css( { 'opacity':'0' } ).animate( { 'opacity':'.5' }, 1000, 'easeInOutExpo' )
	
	
	
	if(json[ i ].items[ j ].title == 'CREMA<br>DE ARROZ') var ingred = 'Vitaminas y Minerales'
	else 
	{	
		if (json[ i ].items[ j ].ingredients2 == '') var ingred = ''
		else var ingred = 'Vitamins and Minerals:'
	}
	
	
	if(json[ i ].items[ j ].title == 'CINNABON') var learnmore = '<div class="learnmore"><br /><br />Cinnabon®, Makara® and the Cinnabon logo are trademarks of Cinnabon, Inc.,<br />and used under license by B&G Foods, Inc.</div>'
	else var learnmore = ''
	
	
	
	if(json[ i ].items[ j ].products){
		
		onproductswitch(i, j, 0)
	}
	
	else{
	
	var $str = '<div class="lightImgColorBkg"><div id="close">CLOSE X</div><div class="detailContent"><div class="productDetailContentLeft"><div class="detailThumb float-left"><img src="' + path + json[ i ].items[ j ].thumb + '"></div>'
	$str +=  '<div><h1>' + json[ i ].items[ j ].title + '</h1></div><div class="clear"></div><div style="margin-top:10px;">' + json[ i ].items[ j ].description + '</div><div class="clear"></div>'
	
	$str +=  '<div class="ingredients"><div class="block"><span class="bold">Ingredients:</span> '  + json[ i ].items[ j ].ingredients1 + '</div><div class="block"><span class="bold">'  +ingred + '</span> '  + json[ i ].items[ j ].ingredients2 + '</div><div class="clear">'+learnmore+'</div></div></div><div class="productDetailContentRight"><img src="' + path + json[ i ].items[ j ].facts + '"></div></div></div>';	
	
	
	$( '.lightImg' ).html( $str )	
	}
	
	$( '.lightImg' ).css( 'left', '0px' )
	
	$( '.lightBox #close' ).hover( ftover, ftout )
	$( '.lightBox #close' ).click( closeImage )

	$( '.lightImg' ).css( { 'visibility':'hidden' } )
	
	$( '.lightBox #bkg' ).click(closeImage)
	
	
	showImage()
	
}


function onproductswitch(i, j, c){
	
	var $str = '<div class="lightImgColorBkg"><div id="close">CLOSE X</div><div class="detailContent"><div class="productDetailContentLeft"><div class="detailThumb float-left"><img src="' + path + json[ i ].items[ j ].thumb + '"></div>'
	
	$str +=  '<div><h1>' + json[ i ].items[ j ].title + '</h1><br/>Click a variety pack flavor to view the nutritional facts.<br/><br/>'
	
	
	
	for ( var b = 0; b < json[ i ].items[ j ].products.length; b++ ){
			
			
			if (b == c) $str +=' <span class="active">'+json[ i ].items[ j ].products[b].item +'</span><br/>'
			else $str +=' <a onclick="onproductswitch('+i+','+ j+','+b+')">'+json[ i ].items[ j ].products[b].item +'</a><br/>'
		}
	
	$str +=  '</div><div class="clear"></div><div style="margin-top:10px;">' + json[ i ].items[ j ].description + '</div><div class="clear"></div>'
	
	$str += '<div class="ingredients"><div class="block"><span class="bold">Ingredients:</span> '  + json[ i ].items[ j ].products[c].ingredients1 + '</div><div class="block"><span class="bold">Vitamins and Minerals:</span> '  + json[ i ].items[ j ].products[c].ingredients2 + '</div><div class="clear"></div></div></div><div class="productDetailContentRight"><img src="' + path + json[ i ].items[ j ].products[c].facts + '"></div></div></div>'
	
	$( '.lightImg' ).html( $str )	
	
	$( '.lightBox #close' ).hover( ftover, ftout )
	$( '.lightBox #close' ).click( closeImage )
	
	
	$( '.lightImgBkg' ).css( { 'width':$( '.detailImg' ).width() + 40 + 'px' } );
	$( '.lightImgColorBkg' ).css( { 'width': 790 + 'px', 'height':580 + 'px' } );
	
	resizeLB();
}


function productBtnOver()
{
	$( this ).stop(true, true).animate( {'color':'#1f499d'}, 1000, 'easeOutQuint' )
}

function productBtnOut()
{
	$( this ).stop(true, true).animate( {'color':'#4d2e1a'}, 250, 'easeOutQuint' )
	
}

function nextClick()
{
	var j = 0
	for ( var i = 0; i < featuredProducts.length; i++ )
	{
		if ( featuredProducts[i] == subPage ) 
		{	
			j = i	
			break;
		}
	}
	
	var k = j + 1;
	if ( k == featuredProducts.length ) k = 0
	
	window.location = path + 'products/' + featuredProducts[ k ] + '/'
	
}

function prevClick()
{
	var j = 0
	for ( var i = 0; i < featuredProducts.length; i++ )
	{
		if ( featuredProducts[i] == subPage ) 
		{	
			j = i	
			break;
		}
	}
	
	var k = j - 1;
	if ( k == -1 ) k = featuredProducts.length - 1
	
	window.location = path + 'products/'  + featuredProducts[ k ] + '/'
}



/***** INDIVIDUAL PRODUCT *******/

function openvideo(){
	$('#video').css( { 'display':'block' } )
	$('#video').append('<div class="youtube"><iframe width="550" height="339" src="http://www.youtube.com/embed/pXQq5iwFXgI" frameborder="0" allowfullscreen></iframe></div>')
	
		$( '.lightBox' ).css( 'display', 'block' )
		$( '.lightImgColorBkg' ).css( 'display', 'none' )
		$( '.lightBox #bkg' ).css( { 'opacity':'0' } ).animate( { 'opacity':'.5' }, 500, 'easeInOutExpo' )
	resizer()
	
	var center = ( ($w.width() - $('#video').width() )/2+ $w.scrollLeft() )	
	$( '#video' ).stop( true, false ).css( { 'visibility':'visible', 'left':-$w.width() } ).delay( 500 ).animate( { 'left': center}, 1500, 'easeInOutExpo' );
	
}

function closevideo(){
	
	
	$( '#video' ).stop( true, false ).animate( { 'left': $w.width() + 100}, 500, 'easeInOutExpo' );
	setTimeout( function(){ $( '#video' ).css( 'display', 'none' );$( '.youtube' ).remove() } , 250 )
	
	closeImage()	
}

$('.watchvideo').click(openvideo)	
$('.vclose').click(closevideo)

/* HEALTHY LIVING */

function initHL()
{
	$( '.subNav' ).hover( subNavOver, subNavOut )
	$( '.top' ).hover( topOver, topOut )
	
	$( '.subNav' ).click(	function(){ $.scrollTo( $( this ).attr('id') , 800, {easing:'easeOutQuint'}) }  )
	$( '.top' ).click(	function(){ $.scrollTo( $( this ).attr('id') , 800, {easing:'easeOutQuint'}) }  )
	
}

function subNavOver()
{
	$( this ).find( 'img' ).stop( true, true ).animate( { 'top':'-20px' }, 500, 'easeOutExpo' )
	$( this ).find( '.subNavTitle' ).stop( true, true ).animate( { 'color':'#1f499d' }, 500, 'easeOutExpo' )
}

function subNavOut()
{
	$( this ).find( 'img' ).stop( true, true ).animate( { 'top':'0px' }, 250, 'easeOutBounce' )
	$( this ).find( '.subNavTitle' ).stop( true, true ).animate( { 'color':'#4d2e1a' }, 500, 'easeOutExpo' )
}

function topOver()
{
	$( this ).stop( true, true ).animate( { 'color':'#1f499d' }, 500, 'easeOutExpo' )
}

function topOut()
{
	$( this ).stop( true, true ).animate( { 'color':'#4d2e1a' }, 500, 'easeOutExpo' )
}









/******* RECIPES *********/
function initRecipes(){

$w = $(window)
resizer()

//$('.printbutton').click(function(event){window.print() });

$('.eclose').click(closeemail)
$('.emailbtn').click(openemail)


}





function twitter() {
  if (window.__twitterIntentHandler) return;
  var intentRegex = /twitter\.com(\:\d{2,4})?\/intent\/(\w+)/,
      windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes',
      width = 550,
      height = 420,
      winHeight = screen.height,
      winWidth = screen.width;
 
  function handleIntent(e) {
    e = e || window.event;
    var target = e.target || e.srcElement,
        m, left, top;
 
    while (target && target.nodeName.toLowerCase() !== 'a') {
      target = target.parentNode;
    }
 
    if (target && target.nodeName.toLowerCase() === 'a' && target.href) {
      m = target.href.match(intentRegex);
      if (m) {
        left = Math.round((winWidth / 2) - (width / 2));
        top = 0;
 
        if (winHeight > height) {
          top = Math.round((winHeight / 2) - (height / 2));
        }
 
        window.open(target.href, 'intent', windowOptions + ',width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
        e.returnValue = false;
        e.preventDefault && e.preventDefault();
      }
    }
  }
 
  if (document.addEventListener) {
    document.addEventListener('click', handleIntent, false);
  } else if (document.attachEvent) {
    document.attachEvent('onclick', handleIntent);
  }
  window.__twitterIntentHandler = true;
};




function closeemail(){
	

	$( '#emailbox' ).stop( true, false ).animate( { 'left': $w.width() + 100}, 500, 'easeInOutExpo', function(){$('#emailbox').css( { 'display':'none' } )} );
	
	$("#sendername").val("")
	$("#senderemail").val("")
	$("#recipientname").val("")
	$("#recipientemail").val("")
	$("#message").val("")
	
	//("#link").val("")
	//("#artist").val("")
	//("#year").val("")
	//("#image").val("")
	//("#page").val("")
	
		
	if (page == 'recipes')	{
		closeImage()
	}
}


function openemail(){
	$('#emailbox').css( { 'display':'block' } )
	if (page == 'recipes')	{
		$( '.lightBox' ).css( 'display', 'block' )
		$( '.lightBox #bkg' ).css( { 'opacity':'0' } ).animate( { 'opacity':'.5' }, 500, 'easeInOutExpo' )
		
	}
	
	var center = ( ($w.width() - $('#emailbox').width() )/2+ $w.scrollLeft() )		
		
	$( '#emailbox' ).stop( true, false ).css( { 'visibility':'visible', 'left':-$w.width() } ).animate( { 'left': center}, 500, 'easeInOutExpo' );
	
}

function email($site, $id, $_image, $_recipe, $_title){	
	
	
	
	//for recipies
	$link = document.getElementById('link')	
	$image = document.getElementById('image')
	$recipe = document.getElementById('recipe')
	$title = document.getElementById('title')
	$page = document.getElementById('page')
	$message = document.getElementById('message')
	
	$link.value = $siteURL+'recipes/recipe/'+ $id	
	$image.value = $siteURL + $_image
	$recipe.value = $_recipe
	$title.value = $_title
	$page.value = $site
	
	$message.value = "I thought you would enjoy this great recipe for " +unescape($_title.replace(/\+/g,'%20'))+". The secret ingredient is Cream of Wheat™!"
	
	
}


function emailabout($site, $id, $_artist, $_year, $_image){	
	
	
	
	$link = document.getElementById('link')
	$artist = document.getElementById('artist')
	$year = document.getElementById('year')
	$image = document.getElementById('image')
	
	$page = document.getElementById('page')
	
	$message = document.getElementById('message')
		
	$link.value = $siteURL+'about/?img=' + $id
	
	$artist.value = $_artist
	$year.value = $_year
	$image.value = $siteURL + $_image
	$page.value = $site
	
	
	
	$message.value = "I thought you would enjoy this memory from Cream of Wheat™’s Memory Gallery. This piece of art is from " +$_year+" by "+  $_artist+":"
	

		
}



/********* Locate Regions ***********/

function initLocate()
{
	

	var  mouse_is_inside	
	
var distance = ($('.region_box').height()+200)*-1;
	//HIDE REGIONS
    $(".region_box").hide();
	
	
	//Open Region
    $("#locate_cow a.region").click(function () {
        $("#locate_cow a.region").hide();
		$( '.close' ).hover( ftover, ftout )
        $(".region_box").hide();
        var activeTab = $(this).attr("href");
        //console.log(activeTab);
        $(activeTab).show().animate({
            "top": "160px",
            "z-index" : "100"
        }, "1000")
        return false;
    });
	
    //Record Mouse location
    $('.region_box').hover(function () {
        mouse_is_inside = true;
    }, function () {
        mouse_is_inside = false;
    });
	//IF mouse clicked outside of region close region
    $("body").mouseup(function () {
        if (!mouse_is_inside) {
            $(".region_box").animate({
                "top": distance
            }, "1000")
            $("#locate_cow a.region").show();
            return false;
        }
    });	
	
	//Close button
    $(".region_box a.close").click(function () {
        $(".region_box").animate({
            "top": distance
        }, "1000");
        $("#locate_cow a.region").show();
        return false;
    });
	
	
	
	
	
	$('#areane').hover(
		function(){
			$('#locate_cow').css({'background-position':'0 -460px'});
		},
		function(){
			$('#locate_cow').css({'background-position':'0px 0px'})	
		}
	);
	$('#areaeast').hover(
		function(){
			$('#locate_cow').css({'background-position':'0 -920px'});
		},
		function(){
			$('#locate_cow').css({'background-position':'0px 0px'})	
		}
	);
	$('#areacentra').hover(
		function(){
			$('#locate_cow').css({'background-position':'0 -1380px'});
		},
		function(){
			$('#locate_cow').css({'background-position':'0px 0px'})	
		}
	);
	
	$('#areawest').hover(
		function(){
			$('#locate_cow').css({'background-position':'0 -1840px'});
		},
		function(){
			$('#locate_cow').css({'background-position':'0px 0px'})	
		}
	);
	
	
}

/************** END ****************/



/************** TRACKING ****************/

function addExternalTracking() {
	$('a[href*="http://"]:not([href^="http://'+$domain+'"]),[href*="https://"]:not([href^="https://'+$domain+'"])').not('[href^="#"]').not('[href^="mailto:"]').click(function() { trackExternalLink( 'outgoing', 'click', $(this).attr('href') ); } );	
	$('a[href^="mailto:"]').click(function() { trackExternalLink( 'mailto', 'click', $(this).attr('href') ); } );
}

function trackExternalLink(category, action, link) {
	try {
		var myTracker = _gat._getTrackerByName();
						_gaq.push(['_trackEvent', category, action, link]);
		
	} catch(err){}
}

/************** / TRACKING ****************/
