    $(function() {
        $('.event').show();

        $('#firstOption').change(function(){
            if($('#secondOption').length > 0 && $('#firstOption').length > 0) {

                $.ajax({
                    url:            "/interface/js/modules/products/AJAXmenus.php",
                    dataType:       "html",
                    data:           "option="+$('#firstOption option:selected').val()+"&prodId="+$('#productId').val()+"&first="+$('#firstOptionLabel').val()+"&second="+$('#secondOptionLabel').val(),
                    success:        function(html){
                                        if(html.length <= 0) {
                                            $('#secondOptionLebel').hide();
                                            $('#secondOptionDiv').hide();
                                            SingleVarientId();
                                        }else{
                                            $('#secondOptionLebel').show();
                                            $('#secondOptionDiv').show();

                                            var arrOptions = html.split(':');
                                            $('#secondOption').children().remove();
                                            for(i=0;i<arrOptions.length;i++) $('#secondOption').append('<option value="'+arrOptions[i]+'">'+arrOptions[i]+'</option>');
                                            DoubleVarientId();
                                        }
                                    }
                });

            }else{
                SingleVarientId();
            }
        });

        $('#secondOption').change(function(){
            DoubleVarientId();
        });

        attachSendEvents();
    });

    function removeEvents() {
        $('*').unbind();
    };

    function strrpos( haystack, needle, offset){
        var i = (haystack+'').lastIndexOf( needle, offset );
        return i >= 0 ? i : false;
    };

    // Bug fix - allows default image to go to the image zoom
    $(document).ready(function(){
        var popupUrl = $('#imageZoomPopupId').attr('rel');
        $('.imageZoomPopup').attr('href', popupUrl);

        return false;
    });

    $('#firstOption').ready(function(){
		if(!$('#firstOption').hasClass('stopAJAX')) {
	        if($('#secondOption').length > 0 && $('#firstOption').length > 0) {
	
	            $.ajax({
	                url:            "/interface/js/modules/products/AJAXmenus.php",
	                dataType:       "html",
	                data:           "option="+$('#firstOption option:selected').val()+"&prodId="+$('#productId').val()+"&first="+$('#firstOptionLabel').val()+"&second="+$('#secondOptionLabel').val(),
	                success:        function(html){
	                                    if(html.length <= 0) {
	                                        $('#secondOptionLebel').hide();
	                                        $('#secondOptionDiv').hide();
	                                        SingleVarientId();
	                                    }else{
	                                        $('#secondOptionLebel').show();
	                                        $('#secondOptionDiv').show();
	                                         var arrOptions = html.split(':');
	                                        $('#secondOption').children().remove();
	                                        for(i=0;i<arrOptions.length;i++) $('#secondOption').append('<option value="'+arrOptions[i]+'">'+arrOptions[i]+'</option>');
	                                        DoubleVarientId();
	                                    }
	                                }
	            });
	
	        }else{
	            SingleVarientId();
	        }
		}
    });

    function SingleVarientId() {
        var myObj = $('#inputProductVarientId');

        $.ajax({
            url:            "/interface/js/modules/products/getVarient.php",
            dataType:       "html",
            data:           "attrs=1&prodId="+$('#productId').val()+"&first="+$('#firstOptionLabel').val()+"&option="+$('#firstOption option:selected').val(),
            success:        function(html){
                                myObj.val(html);
                            }
        });

    }

    function DoubleVarientId() {
        var myObj = $('#inputProductVarientId');

        $.ajax({
            url:            "/interface/js/modules/products/getVarient.php",
            dataType:       "html",
            data:           "attrs=2&prodId="+$('#productId').val()+"&first="+$('#firstOptionLabel').val()+"&option1="+$('#firstOption option:selected').val()+"&second="+$('#secondOptionLabel').val()+"&option2="+$('#secondOption option:selected').val(),
            success:        function(html){
                                myObj.val(html);
                            }
        });

    }

    function attachSendEvents() {

        $('.imageZoomPopup').click(function(){
            window.open(
                $('.imageZoomPopup').attr('href'),
                "imageZoom",
                "status = 0, height = 770, width = 750, resizable = 0"
            )
            return false;
        });


        $('.sendToAFriend').click(function(){
            $('#sendToAFriendWrapper').show();
            return false;
        });

        $('#noscript').ready(function(){
            $('#noscript').show();
            return false;
        });

        $('.closeSendToFriend').click(function(){
            $('#sendToAFriendWrapper').hide();
            return false;
        });

        $('#sendToAFriendWrapper').click(function(){
            $('#sendToAFriendWrapper').hide();
            return false;
        });

        $('#sendToAFriendInner').click(function(){
            return false;
        });

        $('#toEmail').focus(function(){
            if($('#toEmail').val() == "separate multiple email addresses with a comma") {
                $('#toEmail').val("");
            }
            return false;
        });

        $('#toEmail').blur(function(){
            if($('#toEmail').val() == "") {
                $('#toEmail').val("separate multiple email addresses with a comma");
            }
            return false;
        });

        $('#resetEmail').click(function(){
            $('#fromEmail').val("");
            $('#toEmail').val("separate multiple email addresses with a comma");
            $('#sendToFriendMessage').val("I saw this on A2Z Kids and thought of you...");

            return false;
        });

        $('#submitEmail').click(function(){
            var fromEmail = $('#fromEmail').val();
            var toEmail = $('#toEmail').val();
            var message = $('#sendToFriendMessage').val();
            var productId = $('#sendProductId').val();

            if(fromEmail.length == 0) {
                alert('Please enter your email address in the "From" field');
            } else if(strrpos(fromEmail, '@') === false) {
                alert('The "From" email doesn\'t appear to be valid');
            } else if(strrpos(toEmail, '@') === false) {
                alert('The "To" email doesn\'t appear to be valid');
            } else if(toEmail == "separate multiple email addresses with a comma") {
                alert('Please enter at least one email address in the "To" field');
            } else {
                $.ajax({
                    type:           "POST",
                    url:            "/interface/js/modules/products/sendToAFriend.php",
                    dataType:       "html",
                    cache:          false,
                    data:           "from="+fromEmail+"&to="+toEmail+"&message="+message+'&productId='+productId,
                    success:        function(html){
                                        $('#notSent').hide();
                                        $('#successSent').show();
                                    }
                });
            }
            return false;

        });
        // Changes the popup url to the image zoom if JS enabled
        $('.imageZoomPopup').click(function() {
            var popupUrl = $(this).attr('rel');
            $('.imageZoomPopup').attr('href', popupUrl);
            return false;
        });

        // Cycles between product images
        $('.clickToView').click(function() {
            var url = $(this).attr('rel');
            $('#productImage').attr('src', url);
            return false;
        });

        $('#nextImage').click(function(){
            alert('hello');
            return false;
        });

        $('#previousImage').click(function(){
            alert('previous');
            return false;
        });

        $('#eventInfoClick').click(function(){
            $('#eventInfoWrapper').slideDown();
			$('#infoBox').fadeOut(1000);
			$('#infoBoxCopyright').fadeOut(1000);
			$('.productOptions').fadeOut(1000);
            return false;
        });

        $('#closeEventInfo').click(function(){
            $('#eventInfoWrapper').slideUp();
			$('#infoBox').fadeIn(1000);
			$('#infoBoxCopyright').fadeIn(1000);
			$('.productOptions').fadeIn(1000);
            return false;
        });

    }
