var error;
var console;

if(!console) {
    console = { log: function() {} }
}

$(document).ready(function()
{
    // Wrap the contents of any .watchvideo links with a span
    $("a.watchvideo").each(
        function(i)
        {
            $(this).html('<span>' + $(this).text() + '</span>');
        }
    );
		$(".table-listing tbody tr").mouseover(function(){ $(this).addClass( 'active' ) });
		$(".table-listing tbody tr").mouseout(function(){ $(this).removeClass( 'active' ) });
		
	if( $("#column_center").height( ) < 600 )
	{
		$("#column_center").height( 600 );
	}

	$("#popup-show").click( function() {
		$("#popup .text").val('');
		$("#info-message").hide();
		$("#submit").show();
		$("#hide").show();
		$("#popup").show();

		return false;
	});
	
	$("#popup-close").click( function() {
		$("#popup").hide();

		return false;
	});

	$("#colleage").submit( function() {
		return jform.submit(this, {
			onComplete: function(data) {
				console.log(data);
				if(data == 'ok') {
					$("#info-message").html('<p>Your message was sent successfully</p>');
					$(".validate").val('');

					$("#info-message").show();
					$("#submit").hide();
					$("#hide").hide();

				} else {
					$("#info-message").html('<p>Connection to mail server was unsuccessful, please try again later</p>');
					$("#info-message").show();

					$("#submit").hide();
					$("#hide").hide();
				}

				return false;
			}
		});
	});

	$('form').submit( function() {
		
		error = 0;

		$("#" + $(this).get(0).id + " .validate").each( function() {
			if($(this).val() == '') {
				$(this).addClass('error');
				error = 1;
			} else {
				$(this).removeClass('error');
			}
		});

		if(error > 0) {
			alert('Please fill all fields');

			return false;
		}
	});
});


jQuery.preloadImages = function()
{
    for(var i = 0; i<arguments.length; i++)
    {
        jQuery("<img>").attr("src", arguments[i]);
    }

//    setTimeout(slideShowHeader, 5000);
    setTimeout(slideShowHeader, 10000);
}

function slideShowHeader()
{
    if (headers.length < 2) return;

    var obj = null;

    if ($('#header img').get(0))
        obj = $('#header img');

    obj.fadeOut('slow', function()
	{
		var im = obj.get(0);
		if (++j >= headers.length) j = 0;

//		obj.get(0).onload = function() { obj.fadeIn("slow"); };
		obj.get(0).onload = function() { obj.fadeIn( ); };
		obj.attr("src", headers[j]);//.fadeIn("slow");

//		setTimeout(slideShowHeader, 5000);
		setTimeout(slideShowHeader, 10000);
	});
}