var friends_name_def;
var friends_email_def;
var your_name_def;
var your_email_def;

$(document).ready(function(){
    $('ul.sf-menu').superfish({speed: 0});
    
    if($("#nav")) {
        $("#nav dd").hide();
        $("#nav dt b").click(function() {
            if(this.className.indexOf("clicked") != -1) {
                $(this).parent().next().slideUp(200);
                $(this).removeClass("clicked");
            }
            else {
                $("#nav dt b").removeClass();
                $(this).addClass("clicked");
                $("#nav dd:visible").slideUp(200);
                $(this).parent().next().slideDown(500);
            }
            return false;
        });
    }
    
    $("#requestProposalLink").click(function() {
        if ($("#requestProposalImg").attr("src") == "/images/request_a_proposal_c.gif") 
        {
            $("#requestProposalImg").attr("src", "/images/request_a_proposal_o.gif");
            $("#sideRequestProposal").animate({height: "135px"});
        }
        else
        {
            $("#requestProposalImg").attr("src", "/images/request_a_proposal_c.gif");
            $("#sideRequestProposal").animate({height: "24px"});
        }
    });
    $("#shareWithFriendLink").click(function() {          
        if ($("#shareWithFriendImg").attr("src") == "/images/share_with_friend_c.gif") 
        {                                              
            $("#shareWithFriendImg").attr("src", "/images/share_with_friend_o.gif");
            $("#sideShareWithFriend").animate({height: "177px"});
        }
        else
        {                                           
            $("#shareWithFriendImg").attr("src", "/images/share_with_friend_c.gif");
            $("#sideShareWithFriend").animate({height: "24px"});
        }                                              
    });
    
    friends_name_def = $("#friends_name").attr("value");
    friends_email_def = $("#friends_email").attr("value");
    your_name_def = $("#your_name").attr("value");
    your_email_def = $("#your_email").attr("value");
    
    $("#friends_name").focus(function(){
        if ($("#friends_name").attr("value") == friends_name_def)
        {
            $("#friends_name").attr("value", "");
        }
    });
    $("#friends_name").blur(function(){
        if ($("#friends_name").attr("value") == "")
        {
            $("#friends_name").attr("value", friends_name_def);
        }
    });
    $("#friends_email").focus(function(){
        if ($("#friends_email").attr("value") == friends_email_def)
        {
            $("#friends_email").attr("value", "");
        }
    });
    $("#friends_email").blur(function(){
        if ($("#friends_email").attr("value") == "")
        {
            $("#friends_email").attr("value", friends_email_def);
        }
    });
    $("#your_name").focus(function(){
        if ($("#your_name").attr("value") == your_name_def)
        {
            $("#your_name").attr("value", "");
        }
    });
    $("#your_name").blur(function(){
        if ($("#your_name").attr("value") == "")
        {
            $("#your_name").attr("value", your_name_def);
        }
    });
    $("#your_email").focus(function(){
        if ($("#your_email").attr("value") == your_email_def)
        {
            $("#your_email").attr("value", "");
        }
    });
    $("#your_email").blur(function(){
        if ($("#your_email").attr("value") == "")
        {
            $("#your_email").attr("value", your_email_def);
        }
    });
    
    $('#videoPlayer').cycle();
    
    $(".question").click(function() {        
           $(this).children().slideDown("slow");    
    });
    
});



function submitShareForm()
{
    var errors = "";
    if ($("#friends_name").attr("value") == friends_name_def || $("#friends_name").attr("value") == "")
    {
        errors += "Friend's Name is Required\n";
    }
    if ($("#friends_email").attr("value") == friends_email_def || $("#friends_email").attr("value") == "")
    {
        errors += "Friend's Email is Required\n";
    }
    else if (!isValidEmailAddress($("#friends_email").attr("value")))
    {
        errors += "Friend's Email is Invlaid\n";
    }
    if ($("#your_name").attr("value") == your_name_def || $("#your_name").attr("value") == "")
    {
        errors += "Your Name is Required\n";
    }
    if ($("#your_email").attr("value") == your_email_def || $("#your_email").attr("value") == "")
    {
        errors += "Your Email is Required\n";
    }
    else if (!isValidEmailAddress($("#your_email").attr("value")))
    {
        errors += "Your Email is Invlaid\n";
    }
    if (errors == "")
    {
        return true;
    }
    else
    {
        alert(errors);
        return false;
    }
}

function isValidEmailAddress(emailAddress) 
{
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

