﻿$(document).ready(function() {
	
	/*
	$("#analyse").submit(function(e) {
		
		e.preventDefault();
		
		$("#loadOverlay").width($(window).width()).height($(document).height());
	
		$("#loadOverlay").css("opacitiy", "0").show();
		$("#innerOverlay").centre();
		$("#loadOverlay").hide().css("opacity", "0.92");
	
		$("#loadOverlay").fadeIn(500,function(){			
				$("#innerOverlay").fadeIn(500);
		});
			
		$("#analyse").unbind("submit");
		
		setTimeout("$('#analyse').submit()", 1000);	
	});
	*/

	$(window).resize(function() {
		$("#loadOverlay").width($(window).width()).height($(document).height());
		$("#innerOverlay").centre();
	});

    $("#twitterScreenName").click(function() {
        if ($(this).val() == "your twitter name")
            $(this).val("");
    });
	
	$("#orderResults").change(function() {
    	$(this).closest("form").submit();
	});

    $("#moreUserInfoButton").click(function(e) {

        e.preventDefault();

        if ($("#moreUserInfo").is(':visible')) {

            $("#moreUserInfo").slideUp();

        } else {

            $("#moreUserInfo").slideDown();
        }

    });

    $("select[name='jobCategory'] option:eq(0)").attr("selected", "selected");
    $("select[name='industrySector'] option:eq(0)").attr("selected", "selected");

    // initialse job select elements
    $("select[name='jobCategory']").change(function() {

        jobCategoryId = $(this).val();
		
		if (jobCategoryId == "") {
		
			$("select[name='job']").attr('disabled', 'disabled');
		
		}
		else {
		
			$.getJSON("/json/jobs/" + jobCategoryId, function(data){
			
				var options = '<option value="">Please select</option>';
				for (var i = 0; i < data.length; i++) {
					options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
				}
				
				$("select[name='job']").html(options).attr('disabled', '');
				
			});
			
		}

    });


    // initialse industry sector select elements
    $("select[name='industrySector']").change(function() {

        industrySectorId = $(this).val();

		if (industrySectorId == "") {
		
			$("select[name='industrySubSector']").attr('disabled', 'disabled');
		}
		else {
		
			$.getJSON("/json/industry_sectors/" + industrySectorId, function(data){
			
				var options = '<option value="">Please select</option>';
				for (var i = 0; i < data.length; i++) {
					options += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
				}
				
				$("select[name='industrySubSector']").html(options).attr('disabled', '');
				
			});
			
		}

    });

});

$.fn.extend({
	
	centre: function() {
		
		$(this).css("left", ($(window).width() - $(this).width()) / 2);
		$(this).css("top", ($(window).height() - $(this).height()) / 2);
	}
	
});
