﻿/// <reference path="jquery-1.6.1.js" />


jq = jQuery.noConflict();

jq(document).ready(function () {

    DoFlashlessBanners();
    DoTestimonials();
    DoEvents();

    preload([
    '/images/LearnMoreButton.png',
    '/images/LearnMoreButtonHover.png',
    '/images/ChevViewDemo.gif',
    '/images/ChevViewDemoHl.gif',
    '/images/ChevDownloadFreeTrial.gif',
    '/images/ChevDownloadFreeTrialHl.gif',
    '/images/ChevLearnMore.gif',
    '/images/ChevLearnMoreHl.gif',
    '/images/ChevBuyIt.gif',
    '/images/ChevBuyItHl.gif'
    ]);


    jq(".VideoExpandImage").click(function () {
        jq(this).toggle();
        jq(this).next(".VideoExpandVideo").slideDown();
    })




    jq(".SlideToggleTarget").hide(); //Initial hide
    jq(".SlideToggleSource").click(function () {
        jq(this).next(".SlideToggleTarget").fadeToggle()  //.slideToggle();
    })


    jq(".ReadMoreTarget").hide(); //Initial hide
    jq(".ReadMoreSource").click(function () {
        jq(this).hide();
        jq(this).next(".ReadMoreTarget").fadeToggle();
    })



    //    jq("#GettingStartedVideoImage").click(function () {
    //        jq(this).toggle();
    //        jq("#GettingStartedVideoVideo").slideDown();
    //    })





    // Misc
    // =====================

    //jq(".ReadMore").readmore();


    jq("#NextTab01").click(function () {
        jq("#Tab02Link").click();
        //jq("#top").attr({ scrollTop: $("#top").attr("scrollHeight") });  
    })

    jq("#NextTab02").click(function () {
        jq("#Tab03Link").click();

    });
    jq("#NextTab03").click(function () {
        jq("#Tab04Link").click();

    });
    jq("#NextTab04").click(function () {
        jq("#Tab01Link").click();

    });



    jq("#QuoteWerksBoxShot").click(function () {
        //jq("#Terminator").fadeToggle("slow");
        //jq("#Terminator").toggle(

        var url = "/prodinfo.asp";
        window.location.href = url;
    });


    jq("#QuoteWerksBoxShot").hover(function () {

        //jq(".HintBox").fadeToggle("fast");
        //jq(".HintBox").fadeTo("fast", .80);
    });

    /* jq("#QuoteWerksBoxShot").mouseenter(function () {

    jq(".HintBox").fadeTo("fast", .75);

    });

    jq("#QuoteWerksBoxShot").mouseleave(function () {

    jq(".HintBox").fadeOut("fast");

    });*/




    // =====================








    // SearchBox
    // =====================
    var searchText = "Search QuoteWerks.com..."

    jq("#searchBox").addClass("SearchDefaultText");
    jq("#searchBox").attr("value", searchText);


    jq("#searchBox").focusout(function () {
        if (!jq(this).attr("value").length) {
            jq(this).attr("value", searchText);
            jq(this).addClass("SearchDefaultText");
        }
    });

    jq("#searchBox").click(function () {
        if (jq(this).attr("value") == searchText) {
            jq(this).attr("value", "");
            jq(this).removeClass("SearchDefaultText");
        }
    });
    // =====================



    // More/Less Buttons

    var more = "more";
    var less = "less";

    var previousReleases = jq("#PreviousReleases")

    jq("#MoreReleasesButton").click(function () {

        switch (previousReleases.css('display')) {

            case 'none':
                jq(previousReleases).slideDown("fast");
                jq(this).text(less);
                break

            default:
                jq(previousReleases).slideUp("fast");
                jq(this).text(more);
                break

        };

    });

});





// Preload Images
//===================================================
function preload(arrayOfImages) {
    jq(arrayOfImages).each(function () {
        jq('<img/>')[0].src = this;
        // Alternatively you could use:
        // (new Image()).src = this;
    });
}






// Customer Testimonials
// MCK - 5/25/2011
//=======================================================================================
function DoTestimonials() {
    //MCK - 5/25/2011
    jq.get('/Feeds/Testimonials/Testimonials.xml', function (xml) {
        RotateTestimonials(xml, 1);
    });
}

function RotateTestimonials(testimonialXml, currentTestimonialCount) {
    //MCK - 5/25/2011
    setTimeout(
                    function () {

                        var testimonials = jq(testimonialXml).find("Testimonial");
                        var totalCount = jq(testimonials).length;
                        var testimonial = testimonials[currentTestimonialCount];

                        var title = jq(testimonial).find("Title").text();
                        var text = jq(testimonial).find("Text").text();
                        var readMoreUrl = jq(testimonial).find("ReadMoreUrl").text();
                        var customerLogoUrl = jq(testimonial).find("CustomerLogoUrl").text();

                        UpdateTestimonial(title, text, readMoreUrl, customerLogoUrl);

                        if (currentTestimonialCount == totalCount - 1)
                            currentTestimonialCount = 0
                        else 
                            currentTestimonialCount++;
                        
                        RotateTestimonials(testimonialXml, currentTestimonialCount);
                    }
                    , 10 * 1000);
}

function UpdateTestimonial(title, text, readMoreUrl, logoUrl) {
    //MCK - 5/25/2011
    jq('<img />')
        .attr('src', logoUrl)
        .load(function () {

            var img = jq(this);

            jq("#TestimonialWrap").fadeOut("fast", function () {

                img.insertBefore(jq("#TestimonialLogo img"));
                jq("#TestimonialLogo img:last").remove();
                jq("#TestimonialTitle").text(title);
                jq("#TestimonialText").text(text);
                jq("#TestimonialLink a").attr('href', readMoreUrl);
                jq("#TestimonialWrap").fadeIn("fast");

            });
          });
}
//=======================================================================================






// Upcoming Events
// MCK - 5/27/2011
//=======================================================================================

function DoEvents() {
    //MCK - 5/27/2011
    var eventScroller = jq("#EventScroller").clone(true);
    var eventTemplate = jq(".Event", eventScroller).clone(true);
    jq(".Event", eventScroller).remove();

    jq.get('/Feeds/Events/Events.xml', function (xml) {

        jq(xml).find("Event").each(function (index, value) {

            var event = jq(eventTemplate).clone(true);

            var eventDate = jq(value).find("EventDate").text();
            var eventText = jq(value).find("EventText").text();
            var eventLinkUrl = jq(value).find("EventLinkUrl").text();
            var eventLocation = jq(value).find("EventLocation").text();
            var eventImageUrl = jq(value).find("EventImageUrl").text();

            jq(".EventDate", event).text(eventDate);
            jq(".EventText a", event).text(eventText);
            jq(".EventText a", event).attr("href", eventLinkUrl);
            jq(".EventLocation", event).text(eventLocation);
            jq(".EventImage img", event).attr("src", eventImageUrl);

            eventScroller.append(event);

        });

        jq("#EventScroller").replaceWith(eventScroller);

    });
}

//=======================================================================================






// Main Banner Rotation for Flashless Browswers
// MCK - 5/26/2011
//=======================================================================================

function DoFlashlessBanners() {
    //MCK - 5/26/2011
    if (jq("#FlashlessBanner").length) {
        //If FlashlessBanner exists...

        jq.get('/Feeds/Banners/Banners.xml', function (xml){
            RotateBanners(xml,1);
        });
    };
}

function RotateBanners(bannerXml, currentBannerCount) {
    //MCK - 5/26/2011
    setTimeout(
                    function () {

                        var banners = jq(bannerXml).find("item");
                        var totalCount = jq(banners).length;
                        var banner = banners[currentBannerCount];

                        var imageUrl = jq(banner).attr("image");
                        var clickUrl = jq(banner).attr("link");

                        UpdateBanner(imageUrl, clickUrl);

                        if (currentBannerCount == totalCount - 1)
                            currentBannerCount = 0
                        else
                            currentBannerCount++;

                        RotateBanners(bannerXml, currentBannerCount);
                    }
                    , 8 * 1000);
}

function UpdateBanner(imageUrl, clickUrl) {
    //MCK - 5/26/2011
    jq('<img />')
        .attr('src', imageUrl)
        .load(function () {

            var img = jq(this);

            jq("#FlashlessBannerWrap").fadeOut("slow", function () {

                jq("#FlashlessBannerWrap img").replaceWith(img);
                jq("#FlashlessBannerWrap a").attr('href', clickUrl);

                jq("#FlashlessBannerWrap").fadeIn("fast");

            });
        });
}


//=======================================================================================

