/// <reference path="/msbuild/jquery-1.6.1-vsdoc.js" />

/*
*	??Site Title??
*	Author ??domain.com??
*   Copyright © 2011, ??domain.com??
*   All rights reserved.
*/

plan = {
    init: function () {

        plan.cufon.init();

        $(document).ready(function () {
            plan.cufon.ready();
            plan.scroll.init();
            plan.videoPlay.init();
            plan.truncate.init();
            plan.logo.init();
            plan.interactive.init();
        });
    },

    cufon: {
        init: function () {
            Cufon.set('fontFamily', 'StoryTelling').replace('h1:not(.nocufon), h2:not(.nocufon), .cufonit, .cufon, #dropdowninteractForm a .text, #dropdowninteractForm dt a', { hover: true });
            Cufon.set('fontFamily', 'Plan').replace('.lightCufon, .time');
            Cufon.set('fontFamily', 'StoryTelling').replace('#question');
            Cufon.set('fontFamily', 'StoryTelling').replace('#dropdowninteractForm');
            Cufon.set('fontFamily', 'StoryTelling').replace('.girlsName, .girlsNamePlural, .replace');
        },
        ready: function () {
            Cufon.now();
        }
    },

    scroll: {
        init: function () {
            $('.scroll_report').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 580,
                    direction: 'top',
                    easing: 'easeOutQuart',
                    speed: 1000
                });
            });
            $('.scroll_ambassador').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1060,
                    direction: 'top',
                    easing: 'easeOutQuart',
                    speed: 1000
                });
            });
            $('.scroll_invest').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1610,
                    direction: 'top',
                    easing: 'easeOutQuart',
                    speed: 1000
                });
            });

            $('#backTop').click(function () {
                $.smoothScroll({
                    direction: 'top',
                    easing: 'easeOutQuart',
                    speed: 1000
                });
            });

            $(window).scroll(function () {
                var $top = $('#backTop');
                $top.stop().delay(100).animate({ "marginTop": ($(window).scrollTop() + 120) + "px" }, '150', 'easeOutQuart');

                var h = $('body').height();
                var y = $(window).scrollTop();

                if (y > (h * .15)) {
                    // if we are show back to top button
                    $top.show();
                } else {
                    $top.hide();
                }
            });
        }

    },

    videoPlay: {
        init: function () {
            var $videos = $('#featureVideos li a'),
                $details = $('#vidDetails');

            $videos.click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href'),
                    $vidInfo = $(this).siblings('.details').html(),
                    $currentItem = $(this).attr('class');

                //Replace the video with the clicked thumbnail
                //$('#vidPlayer').attr('src', url + '?wmode=transparent').addClass($currentItem);

                //Add and remove selected class for clicked items
                $videos.parent('li').removeClass('selected');
                $(this).parent('li').addClass('selected');

                //Replace video info with clicked item
                $details.html($vidInfo);
            });
        }
    },

    truncate: {
        init: function () {

            $('.textTruncate').jTruncate({
                length: 900,
                minTrail: 0,
                moreText: 'Keep Reading',
                lessText: 'Show less'
            });
        }
    },

    logo: {
        init: function () {
            $(window).scroll(function () {
                // get the height of the body
                var h = $('body').height(),
                    y = $(window).scrollTop(),
                    $logo = $('.logoHome');

                if (y > (h * .15)) {
                    // if we are show logo
                    $logo.fadeIn(200);
                } else {
                    $logo.fadeOut(200);
                }
            });

        }
    },


    interactive: {
        init: function () {
            plan.dropdown.init($('#interactForm'));
            Cufon.refresh('#dropdowninteractForm');


            //Share this
            $('.interactMod').hover(function () {
                if ($(this).hasClass('left')) {
                    $(this).children('.shareThis').stop().animate({ right: '-110' }, { duration: 500, easing: 'easeOutQuart' });
                } else {
                    $(this).children('.shareThis').stop().animate({ right: '-117' }, { duration: 500, easing: 'easeOutQuart' });
                }
            }, function () {
                if ($(this).hasClass('left')) {
                    $(this).children('.shareThis').stop().animate({ right: '5' }, { duration: 500, easing: 'easeOutQuart' });
                } else {
                    $(this).children('.shareThis').stop().animate({ right: '0' }, { duration: 500, easing: 'easeOutQuart' });
                }
            });

            var $girlForm = $('.girlForm'),
                $girlBtn = $('#girlBtn'),
                $callAction = $('.callAction');

            //Keypress function for enter key on girl form
            $('#girlName').keypress(function (event) {
                if (event.keyCode == 13) {
                    event.preventDefault();
                    $girlBtn.click();
                }
            });


            //Choose your type of girl
            $("dd ul li a").click(function () {
                var $typeGirl = $("dd ul li.selected a .value").text(),
                    $question = $('#question');

                $('#dropdowninteractForm').fadeOut(200);
                $girlForm.fadeIn(400);
                $question.append('What is your ' + $typeGirl + ' name?');

                Cufon.replace('#question');
            });

            //Click on OK button and collect girl name
            $girlBtn.click(function () {
                var $name = $('.girlsName'),
                    $namePlural = $('.girlsNamePlural');

                window.girlName = $('#girlName').val();

                //Write their name to the data and fix the terminology
                if (($("dd ul li.selected a .value").html()) == '') {
                    window.girlName.write = $name.html('you');
                    window.girlName.writePlural = $namePlural.html('your');
                    $('#interact1 .replace1').html('are');
                    $('#interact1 .girlsName').html('You');
                    $('#interact2 .replace1').html('you');
                    $('#interact8 .replace1').html('Do');
                    $('#interact8 .replace2').html('your');
                    $('#interact10 .replace1').html('Are');
                    $('#interact10 .replace2').html('your');
                } else {
                    window.girlName.write = $name.html(window.girlName);
                    window.girlName.writePlural = $namePlural.html(window.girlName + "'s");
                    $('#interact1 .replace1').html('is');
                    $('#interact2 .replace1').html('she');
                    $('#interact8 .replace1').html('Does');
                    $('#interact8 .replace2').html('her');
                    $('#interact10 .replace1').html('Is');
                    $('#interact10 .replace2').html('her');
                }

                $.smoothScroll({
                    offset: 280,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $girlForm.fadeOut(300);
                $('#interact1').fadeIn(600, 'easeOutQuart');
                $('#interact2').fadeIn(600, 'easeOutQuart');
                $('#interact1 .line').animate({ opacity: 1 }, { duration: 300, easing: 'easeOutQuart' }).css('display', 'block');
                $('.interactWrapper1').css('height', '330px');
                $callAction.fadeIn(800, 'easeOutQuart');

                Cufon.refresh('.girlsName, .girlsNamePlural, .replace');
            });

            $('#interact1 .nextBtn').click(function () {
                $.smoothScroll({
                    offset: 650,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $(this).fadeOut(600, 'easeOutQuart');
            });

            $('#interact2 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 650,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $('#interact1 .nextBtn').fadeOut(200);
                $(this).parent().fadeOut(200);
                $('#interact3').animate({ opacity: 1 }, { duration: 600, easing: 'easeOutQuart' }).css('display', 'block');
                $('.interactWrapper2').css('height', '330px');
                $('#interact3 .line').fadeIn(400);
                $('#interact4').fadeIn(900, 'easeOutQuart');
            });

            $('#interact3 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 980,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $(this).fadeOut(200);

            });

            $('#interact4 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 980,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $('#interact3 .nextBtn').fadeOut(200);
                $('#interact4').fadeOut(200);
                $('#interact5').animate({ opacity: 1 }, { duration: 600, easing: 'easeOutQuart' }).css('display', 'block');
                $('.interactWrapper3').css('height', '330px');
                $('#interact5 .line').fadeIn(400);
                $('#interact6').fadeIn(900, 'easeOutQuart');
            });

            $('#interact5 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1310,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $(this).fadeOut(600);
            });

            $('#interact6 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1310,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $('#interact5 .nextBtn').fadeOut(200);
                $('#interact6').fadeOut(200);
                $('#interact7').animate({ opacity: 1 }, { duration: 600, easing: 'easeOutQuart' }).css('display', 'block');
                $('.interactWrapper4').css('height', '330px');
                $('#interact7 .line').fadeIn(400);
                $('#interact8').fadeIn(900, 'easeOutQuart');
            });

            $('#interact7 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1630,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $(this).fadeOut(600);
            });

            $('#interact8 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1630,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $('#interact7 .nextBtn').fadeOut(200);
                $('#interact8').fadeOut(200);
                $('#interact9').animate({ opacity: 1 }, { duration: 600, easing: 'easeOutQuart' }).css('display', 'block');
                $('.interactWrapper5').css('height', '330px');
                $('#interact9 .line').fadeIn(400);
                $('#interact9 .line2').fadeIn(600);
                $('#interact10').fadeIn(900, 'easeOutQuart');
            });

            $('#interact9 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1960,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $(this).fadeOut(600);
            });

            $('#interact10 .nextBtn').click(function (e) {
                e.preventDefault();
                $.smoothScroll({
                    offset: 1960,
                    easing: 'easeOutQuart',
                    speed: 900
                });
                $('#interact9 .nextBtn').fadeOut(200);
                $(this).parent().fadeOut(200);
                $('#interact11').animate({ opacity: 1 }, { duration: 600, easing: 'easeOutQuart' }).css('display', 'block');
                $('.callAction .line').animate({ opacity: 1 }, { duration: 1000, easing: 'easeOutQuart' });
            });

        }
    },

    dropdown: {
        init: function (item) {
            item.each(function () {
                var defaults = {
                    showTextClearButton: false,
                    debugMode: false
                };

                var options = $.extend(defaults, options);

                var $obj = $(this);

                var selected = $('option:selected', $obj);

                var items = $("option", $obj);
                $obj.after('<dl id="dropdown' + $obj.attr('id') + '" class="dropdown"></dl>');
                var target = $('#dropdown' + $obj.attr('id'));
                target.append('<dt><a href="#">' + selected.text() + '</a></dt>');
                target.append('<dd><ul></ul></dd>');
                if (!options['debugMode']) { $obj.hide(); }

                items.each(function (i) {
                    var lineClass = "";
                    if (selected.text() == $(this).text()) {
                        lineClass = "selected";
                    }
                    $("dd ul", target).append('<li class="' + lineClass + '"><a href="#"><span class="text">' +
						 $(this).text() + '</span><span class="value">' +
						 $(this).val() + '</span></a></li>');

                });

                $('dt a', target).bind('focusout', function () {
                    var timeoutTarget = $('ul', target);
                    var timeoutTargetSrc = $('dt a', this);
                    dropDowntimer = setTimeout(function () {
                        timeoutTarget.slideUp('fast');
                    }, 200);
                    target.removeClass("selectedMenu")
                });


                $('dt a', target).focus(function () {
                    target.addClass("selectedMenu")
                    $(".dropdown").css({ "z-index": "1000" });
                    target.css({ "z-index": "1001" });
                    $('ul', target).slideDown('fast').trigger('focus');
                    return false;

                });

                $('dt a', target).bind('click', function () {
                    $(".dropdown").css({ "z-index": "1000" });
                    target.css({ "z-index": "1001" });
                    target.addClass("selectedMenu")
                    $('ul', target).slideDown('fast').trigger('focus');
                    return false;
                });

                $(target).bind('mouseleave', function () {
                    var timeoutTarget = $('ul', target);
                    var timeoutTargetSrc = $('dt a', this);
                    dropDowntimer = setTimeout(function () {
                        timeoutTarget.slideUp('fast');
                    }, 200);
                    target.removeClass("selectedMenu")

                });

                $('ul', target).bind('mouseenter', function () {
                    if (typeof dropDowntimer != 'undefined')
                        clearTimeout(dropDowntimer);
                });


                $("dd ul li a", target).bind('click', function () {
                    var text = $('.text', this).html();
                    $("dt a", target).html(text);
                    //$("dd ul", target).fadeOut(200);
                    $('dd ul li.selected', target).removeClass('selected');
                    $(this).parent().addClass('selected');
                    $obj.val($(this).find("span.value").html());
                    $obj.change();
                    return false;
                });

            });
        }
    }

};

plan.init();

