﻿/*-----------------------------------------------
'	Company: Community Engine (www.communityengine.com)
'	Copyright (c) 2009, All rights reserved.
'	Date Created: April 2009
'
'	Last Modified Date: 21st April, 2009
'	Last Modified By: Benjamin -> ben.ruhe@communityengine.com
'
'	DO NOT MODIFY THIS DOCUMENT WITHOUT
'	NOTIFYING THE AUTHOR FIRST
'
------------------------------------------------*/



$(function() {

    $("button").focus(
		function() {
		    $(this).blur();
		}
	).css("cursor", "pointer");

    $("form input").keypress(function(e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $("#subscribe").click();
            return false;
        }
    });


    $("#subscribe").click(function() {
        //        // Validate email address with regex
        if (!checkEmail($(".newsLetterInput").val())) {

            $('.newsLetterInput').css('background', '#000000');
            $('.newsLetterInput').css('color', '#ff0000');
            return false;
        }

        // Submit the form via ajax
        $.ajax({
            type: "GET",
            url: "/Subscribe.ashx",
            data: { email: $(".newsLetterInput").val() },
            dataType: "html",
            error: function() {
                //

            },
            success: function(data) {
                $("div.subscription").fadeOut(100); // If successfully submitted hides the form
                $("div.subInput").fadeOut(100); // If successfully submitted hides the form
                $("div.subButton").fadeOut(100); // If successfully submitted hides the form

                $("div.thankYou").fadeIn(500);  // Shows "Thanks for subscribing" div
                return false;
            }
        });

        return false;

    });

    $('A[rel="external"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    // Slideshow

    $('#slideShow img').css({ opacity: 0 });

    vCycleImages = setInterval(function() {
        var bImgLoaded = true;
        var images = $("#slideShow img");

        for (var i = 0; i < images.length; i++) {
            var img = images[i];
            if (img.complete == false)
                bImgLoaded = false;
        }

        if (bImgLoaded) {
            setTimeout(function() {
                $('#slideShow').cycle({
                    random: 1,
                    delay: -2000
                });
                $('#slideShow img').css({
                    opacity: 0
                });
            }, 1000);
            clearInterval(vCycleImages);
        }
    }, 1000);





});

function checkEmail(email) {
    var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    //var emailVal = $("#" + email).val();
    return pattern.test(email);
}
	
	