
jQuery(document).ready(
	function(){
		
		jQuery.fn.exists = function(){return ($(this).length > 0);}
		
		// Konkurrence
		if(jQuery('form#konkurrence').exists()) {
			jQuery('ul.multiplechoice li').click( function() {
				var id = jQuery(this).parent().attr('id').replace('spoergsmaal-id-', '');
				var svar = jQuery(this).text();
				jQuery('form#konkurrence input#svar-id-'+id).attr('value', svar);
				jQuery('ul#spoergsmaal-id-'+id+' li').removeClass('choosen');
				jQuery(this).addClass('choosen');
			});
		}
		
		// Lykønskningskort
		if(jQuery('form#kort').exists()) {
			// valg af kort
			jQuery('select#billede').change( function() {
				sel = jQuery('select#billede :selected').attr('value');
				sel_filename = kortbilleder[sel];
				if(sel_filename) {
					jQuery('div#previewkort').html('<img style="max-width:392px;" src="http://huskerdu.dk/wp-content/themes/huskerdu/thumb.php?w=392&h=460&method=resize&src=http://huskerdu.dk/'+sel_filename+'"/>');
				}
				else {
					jQuery('div#previewkort').html('&nbsp;');
				}
			});

			// jQuery('div.kort-billede').click( function() {
			// 	var id = jQuery(this).attr('id').replace('billede-id-', '');
			// 	jQuery('input#billede').attr('value', id);
			// 	jQuery('div.kort-billede').removeClass('kort-billede-active');
			// 	jQuery(this).addClass('kort-billede-active');
			// });
			
			// valg af font
			jQuery('ul#fontchoice li').click( function() {
				var svar = jQuery(this).attr('id');
				jQuery('input#font').attr('value', svar);
				jQuery('ul#fontchoice li').removeClass('choosen');
				jQuery(this).addClass('choosen');
			});
			
		}
		
		if(jQuery('div.overview-item').exists()) {
			jQuery('div.overview-item p img').each( function() {
				var h = jQuery(this).parent().parent().height();
				if(h<40)
					jQuery(this).css('paddingTop', 40-h+8);
			});
		}
	});

