$(document).ready(function(){
	makeScrollable("div.sc_menu_wrapper", "div.sc_menu");
	makeScrollable("div.sc_menu_wrapper1", "div.sc_menu1");
	setTimeout("init()", 500);

$(".sc_menu1 ul li a").each(function(){
		var content = $(this).html();
		var result = content.indexOf("(new)", 0)
		if(result != -1){
			var content_without_new = content.replace("(new)", "");
			var new_txt = content_without_new+"<font class='new'>(new)</font>";
			$(this).html(new_txt);
		}
	});
});


function init(){
	$('.color').each(function(){
		var src_big = $(this).next().attr('src');
		var src_medium = $(this).next().attr('rel');

		$(this).click(function(){
			if (window.innerWidth > 1188){
				var html = '<img id="src_big" src="'+src_big+'" />';
			}else{
				var html = '<img id="src_big" src="'+src_medium+'" />';
			}
			$('#img_big').empty();
			$('#img_big').html(html);
		});
	});
	$('#pane7').hide();
	$('#pane6').show();	
}

function makeScrollable(wrapper, scrollable){
	// Get jQuery elements
	var wrapper = $(wrapper), scrollable = $(scrollable);
	// Hide images until they are not loaded
	scrollable.hide();
	var loading = $('<div class="loading"><b>Loading...</b></div>').appendTo(wrapper);
	// Set function that will check if all images are loaded
	var interval = setInterval(function(){
		var images = scrollable.find('img');
		var completed = 0;
		
		// Counts number of images that are succesfully loaded
		images.each(function(){
			if (this.complete) completed++;	
		});
		if (completed == images.length){
			clearInterval(interval);
			// Timeout added to fix problem with Chrome
			setTimeout(function(){
				
				loading.hide();
				// Remove scrollbars	

				wrapper.css({overflow: 'hidden'});						
				
				scrollable.slideDown('slow', function(){
					enable();	
				});					
			}, 10);	
		}
	}, 10);
	
	function enable(){
		// height of area at the top at bottom, that don't respond to mousemove
		var inactiveMargin = 600;					
		// Cache for performance
		var wrapperWidth = wrapper.width();
		var wrapperHeight = wrapper.height();
		// Using outer height to include padding too
		var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		var lastTarget;
		//When user move mouse over menu			
		wrapper.mousemove(function(e){
			// Save target
			lastTarget = e.target;
			var wrapperOffset = wrapper.offset();
			// Scroll menu
			var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
			if (top < 0){
				top = 0;
			}			
			wrapper.scrollTop(top);
		});		
	}
}


