/* Copyright (c) 2010 Coding Staff Inc. All rights reserved. */

(function($) {
	$(function() {
		$('.central-column').css('overflow', 'visible');

		var thumbnail = $('#product_thumbnails img');
		try {
			var thulbox = document.getElementById('product_thumbnails');
                        if(thulbox) {
                            var thul = thulbox.getElementsByTagName('img');
                            var thull = thul.length;
                            var thulm = [];
                            for(var u=0; u<thull; u++) {
				thulm.push([thul[u].id, u]);
                            }
                        }
		}
		catch(e) {}

		var thumbnaill = thumbnail.length;
		if(thumbnaill) {
			var active = $('.cs-image-zoom');

			active.css('position', 'absolute').css('left', '-9999px');
			active.eq(0).css('position', 'relative').css('left', '0');
			var activel = active.length;

			function ini(num) {
				document.getElementById(num[0]).onclick = function() {
					active.css('position', 'absolute').css('left', '-9999px').eq(num[1]).css('position', 'relative').css('left', '0');
				}
			}
			function re() {
				for(var i=0; i<thumbnaill; i++) {
					ini(thulm[i]);
				}
			}
			re();
			$('.jcarousel-prev').click(re).click(function() {$(this).fadeOut(100).fadeIn(100)});
			$('.jcarousel-next').click(re).click(function() {$(this).fadeOut(100).fadeIn(100)});
			active.parent().find('>img').wrap('<div class="cs-image-zoom" />');
			var active_new = $('.cs-image-zoom');
			active_new.find('.cm-thumbnails').addClass('cs-show');
			$('ul.dropdown li.dir').hover(
				function(){active_new.css('z-index',0);},
				function() {active_new.css('z-index',7)}
			);
		}
	})
})(jQuery);
