﻿function InitOptions() {
    var $Base = $('.product-detail .image');
    if($Base.length > 0)
    {
        var $Colours = $('.colour');
        $OptionsSrc = $('a', $Base).attr('href').split('?')[0];

        $Colours.bind('click', function () {
            $Thumbnail = $('img', $Base);
            $Link = $('a', $Base);
            $Src = $('.option-img-url', $(this));

            $Thumbnail.hide();

            if($Src.length > 0 && $Src.text().length > 0) {
                if ($.browser.msie) { // ie doesn't like fade on .png so just show for ie
                    $Thumbnail.attr('src', $Src.text() + '?maxSideSize=200').show();
                } else {
                    $Thumbnail.attr('src', $Src.text() + '?maxSideSize=200').stop(true, true).fadeIn(500);
                }
                $Link.attr('href', $Src.text() + '?maxSideSize=600');
            }
            else
            {
                if ($.browser.msie) { // ie doesn't like fade on .png so just show for ie
                    $Thumbnail.attr('src', $OptionsSrc + '?maxSideSize=200').show();
                } else {
                    $Thumbnail.attr('src', $OptionsSrc + '?maxSideSize=200').stop(true, true).fadeIn(500);
                }
                $Link.attr('href', $OptionsSrc + '?maxSideSize=600');
            }
        });
    }
}

$(document).ready(function () {
    InitOptions();
});
