$(document).ready( function() { 

    // Put any scripts to run on startup here.

    // Draw the cameras on the course tour.
    if ( $('cam1').length ) { draw_cameras(1); }

    // Insert the Google map when required.
    if ( $('#map_canvas').is(':visible') ) { map_init(); }
    
    // Changing icons
    $('.pdf_icon').hover(
        function() { $(this).attr("src", "/wp-content/themes/loyalist/images/pdf_hover.jpg"); },
        function() { $(this).attr("src", "/wp-content/themes/loyalist/images/pdf.jpg"); }
    );

    $('.pdf_text').hover(
        function() { $('.pdf_icon').attr("src", "/wp-content/themes/loyalist/images/pdf_hover.jpg"); },
        function() { $('.pdf_icon').attr("src", "/wp-content/themes/loyalist/images/pdf.jpg"); }
    );


    // Change things with class "signature" to a graphic of what it says in a handwriting font
    $('.signature').loyalistttf( {size: 18, font: 'handsean', padding: 1, bgColor: 'FFFFFF', fgColor: '0000A0'} ); 


    $('#familyclassic').click( function() {
        var all_filled_in = true;
        $('.club-reqd').each( function() { if ( $(this).val() == '' ) { all_filled_in = false; } });

        if ( $('#competition').val() == 'handicap' ) {
            if ( all_filled_in == false ) { 
                alert("You have selected to enter in the handicap tournament.\n\nPlease ensure that you fill in your club details and handicap index.\n\n"
                        + "If you do not wish to enter in the handicap tournament, please change your selection on the right.");
                return false;
            }
        }
    });


} );



// Default values for various subroutines
var current_hole = 1;


var course_pictures = new Array();
for (var i = 1; i <= 18; i++) { course_pictures['hole'+i] = new Array(); }

course_pictures['hole1']['cam1'] = "70,300";
course_pictures['hole1']['cam2'] = "3,225";
course_pictures['hole1']['cam3'] = "58,38";





function draw_cameras(hole) {

    hide_all_cams();

    var holenum = 'hole'+hole;

    for (var i = 1; i <= 12; i++) {

        var camname = 'cam'+i;
        if ( course_pictures[holenum][camname]) { 

            var camid = '#' + camname; 
            var camcoords = course_pictures[holenum][camname].split(/,/);

            $(camid).css("left",camcoords[0]+"px").css("top",camcoords[1]+"px").show();

        }

    }

}


function show_cam_pic(number) {

    var new_photo = 'hole_' + current_hole + '_photo_' + number;

    $('#course_photo_link').attr("href", "/wp-content/themes/loyalist/images/" + new_photo + ".jpg");
    $('#course_photo').attr("src", "/wp-content/themes/loyalist/images/" + new_photo + "_tn.jpg");

}


function hide_all_cams() {

    for (var i = 1; i <= 12; i++) {
        var camid = "#cam" + i;
        $(camid).hide();
    }

}


function map_init() {

    var latlng = new google.maps.LatLng( 44.232728, -76.778355 );
    var myOptions = {
        zoom:      12,
        center:    latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: false
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


    var image = new google.maps.MarkerImage( 'http://loyalist.dev.bcmtech.net/wp-content/themes/loyalist/images/icon_loyalist.png',
        new google.maps.Size( 75, 75 ),
        new google.maps.Point( 0, 0 ),
        new google.maps.Point( 37, 73 ) 
    );

    var shadow = new google.maps.MarkerImage('http://loyalist.dev.bcmtech.net/wp-content/themes/loyalist/images/shadow_loyalist.png',
        new google.maps.Size( 105, 49 ),
        new google.maps.Point( 0, 0 ),
        new google.maps.Point( 18, 40 )
    );

    var shape = {
        coord:  [ 1, 1,  75, 75 ],
        type:   'rect'
    }

    var myLatLng = new google.maps.LatLng( 44.189871, -76.786391 );
    var marker   = new google.maps.Marker( {
        position:   myLatLng,
        map:        map,
        icon:       image,
        shadow:     shadow,
        shape:      shape,
        title:      'Loyalist Golf & Country Club',
        zIndex:     100
    } );

}

function comingsoon() {

    alert("Soon, you will be able to book your tee times online.\n\nWe are currently working on this feature for our members... please check back soon!");

}

