﻿$(document).ready(function() {

    // When competition image is clicked set the co-ords in the hidden form field
    $('#compImage img').click(function(e) {
        var offset = $('#compImage img').offset();
        var x = (e.pageX - offset.left).toFixed(0);
        var y = (e.pageY - offset.top).toFixed(0);
        var coords = ('x: ' + x + ', y: ' + y);
        $('input#Coords').attr('value', coords);
        $('.selection').css({ 'display': 'inline', 'left': (x - -58) + 'px', 'top': (y - 10) + 'px' });
        $('.submitEntry').css({ 'display': 'inline' });
    });

    // If the form has been submitted but there is a problem with validation then re-modal form and show it
    if (validation) {
        // Call modalForm function
        modalForm();
        // Call showForm function
//        showForm();
    }
    
    // Show form to ask if music has been bought
    $('.submitEntry').click(function() {
        // Call modalForm function
         modalForm();

    });

    // If music has been bought then show the form
//    $('.Purchased').click(function() {
//        // Call showForm function
//        showForm();
//    });
    
    // If music has not been purchased re-direct to Buy Music Page
//    $('.notPurchased').click(function() {
//    //        window.location = 'http://simlawrence.ds01.eonic.co.uk/Buy-Music';
//              window.location = 'http://demo.simlawrence.com/Buy-Scandal';
//    });
    
    // When a link in the Buy Music page has been clicked with this class re-direct to Competition page
    $('.buymusic').click(function() {
//      window.location = 'http://simlawrence.ds01.eonic.co.uk/Competition';
//        window.location = 'http://demo.simlawrence.com/Competition';
        window.location = 'http://www.simlawrence.com/Competition';
    });


    //lightbox function
    $(".lightbox").lightbox();
});

// Function to modal form
function modalForm()  {
    $('#compForm').modal({
        opacity: 40,
        close: true,
        escClose: true,
        overlayCss: { backgroundColor: "#696969" }
    });
}

// Function to show form
//function showForm() {
////    $('.actualForm').css({ 'display': 'inline' });
////    $('.questionMusic').css({ 'display': 'none' });
//    $('#compForm').css({ 'position': 'absolute', 'top': '-300px', 'left': '-250px' });
//}
