$(document).ready(function(){
	
	//$(document).pngFix();
	
	$("a[href*=.doc]").before('<img class="icon" src="/_ui/images/icon_DOC_big.gif" />');

	$("a[href*=.doc]").click(function(){
		window.open(this.href);
		return false;
	});

	$("a[href*=.pdf]").before('<img class="icon" src="/_ui/images/icon_PDF_big.gif" />');

	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});

	$("a[href*=.doc], a[href*=.pdf]").closest('p').addClass('w-icon');
	
	if ($('.cals').length > 0){

		$('.cals').cycle({
			
			fx:			'fade', 
			speed:		'fast', 
			timeout:	0, 
			next:		'.controls .next', 
			prev:		'.controls .prev',
			after:		function(){ 
							
							if (this.id != 0){

								$('.controls .prev').show(); 
							
							} else {
								
								$('.controls .prev').hide(); 
							}

							if (this.id != 11){

								$('.controls .next').show(); 
							
							} else {
								
								$('.controls .next').hide(); 
							}
						}
		});
	}


	// recipes area

	$('#recipes-cont td.col-1').click(function(){
		
		window.location = $(this).next().find('a:first').attr('href');
	});


	// Event Image Uploading

	if ($('#uploader-button').length > 0){

		swfu = new SWFUpload({

			// Backend Settings
			upload_url: "/recipes/add_image/",

			// File Upload Settings
			file_size_limit : "7 MB",	// 7 MB
			file_types : "*.jpg;*.png",
			file_types_description : "JPG or PNG Images",
			file_upload_limit : "1",

			// Event Handler Settings - these functions as defined in Handlers.js
			//  The handlers are not part of SWFUpload but are part of my website and control how
			//  my website reacts to the SWFUpload events.
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,

			// Button Settings
			// button_image_url : "/_ui/images/ico_up_arrow.gif",
			button_placeholder_id : "uploader-button",
			button_width: 150,
			button_height: 22,
			button_text : '<span class="button">Add Image <span class="buttonSmall">(optional, 7 MB max)</span></span>',
			button_text_style : '.button { font-family: Arial, sans-serif; font-size: 13pt; font-weight: bold; color: #51AB20 } .buttonSmall { font-size: 10pt; }',
			button_text_top_padding: 0,
			button_text_left_padding: 0,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			
			// Flash Settings
			flash_url : "/_ui/js/lib/SWFUpload-v2.2.0.1-Core/Flash/swfupload.swf",

			custom_settings : {
				upload_target : "divFileProgressContainer"
			},
			
			// Debug Settings
			debug: false
		});
	}
});