﻿// JavaScript Document
//Global js for Future Transport Systems

$(function(){
    initMenu();

    $("input.labelled").focus(function(){
        if ( this.value == this.title ) {
            this.value = "";
            $(this).data("color", $(this).css("color"));
            $(this).css("color","#555");
        }
    }).blur(function(){
        if ( this.value == "" ) {
            this.value = this.title;
            $(this).css("color", $(this).data("color"));
        }
    });

    $("#search .text").keydown(function(event){
        if (event.keyCode == 13) {
            event.stopPropagation();
            event.preventDefault();
            $("#search .submit").click();
        }
    });

    $('ul.revolver').each(function() {
        var first = $(this).find(":visible :first");
        $(this).innerfade({
            speed: 1000,
            timeout: 3000,
            type: 'sequence',
            containerheight: first.height()
        }).width(first.width());
    });

    //Set column height
    setHeight();
});

function setHeight() {
    var heightCols = $(".setHeight");
    var maxHeight = 0;
    for (i = 0; i < heightCols.length; i++) {
        if ($(heightCols[i]).height() > maxHeight)
            maxHeight = $(heightCols[i]).height();
    }
    $(".setHeight").each(function() { $(this).height(maxHeight) });
}

//Set column height
function getMaxHeight(col) {
	var maxHeight = 0;
	var columns = ( typeof(col) == 'string' ) ? $(col) : col;
    columns.each(function() {
        var thisheight = $(this).height();
		if(thisheight > maxHeight) {
            maxHeight = thisheight;
        }
    });
    return maxHeight;
}

function initMenu()
{
	$("#primaryNav ul li").hoverIntent({
	    timeout: 100,
		over: function()
		{
			$(this).children("ul").slideDown(200);

			if( $(this).hasClass("current"))
				$(this).addClass("ac");

			$(this).addClass("current");
		},
		out: function()
		{
			$(this).children("ul").slideUp(200);

			if( $(this).hasClass("ac") )
				$(this).removeClass("ac");
			else
				$(this).removeClass("current");
		}
	});
}