﻿//////////////////////////////////////////////////////////////////////////////////
//All generic scripts for the GD website. Includes the dropdown funtionality /////
//as well as those for inputs, asp buttons etc ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
//Author:   Stephen Zsolnai///////////////////////////////////////////////////////
//Date:     22/10/2009////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
/// <reference path="jquery-1.3.2-vsdoc2.js" />
var fbHgt = "260px"; //The set height of the feed back form

$(document).ready(function() {


    //Show / hide the client list
    $("#clientListWrap").mouseover(function() {

        //The login dropdown will have been forced to stay open if the page posted back with an unsuccessful login attempt. This will close it if it is.
        releaseWindow();
        $("#clientList").stop().animate({ height: '205px' }, { duration: 400, easing: 'easeInOutExpo' });
        $("a.aProjects").addClass('linkOver');
    });
    $("#clientListWrap").mouseout(function() {
        $("#clientList").stop().animate({ height: '0px' }, { duration: 100, easing: 'easeInOutExpo' });
        $("a.aProjects").removeClass('linkOver');
    });

    //Show / hide the login
    $("#loginDropDownWrap").mouseover(function() {
        $("#loginWrap div.inner").stop().animate({ height: '260px' }, { duration: 400, easing: 'easeInOutExpo' });
        $("a.aLogin").addClass('linkOver');
    });
    $("#loginDropDownWrap").mouseout(function() {
        $("#loginWrap div.inner").stop().animate({ height: '0px' }, { duration: 100, easing: 'easeInOutExpo' });
        $("a.aLogin").removeClass('linkOver');
    });

    $("a#showFeedback").click(function() {
        //If the form is already showing, we need to close it
        if ($("#feedbackForm div.inner").css('height') == fbHgt) {
            $("#feedbackForm div.inner").stop().animate({ height: '0px' }, { duration: 400, easing: 'easeInOutExpo' });
            $("#hideFeedback").fadeOut("fast");

        } else {
            $("#feedbackForm div.inner").stop().animate({ height: fbHgt }, { duration: 400, easing: 'easeInOutExpo' });
            $("#hideFeedback").fadeIn("slow");
        }
    });
    $("#hideFeedback").click(function() {
        $("#feedbackForm div.inner").stop().animate({ height: '0px' }, { duration: 400, easing: 'easeInOutExpo' });
        $("#hideFeedback").fadeOut("fast");
    });




    //Logic for the client groups in the dropdown nav

    //over events
    $("div.selections span").mouseover(function() {
        //$(this).css({ color: '#6dcff6' });
        $(this).addClass('hover');
    });
    $("div.selections span").mouseout(function() {
        if ($(this).attr('class') != 'active') {
            //$(this).css({ color: '#a0a0a0' });
            $(this).removeClass("hover");
        }
    });


    //highlight clicked link and deselect others
    $("div.selections span").click(function() {
        $('div.selections ul li').children().each(
            function() {
                //console.log("each!")
                $(this).removeClass("active");
            }
        );
        $(this).addClass('active');

    });

    $("input.aspButton").hover(
        function() {
            $(this).addClass('aspButtonOver');
        },
        function() {
            $(this).removeClass('aspButtonOver')
        }
    );

    $("input.formButton").hover(
        function() { $(this).addClass('hover'); },
        function() { $(this).removeClass('hover'); }
    );

    /*Hover effect for the slideshow the color changes based on what is stored as a hex in the database.*/
    /*This hex is stored as the link's id and accessed here.*/
    $("a.slideShowLink").hover(function() {

        //get the hex that is stored as the id and assign it to the child span
        var hex = $(this).attr('id').substring(6);
        $(this).find('span.link').css({ color: '#' + hex })
    }, function() {
        $(this).find('span.link').css({ color: '#ffffff' })


    });
    //    $("div.overlay").hover(function() {

    //        //get the hex that is stored as the id and assign it to the child span
    //        var hex = $(this).find('div.inner div.trans').attr('id');
    //        $(this).find('div.inner div.trans').css({ background: '#' + hex, opacity : 0.5 });
    //    }, function() {
    //        $(this).find('div.inner div.trans').css({ background: '#212221', opacity: 0.8 });


    //    });

});


////////////////////////////////////////////////////
//Functions/////////////////////////////////////////
////////////////////////////////////////////////////

//Set start up page variables for the projects pages
function pageLoad() {

    //animate the scrollable tool's container to move in from off the right of the screen to the centre.
    setTimeout(function() {
        $("#workImages div.inner").animate(
    {
        left: 0
    }, 400);
    }, 400);
    //    $("#clientList div.inner").animate({
    //        opacity: 0.1
    //    }, 500);
}

/*Manage the default text for the login username field*/
function clearText(elem) {
    elem.value = "";
    //document.form1.userName.value = ""
}

function resetText(elem, value) {
    if (elem.value == "")
        elem.value = value
}

//If a user clicks in a field in the dropdown, it needs to stay visible.
function holdWindow() {

    $("#loginWrap div.inner").addClass('holdDropDown');
    $("a.aLogin").addClass('holdLinkOver');

}
function releaseWindow() {

    $("#loginWrap div.inner").removeClass('holdDropDown');
    $("a.aLogin").removeClass('holdLinkOver');

}

//Hide the feedback dropdown if it has been completed successfully.
function hideFeedback() {
    $("#hideFeedback").fadeOut("fast");
    setTimeout(function() {
        $("#feedbackForm div.inner").stop().animate({ height: '0px' }, { duration: 400, easing: 'easeInOutExpo' });
    
    }, 3000);
}
