document.getElementsByTagName('html')[0].className += ' js';

//IE png fix with background-repeat and background-position
document.write('<!--[if IE 6]><script type="text/javascript">DD_belatedPNG.fix(\'div, span, a\');</script><![endif]-->');

//create equal height columns
function equalHeight(group){
    tallest = 0;
    group.each(function(){
        thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function confirmSubmit(){
    return confirm("Are you sure you wish to continue?");
}

//open external links
$('a[rel="external"]').attr('target', '_blank');

jQuery.validator.addMethod("defaultInvalid", function(value, element){
    return value != element.defaultValue;
}, "");

//	$('#registerForm').submit({
//		return: confirm('Are you sure?')
//	});
//slideshow
$('#slideshow, #sec_slideshow').cycle({
    timeout: 9000,
    random: true
});

$('#slideshow').toggle(function(){
    $(this).cycle('pause');
}, function(){
    $(this).cycle('resume', true);
});

jQuery.extend({
    random: function(X){
        return Math.floor(X * (Math.random() % 1));
    },
    randomBetween: function(MinV, MaxV){
        return MinV + jQuery.random(MaxV - MinV + 1);
    }
});

//newsticker
$.ajax({
    type: 'GET',
    url: '/annoucements',
    dataType: 'json',
    cache: false,
    success: function(response){
        //    	var i = -1;
        function getMessages(){
            //    		alert(response.messages[i].message);
            var numRand = jQuery.random(response.messages.length);
            $('.message p').fadeTo("slow", 0, function(){
                $(this).html(response.messages[numRand].message).fadeTo("slow", 1);
            });
            
            //    		i++;
            // if we reached the end of the messages, start over
            //            if (i == response.messages.length) {
            //                i = 0;
            //            }
        }
        
        getMessages();
        setInterval(function(){
            getMessages();
        }, 8000);
    }
});

//validate forms
$('#contactForm, #joinForm').validate({});

$('#surveyorSubmit').click(function(){
    $(this).valid();
});
//    $('#tscsFail').click(function(){$(this).location = '/paypal';});

//clear form inputs
$(':text, textarea', '#contactForm, #joinForm').focus(function(){
    if (this.value == this.defaultValue) {
        this.value = '';
    }
});

$(':text, textarea', '#contactForm, #joinForm').blur(function(){
    if (this.value === '') {
        this.value = this.defaultValue;
    }
});

$('.answer-form').hide();
$('.answer-popup').click(function(){
	$(this).next('form').show();
	return false;
});

$('#add_question_form').hide();
$('#add_question').click(function(){
	$('#add_question_form').toggle();
	return false;
});

window.onload = function(){
    equalHeight($(".line > div"));
};