﻿$(document).ready(function() {
    $('a.helpline').hover(function() {
        $(this).addClass('helpline-on');
    }, function() {
        $(this).removeClass('helpline-on');
    });

    $('#viewer a').nyroModal({
        gallery: 'lightbox',
        addImageDivTitle: false,
        galleryCounts: NoCount,
        zIndexStart: 1000
    });

    $('ul.tabs li a').click(function(e) {
        e.preventDefault();
    });
    $('ul.tabs').tabs('div.panes > div', { tabs: 'li',
        current: 'selected',
        event: 'click'
    });

    $('#thumbnails a').each(function() {
        (new Image()).src = $(this).attr('href');
    });

    var link = $(lnkFirstThumbnailImageClientId);
    $('#thumbnails a').click(function(e) {
        e.preventDefault();
        $(link).attr('rel', 'lightbox nofollow')
        link = this;
        $(imgProductClientId).stop('true').animate({ opacity: 0 }, 'fast', '', function() {
            $(imgProductClientId).attr('src', $(link).find('img').attr('src').split("?z=")[1])
                                         .animate({ opacity: 1 }, 'slow');
            $(lnkMainImageClientId).attr('href', $(link).attr('href'));
            $(link).attr('rel', 'nofollow')
        });
    });

    var ddlVariants = $('.variants');
    if (ddlVariants.length > 0) {
        ddlVariants.change(function() {
            var selectedOpt = $('option:selected', ddlVariants);
            var addBtn = $('.add-to-basket input');
            var messageDiv = $('div.message');
            var instockMsg = $('span.in-stock');
            if (selectedOpt.attr('value').indexOf('NA') >= 0) {
                messageDiv.html('<p>Sorry this option is currently out of stock. Please select another one.</p>').show();
                if (addBtn.css('opacity') != 0) {
                    addBtn.css('cursor', 'default').removeAttr('title').animate({ opacity: '0' });
                    instockMsg.animate({ opacity: '0' });
                }
            } else if (selectedOpt.attr('value').indexOf('-1') >= 0) {
                messageDiv.html('<p>Please select an option.</p>').show();
                if (addBtn.css('opacity') != 0) {
                    addBtn.css('cursor', 'default').removeAttr('title').animate({ opacity: '0' });
                }
            } else {
                messageDiv.html('').hide();
                if (addBtn.css('opacity') != 1) {
                    addBtn.css('cursor', 'pointer').attr('title', 'Add to basket').animate({ opacity: '1' });
                    instockMsg.animate({ opacity: '1' });
                }
            }
        });

        $('.add-to-basket input').click(function(e) {
            var selectedOpt = $('.variants option:selected');
            if (selectedOpt.attr('value').indexOf('NA') >= 0) {
                return false;
            } else if (selectedOpt.attr('value').indexOf('-1') >= 0) {
                return false;
            }
            return true;
        });
    }

    //    $(ddlQuantityClientId).change();

    //    $(ddlQuantityClientId).change(function() {
    //        var rfvEl = document.getElementById(rfvQuantityClientId);
    //        var revEl = document.getElementById(revQuantityClientId);
    //        if ($(this).val() == '6+') {
    //            $(this).hide();
    //            $(txtQuantityClientId).show().focus().select();
    //            ValidatorEnable(rfvEl, true);
    //            ValidatorEnable(revEl, true);
    //        }
    //        else {
    //            ValidatorEnable(rfvEl, false);
    //            ValidatorEnable(revEl, false);
    //        }
    //    });
});


function NoCount(nb, total, elts, settings) {

}
        
