var $j = jQuery.noConflict();
$j(function() {
    $j('#tabs').tabs();
});

function toggleReview() {
    $j('#review-form').toggle();
}

function clickedList(val, image) {
	var mainImage = $("image");
	mainImage.src = image;
	Form.Element.setValue("attribute80", val);
	$('attribute80').simulate('change');

    var box = $('attribute80');
    var text = box.selectedIndex >= 0 ? box.options[box.selectedIndex].innerHTML : undefined;
    $('product_color').innerHTML = text;
}

function myHandler() {
    var mainImage = $("image");
    mainImage.src = $j($($F('attribute80'))).attr('longdesc');

    $j('li.loaded-by-children a.selected').removeClass();
    $j($($F('attribute80'))).parent().addClass('selected');

    var box = $('attribute80');
    var text = box.selectedIndex >= 0 ? box.options[box.selectedIndex].innerHTML : undefined;
    $('product_color').innerHTML = text;
}

$j(document).ready(function() {

    if ($j('#attribute80').length > 0) {
        $('attribute80').observe('change',myHandler);
    }

    $j(".hover-modal").live('mouseenter', function() {
        var modal = $j(this).parent().next(".modal-window");
        var offset = $j(this).offset();
        var height = modal.height();
        var top = offset.top - 50 - height;
        var top = top + 'px';
        var left = offset.left + 'px';
        modal.attr('style', 'left:' + left + ';top:' + top);
        modal.fadeIn();
    });
    
    $j(".hover-modal").live('mouseleave', function() {
        $j(this).parent().next(".modal-window").fadeOut();
    });

    // Automatically select the first frame size if we're on the
    // product details page.
    if ($j('div#attribute122').length > 0) {
        $j('div#attribute122 input[type="radio"]').first().attr('checked', 'checked');
    }
});


