/**
 * @author Touchnote
 */		


	$(document).ready(function(){
		if(uiMode == 'flip'){
			previewBindWidth = 790;
		}else{
			previewBindWidth = 400;
			$('#hotPreview').fadeTo(1, 0.25).show();// Initial disabled hotlinkn of original image 
		}
		
		// wait for the main image to load before activating the formmain image load
		//
		activeSubmitButton(false); // disable the submit button 
		load_interval=self.setInterval("checkimageLoaded()",2000);	// start looking for a retrieved user image

	    /**
	     * When their image is finished importing, tweak the page to let them know, etc.
	     * @param {Object} data
	     */
		readyForCardCreator=function(fPath){	
			//change the img src a little
			locPath = postcardTnailPath(fPath, '790');
			$('#usersImage').attr({ 'src': locPath, 'style': 'width:790px' });
			$(document).data('locPath',locPath);		// set for other behaviors to use
			setUUIDfromPath(fPath); // set the page form for submission
			activeSubmitButton(true);
		}

	if(ClickTalePlayback.instances[0].CTIsRecording()){
	
		// Paths
		fullUrl="/photo/createFromAjax/"+document.location.search + '&product=postcard'; 	// append to the proper URL
		showImageUrl='/photo/latestImage.ajax';

		// This XHR is for a background simple upload of our partner image 
		// The success response will fire a request for our imported image
		$.ajax({
				type:"GET",
				url:fullUrl,
				cache:false,
				//data: for query params...
				success: function(data){
					if(data=='success'){
						//on successful receipt, ask for new image
						$.get(showImageUrl+'?'+Math.random()*110, readyForCardCreator); // deprecated - fullUrl should now bring this with it | see retrieved
					}else if(data.substr(0,10)=='retrieved|'){
						// a known image is returned
						fPath = data.substr(10,data.length);
						readyForCardCreator(fPath);
					}else if(data.substr(0,7)=='errors|'){
						alert(data.substr(7,data.length));
					}else{
						$('#errors').html(data);
						$('#errors').dialog({ width: 560,height: 355,bgiframe: true,autoOpen: false,closeOnEscape: true,hide: 'slide',show: 'slide',resizable: false,modal: true});
						window.href='/photo';
					}
				}
		});	
		
	}else{	
		// ClickTale Playback Mode
		readyForCardCreator(clickTaleDummyImage);
	}
		
}); // end doc ready