function uploadChange(name, type)
{
	//$('#' + name + '_container').hide();
	$('#' + name+'_upload').show();
	
	frames[name + '_iframe'].openUpload();
	//var iframe = $('#' + name + '_upload iframe').get(0);
	//.document.getElementById('SWFUpload_0BrowseBtn').onclick();
	//uploadFrame.getElementById('SWFUpload_0BrowseBtn').onclick();
	return false;
}


function uploadRemove(name, type)
{
	//alert(document.getElementById(name+'_preview').src);
  if(type == 'image')
  {
    $('#' + name + '_preview').attr('src', baseDir+'img/placeholder.png');
  }
  if(type == 'file')
  {
    $('#' + name +'_fileIcon').attr('src', baseDir + 'img/filetypes/none.gif');
    $('#' + name +'_filename').html('No file uploaded');
  }
	$('#' + name).val('');	
	
	return false;
}

$(document).ready(function(){
  $('iframe').attr('allowtransparency', 'true');
  var focus = $('.form_error').get(0);
  if(focus != undefined)
  { 
    focus.focus(); 
  }
  // #homepage_images div.image:hover, #homepage_images div.hover 
  $('#homepage_images div.image').hover(function(){ $(this).addClass('hover')}, function(){ $(this).removeClass('hover')});
})

$(document).ready(function(){
  $("tr:nth-child(odd)").addClass("odd");
  
  $('.textile-editor textarea').each(function(){
    edToolbar(this.id, 'extended');
  });  
  
  $.datePicker.setDateFormat('ymd','-');
  //$('.dateSelector').datePicker({startDate:'05/03/2006'});
  $('.dateSelector').datePicker({startDate:'2006-01-01'});
  $('#DateFrom').change(function(){
    $('#DateTo').val($('#DateFrom').val());
  });
  
 $('a.tooltip, area').Tooltip({
    track: true,
    showURL: false,
    delay: 0
  });
  
  $('#DestinationDestination,#ThemeTheme,#TourTour,#ArticleArticle,#TourGuideTourGuide,#WineGuideWineGuide').before('<a class="expand_select" href="#">+ Expand</a>');
  $('.expand_select').toggle(function(){
    $(this).text('- Collapse');
    $('select', $(this).parent()).css('height', '500px');
    
  }, function(){ 
    $(this).text('+ Expand');
    $('select', $(this).parent()).css('height', '70px');
  });
  
    $('#hideAdminLinks').toggle(function(){
      $('ul.actions').hide();
      $(this).html('Show Admin Links');
    }, function(){
      $('ul.actions').show();
      $(this).html('Hide Admin Links');
    });  
});

function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue
    + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
  myField.focus();
  return false;
}

		// When the DOM is ready, initialize the scripts.
		jQuery(function( $ ){
 
			// Get a reference to the placeholder. This element
			// will take up visual space when the message is
			// moved into a fixed position.
			var placeholder = $( "#client_comments_placeholder" );
			if(placeholder.length != 0) { 
			// Get a reference to the message whose position
			// we want to "fix" on window-scroll.
			var message = $( "#client_comments" );
 
			// Get a reference to the window object; we will use
			// this several time, so cache the jQuery wrapper.
			var view = $( window );
 
 
			// Bind to the window scroll and resize events.
			// Remember, resizing can also change the scroll
			// of the page.
			view.bind(
				"scroll",
				function(){
                    console.log('bind resize');
					// Get the current offset of the placeholder.
					// Since the message might be in fixed
					// position, it is the plcaeholder that will
					// give us reliable offsets.
					var placeholderTop = placeholder.offset().top;
 
					// Get the current scroll of the window.
					var viewTop = view.scrollTop();
 
					// Check to see if the view had scroll down
					// past the top of the placeholder AND that
					// the message is not yet fixed.
					if (
						(viewTop > placeholderTop) &&
						!message.is( ".site-message-fixed" )
						){
 
						// The message needs to be fixed. Before
						// we change its positon, we need to re-
						// adjust the placeholder height to keep
						// the same space as the message.
						//
						// NOTE: All we're doing here is going
						// from auto height to explicit height.
						placeholder.height(
							placeholder.height()
						);
 
						// Make the message fixed.
						message.addClass( "site-message-fixed" );
 
					// Check to see if the view has scroll back up
					// above the message AND that the message is
					// currently fixed.
					} else if (
						(viewTop <= placeholderTop) &&
						message.is( ".site-message-fixed" )
						){
 
						// Make the placeholder height auto again.
						placeholder.css( "height", "auto" );
 
						// Remove the fixed position class on the
						// message. This will pop it back into its
						// static position.
						message.removeClass( "site-message-fixed" );
 
					}
				}
			);
		}
 
		});
