/* ---------------------------------------
 * Filename: engine.js
 * Version: 1.5.0 (2009-8-05) yyyy-mm-dd
 * Description: script configurations and document onload functions - multiple dependencies
 * Website:
 * Author: Anthony Eggert - http://www.stylephreak.com
 ----------------------------------------- */
var Stylephreak = {
    hideOnLoad: function() {
        $("#page").hide();
        $("#loading-overlay").animate({
            opacity: '1'
        },
        'fast');
    },
    // Link Treatments
    treatLinks: function() { // Link Treatment - Find all links with external designations and open them in a new window (validates Strict)
        $('a[rel="external"]').click(function() {
            window.open($(this).attr('href'));
            return false;
        }); 
    },
    // Cufon Font Replacements (http://cufon.shoqolate.com)
    cufonFonts: function() {
        $.getScript("lib/ext/jquery.cufon-yui.js");
        $.getScript("lib/ext/font.js",
        function() {
            Cufon.replace('#content h2', {
                textShadow: '#ccc 1px 1px 1px'
            });
            Cufon.replace('#tagline', {
                textShadow: '#333 1px 1px 1px'
            });
            Cufon.replace('h3');
            Cufon.replace('h4');
        });
    },
    // UI Tabs
    uiTabs: function() {
        $("#wrapper").tabs({
            fx: {
                opacity: 'toggle'
            }
        });
        var $tabs = $("#wrapper").tabs(); // first tab selected
        $('.home-link').click(function() { // bind click event to link
            $tabs.tabs('select', 0);
            return false;
        });
        $('.questions-link').click(function() { // bind click event to link
            $tabs.tabs('select', 1);
            return false;
        });
        $('.testimonial-link').click(function() { // bind click event to link
            $tabs.tabs('select', 2);
            return false;
        });
        $('.buy-link').click(function() { // bind click event to link
            $tabs.tabs('select', 3);
            return false;
        });
        $('.ingredients-link').click(function() { // bind click event to link
            $tabs.tabs('select', 4);
            return false;
        });
        $('.contact-link').click(function() { // bind click event to link
            $tabs.tabs('select', 5);
            return false;
        });
    },
    // Main Feature Panel
    featureList: function() {
        $('head').append('<link rel="stylesheet" href="assets/css/ext/featured.css" type="text/css" />');
        $.getScript("lib/ext/jquery.featureList-1.0.0.js",
        function() {
            $('#features li a').featureList({
                output: '#output li',
                start_item: 1
            });
        });
    },
    exposeItem: function() {
        $.getScript("lib/ext/jquery.expose.js",
        function() { // assign a click event to the exposed element, using normal jQuery coding 
            $("#ebook").click(function() { // perform exposing for the clicked element 
                $(this).expose({
                    api: true
                }).load();
            });
            $(".contact-link").click(function() { // perform exposing for the clicked element 
                $("#signup").expose({
                    api: true
                }).load();
            });
        });
    },
    // Rounded Corners (http://malsup.com/corner/)
    roundedCorners: function() {
        $.getScript("lib/ext/jquery.corners.js",
        function() {
            $('.rounded').corner();
            $('.opt form').corner();
            $('.testimonial').corner();
        });
    }
} // functions to run when the DOM is ready
$(document).ready(function() {
    Stylephreak.cufonFonts();
    Stylephreak.treatLinks();
    Stylephreak.uiTabs();
    Stylephreak.roundedCorners();
    Stylephreak.exposeItem();
}); // functions to run after page is fully loaded
$(window).load(function() {
    Stylephreak.hideOnLoad();
    $("#loading-overlay").animate({
        opacity: '0'
    },
    'slow');
    $("#page").show();
    setTimeout(function() {
        $("#loading-overlay").remove();
    },
    1500);
});