﻿//*************************************************************************************
// File     : dran_functions.js
// Version  : 1
// Requires : jquery.js (version 1.2.6+), braingnat.js (version 0.1.2+)
// Author   : Kyle Weems (ksw), Janae Wiedmaier (jlw)
// Origin   : mindfly.com
// Created  : November 24, 2008
// Modified : December 15, 2010
//*************************************************************************************

$(document).ready(function(){ startSequence(); });

function startSequence() {
    randomMainImage();
    menuFix();
    BrainGnat.stickyList();
    BrainGnat.setContentHeight(40);
}

function menuFix() {
    // Adds spans into the top-level menu items so that the "wine making" generates a line break.
    $('.ulCategories > li > a:contains("Wine Making")').each( function(){
            $(this).html('<span>Wine Making</span>' + $(this).html().split('Wine Making')[1]);
    });
    $('.ulCategories > li > a:contains("Homebrew")').each( function(){
            $(this).html('<span>Homebrew</span>' + $(this).html().split('Homebrew')[1]);
    });
}

function randomMainImage() {
    $.get("/imageList.aspx?dir=/Assets/rotatingImages/", function(data) {
        var imageList = data.split("|");
        imageList.pop();
        BrainGnat.randomBackgroundImage('#content_sub', imageList);
    });
}

function paypalPopup() {
    if ($('input[name*="PayPalPayNowButton"]').length > 0) {
        $('form').append('<div id="overlay">&nbsp;</div>');
        $('#overlay').css({ width: $(document).width() + 'px', height: $(document).height() + 'px', opacity: '.7', zIndex: 998 });
        $('form').append('<div id="paypalPopup"><h4>Please Proceed with PayPal</h4><p>To complete your order, you need to click the PayPal button below.  As soon as you have finished paying through PayPal, you will be redirected to your order confirmation.</p><p>Thank you for your patience.</p></div>');
        $('#paypalPopup').append($('input[name*="PayPalPayNowButton"]'));
        $('#paypalPopup').append('<a href="#" class="paypalClose">I have already paid through PayPal, and would just like to view my order now.</a>');
        $('.paypalClose, #paypalLink').click(function() {
            $('#overlay').fadeToggle();
            $('#paypalPopup').fadeToggle();
        });
    }
}
