$(document).ready(function(){
	
	
	newColorSelector="";
	newSizeSelector="";
	pathToColorImages="farbfelder/thumb/";
	fileTypeColorImages="jpg";
	thumbsize="20";
	
	colorOption=$("*[name='id[2]']");
	sizeOption=$("*[name='id[1]']");
	
	//colors
	colorOption.find("option").each(function(){
		
		id=$(this).val();
		name=$(this).text();
		
		newColorSelector=newColorSelector+'<img class="color_selector hand" src="'+pathToColorImages+id+'.'+fileTypeColorImages+'" alt="'+name+'" title="'+name+'" id="'+id+'" width="'+thumbsize+'" height="'+thumbsize+'" />';
		
	});
	//size
	sizeOption.find("option").each(function(){
		id=$(this).val();
		name=$(this).text();
		newSizeSelector=newSizeSelector+'<li class="size_selector hand" id="'+id+'" >'+name+'</li>';
	});
	
	$("a[href*='mediapool']").each(function(){
		old=$(this).attr("href");
		zusatz="http://www.literaturradio.at";
		$(this).attr("href",zusatz+old);
		$(this).attr("target","_blank");
	});
	
	
	//add new colorpicker
	colorOption.after('<span id="colorbox">'+newColorSelector+'</span>');
	colorOption.hide();
	$(".color_selector:first").addClass("active_selection");
	
	//add new sizepicker
	sizeOption.after('<ul id="sizebox">'+newSizeSelector+'</ul>');
	sizeOption.hide();
	$(".size_selector:first").addClass("active_selection");
	
	
	//bind action to color images
	$(".color_selector").click(function(){
		colorID=$(this).attr("id");
		$("#colorbox .active_selection").removeClass("active_selection");
		$(this).addClass("active_selection");
		//loop options
		colorOption.find("option").each(function(){
			
			$(this).removeAttr("selected"); // clear selection
			if(colorID==$(this).val()){ // if matching
				$(this).attr("selected","selected");
				
			}
		});
		
	});
	//bind action to size selection
	$(".size_selector").click(function(){
		sizeID=$(this).attr("id");
		$("#sizebox .active_selection").removeClass("active_selection");
		$(this).addClass("active_selection");
		//loop options
		sizeOption.find("option").each(function(){
			
			$(this).removeAttr("selected"); // clear selection
			if(sizeID==$(this).val()){ // if matching
				$(this).attr("selected","selected");
				
			}
		});
		
	});
	
});
