$(document).ready(function(){
	/*
	
			menu
	
	*/
	if ($('.main_images').length) {
		var main_images = new Array;
		var sub_images = new Array;
		
		var main_images_on = new Array;
		var sub_images_on = new Array;
		
		
		
		
		$('.main_images').each(function(){
			var id = $(this).attr('id');
			
			main_images[id] = new Image;
			main_images[id].src = $(this).attr('src');
			
			if ($(this).attr('rel')) {
				main_images_on[id] = new Image;
				main_images_on[id].src = $(this).attr('rel');
			}
		});
		
		
		$('.main_images').mouseover(function(){
			var id = $(this).attr('id');
			
			if (main_images_on[id].src) {
				$(this).attr('src',main_images_on[id].src);
			}
		});
		
		$('.main_images').mouseout(function(){
			var id = $(this).attr('id');
			
			$(this).attr('src',main_images[id].src);
		});
		
		
		
		$('.sub_images').each(function(){
			var id = $(this).attr('id');
			
			sub_images[id] = new Image;
			sub_images[id].src = $(this).attr('src');
			
			sub_images_on[id] = new Image;
			sub_images_on[id].src = $(this).attr('rel');
		});
		
		
		$('.sub_images').mouseover(function(){
			var id = $(this).attr('id');
			
			$(this).attr('src',sub_images_on[id].src);
		});
		
		$('.sub_images').mouseout(function(){
			var id = $(this).attr('id');
			
			$(this).attr('src',sub_images[id].src);
		});
	}
	
	
	/*
	
			sort_by
	
	*/
	$('#sort_by').change(function(){
		var loc = window.location.href;
		loc = loc.replace(/\/sort-\w+/i,'');
		
		if (loc.substr(loc.length - 1,1) == '/') {
			loc = loc.substr(0,loc.length - 1);
		}
		
		if (loc.indexOf('browse') == -1) {
			loc = '/browse';
		}
		
		window.location = loc + '/sort-' + $(this).val();
	});
	
	
	
	/*
	
			eraser
	
	*/
	$('.eraser').each(function(){
		$(this).attr('original',$(this).val())
	});
	
	$('.eraser').focus(function(){
		if ($(this).val() == $(this).attr('original')) {
			$(this).val('');
		}
	}),
	
	$('.eraser').blur(function(){
		if ($(this).val() == '') {
			$(this).val($(this).attr('original'));
		}
	});
});
