﻿var productSlideshow;
$(document).ready(function() {
    initProductsNavigation();
    initBookDimentionsDropdown();
    initProductSlideshow();
});


/*** Book Dimensions combobox ***/
function initBookDimentionsDropdown() {
    $('table.book-dimensions').each(function() {
        if ($('.combobox', this).length > 0) {
            ShowRow();
            $('.combobox select').change(ShowRow);
            $('.combobox select').keyup(ShowRow);
        }
    });
}

function ShowRow() {
    $.each($('table.book-dimensions tbody tr'), function(i, n) {
        if (i + 2 == $('.combobox select').val()) { $(this).show() }
        else { $(this).hide() }
    });
}


/*** Slideshow ***/
function initProductSlideshow() {
    productSlideshow = $('.ProductSlideshow');
    ff = $('.previews a');
    if (ff.length <= 1) { return false }
    switchProductSlideshow($('.previews a:first'), $('.previews a:first').attr('href'), $('.previews a:first').parent().parent().parent().get(0), 0); productSlideshow.each(function() {
        $('.previews a', $(this)).click(function() {
            switchProductSlideshow($(this), $(this).attr('href'), $(this).parent().parent().parent().get(0), 'fast');
            return false;
        });
    });
}

function switchProductSlideshow(selected_a, slide_id, slider_obj, speed) {
    var currentFrame = $('.large-picture img', slider_obj).get(slide_id.replace('#pic', '') - 1);
    $('.large-picture img', slider_obj).each(function() {
        if (this != currentFrame) {
            $(this).fadeOut('fast');
        }
    });
    if (speed != 0) { $(currentFrame).fadeIn(speed); }
    else { $(currentFrame).show(); }
    $('.previews a').css("opacity", "1");
    selected_a.css("opacity", "0.5");

}


/*** Products navigation menu ***/
function initProductsNavigation() {
    var navMenu = $('ul.products-navigation');


    $('li a', navMenu).each(function() {
        if ($(this).attr('href') == path) {
            $(this).parents('ul.products-navigation li').addClass('selected');
            $('img', this).unwrap();
        }
    });

    $('li', navMenu)
			.mouseover(function() {
			    $(this).addClass('hover');
			})
			.mouseout(function() {
			    $(this).removeClass('hover');
			});

}

