var images_id;
jQuery(document).ready(
	function() {
		var center = jQuery('#center-scroll-panel').parent();
		if(center.length > 0) {
			var center_height = center.css('height');
			var scroll_panel_height = jQuery('#center-scroll-panel').attr('offsetHeight');
			center_height = parseInt(center_height) - 5;
			
			if(scroll_panel_height > center_height) {
				center.removeClass('center');
				center.addClass('center_scroll');
				scroll_panel_height = jQuery('#center-scroll-panel').attr('offsetHeight');
				
				scrollableHeight = scroll_panel_height - center_height || 0;
				jQuery('#center-scroll-panel').removeClass('center-panel');
				jQuery('#center-scroll-panel').addClass('center-scroll-panel');
				jQuery('#center-scroll-panel').css('height',center_height + 'px');
				
				jQuery("#center-slider").slider({
					orientation: "vertical",
					range: "min",
					min: 0,
					max: scrollableHeight,
					value: scrollableHeight,
					slide: function(event, ui) {
						jQuery('#center-scroll-panel').css({top: ui.value - scrollableHeight}); 
					}
				});
			} else {
				jQuery('#center-slider-panel').remove();
			}
		}
		
		var right = jQuery('#right-scroll-panel').parent();
		if(right.length > 0) {
			var right_height = right.css('height');
			var right_scroll_panel_height = jQuery('#right-scroll-panel').find('img').length * 110;
			right_height = parseInt(right_height) - 10;
			if(right_scroll_panel_height > right_height) {
				jQuery('div[id="right_image_position"]').removeClass('right_image_position');
				jQuery('div[id="right_image_position"]').addClass('right_image_position_scroll');
				right_scroll_panel_height = right_scroll_panel_height - right_height || 0;
				
				jQuery("#right-slider").slider({
					orientation: "vertical",
					range: "min",
					min: 0,
					max: right_scroll_panel_height,
					value: right_scroll_panel_height,
					slide: function(event, ui) {
						jQuery('#right-scroll-panel').css({top: ui.value - right_scroll_panel_height}); 
					}
				});
			}
			
			right.find('img').hover(
				function () {
					if(jQuery(this).attr('class') != 'selected') {
						images_id = jQuery(this).attr('id');
						var src = jQuery('#hidden_images').find('#small_' + images_id).attr('src');
						jQuery(this).attr('src',src);
					}
				},
				function () {
					if(jQuery(this).attr('class') != 'selected') {
						var src = jQuery('#hidden_images').find('#hover_' + images_id).attr('src');
						jQuery(this).attr('src',src);
					}
				}
			); 
			
			right.find('img').click(
				function() {
					if(jQuery(this).attr('class') != 'selected') {
						var src = jQuery('#hidden_images').find('#big_' + images_id).attr('src');
						jQuery('#left_image').find('img:first').attr('src',src);
						
						src = jQuery('#hidden_images').find('#small_' + images_id).attr('src');
						jQuery(this).attr('src',src);
						
						var hover_id = right.find('img[class="selected"]').attr('id');
						src = jQuery('#hidden_images').find('#hover_' + hover_id).attr('src');
						right.find('img[class="selected"]').attr('src',src);
						right.find('img[class="selected"]').removeClass('selected');
						
						jQuery(this).addClass('selected');
					}
				}
			);
			
			right.find('div[class="right_images_info"]').hover(
				function () {
					var parent = jQuery(this).parent();
					var image = parent.find('img:first');
					if(image.attr('class') != 'selected') {
						images_id = image.attr('id');
						var src = jQuery('#hidden_images').find('#small_' + images_id).attr('src');
						image.attr('src',src);
					}
				},
				function () {
					var parent = jQuery(this).parent();
					var image = parent.find('img:first');
					if(image.attr('class') != 'selected') {
						var src = jQuery('#hidden_images').find('#hover_' + images_id).attr('src');
						image.attr('src',src);
					}
				}
			); 
			
			right.find('div[class="right_images_info"]').click(
				function() {
					var parent = jQuery(this).parent();
					var image = parent.find('img:first');
					if(image.attr('class') != 'selected') {
						var src = jQuery('#hidden_images').find('#big_' + images_id).attr('src');
						jQuery('#left_image').find('img:first').attr('src',src);
						
						src = jQuery('#hidden_images').find('#small_' + images_id).attr('src');
						image.attr('src',src);
						
						var hover_id = right.find('img[class="selected"]').attr('id');
						src = jQuery('#hidden_images').find('#hover_' + hover_id).attr('src');
						right.find('img[class="selected"]').attr('src',src);
						right.find('img[class="selected"]').removeClass('selected');
						
						image.addClass('selected');
					}
				}
			);
		}
	}
);
