﻿$(document).ready(function() {

    $('#rightFooter img').animate({
        opacity: 0.25
    }, 100, function() {
        // Animation complete.
    });

    $("#rightFooter img").hover(function() {
        $(this).animate({
            opacity: 0.45
        }, 100, function() {
            // Animation complete.
        });
    }, function() {
        $(this).animate({
            opacity: 0.25
        }, 100, function() {
            // Animation complete.
        });
    });

    // Radio select/deselect
    $("#dimensions .radio").click(function() {
        $("#dimensions .radio").removeClass('selected');
        $(this).addClass('selected');

        // Change price
        $('.bigPrice').html('').addClass('loading');
        var size = $(this).attr('id');
        var type = $('input[name="printType"]').val();

        var selectedSizeArray = $(this).attr('id').split('size');
        var selectedSize = selectedSizeArray[1];
        $('input[name="printSize"]').val(selectedSize);

        var selectedPrice = $('input[name="' + size + 'type' + type + '"]').val();

        $('#type1price').html($('input[name="' + size + 'type1"]').val() + ",00 €");
        $('#type2price').html($('input[name="' + size + 'type2"]').val() + ",00 €");


        // Set hidden fields
        var sizeString = $("#dimensions").find("span.radio.selected").next().html();
        var printTypeString = "";
        if (type == 1)
            printTypeString = "Photographic print";
        else if (type == 2)
            printTypeString = "Unstretched canvas";

        $("input[name=os0]").val("Size: " + sizeString + ", " + printTypeString);
        $("input[name=option_select0]").val("Size: " + sizeString + ", " + printTypeString);
        $("input[name=option_amount0]").val(selectedPrice);

        setTimeout(function() {
            $('.bigPrice').removeClass('loading');
            $('.bigPrice').html(selectedPrice + ',00 €');
        }, 500);
    });

    $("#printType .radio").click(function() {
        $("#printType .radio").removeClass('selected');
        $(this).addClass('selected');

        // Change price
        $('.bigPrice').html('').addClass('loading');

        var selectedTypeArray = $(this).attr('id').split('type');
        var selectedType = selectedTypeArray[1];
        $('input[name="printType"]').val(selectedType);

        var size = $('input[name="printSize"]').val();
        var selectedPrice = $('input[name="size' + size + 'type' + selectedType + '"]').val();

        // Set hidden fields
        var sizeString = $("#dimensions").find("span.radio.selected").next().html();
        var printTypeString = "";
        if (selectedType == 1)
            printTypeString = "Photographic print";
        else if (selectedType == 2)
            printTypeString = "Unstretched canvas";

        $("input[name=os0]").val("Size: " + sizeString + ", " + printTypeString);
        $("input[name=option_select0]").val("Size: " + sizeString + ", " + printTypeString);
        $("input[name=option_amount0]").val(selectedPrice);

        setTimeout(function() {
            $('.bigPrice').removeClass('loading');
            $('.bigPrice').html(selectedPrice + ',00 €');
        }, 500);

    });


    // Tooltip
    $('a.explanation').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        fade: 250
    });



    $('#web img.servicesSmall').animate({
        opacity: 0.25
    }, 100, function() {
        // Animation complete.
    });

    $('#web img.servicesSmall').hover(function() {
        $(this).animate({
            opacity: 0.85
        }, 100, function() {
            // Animation complete.
        });
    }, function() {
        $(this).animate({
            opacity: 0.25
        }, 100, function() {
            // Animation complete.
        });
    });

    // Contact validation
    $(".contactButton").click(function() {

        $(this).hide();
        $(".bigLoader").show();

        var contactName = $('input[name="name"]').val();
        var contactEmail = $('input[name="email"]').val();
        var contactSubject = $('input[name="subject"]').val();
        var contactMessage = $('textarea[name="message"]').val();

        if (contactName == "" || contactEmail == "" || contactMessage == "") {
            alert("Please fill all the required fields!");

            $(this).show();
            $(".bigLoader").hide();
        }
        else {

            // Send request....
            $.ajax({
                type: "POST",
                url: "/Home/SendMail",
                data: 'name=' + contactName + '&email=' + contactEmail + '&subject=' + contactSubject + '&message=' + contactMessage,
                cache: false,
                success: function(html) {
                    $("#contactForm").slideUp();
                    $("#contactSent").show();
                }
            });
        }
    });

    $("#nl-signup").click(function() {

        $(this).hide();
        $("#nl-loading").show();

        var contactName = $('input[name="nl-name"]').val();
        var contactEmail = $('input[name="nl-email"]').val();

        if (contactName == "" || contactEmail == "") {
            alert("Please fill all the required fields!");

            $(this).show();
            $("#nl-loading").hide();
        }
        else {

            $.ajax({
                type: "POST",
                url: "/Home/AddEmail",
                data: 'name=' + contactName + '&email=' + contactEmail,
                cache: false,
                success: function(html) {
                    $("#newsletter").slideUp();
                    $("#nl-signed").show();
                }
            });
        }
    });

    $("#addToCart").click(function(event) {
        event.preventDefault();
        $("form#paypalForm").submit();
    });

    // Navigation photos fade
    $('#photoNavigation img.smallThumb').animate({
        opacity: 0.25
    }, 100, function() {
        // Animation complete.
    });

    $('#photoNavigation img.smallThumb').hover(function() {
        $(this).animate({
            opacity: 1
        }, 100, function() {
            // Animation complete.
        });
    }, function() {
        $(this).animate({
            opacity: 0.25
        }, 100, function() {
            // Animation complete.
        });
    });

    // Facebook like button
    $('.fb_like_button').animate({
        opacity: 0.45
    }, 100, function() {
        // Animation complete.
    });

    $('.fb_like_button').hover(function() {
        $(this).animate({
            opacity: 1
        }, 100, function() {
            // Animation complete.
        });
    }, function() {
        $(this).animate({
            opacity: 0.45
        }, 100, function() {
            // Animation complete.
        });
    });


    $(".buyPrintLink").click(function(event) {
        event.preventDefault();

        $(".buyPrintLink").slideUp();

        $("#shopBox").slideDown();
    });



    // Fancybox
    $("a[rel=big]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false,
        'titlePosition': 'over',
        'overlayColor': '#141312',
        'overlayOpacity': '0.9',
        'autoScale': false
    });




});
