  /*-----------------------------------------------
'	Company: Community Engine (www.communityengine.com)
'	Copyright (c) 2009, All rights reserved.
'	Date Created: June 2009
'
'	Last Modified Date: 21st June, 2009
'	Last Modified By: Benjamin -> ben.ruhe@communityengine.com
'
'	DO NOT MODIFY THIS DOCUMENT WITHOUT
'	NOTIFYING THE AUTHOR FIRST
'
------------------------------------------------*/

$(function() {

    // Generic value swap. Add defaultVal as a class to any field that you require the value to change on focus
    $('.defaultVal').livequery(function() {
        var default_value = this.value;
        $(this).focus(function() {
            if (this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if (this.value === '') {
                this.value = default_value;
            }
        });
    });


    // Take border off submit buttons
    $("input:button").focus(function() {
        $(this).blur();
    }).css("cursor", "pointer");



    $('a[rel="external"]').click(function() {
        window.open($(this).attr('href'));
        return false;
    });

    // requiredfieldvalidator workaround. Swaps out the bullet for when an error is thrown.     

    // Tool tip function
    $('.toolTip').hide();

    var imgID = $('a.tn img').ready(function() {
        $(this).attr('id');
    });

    $(document.body).append('<div style="display:none;" class="toolTip" id="thumbTooltipContainer"></div>');
    $(imgID).mousemove(function(e) {
        var myID = $(this).attr('id');
        var xPos = e.pageX;
        var yPos = e.pageY;
        var descCont = $('#' + myID + 'Desc');
        if ($('#thumbTooltipContainer').attr('rel') != (myID + 'Desc')) {
            $('#thumbTooltipContainer').attr('rel', (myID + 'Desc'));
            $('#thumbTooltipContainer').html($(descCont).html());
        }

        e.stopPropagation();

        if ($(descCont).length > 0) {
            $('#thumbTooltipContainer').css({
                top: (yPos) + 10 + 'px',
                left: (xPos) + 20 + 'px'
            }).show();
        }
    });

    $(imgID).mouseout(function() {
        $('#thumbTooltipContainer').hide();
    });
    // replace password field for real password field

    $('input.txtPasswordFake').show();
    $('input.txtPassword').hide();

    $('input.txtPasswordFake').focus(function() {
        $('input.txtPasswordFake').hide();
        $('input.txtPassword').show();
        $('input.txtPassword').focus();
    });
    $('input.txtPassword').blur(function() {
        $('input.txtPassword').hide();
        $('input.txtPasswordFake').show();
        $('input.txtPasswordFake').val('Password');
    });

    // Sets event detail columns to equal heights	
    $(".eventDets").equalHeights();
}); 



// jQuery Randomiser to be used wherever you need randomization
jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],{
    random: function(a, i, m, r) {
        if (i === 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        }
        return i == jQuery.jQueryRandom;
    }
});


// Equal height columns
$.fn.equalHeights = function(minHeight, maxHeight) {
    tallest = (minHeight) ? minHeight : 0;
    this.each(function() {
        if ($(this).height() > tallest) {
            tallest = $(this).height();
        }
    });
    if ((maxHeight) && tallest > maxHeight) { tallest = maxHeight; }
    return this.each(function() {
        $(this).height(tallest).css("overflow", "hidden");
    });
};

//Added by DW:
//24th July 2009
//For a lot of the autocomplete adding/removing objects to other objects javascript, I have been using the indexOf function on arrays which
//IE doesn't like very much. Code below fixes the problem.
if (!Array.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == obj) {
                return i;
            }
        }
        return -1;
    };
}
