/*

Filename             sitewide.js
Detail               Site functionality
Author:              thunder::tech inc.
License:             CLIENT is defined as the owner of online property from which this file resides or this code is referenced in.
ADDITIONAL PARTY is defined as anyone other than thunder::tech or CLIENT.
No right is granted to ADDITIONAL PARTY to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by CLIENT or thunder::tech.

*/

/*  ================================
Sitewide JavaScript
================================ */

var Project = {};

Project.pageLoaded = function () {
    //thunder.client.project.flashReplace();
    //thunder.client.modify.rollImages();
    //thunder.client.modify.linkOptions();
    //thunder.client.modify.tabSet();
    //thunder.client.modify.treeMenu(false);
    //thunder.client.modify.treeMenu(false, [thunder.client.modes.separatorTreeMenu]);
    //thunder.client.modify.treeMenu(false, [thunder.client.modes.imageTreeMenu]);
    thunder.client.modify.selfLabelFields();
    //thunder.client.modify.requireFields();
    //thunder.client.modify.dropSelector(true);
    //thunder.client.modify.scrollFeature(640, 3000, 500);
    thunder.client.workarounds.alphaImages();
    thunder.client.workarounds.labelAsBrowser();
    $('.menu-on, .menu-other, .heading-over').css('opacity', 0);
    Project.buttons = $('.button').mouseenter(Project.buttonPage);
    Project.pages = $('.page');
    Project.pageContainer = $('.pages');
    $('.close-pages').click(Project.closePages);
    Project.associatedTexts = $('.associated-text').css({ opacity: 0 });
    Project.features = $('.rotating-features').children();
    Project.dots = $('.dots').children().click(Project.clickToFeature).filter('.dot');
    Project.canMoveFeature = true;
    Project.featureDirection = true;
    Project.selectFeature(0);
    Project.featureTimer = setTimeout(Project.timeToFeature, 7000);
    Project.canGoPage = true;
    $('.work-for-us, .close-work').click(Project.toggleResume);
    $('.work-file').css('opacity', 0).change(Project.reflectUpload);

    if ($('#templateEditorUserID').length <= 0) {
        //replace the h2 text        
        $.each($(".page h2"), function (i, item) {
            var currentHTML = $(item).html();
            var newHTML = '<img src="/dynamicTitles/pagetitle.ashx?action=pageTitle&text=' + currentHTML + '"/>';
            $(item).html(newHTML);
        });
    }
}



function resumeSubmissionSuccess() {
    $(this).jBox().showWindow('<div style="padding: 10px;">Congratulations! <br/><br/>Your resume submission was successful!<br/><br/>Thank you.</div>');
}
function resumeSubmissionFailed() {
    $(this).jBox().showWindow('<div style="padding: 10px;">Oops, Your resume submission failed! <br/><br/>Please try again.</div>');
}

Project.timeToFeature = function (n) {
    Project.selectFeature('direction');
    Project.featureTimer = setTimeout(Project.timeToFeature, 7000);
}

Project.clickToFeature = function (n) {
    clearTimeout(Project.featureTimer);
    var t = $(this);
    if (t.hasClass('arrow-dot')) {
        if (t.hasClass('left-dot')) {
            Project.featureDirection = false;
            Project.selectFeature('direction');
        }
        else {
            Project.featureDirection = true;
            Project.selectFeature('direction');
        }
    }
    else {
        var n = Project.dots.index(this);
        if (Project.currentFeature != n) {
            Project.featureDirection = n > Project.currentFeature;
            Project.selectFeature(n);
        }
    }
    Project.featureTimer = setTimeout(Project.timeToFeature, 7000);
}

Project.selectFeature = function (n) {
    if (Project.canMoveFeature) {
        if (n == 'direction') {
            n = Project.featureDirection ? ((Project.currentFeature < Project.features.length - 1) ? (Project.currentFeature + 1) : 0) : ((Project.currentFeature > 0) ? (Project.currentFeature - 1) : (Project.features.length - 1));
        }
        Project.canMoveFeature = false;
        Project.associatedTexts.stop(true, false);
        Project.features.stop(true, false);
        Project.dots.stop(true, false);
        var text = Project.associatedTexts.eq(n).css({ left: Project.featureDirection ? 530 : -530 }).animate({ opacity: 1, left: 0 }, { duration: 800, complete: function () { Project.canMoveFeature = true; } });
        Project.associatedTexts.not(text).animate({ opacity: 0, left: Project.featureDirection ? -530 : 530 }, { duration: 800 });
        var feature = Project.features.eq(n).animate({ opacity: 1 }, { duration: 400 });
        Project.features.not(feature).animate({ opacity: 0 }, { duration: 400 });
        var dot = Project.dots.eq(n);
        dot.children('.dot-off').animate({ opacity: 0 }, { duration: 400 });
        Project.dots.not(dot).children('.dot-off').animate({ opacity: 1 }, { duration: 400 });
        Project.currentFeature = n;
    }
}

Project.reflectUpload = function () {
    $('.work-file-changer').text($(this).val());
}

Project.toggleResume = function () {
    Project.resumeOpen = !Project.resumeOpen;
    $('.work-dropdown').stop(true, false).animate({ height: Project.resumeOpen ? 345 : 0 }, { duration: 300 });
}

Project.closePages = function () {
    Project.buttons.find('.menu-other, .menu-on, .heading-over').stop(true, false).animate({ opacity: 0 }, { duration: 400 });
    Project.buttons.find('.heading-off, p, .button-content').stop(true, false).animate({ opacity: 1 }, { duration: 400 });
    Project.pageContainer.stop(true, false).animate({ width: 0 }, { duration: 400 });
}

Project.buttonPage = function () {
    if (Project.canGoPage == true) {
        Project.nextPage = false;
        Project.canGoPage = false;
        var t, o;
        // Buttons

        if ($('#templateEditorUserID').length <= 0) {
            t = $(this);
            t.find('.menu-other, .heading-off, p').stop(true, false).animate({ opacity: 0 }, { duration: 400 });
            t.find('.menu-on, .heading-over, .button-content').stop(true, false).animate({ opacity: 1 }, { duration: 400 });
            o = Project.buttons.not(this);
            o.find('.menu-other, .heading-off, p').stop(true, false).animate({ opacity: 1 }, { duration: 400 });
            o.find('.menu-on, .heading-over').stop(true, false).animate({ opacity: 0 }, { duration: 400 });
            o.find('.button-content').stop(true, false).animate({ opacity: 0.4 }, { duration: 400 });
        }


        // Pages
        Project.pages.filter('.page-active').removeClass('page-active').stop(true, false).animate({ top: -400 }, { duration: 400 });
        t = Project.pages.eq(Project.buttons.index(this));
        t.stop(true, true).css('top', 400).animate({ top: 184 - (t.height() / 2) }, { duration: 400 }).addClass('page-active');
        Project.pageContainer.stop(true, false).delay(100).animate({ width: 625 }, { duration: 800 });
        setTimeout(Project.checkNextPage, 500)
    }
    else {
        Project.nextPage = this;
    }
}

Project.checkNextPage = function () {
    Project.canGoPage = true;
    if (Project.nextPage != false) {
        Project.buttonPage.call(Project.nextPage);
    }
}

Project.flashReplace = function () {
    var so;
    so = new SWFObject("../flash/swf1.swf", "swf-obj-1", "300", "250", "9", "");
    so.addParam("quality", "high");
    so.addParam("wmode", "transparent");
    so.write("swf-holder-1");
}

$(document).ready(Project.pageLoaded);

