﻿///<reference path="jquery-1.2.6.vs.js"> This adds intellisense for jQuery
// special call/function for sustainability overlay
function LoadSustainability(){
        $('#panelSustain').jqm({
            ajax: '/Content/overlay/sustainability.aspx',
            overlay: 75,
            target: '#panelContentSustain'
        }).jqmShow();
}

//Main function to load JS when page is finished loading
$(document).ready(function() {

/* mouseover for the top-right search button */
$("#btn_search").mouseover(function(){
$(this).css("background","url(/Content/images/search_btn_hover.png) no-repeat top left"); 
});
$("#btn_search").mouseout(function(){
$(this).css("background","url(/Content/images/search_btn.png) no-repeat top left"); 
});

    // add mouseover to EXPLORE button
    $("#link_exploreProd").hover(function(){
		    onQuickNavMouseOver();
		    },
		    function(){}
		    );
		    
    // add mouseover to MEET PAD button
    $("#link_pad").hover(function(){
		    onDropdownNavMouseOver();
		    },
		    function(){}
		    );


    //Add toggle func to mini cart
    $('#link_shoppingtote').click(function() {
        if ($(this).hasClass('tote-open')) {
            $(this).removeClass('tote-open');
            $('#miniCart').hide();
        } else {
            $(this).addClass('tote-open');
            $('#miniCart').show();
        }
    });
    
    //Add toggle func to mini cart from buy now button
    $('#buy_now').click(function() {
        if ($('#link_shoppingtote').hasClass('tote-open')) {
            //do nothing; just add the merch to the cart
        } else {
            $('#link_shoppingtote').addClass('tote-open');
            $('#miniCart').show();
        }
    });
    
    //Add mouse over to mood meter
    $('#is_feeling_wrapper').hover(
       function () {
        $('#layer_dailyWord').addClass("layer_dailyWord_visible", 250);
      },
      function () {
        $('#layer_dailyWord').removeClass("layer_dailyWord_visible", 250);
      }
      );

//    //Add popup panel triggers to footer links
//    $('#panel').jqm({
//    //trigger:   //"#signup",//'#company_info, #contact_us, #privacy_policy,,',  , #link_explore_ingredients #link_view_more #link_wheretobuy,
//        ajax: '@href',
//        overlay: 75,
//        target: '#panelContent',
//        onLoad: function(hash) {
////            //Add swap feature to companyinfo about menu
////            $('#AboutMenu a').click(function() {

////                //remove active class from current item, add to this item
////                $('#AboutMenu .active-item').removeClass('active-item').addClass('off-item');
////                $(this).removeClass('off-item').addClass('active-item');

////                //hide current content and show this one
////                $('.companyInfoContent').hide();
////                $('#' + this.id + 'Content').show();
////            });

////            //Add photo swap feature to contact us menu
////            $('#ContactUs .cu-thumbnail-block img').click(function() {
////                $('#lgContactImage').attr('src', Constants.BASE_URL + 'content/images/ContactUs/' + this.className + '.gif');
////            });

//            //Add trigger to load contact from about
//            $('#contactUsCompanyInfo').click(function() {
//                //Hide it first, jqm won't open new window if current one is open.
//                $('#panel').jqmHide();
//            });
//            
//            
////            $('#panel').jqmAddTrigger('#contactUsCompanyInfo');
////            //re-write cancel button on sign up page
////            //in the sign up overlay this is still written as a YUI request; we should fix it
////            if ($('#signup')) {
////                $('#BtnCancelStep1').replaceWith("<img tabindex=\"14\" onclick=\"$('#panel').jqmHide();\" src=\"/m/images/advocates_btnCancel.gif\" id=\"BtnCancelStep1\" />");
////                $('#advocacySignUpStep2CancelBtn').replaceWith("<img tabindex=\"32\" style=\"cursor: pointer;\" src=\"/m/images/advocates_btnCancel.gif\" onclick=\"$('#panel').jqmHide();\" id=\"advocacySignUpStep2CancelBtn\" />");
////            }
//        }
//    });
    // add overlay for invite a friend
    $('#panel').jqm({
    trigger: '#invite',
        ajax: '@href',
        overlay: 75,
        target: '#panelContent'
    });
    
    // add overlay for naturals FAQ
    $('#panelNaturals').jqm({
        trigger: '#naturalsFAQ',
        closes : '.jqmCloseNaturals',
        ajax: '@href',
        overlay: 75,
        target: '#panelNaturalsContent'
    });
});

    
// begin toggle copy for sustainability overlay
function ToggleCopy(ele)
{
   //menu toggle
    var elements = document.getElementsByTagName('a');
    
    for (e=0;e < elements.length ;e++)
    {
        if(elements[e].id == ele.id){
            elements[e].className = 'active-item';
            }
        else{
            if(elements[e].className == 'active-item') {
                elements[e].className = 'off-item';
                }
             else{}
            }

    }

    //title toggle
    var HeaderText = document.getElementById('HeaderText');
    HeaderText.innerHTML = document.getElementById(ele.id + 'Title').innerHTML;

    //copy toggle
    var blocks = document.getElementsByTagName('div');
    var i = 0;

    for (i=0;i < blocks.length ;i++)
    {
        if(blocks[i].className == 'sustain-copy'){
                if( blocks[i].id == ele.id + 'Block')
                   blocks[i].style.display = 'block';
                else
                   blocks[i].style.display = 'none';
        }
        else{}
    }
}
// end toggle copy

// begin adjust_flashHeight.js

//adjust the flash movie height based on the available browser window size, minus top and footer nav
//it won't reload on resize: too many bugs in IE6 and IE7 and it takes too long too.
// removing $j from this script to prevent override of $ function calls
//var $j = jQuery.noConflict();
//var browsers = {"ie":$.browser.msie, "mozilla":$.browser.mozilla,"opera":$.browser.opera,"safari":$.browser.safari, "version":version = $.browser.version };
//var flashHeightAdj;
//if (browsers["ie"] && (browsers["version"]==6)) {flashHeightAdj = -2;}//10
//else {flashHeightAdj = -2;}

function adjustHeight(){
var topDivHeight = $(".header").height();
var footerDivHeight = $(".footer").height();
var availableFlashHeight = 0;
//alert("topDivHeight is "+topDivHeight+"; footerDivHeight is "+footerDivHeight+"; availableFlashHeight is "+availableFlashHeight);
availableFlashHeight = $(window).height() - topDivHeight - footerDivHeight;
//alert("availableFlashHeight is "+availableFlashHeight);
$("#flashMovie").css("height",availableFlashHeight);
}

$(document).ready(adjustHeight);
$(window).resize(adjustHeight); // this is gonna fire twice in IE (not a big deal in this case)

// end adjust_flashHeight.js

//function IsEmailValid(text)
//{
//    if (text.match(/^([\w_\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|((([\w_\-]+\.)+)([a-zA-Z]{2,4})))$/) != null)
//    {
//        return true;
//    }
//    else
//    {
//        return false;
//    }
//}

//function SubmitEmail(){
//    var f = document.getElementById('getEmailsForm'), e = document.getElementById('getEmails');                    
//    if (IsEmailValid(e.value)){
//    AIM.submit(f, {onStart: function(){}, onComplete: function(){
//            $('#panelEmailThankYou').jqm({
//            ajax: '/Content/overlay/emailSignUpThanks.aspx',
//            overlay: 75,
//            target: '#panelContentEmailThankYou'
//        }).jqmShow();
//    }});
//    return true;
//    }
//    else{
//    e.style.color = "#ff0000";
//    e.value = "Invalid Email";
//    return false;
//    }
//}

/* begin toggleDivAlwaysOn - this turns on the shopping cart when BUY NOW is clicked from a flash popup */

function toggleDivAlwaysOn( divLayer )
{
  var elem, vis;
  if( document.getElementById )
    elem = document.getElementById( divLayer );
  else if( document.all )
      elem = document.all[divLayer];
  else if( document.layers )
    elem = document.layers[divLayer];
  vis = elem.style;
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'block';
  vis.display = (vis.display==''||vis.display=='block')?'block':'block';
//changing the shopping tote image to shoppingTote_hide.gif since the miniCart is always on. 
document.getElementById('img_shoppingTote').src=ApplicationBaseUrl() + "images/shoppingTote_hide.gif";  
}

/* end toggleDivAlwaysOn */
