﻿jQuery.noConflict();

function spambuster(mailbox, domain) {
    location.href = "mailto:" + mailbox + "@" + domain;
}

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function winOpen(url, scrollable) {

    if (scrollable == 1) {
        newWindow(url, null, 660, 480, 1);
    }
    else {
        newWindow(url, null, 660, 480);
    }
}

function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
    var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
    var int_windowTop = (screen.height - a_int_windowHeight) / 2;
    var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=false,menubar=false,toolbar=false,location=false,statusbar=false';
    var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
        obj_window.window.focus();
    }
}

jQuery(document).ready(function() {

    // Sets both columns to same height
    equalHeight(jQuery(".contentframe"));


    // Start slideshow of screenshots above footer
    slideSwitch();

    function slideSwitch() {

        jQuery('#script-thumb').fadeTo('slow', 1).delay(3000).fadeTo('slow', 0.3, function() {
            jQuery('#outline-thumb').fadeTo('slow', 1).delay(3000).fadeTo('slow', 0.3, function() {
                jQuery('#stepcards-thumb').fadeTo('slow', 1).delay(3000).fadeTo('slow', 0.3, function() {
                    jQuery('#powerview-thumb').fadeTo('slow', 1).delay(3000).fadeTo('slow', 0.3, function() {
                        jQuery('#feelfactor-thumb').fadeTo('slow', 1).delay(3000).fadeTo('slow', 0.3, function() {
                            jQuery('#cpwizard-thumb').fadeTo('slow', 1).delay(3000).fadeTo('slow', 0.3, function() {
                                slideSwitch();
                            });
                        });
                    });
                });
            });
        });

    }

    $('#screenshots').hover(function() { jQuery('#screenshots-content').show(600) });


    // Initiate hover action which doesn't work via css once animation as begun
    $('#script-thumb').hover(function() {
        jQuery('#script-thumb').fadeTo('slow', 1);
        jQuery('#outline-content').hide();
        jQuery('#stepcards-content').hide();
        jQuery('#powerview-content').hide();
        jQuery('#feelfactor-content').hide();
        jQuery('#cpwizard-content').hide();
        jQuery('#script-content').show();
    }, function() {
        jQuery('#script-thumb').fadeTo('slow', 0.3);
    });

    $('#outline-thumb').hover(function() {
        jQuery('#outline-thumb').fadeTo('slow', 1);
        jQuery('#script-content').hide();
        jQuery('#stepcards-content').hide();
        jQuery('#powerview-content').hide();
        jQuery('#feelfactor-content').hide();
        jQuery('#cpwizard-content').hide();
        jQuery('#outline-content').show();
    }, function() {
        jQuery('#outline-thumb').fadeTo('slow', 0.3);
    });

    $('#stepcards-thumb').hover(function() {
        jQuery('#stepcards-thumb').fadeTo('slow', 1);
        jQuery('#script-content').hide();
        jQuery('#outline-content').hide();
        jQuery('#powerview-content').hide();
        jQuery('#feelfactor-content').hide();
        jQuery('#cpwizard-content').hide();
        jQuery('#stepcards-content').show();
    }, function() {
        jQuery('#stepcards-thumb').fadeTo('slow', 0.3);
    });

    $('#powerview-thumb').hover(function() {
        jQuery('#powerview-thumb').fadeTo('slow', 1);
        jQuery('#script-content').hide();
        jQuery('#outline-content').hide();
        jQuery('#stepcards-content').hide();
        jQuery('#feelfactor-content').hide();
        jQuery('#cpwizard-content').hide();
        jQuery('#powerview-content').show();
    }, function() {
        jQuery('#powerview-thumb').fadeTo('slow', 0.3);
    });

    $('#feelfactor-thumb').hover(function() {
        jQuery('#feelfactor-thumb').fadeTo('slow', 1);
        jQuery('#outline-thumb').fadeTo('slow', 1);
        jQuery('#script-content').hide();
        jQuery('#outline-content').hide();
        jQuery('#stepcards-content').hide();
        jQuery('#powerview-content').hide();
        jQuery('#cpwizard-content').hide();
        jQuery('#feelfactor-content').show();
    }, function() {
        jQuery('#feelfactor-thumb').fadeTo('slow', 0.3);
    });

    $('#cpwizard-thumb').hover(function() {
        jQuery('#cpwizard-thumb').fadeTo('slow', 1);
        jQuery('#outline-thumb').fadeTo('slow', 1);
        jQuery('#script-content').hide();
        jQuery('#outline-content').hide();
        jQuery('#stepcards-content').hide();
        jQuery('#powerview-content').hide();
        jQuery('#feelfactor-content').hide();
        jQuery('#cpwizard-content').show();
    }, function() {
        jQuery('#cpwizard-thumb').fadeTo('slow', 0.3);
    });

    // Fancybox screenshot click action to display gallery
    jQuery('a[rel=screenshots]').fancybox({
        'padding': '0',
        'cyclic': true
    });

    // Fancybox ebook click action to display gallery
    jQuery('a[rel=ebook]').fancybox({
        'padding': '0',
        'cyclic': true
    });

    // Fancybox script it click action to display gallery
    jQuery('a[rel=script-it]').fancybox({
        'padding': '0',
        'cyclic': true
    });

    // hides the search box as soon as the DOM is ready
    jQuery('#toggle_search').hide();

    // toggles the search box on clicking the view link 
    jQuery('a#slide_toggle_search').click(function() {
        jQuery('#header_contact_wrapper2').hide();
        jQuery('#header_search_show_button').hide();
        jQuery('#toggle_search').slideToggle(400);
        return false;
    });

    // toggles the search box on clicking the close link 
    jQuery('a#slide_toggle_search_close').click(function() {
        jQuery('#toggle_search').slideToggle(400, function() {
            jQuery('#header_contact_wrapper2').show();
            jQuery('#header_search_show_button').show();
            return false;
        });
        return false;
    });

    // Need to use differnet code for ASP.NET page
    if (jQuery('#ajax_subscribe_form').length) {

        // toggles the subscribe panel on clicking the view link and resets form once complete
        jQuery('a#slide_toggle_subscribe').click(function() {
            jQuery('#subscribe_panel').animate({ width: 'toggle' }, 400, function() {
                var validator = jQuery("#ajax_subscribe_form").validate();
                validator.resetForm();
                jQuery('#subscribe_success').hide();
                jQuery('#subscribe_form').show();
                return false;
            }
		);
            return false;
        });

        // bind subscribe form using ajaxForm 
        jQuery('#ajax_subscribe_form').ajaxForm({

            beforeSubmit: function() {
                var validator = jQuery("#ajax_subscribe_form").validate();
                if (!jQuery("#ajax_subscribe_form").valid()) {
                    return false;
                }
                else { jQuery('#subscribe_progress').show(); }
            },

            // target identifies the element(s) to update with the server response 
            //target: '#subscribe_success',

            // success identifies the function to invoke when the server response 
            // has been received; here we apply a fade-in effect to the new content 
            success: function() {
                jQuery('#subscribe_form').hide();
                jQuery('#subscribe_success').fadeIn();
            }
        });

    }

    jQuery('#quotes').innerfade({
        animationtype: 'slide',
        speed: 1000,
        timeout: 7000,
        type: 'random_start',
        containerheight: '200px'
    });


    return false;
});
