
// The TrackTag variable refers to the location of the
// base action tag. In the actual implementation this 
// action tag will point to a 1x1 pixel GIF.

var TrackTag = 'http://switch.atdmt.com/action/';

function GetActionTag(URL){ 
  document.action_tag.src = TrackTag + URL;

// The URL passed from the SWF will be appended to TrackTag.
// The image will be loaded into the img src tags below the 
// Flash ad's OBJECT tag.
}


//projects subnav location dropdown
function selectLocation(dropdown) {
    var myindex  = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value
    top.location.href = SelValue;
    return true;
}



var totalDollars;

function addDollar() {
	totalDollars = 4; // To do: assign stored value of total donations to totalDollars.
	totalDollars += 1;
	// to do: update the stored value with the new value
	// to do: check to make sure value is not greater than 250,000?  Or will there be a different Flash display for that?
}

function popDonationSubpage() {
	//addDollar();
	var overlayContent = "Flash/donation_animation3.swf?voteURL=votecontroller.ashx&totalDonations=" + totalDollars + "&amp;nationalFFA=supporting.aspx&amp;tellFriend=tell_a_friend.aspx";
	openOverlay(overlayContent, "swf", "")
	document.getElementById('donationpromoon').style.display = "none";
	document.getElementById('donationpromooff').style.display = "block";
}

var openOverlay = function(content, player, title, width, height){
    Shadowbox.open({
        content:    content,
        player:     player,
        title:      title,
		height:     height,
		width:      width,
		showOverlay: "false"
    });
};



/*
 *	Fix IE6 bg flicker
 */
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}






function showLayer(id)
{
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "block";
  alert('hi');
}

function hideLayer(id)
{
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "none";
}

function getElemRefs(id)
{
    var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
    if (el) el.css = (el.style)? el.style: el;
    return el;
}

// get reference to nested layer for ns4
// from old dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc)
{
    if (document.layers) {
	    var theLyr;
	    for (var i=0; i<doc.layers.length; i++) {
  	    theLyr = doc.layers[i];
		    if (theLyr.name == lyr) return theLyr;
		    else if (theLyr.document.layers.length > 0) 
    	    if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
				    return theLyr;
      }
	    return null;
  }
}

function linkExternal(obj, linkName) {
    var s=s_gi(s_account);
    s.linkTrackVars='None';
    s.linkTrackEvents='None';
    var lt=obj.href!=null?s.lt(obj.href):"";
    if (lt=="") { s.tl(obj,'e',linkName); }
}

function donationClickTrack(){
    var trackingImage = document.getElementById('donationClickTrackingImage');
    trackingImage.src = 'http://view.atdmt.com/action/denrwe_HelpGrowYourSoupDonationButton_1';
}

// Homepage FAQs popup
function openFAQpopup() {
	var wt = 530;
	var ht = 480;
	var str = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,screenx=30,screeny=20,width="+wt+",height="+ht+",top=50,left=50";
	FAQsPop = window.open("faqs.aspx","FAQs",str).focus;
}

/* Define a namespace */
var GrowYourSoup = {};

/* Vote Call to Action button toggle */
GrowYourSoup.enableVoteToggle = function () {
	$("div.ctavote").hover( function() {
		$(this).children("div.ctavotenote").show();
	},
	function() {
		$(this).children("div.ctavotenote").hide();
	});
};

GrowYourSoup.enableModalPop = function() {
    $('#footer').before('<div id="modal-pop" class="jqmWindow png"><div class="jqmContent tellafriend"><div class="jqmContentInner"><div id="jqmAjaxTarget"></div><img src="images/btn_close.gif" width="29" height="26" alt="Close window" class="jqmClose" /></div></div></div>');
    $('#footer').before('<div id="flashmodal" class="jqmWindow"></div>');
    $('#modal-pop').jqm({
        modal: true, 
        ajax:'@href',
        trigger: 'a.open-modal',
        target: 'div#jqmAjaxTarget',
        toTop: true
    });
};

function jsVoteFunction(selectedBarn) {
	selectedBarn = selectedBarn + 1;
	if ((selectedBarn > 10) || (selectedBarn < 1)) {  //illegal numbers
		selectedBarn = 0; // for error testing in swf
	}
	//alert(selectedBarn);
	var ajaxstring = 'seed_giveaway.aspx?selectedBarn='+selectedBarn;
	$('#flashmodal').jqm({
        modal: true, 
        ajax: ajaxstring,
        //trigger: 'a.open-flash-modal',
        toTop: true
    }).jqmShow();
}

function closeWindow() {
	$("#modal-pop").jqmHide();
	$("#flashmodal").jqmHide();
};

$(document).ready(function(){
	GrowYourSoup.enableVoteToggle();
	GrowYourSoup.enableModalPop();
});