// JavaScript Document
var allSections = Array("landingpage","searchresults","textresults","iwantsomething","az","top10");
var showScrollFlag = "false";
var categoryName = "";
var categoryAllName = "";
var alternateFood = "";
function showContent(whichOne){
     var nonActiveSection = "";

     if((whichOne=="iwantsomething")||(whichOne=="az")||(whichOne=="top10")){
        loadResults = "";
        document.getElementById("crav_food").value = "";
     }
     if(loadResults == ""){
       	var activeSection = whichOne;
		activeSection = document.getElementById(whichOne);
        activeSection.style.display = 'block';
        for(var i =0; i< allSections.length; i++){
		 nonActiveSection = document.getElementById(allSections[i]);
                 if(nonActiveSection !== activeSection){
                     nonActiveSection.style.display = 'none';
		}
	  }
     }else{
        if(whichResultPage == "searchresults"){
         var searchRes = document.getElementById(whichResultPage);
		 searchRes.style.display = 'block';
                
    	 for(var i =0; i< allSections.length; i++){
		 nonActiveSection = document.getElementById(allSections[i]);
                 if(nonActiveSection !== searchRes){
                    nonActiveSection.style.display = 'none';
		}
	     }
                        
        }
        if(whichResultPage == "textresults"){
         var textRes = document.getElementById(whichResultPage);
		 textRes.style.display = 'block';
    	 for(var i =0; i< allSections.length; i++){
		 nonActiveSection = document.getElementById(allSections[i]);
                 if(nonActiveSection !== textRes){
                    nonActiveSection.style.display = 'none';
		}
	       }
         }
      }
   }
var allBtns = Array("searchbar_iwantsomething","searchbar_az","searchbar_top10");
function navon(img){
	if(document.getElementById(img))
	{
	  var activeBtn = document.getElementById(img);
      activeBtn.setAttribute("src", '/images/cravingconverter/' + img + '_on.gif');
	 }
   	 for(var i =0; i< allBtns.length; i++)
	 {
		var nonActiveBtn = document.getElementById(allBtns[i]);
			if(nonActiveBtn !== activeBtn)
			{
			nonActiveBtn.setAttribute("src",'/images/cravingconverter/' + allBtns[i] + '_off.gif');
			}
	  }
	
}
// show popups when clicking convert
function showConvert(whichOne){
		var sentFrom = document.getElementById(whichOne);
		sentFrom.style.visibility = 'visible';
		var container = document.getElementById('cravingcontainer');
		container.appendChild(sentFrom);
		
}

// hide popups when clicking close
function hideConvert(whichOne){
		var sentFrom = document.getElementById(whichOne);
		sentFrom.style.visibility = 'hidden';
                
}
// show popups for categories when clicking convert
function showCatConvert(whichOne){
		var sentFrom = document.getElementById(whichOne);
		sentFrom.style.visibility = 'visible';
                if((document.getElementById("jScrollPaneContainer")==null)||(showScrollFlag=="true")){
                 
                  var J = jQuery.noConflict();
			J(function()
			{
               var Jpane2 = J('#pane3');
				J('#pane3').jScrollPane({scrollbarWidth:19, scrollbarMargin:10, animateTo:true, showArrows:true})
                               	J('a.scroll-to-element').bind(
				'click',
				function()
					{
						Jthis = J(this);
						var destinationSelector = J(this).attr('rel');
                                        	J('#pane3', Jthis.parent().parent().parent()).each(
							function()
							{
								this.scrollTo(destinationSelector);
							}
						);
						return false;
					}
				);
				
			});
                  showScrollFlag="false";
                  categoryAllName=whichOne;
	}//if
}

function on(img){
      document[img].src = '/images/cravingconverter/iwantsomething/' + img + '_on.gif';
   }
function off(img){
      document[img].src = '/images/cravingconverter/iwantsomething/' + img + '_off.gif';
   }


/* a thru z */
var  thisActive_az = '';
function a_thru_z_on(img){
      document['btn' + img].src = '/images/cravingconverter/a_thru_z/' + img + '_on.gif';
   }
function a_thru_z_off(img){
	if(img !== thisActive_az){
      document['btn' + img].src = '/images/cravingconverter/a_thru_z/' + img + '_off.gif';
	}
   }
   


var a_thru_zBtns = Array("a","b","c","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","w","y");
function a_thru_z_active(img){
	if(document.getElementById('btn' + img))
	{
	  var activeBtn = document.getElementById('btn' + img);
         activeBtn.setAttribute("src", '/images/cravingconverter/a_thru_z/' + img + '_on.gif');
	  thisActive_az =  img;
	 }
   	 for(var i =0; i< a_thru_zBtns.length; i++)
	 {
		var nonActiveBtn = document.getElementById('btn' + a_thru_zBtns[i]);
			if(nonActiveBtn !== activeBtn)
			{
			nonActiveBtn.setAttribute("src",'/images/cravingconverter/a_thru_z/' + a_thru_zBtns[i] + '_off.gif');
			}
	  }
	
}




/* top10 */
var thiisActive_top10 = '';
function top10_on(img){
      document['btn' + img].src = '/images/cravingconverter/top10/' + img + '_on.gif';
   }
function top10_off(img){

	if(img !== thiisActive_top10){
		
      document['btn' + img].src = '/images/cravingconverter/top10/' + img + '_off.gif';
	}
   }
   
var top10Btns = Array("1","2","3","4","5","6","7","8","9","10");
function top10_active(img){
	if(document.getElementById('btn' + img))
	{
	  var activeBtn = document.getElementById('btn' + img);
         activeBtn.setAttribute("src", '/images/cravingconverter/top10/' + img + '_on.gif');
	  thiisActive_top10 =  img;
	 }
   	 for(var i =0; i< top10Btns.length; i++)
	 {
		var nonActiveBtn = document.getElementById('btn' + top10Btns[i]);
			if(nonActiveBtn !== activeBtn)
			{
			nonActiveBtn.setAttribute("src",'/images/cravingconverter/top10/' + top10Btns[i] + '_off.gif');
			}
	  }
	
}
function  createScrollBar()
{
       
        showScrollFlag = "true";
  	var J = jQuery.noConflict();
			J(function()
			{
               var Jpane2 = J('#pane2');
				J('#pane2').jScrollPane({scrollbarWidth:19, scrollbarMargin:10, animateTo:true, showArrows:true})
                               	J('a.scroll-to-element').bind(
				'click',
				function()
					{
						Jthis = J(this);
						var destinationSelector = J(this).attr('rel');
                                        	J('#pane2', Jthis.parent().parent().parent()).each(
							function()
							{
								this.scrollTo(destinationSelector);
							}
						);
						return false;
					}
				);
				
			});
                        
}

function  createScrollBar1()
{
 	var J = jQuery.noConflict();
			J(function()
			{
               var Jpane2 = J('#pane4');
				J('#pane4').jScrollPane({scrollbarWidth:19, scrollbarMargin:10, animateTo:true, showArrows:false})
                               	J('a.scroll-to-element').bind(
				'click',
				function()
					{
						Jthis = J(this);
						var destinationSelector = J(this).attr('rel');
                                        	J('#pane4', Jthis.parent().parent().parent()).each(
							function()
							{
								this.scrollTo(destinationSelector);
							}
						);
						return false;
					}
				);
				
			});
                        
}
 function createResultsScrollBar()
     {
      
         var J1 = jQuery.noConflict();
                J1(function()
                {
                    
                        J1('#search_results').jScrollPane({scrollbarWidth:19, scrollbarMargin:10, animateTo:true, showArrows:true})
                        
               
                });
      
	
     }
function hidePopups(){
    if((categoryName != "")||(categoryAllName != "")){
    if((document.getElementById(categoryName) !=null)||(document.getElementById(categoryAllName) !=null) ){
    var sentFrom = document.getElementById(categoryName);
		sentFrom.style.visibility = 'hidden';
    }
    }
    
    if(categoryAllName != ""){
    if(document.getElementById(categoryAllName) !=null) {
    var sentFrom = document.getElementById(categoryAllName);
		sentFrom.style.visibility = 'hidden';
    }
    }
    
     if(alternateFood != ""){
      if(document.getElementById(alternateFood) !=null) {
      var sentFrom = document.getElementById(alternateFood);
                  sentFrom.style.visibility = 'hidden';
     }
     }
}
