$(document).ready(function(){

    //fires initial menu
    $('.linkContainer').hover(function(){
        
        $(this).children('.submenu').show();
        var associatedWidth = $(this).width(true);
        
        $(this).find('.submenu a').each (function(){

            if ($(this).width() > associatedWidth) {
                associatedWidth = $(this).width(true);
            }
        })
        
        $(this).find('.submenu a').each (function(){
            $(this).width(associatedWidth);
        })
        
    }, function(){
        $(this).children('.submenu').hide();
    }) 
    
    $('.newsMinContainer:nth-child(4)').css('border-right','none');
    
    $('.sublink').prepend('&bull; ');
    
    $('.sublink:first').css('padding-top',12);
    $('.sublink:first').css('background-position','21px 16px');
    
    $('.sublink:last').css('padding-bottom',12);
    
    $('#callbackRequestForm input, #callbackFooterElements input, #search-input').click(function() {
        
        var currentText = $(this).val()
        $(this).val('');
        var newText = '';
        
        $(this).blur(function(){
            newText = $(this).val();
            if (newText == '') {
                $(this).val(currentText);
            }
        })
    
    })
    
    $('#callbackRequestForm').submit(function(){
        
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var emailAddress = $('#callbackEmail').val();
        var theName = $('#callbackName').val();
        var theContactNumber = $('#callbackTelephone').val();
        
        //removes any default text
        if (theName == 'Your name...') {
            theName = '';
        }
        
        //removes any default text
        if (theContactNumber == 'Your contact number...') {
           theContactNumber = ''; 
        }
        
        if(reg.test(emailAddress) == false || theContactNumber == '' || theName == '') {
            alert('Please fill in your name, your contact number and your email address to continue');
            return false;
        } else {
            return true;
        }
        
    })
    
    $('#callbackRequestFormFooter').submit(function(){
        
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var emailAddress = $('#callbackEmailFooter').val();
        var theName = $('#callbackNameFooter').val();
        var theContactNumber = $('#callbackTelephoneFooter').val();
        
        //removes any default text
        if (theName == 'Your name...') {
            theName = '';
        }
        
        //removes any default text
        if (theContactNumber == 'Your contact number...') {
           theContactNumber = ''; 
        }
        
        if(reg.test(emailAddress) == false || theContactNumber == '' || theName == '') {
            alert('Please fill in your name, your contact number and your email address to continue');
            return false;
        } else {
            return true;
        }
        
    })
    
    function alterButtons() {
        $('#sliderNavigation li').each(function(){
            $(this).removeClass('highLighted');
        })
        
        $('#sliderNav'+animatorTracker).addClass('highLighted');
    }
    
    //all pages other than home page use this for slide in text 
    function slideInText() {
        $('.bannerTextImage').animate({
            'margin-left': 43
        }, function(){
            //setTimeout(slideOff,2000)   
        })
   }

    setTimeout(slideInText, 1000);
   
    //news Ticker
   
    var mainPageColour = $('.solutions-content').css('color');
    $('#newsTicker').css('background-color',mainPageColour);
    
    $.get('/news/allnews/', function(data){
        trimmedData = $.trim(data);
        if (trimmedData != '') {
            $('#newsTicker').show();
            $('#newsTicker').html(trimmedData);
            $('#js-news').ticker();
        }
    })
})

