$(document).ready(function() {
	$("ul li:first-child").addClass("firstchild");
	$("ul li:last-child").addClass("lastchild");
	
    $('#featured').cycle({
		fx: 'scrollLeft',
		next:   '#next', 
   	    prev:   '#prev',
		timeout: 10000
	});

	/*$('#marquee').cycle({
	    fx: 'fade',
	    pause: 1,
	    timeout: 9000
	});*/
	

});

var tmpWheelTxt = new Array()
var tmpWheelInd = new Array()

function SetIndustriesList() {

    //Makes the list of industries when the client form loads

    //This is the order for the wheel
    tmpWheelTxt[1] = '<img src=' + '"' + 'images/industries/aviation.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Aviation' + '"' + ' /><span>Aviation</span>'
    tmpWheelInd[1] = 'aviation'
    tmpWheelTxt[2] = '<img src=' + '"' + 'images/industries/ports.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Ports' + '"' + ' /><span>Ports</span>'
    tmpWheelInd[2] = 'ports'
    tmpWheelTxt[3] = '<div><img src=' + '"' + 'images/industries/manufacturing.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Manufacturing' + '"' + ' /><span>Manufacturing</span></div>'
    tmpWheelInd[3] = 'manufacturing'
    tmpWheelTxt[4] = '<div><img src=' + '"' + 'images/industries/home-products.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Home Products' + '"' + ' /><span>Home Products</span></div>'
    tmpWheelInd[4] = 'home-products'
    tmpWheelTxt[5] = '<div><img src=' + '"' + 'images/industries/chemical.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Chemical' + '"' + ' /><span>Chemical</span></div>'
    tmpWheelInd[5] = 'chemical'
    tmpWheelTxt[6] = '<div><img src=' + '"' + 'images/industries/building-products.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Building Products' + '"' + ' /><span>Building Products</span></div>'
    tmpWheelInd[6] = 'building-products'
    tmpWheelTxt[7] = '<div><img src=' + '"' + 'images/industries/reinforcing.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Reinforcing' + '"' + ' /><span>Reinforcing</span></div>'
    tmpWheelInd[7] = 'reinforcing'
    tmpWheelTxt[8] = '<div><img src=' + '"' + 'images/industries/pharmaceutical.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Pharmaceutical' + '"' + ' /><span>Pharmaceutical</span></div>'
    tmpWheelInd[8] = 'pharmaceutical'
    tmpWheelTxt[9] = '<div><img src=' + '"' + 'images/industries/distribution.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Distribution' + '"' + ' /><span>Distribution</span></div>'
    tmpWheelInd[9] = 'distribution'
    tmpWheelTxt[10] = '<div><img src=' + '"' + 'images/industries/civil-engineering.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Civil Engineering' + '"' + ' /><span>Civil Engineering</span></div>'
    tmpWheelInd[10] = 'civil-engineering'
    tmpWheelTxt[11] = '<div><img src=' + '"' + 'images/industries/call-centre.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Call Centre' + '"' + ' /><span>Call Centre</span></div>'
    tmpWheelInd[11] = 'call-centre'
    tmpWheelTxt[12] = '<div><img src=' + '"' + 'images/industries/fertiliser.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Fertiliser' + '"' + ' /><span>Fertiliser</span></div>'
    tmpWheelInd[12] = 'fertiliser'
    tmpWheelTxt[13] = '<div><img src=' + '"' + 'images/industries/earthmoving.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Earthmoving' + '"' + ' /><span>Earthmoving</span></div>'
    tmpWheelInd[13] = 'earthmoving'
    tmpWheelTxt[14] = '<div><img src=' + '"' + 'images/industries/contracting.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Contracting' + '"' + ' /><span>Contracting</span></div>'
    tmpWheelInd[14] = 'contracting'
    tmpWheelTxt[15] = '<div><img src=' + '"' + 'images/industries/ports.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Steel Fabrication' + '"' + ' /><span>Steel Fabrication</span></div>'
    tmpWheelInd[15] = 'fabrication'
    tmpWheelTxt[16] = '<div><img src=' + '"' + 'images/industries/insurance.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Insurance' + '"' + ' /><span>Insurance</span></div>'
    tmpWheelInd[16] = 'insurance'
    tmpWheelTxt[17] = '<div><img src=' + '"' + 'images/industries/fragrance.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Fragrance' + '"' + ' /><span>Fragrance</span></div>'
    tmpWheelInd[17] = 'fragrance'
    tmpWheelTxt[18] = '<div><img src=' + '"' + 'images/industries/electrical.jpg' + '"' + ' width=' + '"' + '122' + '"' + ' height=' + '"' + '77' + '"' + ' alt=' + '"' + 'FIRST Software - Electrical' + '"' + ' /><span>Electrical</span></div>'
    tmpWheelInd[18] = 'electrical'

    displayIndustries(); //Put images in initially
    
    setInterval("displayIndustries();", 9000);

}

function displayIndustries() {

    //This inserts images for the industries section of the clients page, they display like a wheel going round

    var tmpCurTxt = document.getElementById('mar1').innerHTML;
    var i = 1
    if (tmpCurTxt != "") { //Its not the first cycle
        var j = 1
        while (tmpCurTxt.search(tmpWheelInd[j]) == -1 && i <= 18) {
            //stop when have found the index of the first image
           j++;
       }    
       i = j + 5
   }

   if (i > 18) {
       document.getElementById('mar1').innerHTML = tmpWheelTxt[i - 18]
   } else {
       document.getElementById('mar1').innerHTML = tmpWheelTxt[i]
   }
   if (i > 17) {
       document.getElementById('mar2').innerHTML = tmpWheelTxt[i - 17]
   } else {
       document.getElementById('mar2').innerHTML = tmpWheelTxt[i + 1]
   }
   if (i > 16) {
       document.getElementById('mar3').innerHTML = tmpWheelTxt[i - 16]
   } else {
       document.getElementById('mar3').innerHTML = tmpWheelTxt[i + 2]
   }

   if (i > 15) {
       document.getElementById('mar4').innerHTML = tmpWheelTxt[i - 15]
   } else {
       document.getElementById('mar4').innerHTML = tmpWheelTxt[i + 3]
   }

   if (i > 14) {
       document.getElementById('mar5').innerHTML = tmpWheelTxt[i - 14]
   } else {
       document.getElementById('mar5').innerHTML = tmpWheelTxt[i + 4]
   }
 
}

function homeClientRandom_img() {

    var myimages = new Array()
    myimages[1] = "images/home-clients.jpg"
    myimages[2] = "images/macalister-logo.gif"
    //myimages[3]=""

    var alttexts = new Array()
    alttexts[1] = "Client Vero"
    alttexts[2] = "Client Macalister"
    //imagelinks[3]="Client Forman"

    var ry = Math.floor(Math.random() * myimages.length)
    if (ry == 0)
        ry = 1;

    var MakeupTag = '<img src=' + '"' + myimages[ry] + '"' + ' alt=' + '"' + alttexts[ry] + '"' + ' height=' + '"' + '68' + '"' + ' width=' + '"' + '284' + '"' + '/>'
    document.getElementById('ClientRndLoad').innerHTML = MakeupTag;
    //document.write('<img src=' + '"' + myimages[ry] + '"' + ' alt=' + '"' + alttexts[ry] + '"' + '/>')
}

function doMap(){
 var a="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=34+Vestey+Drive,+Mount+Wellington+Auckland+1060,+New+Zealand&sll=37.0625,-95.677068&sspn=50.51141,114.169922&ie=UTF8&hq=&hnear=34+Vestey+Dr,+Westfield,+Auckland+1060,+New+Zealand&ll=-36.924337,174.83767&spn=0.025113,0.055747&z=15";
 window.open(a,"_blank");
}

//function FooterPos() {

//    var tmpScreenHeight = screen.height;
//    var tmpPageHeight = document.getElementById('content').offsetHeight;
//    var tmpFooterPos = tmpScreenHeight - 220;
//    var tmpStyleValue = 'top:' + tmpFooterPos + 'px; position:absolute;'

//    if (tmpPageHeight >= tmpFooterPos) { //The screen height is too big to fix the position of the footer
    
//    } else { //There will be some white space as the screen height hasn't reached the max
//        document.getElementById('footer').setAttribute("style", tmpStyleValue);
//    }
//}

function LoginButtonClick() {

    //When the login button is clicked on the footer section pass the login name and password to the login form

    var tmpUsername;
    if (document.getElementById('zUser').value == null) {
        tmpUsername = "";
    }
    else {
        tmpUsername = document.getElementById('zUser').value;
    }

    var tmpPassword;
    if (document.getElementById('zpass').value == null) {
        tmpPassword = "";
    }
    else {
        tmpPassword = document.getElementById('zpass').value;
    }

    var tmpCheckBox;
    if (document.getElementById('zchk').checked) {
        tmpCheckBox = "Y";
    }
    else {
        tmpCheckBox = "N";
    }

    var tmpHref = "Login.aspx?Username=" + tmpUsername + "&Password=" + tmpPassword + "&SavePassword=" + tmpCheckBox
    window.location.href = tmpHref;

}

function GetLogin() {

    var tmpVarList = window.location.href.slice(window.location.href.indexOf('?') + 1);
    
    //Get the username
    var tmpUser = tmpVarList.slice(tmpVarList.indexOf('Username=') + 9);
    if (tmpUser.search('&') != -1)
    tmpUser = tmpUser.substring(0, tmpUser.indexOf('&'));

    //Get password
    var tmpPassword = tmpVarList.slice(tmpVarList.indexOf('Password=') + 9);
    if (tmpPassword.search('&') != -1)
    tmpPassword = tmpPassword.substring(0, tmpUser.indexOf('&'));

    document.getElementById('UserName').innerHTML = tmpUser
    document.getElementById('Password').innerHTML = tmpPassword
}

function RemoveTextUser() {

    if (document.getElementById('zUser').value == 'Username')
    document.getElementById('zUser').value = "";

}

function RemoveTextPassword() {

    if (document.getElementById('zpass').value == 'Password')
    document.getElementById('zpass').value = "";

}
