
$(document).ready(function(){

	// global

		$("a[href^='http']").attr('target','_blank');

	// eletter sign up
		
		$('input.eletter').focus(function(){
			
			$(this).val('');
		});

		$('form.email-subscribe').submit(function(){

			$(this).ajaxSubmit({ url: 'http://www.thecanarycollective.com/subscribers/add_email/11/' + $(this).find('.eletter').val() + '/?format=json&callback=?', type: 'GET', dataType: 'json', success: function(e){
				
				$('.eletter').val(e.message);
				$('.eletter').css('color', e.status > 0 ? '#05931C' : '#FF0000');
			} });

			return false; 
		});	
		
		$('.join-btn').click(function(){
			
			$(this).closest('form.email-subscribe').trigger('submit');
			return false;
		});


	// contact
		
		$('#contact-form input[name="name"]').each(function(){
			
			if ($(this).val() == ''){
				
				$(this).val('Name');
			}
		});

		$('#contact-form input[name="name"]').focus(function(){
			
			if ($(this).val() == 'Name'){
				
				$(this).val('');
			}	
		});

		$('#contact-form input[name="email"]').each(function(){
			
			if ($(this).val() == ''){
				
				$(this).val('Email');
			}
		});

		$('#contact-form input[name="email"]').focus(function(){
			
			if ($(this).val() == 'Email'){
				
				$(this).val('');
			}	
		});

		$('#contact-form input[name="phone"]').each(function(){
			
			if ($(this).val() == ''){
				
				$(this).val('Phone');
			}
		});

		$('#contact-form input[name="phone"]').focus(function(){
			
			if ($(this).val() == 'Phone'){
				
				$(this).val('');
			}	
		});

		$('#contact-form textarea[name="comments"]').each(function(){
			
			if ($(this).val() == ''){
				
				$(this).val('Message');
			}
		});

		$('#contact-form textarea[name="comments"]').focus(function(){
			
			if ($(this).val() == 'Message'){
				
				$(this).val('');
			}	
		});

	// home

		if ($('#home-slides').length){

			$('#home-slides').cycle({

				fx:     'scrollHorz', 
				speed:  'fast', 
				timeout: 0, 
				next:   '#home-next', 
				prev:   '#home-prev',

				after:	function(curr, next, opts){
					
					var index = opts.currSlide;
					if ($('#home-slides > div:eq(' + index + ') iframe').length){
						
						$('#home-slides > div:eq(' + index + ') .text-container').fadeOut(3000);
					}
				}
			});
		}

		if ($('#history-slide').length){

			$('#history-slide').cycle({

				fx:     'scrollHorz', 
				speed:  500, 
				timeout: 0, 
				next:   '#history-next', 
				prev:   '#history-prev' 
			});
		}

	// journal

		$('#sidebar select').change(function(){
		
			window.location = $(this).val();
		});
	
	// press

		$('#page-8 h3 a').click(function(){
			
			$('#page-8 h3 a').removeClass('active');
			$(this).addClass('active');

			rel = parseInt($(this).parent().index()) -1;
			$('#page-8 .on-right .holder').hide();
			$('#page-8 .on-right .holder:eq(' + rel + ')').fadeIn();

			$(this).blur();
			return false;
		});

	// 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
			});
		}

});
