﻿// Load plugins, this can also be done on any page.
//$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.c-carousel.js'></script>");
$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.suckerfish.js'></script>");
$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.cycle.js'></script>");
$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.fancybox.js'></script>");
$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.hoverIntent.js'></script>");
$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.superfish.js'></script>");
$("body").append("<script type='text/javascript' src='/_scripts/jQuery/plugins/plugin.preload.js'></script>");


function shwSelected() {

    $("li.selected").each(function() {
        $(this).parents("li").each(function() {
            $(this).addClass("selected");
        });
    });

//    var objSel = $(".nav").find("li.selected");
//    if (objSel) {
//        objSel.parent().show()
//        objSel.children("ul").show()
//    }
}

$(document).ready(function() {

    // Initialize plugins here.

    // init active menu item
    //    shwSelected();
    //
    //    $(".nav").mouseleave(function() {
    //        shwSelected();
    //    });

    // Suckerfish main navigation
    //    $(".nav").Suckerfish();


        // Preload big bg images
    jQuery.preLoadImages("bg-news.jpg", "/_images/bg-news.jpg");
    jQuery.preLoadImages("bg_trees.jpg", "/_images/bg_trees.jpg");
    jQuery.preLoadImages("bg_rosewhite.jpg", "/_images/bg_rosewhite.jpg");
    jQuery.preLoadImages("bg_vegetables.jpg", "/_images/bg_vegetables.jpg");
    jQuery.preLoadImages("bg_rose.jpg", "/_images/bg_rose.jpg");

    // hover home buttons
          $(".top-category-0").hover(
                function() {
                    $(this).removeClass("top-category-0").addClass("top-category-0-over");
                    $(this).find("h1 a").addClass("active");
                    
                        $('body').removeClass(function() {
                            return $(this).prev().attr('class');
                        }).attr('class','fruit');
                 },
               function() {
                    $(this).removeClass("top-category-0-over").addClass("top-category-0");
                    $(this).find("h1 a").removeClass("active");

                        $('body').removeClass(function() {
                            return $(this).prev().attr('class');
                        }).attr('class', 'all');
                }
            );

    $(".top-category-1").hover(
          function() {
              $(this).removeClass("top-category-1").addClass("top-category-1-over");
              $(this).find("h1 a").addClass("active");

                  $('body').removeClass(function() {
                      return $(this).prev().attr('class');
                  }).attr('class', 'treenursery');
          },
          function() {
              $(this).removeClass("top-category-1-over").addClass("top-category-1");
              $(this).find("h1 a").removeClass("active");

                  $('body').removeClass(function() {
                      return $(this).prev().attr('class');
                  }).attr('class', 'all');
          }
      );

    $(".top-category-2").hover(
          function() {
              $(this).removeClass("top-category-2").addClass("top-category-2-over");
              $(this).find("h1 a").addClass("active");

                  $('body').removeClass(function() {
                      return $(this).prev().attr('class');
                  }).attr('class', 'ornamentals');
          },
          function() {
              $(this).removeClass("top-category-2-over").addClass("top-category-2");
              $(this).find("h1 a").removeClass("active");

                  $('body').removeClass(function() {
                      return $(this).prev().attr('class');
                  }).attr('class', 'all');
          }
      );

    $(".top-category-3").hover(
          function() {
              $(this).removeClass("top-category-3").addClass("top-category-3-over");
              $(this).find("h1 a").addClass("active");

                  $('body').removeClass(function() {
                      return $(this).prev().attr('class');
                  }).attr('class', 'vegetablesandpotatoes');
          },
          function() {
              $(this).removeClass("top-category-3-over").addClass("top-category-3");
              $(this).find("h1 a").removeClass("active");

                  $('body').removeClass(function() {
                      return $(this).prev().attr('class');
                  }).attr('class', 'all');
          }
      );


//    // hover click
//    $(".top-category-0").bind('click', function() {
//        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphContent$uscFruitWorldSelectionBlock$lnkToWebshop", "", true, "", "", false, true));
//    });
//    // hover click
//    $(".top-category-1").bind('click', function() {
//        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphContent$uscFruitWorldSelectionBlock$lnkToWebshop", "", true, "", "", false, true));
//    });
//    // hover click
//    $(".top-category-2").bind('click', function() {
//        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphContent$uscFruitWorldSelectionBlock$lnkToWebshop", "", true, "", "", false, true));
//    });
//    // hover click
//    $(".top-category-3").bind('click', function() {
//        WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cphContent$uscFruitWorldSelectionBlock$lnkToWebshop", "", true, "", "", false, true));
//    });



    // first set all selected
    shwSelected()

    // init superfish menu
    $('div.nav ul').superfish({
        delay: 500,
        animation: { opacity: 'show', height: 'show' },
        speed: 'fast',
        pathClass: 'selected',
        onInit: shwSelected()
    });


    //zuigvis language
    $(".lang").Suckerfish();

    // Cycle
    var cycle_index = 1;

    $(".banner-list").cycle({

        timeout: 9000

    });

    // Product details popups
    $(".product-details-popup, .monster-lnk").fancybox({
        width: 960,
        height: 720,
        padding: 0,
        margin: 0,
        overlayOpacity: 0.8,
        overlayColor: '#fff',
        hideOnOverlayClick: false
    });

    // Sample intake popup
    $(".sample-intake-popup-link").fancybox({
        width: 960,
        height: 720,
        padding: 0,
        margin: 0,
        overlayOpacity: 0.8,
        overlayColor: '#fff',
        hideOnOverlayClick: false
    });

    // Payment popups
    $(".shopping-lnk-pay-order").fancybox({
        width: 960,
        height: 720,
        padding: 0,
        margin: 0,
        overlayOpacity: 0.8,
        overlayColor: '#fff',
        hideOnOverlayClick: false
    });

    // Copy invoice address to delivery address
    $("input#ctl00_cphContent_uscUserAccountData_chkCopyDeliveryToInvoice").click(function() {
    if ($("input#ctl00_cphContent_uscUserAccountData_chkCopyDeliveryToInvoice").is(':checked')) {
            // Checked, copy values
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtStreet").val($("input#ctl00_cphContent_uscUserAccountData_nedVisitingAddressDataView_EditView_txtStreet").val());
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtHouseNumber").val($("input#ctl00_cphContent_uscUserAccountData_nedVisitingAddressDataView_EditView_txtHouseNumber").val());
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtHouseNumberSuffix").val($("input#ctl00_cphContent_uscUserAccountData_nedVisitingAddressDataView_EditView_txtHouseNumberSuffix").val());
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtZipCode").val($("input#ctl00_cphContent_uscUserAccountData_nedVisitingAddressDataView_EditView_txtZipCode").val());
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtCity").val($("input#ctl00_cphContent_uscUserAccountData_nedVisitingAddressDataView_EditView_txtCity").val());
            $("select#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_ddlCountryList").val($("select#ctl00_cphContent_uscUserAccountData_nedVisitingAddressDataView_EditView_ddlCountryList").val());
        }
        else {
            // Clear on uncheck
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtStreet").val("");
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtHouseNumber").val("");
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtHouseNumberSuffix").val("");
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtZipCode").val("");
            $("input#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_txtCity").val("");
            $("select#ctl00_cphContent_uscUserAccountData_nedInvoiceAddressDataView_EditView_ddlCountryList").val("12");
        }
    });

});
