var reel_initial = function () { }

function product_initCallback(carousel) {
    $('.product-images .thumbs li:eq(0)').addClass('current');
    $('.product-images .thumbs img').bind('click', function () {
        carousel.scroll($.jcarousel.intval($(this).parent().index() + 1));
        $(this).parent().addClass('current').siblings('.current').removeClass('current');
    });
    window.setTimeout("reel_initial()", 1000); // You have to define this function in detail view

}


$(function () {
    $('.product-images .large').jcarousel({
        visible: 1,
        scroll: 1,
        initCallback: product_initCallback,
        easing: 'easeInOutQuart',
        animation: 700,
        buttonPrevHTML: null,
        buttonNextHTML: null
    });

    $('a.colorbox').colorbox();

    $('.submit').click(function () {

        if ($('#name').val().trim().length == 0) {
            $('#name').focus();
            alert('Please enter a valid name');
            return false;
        }
        if ($('#email').val().trim().length == 0) {
            $('#email').focus();
            alert('Please enter a valid email address');
            return false;
        }
        else {
            if (!validateEmail($('#email').val())) {
                $('#email').focus();
                alert('Please enter a valid email address');
                return false;
            }
        }
        if ($('#comments').val().trim().length == 0) {
            $('#comments').focus();
            alert('Please enter a valid comment');
            return false;
        }
        return true;
    }
    )
    // IE6 PNG FIX
    if ($.browser.msie && $.browser.version == 6) {
        $('#nav a, #sidebar .widget li > a').hover(function () {
            $(this).toggleClass('hover');
        });
        DD_belatedPNG.fix('#slider .jcarousel-prev, #slider .jcarousel-next, .product-details-button, .submit-button');
    }

});

function validateEmail($email) {
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if (!emailReg.test($email)) {
        return false;
    } else {
        return true;
    }
}


$(window).resize(function () {
    if ($.browser.msie && $.browser.version < 8) {
        fixSlider();
    }
});

function fixSlider() {
    var li_leng = $('#slider li').length;
    var ul_wid = $('#slider ul').width();
    var li_wid = Math.round(ul_wid / li_leng);
    $('#slider li').each(function () {
        $(this).css('width', li_wid);
    });
}

