﻿$(document).ready(function() {
        //$('.flying-text').css({ opacity: 0 });
        //$('#readMore').css({ opacity: 0 });
        //$('.flying-text').css('margin-left', '-100px');
        //$('#readMore').css('margin-left', '-100px');

        var selType = "aerospace";
        runText('', selType);
        $('.subNavImage').hover(
      	function() {
      	    //reset
      	    $('.flying-text').css({ opacity: 0 });
      	    $('#readMore').css({ opacity: 0 });
      	    $('.flying-text').css('margin-left', '-100px');
      	    $('#readMore').css('margin-left', '-100px');

      	    var selType = $(this).attr("alt");
      	    var newURL = "url(images/header/" + selType + ".jpg)";
      	    //alert(newURL);

      	    $('#mainBanner').css("background-image", newURL);

      	    runText('', selType);
      	},
      function() {
          //$(this).find("span:last").remove();
          //alert('out');
      }

      );

    });


//flying texts

    function runText(id, text) {
        var seltype = text.toLowerCase();
        switch (seltype) {
            case "aerospace":
                text = "From safety critical flight components through to ground requirements, discover more about our range of casting solutions for your Aerospace project";
                break;
            case "automotive":
                text = "With over 15 years experience in the Automotive industry, Haworth specialise in sampling, pre-production volumes, medium production volume and development";
                break;
            case "defence":
                text = "Our Defence expertise lays within producing high integrity castings with exacting non-destructive testing requirements, suitable for any project";
                break;
            case "energy":
                text = "For over 20 years we have been providing Energy clients with castings which pass the highest scrutiny UKAS and International standards";
                break;
            case "marine":
                text = "Our experience in the Marine industry spans high quality casting for bespoke and low volume requirements";
                break;
            case "medical":
                text = "Experienced in the Medical industry, we have developed a wide range of castings for various Medical applications from general castings for operating theatre equipment and other elaborate castings";
                break;
            case "oilandgas":
                text = "Commanding high standards and large-scale production capabilities, we have been supplying the Oil & Gas industry for over 15-years";
                seltype = "oil-and-gas";
                break;
            case "safety":
                text = "As our main area of expertise, our Safety Critical castings often require significant or full features validation carrying full CMM reports";
                seltype = "safety-critical";
                break;
        }
        $("#readMoreLink").attr("href", "/industries/" + seltype + ".aspx");
        $('.flying-text').text(text);
        //animate
        $('.flying-text').animate({ opacity: 1, marginLeft: "466px" }, 1000);
        setTimeout(function() {
            $('#readMore').animate({ opacity: 1, marginLeft: "646px" }, 500);
        }, 1000);
    }
    (function($) {
        var cache = [];
        // Arguments are image paths relative to the current page.
        $.preLoadImages = function() {
            var args_len = arguments.length;
            for (var i = args_len; i--; ) {
                var cacheImage = document.createElement('img');
                cacheImage.src = arguments[i];
                cache.push(cacheImage);
            }
        }
    })(jQuery)
    jQuery.preLoadImages("images/header/automotive.jpg)",
    "images/header/Defence.jpg)",
    "images/header/Energy.jpg)",
    "images/header/marine.jpg)",
    "images/header/medical.jpg)",
    "images/header/OilandGas.jpg)",
    "images/header/Safety.jpg)");
