// JavaScript Document
var allSections = Array("landingpage","searchresults","textresults","iwantsomething","az","top10","regional","showAll","showAllcataltfoods","r_guide","showRestaurants","cravingTips");
var showScrollFlag = "false";
var categoryName = "";
var categoryAllName = "";
var alternateFood = "";
var hideiwant_flag = "";
function showContent(whichOne){
    var nonActiveSection = "";

    if((whichOne=="iwantsomething")||(whichOne=="az")||(whichOne=="top10") ||(whichOne=="regional")||(whichOne=="r_guide")){
        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 !=null){
                if(nonActiveSection !== activeSection){
                    nonActiveSection.style.display = 'none';
                }
            }
        }
    }else{
        if(whichResultPage == "searchresults"){
            var searchRes = document.getElementById(whichResultPage);
            searchRes.style.display = 'block';


            for(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(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","searchbar_regional","searchbar_guide","searchbar_tips","searchbar_leftcap");
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');
        }
    }
    //turn on left cap for I want button
    if(img =="searchbar_iwantsomething"){
        var leftcap =  document.getElementById("searchbar_leftcap");
        leftcap.setAttribute("src", '/images/cravingconverter/searchbar_leftcap_on.gif');
    }
    //turn on craving tips r guide button
    if(img =="searchbar_guide"){
        var ctips =  document.getElementById("searchbar_tips");
        ctips.setAttribute("src", '/images/cravingconverter/searchbar_tips_4guide.gif');
    }

}


/* show hide sections */

// show restaurants
function showRestaurant(whichOne){
    var a = jQuery.noConflict();

    var links = document.getElementsByTagName("div");
    for (var i=0; i < links.length; i++) {
        if (links[i].className.match("restaurant")) {
            links[i].style.display= "none";
        }
    }
    a('.scroll-to-demo').bind(
        'click',
        function()
        {
            a('#rest_pane')[0].scrollTo(0);
            return false;
        }
        );

    var sentFrom = document.getElementById(whichOne);
    sentFrom.style.display = 'block';
    showRestaurantContainer();
    createShowRestaurantScrollBar();
}
// 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);

}

function decideprotocal(){
    // var prot = window.location+'';
    var prot= window.location+'';
    if(prot.indexOf("http:")!=-1){
        var url= prot.replace("http", "https");
        var hashindex = url.indexOf("#");        
        if(hashindex!=-1){
        var substring = url.substr(hashindex,url.length);        
        url=url.replace(substring,"");
        }
        //if(url.indexOf("popup")=-1){
        url = url.replace("?popup=true","");
        window.location = url+"?popup=true";
    //}
    }else {
        newMethod('spreadtheword');
    }
}


function getParameter ( queryString, parameterName ) {
    parameterName = parameterName + "=";
    if ( queryString.length > 0 ) {
        begin = queryString.indexOf ( parameterName );
        if ( begin != -1 ) {
            //begin += parameterName.length;
            end = queryString.indexOf ( "true");
            if ( end == -1 ) {
                return "null";
            }
            return "true" ;
        }
        return "null";
    }
    return "null";
}
// show spreadtheword popup
function showSpreadtheword(whichOne){

    if(window.location.protocol=="http:"||window.location.protocol=="https:"){

        if(window.location.protocol!="http:"){
            var queryString = window.top.location.search.substring(1);
            
            var popup = getParameter(queryString,"popup");
            if(popup==null || popup!="true"){
                return;
            }
        }else{
            return;
        }
    }
    var sentFrom = document.getElementById(whichOne);
    sentFrom.style.visibility = 'visible';
    var container = document.getElementById('cravingcontainer');
    container.appendChild(sentFrom);

}

function newMethod(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);
    var prot = window.location+'';
        if(prot.indexOf("https:")!=-1){
            var url= prot.replace("https", "http");
            url = url.replace("?popup=true","");
            url = url.replace("#","");
            window.location = url;
    }
    sentFrom.style.visibility = 'hidden';
    document.getElementById("spreadthewordpreview_container").style.display = 'none';
    document.getElementById("spreadthewordthanku_container").style.display = 'none';
    document.getElementById("spreadtheword_container").style.display = 'block';

}
function hideConvertThankYou(whichOne){
    var sentFrom = document.getElementById(whichOne);
      var prot = window.location+'';
        if(prot.indexOf("https:")!=-1){
            var url= prot.replace("https", "http");
            url = url.replace("?popup=true","");
            url = url.replace("#","");
            window.location = url;
    }
    sentFrom.style.visibility = 'hidden';
    document.getElementById("spreadthewordpreview_container").style.display = 'none';
    document.getElementById("spreadthewordthanku_container").style.display = 'none';
    document.getElementById("spreadtheword_container").style.display = 'block';

}


/* scroll bars */


function createShowAllScrollBar() {
    var a = jQuery.noConflict();

    a(function(){
        a('#pane1').jScrollPane({
            scrollbarWidth:24,
            scrollbarMargin:10,
            showArrows:true
        });

    });
}
function createCatShowAllScrollBar() {
    var a = jQuery.noConflict();

    a(function(){
        a('#pane2').jScrollPane({
            scrollbarWidth:24,
            scrollbarMargin:10,
            showArrows:true
        });

    });
}
function createShowRestaurantScrollBar() {
    var a = jQuery.noConflict();

    a(function(){
        a('#rest_pane').jScrollPane({
            scrollbarWidth:24,
            scrollbarMargin:10,
            showArrows:true
        });

    });
}
function createTipsScroll() {
    var a = jQuery.noConflict();

    a(function(){
        a('#tipspane').jScrollPane({
            scrollbarWidth:24,
            scrollbarMargin:10,
            showArrows:true
        });

    });
}
// for serach results based on search string
function verticalScroll() {
    var x = jQuery.noConflict();

    // execute your scripts when the DOM is ready. this is a good habit
    x(function() {

        // initialize scrollable
        var api = x("div.scrollable").scrollable({
            size:1,
            clickable:false,
            globalNav:true

        }).navigator({
            api:true
        });
        // has to be the same value as defined in scrollable config
        var totalSize = api.getPageAmount();
        if (totalSize == 1) // has to be the same value as defined in scrollable config
        {
            x('.nextPage').addClass('disabled');
            x('.navi').addClass('disabled');
        }
    });

}
function verticalScroll_IWant() {
    var x = jQuery.noConflict();

    // execute your scripts when the DOM is ready. this is a good habit
    x(function() {

        // initialize scrollable
        var api = x("div.scrollable_iwant").scrollable({
            size:1,
            clickable:false,
            api:true
        });
        api.begin();
    });

}
function verticalScroll_top10() {
    var q = jQuery.noConflict();

    // execute your scripts when the DOM is ready. this is a good habit
    q(function() {
        // initialize scrollable
        q("div.scrollable_top10").scrollable({
            size:1,
            clickable:false,
            globalNav:true
        }).navigator({

            // ul.tabs now functions as our navigator
            navi:'ul.tabs_top10'
        });

    });

}
function verticalScroll_athruz() {
    var x = jQuery.noConflict();

    // execute your scripts when the DOM is ready. this is a good habit
    x(function() {

        // initialize scrollable
        x("div.scrollable_athruz").scrollable({
            size:1,
            clickable:false

        }).navigator({
            // ul.tabs now functions as our navigator
            navi:'ul.tabs'

        });



    });

}
function verticalScroll_rest() {
    var x = jQuery.noConflict();

    // execute your scripts when the DOM is ready. this is a good habit
    x(function() {

        // initialize scrollable
        var api =   x("div.scrollable_rest").scrollable({
            size:1,
            clickable:false,
            api:true
        });
        api.begin();
    });

}
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) {
            sentFrom = document.getElementById(categoryAllName);
            sentFrom.style.visibility = 'hidden';
        }
    }

    if(alternateFood != ""){
        if(document.getElementById(alternateFood) !=null) {
            sentFrom = document.getElementById(alternateFood);
            sentFrom.style.visibility = 'hidden';
        }
    }
}

//add box outline to clicked resultitems
function addBoxStyle(whichOne){
    turnOffOtherboxes();
    whichOne.parentNode.style.border = "5px solid #c4d8ec";
    whichOne.parentNode.style.padding = "0px";

}
function turnOffOtherboxes(){
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_resultitem")) {
                links[i].parentNode.style.border = "0px none #ffffff";
                links[i].parentNode.style.padding = "5px";

            }
        }
    }
}
//'show all' results
function showAll(){
    var showAll = document.getElementById('showAll');
    showAll.style.display= 'block';
}
//'show cat all' results
function showcategoryAll(){
    var showAll = document.getElementById('showAllcataltfoods');
    showAll.style.display= 'block';
}
//'show restaurants' results
function showRestaurantContainer(){
    var showAll = document.getElementById('showRestaurants');
    showAll.style.display= 'block';
}
function hideRestaurantContainer(){
    var showAll = document.getElementById('showRestaurants');
    showAll.style.display= 'none';
}

//menu functions
//search for somthings
function doSearch() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_search")) {
                links[i].onclick = function() {
                    fnSetAction();
                    return false;
                };
            }
        }
    }
}
//I want something
function iWantSomething() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_i_want_something")) {
                links[i].onclick = function() {
                    showContent('iwantsomething');
                    navon('searchbar_iwantsomething');
                    verticalScroll_IWant();
                    //KeyPageTrack('I Want Something');

                    return false;
                };
            }
        }
    }
}
//regional
function regional() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_regional")) {
                links[i].onclick = function() {
                    showContent('regional');
                    navon('searchbar_regional');
                    //KeyPageTrack('regional');
                    return false;
                };
            }
        }
    }
}
//a thru z
function a_z() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_a_thru_z")) {
                links[i].onclick = function() {
                    showContent('az');
                    navon('searchbar_az');
                    getathruz();
                    anchorlinks_off();
                    //KeyPageTrack('A-Z');
                    return false;
                };
            }
        }
    }
}
//top 10
function top10() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_top10")) {
                links[i].onclick = function() {
                    showContent('top10');
                    navon('searchbar_top10');
                    getTop10();
                    anchorlinks_off();
                    // KeyPageTrack('Top 10');
                    return false;
                };
            }
        }
    }
}
//r guide
function r_guide() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_guide")) {
                links[i].onclick = function() {
                    hideRestaurantContainer();
                    showContent('r_guide');
                    navon('searchbar_guide');
                    verticalScroll_rest();
                    // KeyPageTrack('Restaurant Guide');
                    return false;
                };
            }
        }
    }
}
//craving tips
function cravingTips() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("js_tips")) {
                links[i].onclick = function() {
                    showContent('cravingTips');
                    hideEpandedCravingTips();
                    navon('searchbar_tips');
                    // KeyPageTrack('Craving Tips');
                    return false;
                };
            }
            // close expanded tips
            if (links[i].className.match("close_expanded")) {
                links[i].onclick = function() {
                    hideEpandedCravingTips();
                    return false;
                };
            }
        }
    }
}

//show expanded craving tips
function showEpandedCravingTips(whichone){
    hideEpandedCravingTips();
    var sentFrom = document.getElementById(whichone);
    sentFrom.style.display = 'block';
    createTipsScroll();
    return false;

}
// hide expanded
function hideEpandedCravingTips(){
    var links = document.getElementsByTagName("div");
    for (var i=0; i < links.length; i++) {
        if (links[i].className.match("expandedTabs")) {
            links[i].style.display = "none";
        }

    }
}
// hide expanded
function closeCravingTips(){
    var sentFrom = document.getElementById("cravingTips");
    sentFrom.style.display = 'none';
    return false;
}


function anchorlinks() {
    if (document.getElementsByTagName) {
        var links = document.getElementsByTagName("a");
        for (var i=0; i < links.length; i++) {
            if (links[i].className.match("anchorlinks")) {
                links[i].onclick = function() {
                    anchorlinks_off();
                    this.style.background = "#0054a6 url('/images/cravingconverter/anchrorlink_bkg.gif')no-repeat 0 0";
                    this.style.color = "#ffffff";
                };
            }
        }
    }
}
function anchorlinks_off() {
    var links = document.getElementsByTagName("a");
    for (var i=0; i < links.length; i++) {
        if (links[i].className.match("anchorlinks")) {
            links[i].style.background = "#ebebeb url('/images/cravingconverter/anchrorlink_bkgoff.gif')no-repeat 0 0";
            links[i].style.color = "#838383";
        }
    }
}

