$(document).ready(function(){
	
	
/*
Uploadify Function	
*/
	$('#fileupload').uploadify({
		'uploader'	: '../scripts/uploadify/uploadify.swf',
		'script'	: 'uploadify.cfm',
		'multi'		: true,
		'cancelImg'	: '../scripts/uploadify/cancel.png',
		'folder'	: '../uploads',
		'queueID'	: 'upload-queue',
		'scriptData' : {'CFID' : $('#cfid').val(),'CFTOKEN' : $('#cftoken').val(),'boatID' : $('#boatID').val()},		
		'auto'		: true,	
		'sizeLimit'   : 501200,	
		'wmode'       : 'transparent',
		'onOpen'	:	function(){$('#skip').hide();},
  		'onAllComplete': function(event, data){		
			$('#message').html('Files uploaded successfully.<br> Click <a href="admin-sortimages.cfm">here</a> to continue').fadeIn('slow');
		}
	});
	
	
/*
Image Sort Function	
*/
	var imgorder  = '';
	
		$( "#sortable" ).sortable({
			update: function(event, ui){
				
				imgorder = $("#sortable").sortable('toArray').toString();
				
				$.ajax({
		            url: 'components/crud.cfc',
		            type: 'POST',
		            data: ({method: 'orderImages', orderList: imgorder})
	   			});
			}			
		});
		
		$( "#sortable" ).disableSelection();


/*
Image Delete Function	
*/
$(function() {
        $(".delete-image-item").draggable({
			revert: true
		});
		$('#delete-over').droppable({
			over: function(event,ui){
				$(this).css('backgroundColor', '#710040');
			},
			out: function(){
				$(this).css('backgroundColor', '#ffffff');
			},			
			drop: function(event,ui) {
				var answer = confirm('Are you sure you want to remove this image?');
				if (answer)
				{
					imageID = ui.draggable.attr('id');
					$("#"+imageID).hide();
				$.ajax({
		            url: 'components/crud.cfc',
		            type: 'POST',
		            data: ({method: 'deleteimage', deleteid: imageID}),
					success: function(){
						location.reload(); 
					}
	   			});					
				}
				else
				{
					$(this).css('backgroundColor', '#ffffff');
				}
			}			
		});
});


/*
Jcarousel code
*/

//check for images & set paths
var imagePath = $('#imgpath').val();
var autoValue = 6;
	if ($('#imgcount').val() == 0) {
		autoValue = 0;
		imagePath = "";
	}
//scroll carousel if more than 5 images
var scrollValue	= 0
	if ($('#imgcount').val() > 5) {
		scrollValue = 1;
	}

function mycarousel_itemFirstInCallback(carousel, liElement) {
                    var item_name = $(liElement).attr('id');
					$('#boat-details-image').hide();
					$('#boat-details-image').fadeIn('slow');
                    $('#boat-details-image').html('<img src="' + imagePath+item_name + '"/>');
}; 

/*
Convert length
*/
$('#speclengthunits').change(function(){
  
	if ($('#speclengthunits').val()== 'M') {
  		var lengthUnit = 0.3048;
	}
	else {
		var lengthUnit = 3.2808399;
	};
		
	if ($('#speclength').val() > 0) {
			var boatLength = $('#speclength').val();
			newLength = boatLength * lengthUnit;			
		$('#speclength').val(Math.round(newLength*100)/100);
	}
})

/*
Convert beam
*/
$('#specbeamunits').change(function(){
  
	if ($('#specbeamunits').val()== 'M') {
  		var beamUnit = 0.3048;
	}
	else {
		var beamUnit = 3.2808399;
	};
		
	if ($('#specbeam').val() > 0) {
			var boatbeam = $('#specbeam').val();
			newbeam = boatbeam * beamUnit;			
		$('#specbeam').val(Math.round(newbeam*100)/100);
	}
})

/*
Convert draft
*/
$('#specdraftunits').change(function(){
  
	if ($('#specdraftunits').val()== 'M') {
  		var draftUnit = 0.3048;
	}
	else {
		var draftUnit = 3.2808399;
	};
		
	if ($('#specdraft').val() > 0) {
			var boatdraft = $('#specdraft').val();
			newdraft = boatdraft * draftUnit;			
		$('#specdraft').val(Math.round(newdraft*100)/100);
	}
})


$('#thumbs-carousel').jcarousel({
	vertical: true,
	scroll: scrollValue,
	auto: autoValue,
	wrap: 'circular',
	itemFirstInCallback: mycarousel_itemFirstInCallback
})
	
$("a#fancybox").fancybox({
		'hideOnContentClick': true
	});
	
		
});

/*
Cufon Fon Replacement
*/
            
			Cufon.replace('h1', { fontFamily: 'PT_Sans_700' });
			Cufon.replace('h2', { fontFamily: 'PT_Sans_700' });
			Cufon.replace('h3', { fontFamily: 'PT_Sans_700' });
			Cufon.replace('h4', { fontFamily: 'PT_Sans_700' });
			Cufon.replace('h5', { fontFamily: 'PT_Sans_400' });
			Cufon.replace('h6', { fontFamily: 'PT_Sans_400' });
