// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

if (self != top) {
  if (document.images)
    top.location.replace(window.location.href);
  else
    top.location.href = window.location.href;
}

$(document).ready(function(){
	
	// fix for IE png images
	$(document).pngFix();

	// attach slimbox to links with rel=slimbox
	$('a[rel*=slimbox]').slimbox();

	// attach facebox to links with rel=facebox
	$('a[rel*=facebox]').facebox();
	
	// attach cluetip to a.tooltip
	$('a.tooltip').cluetip({splitTitle: '|', showTitle: true, width: '300', insertionType: 'appendTo' });

	// create rounded corners
	$('.rounded').corners("12px");
	
	// show-hide help
	var isvisible = 0;
	$('#helpLink a#slidetoggle').click(function() {
    if ($('#help').is(':visible')) {
      $(this).html('<img src="/images/navArrow.gif" width="8" height="8" alt="" style="border: 0px; margin-right: 6px;" />show help');
    } else {
		  $(this).html('<img src="/images/navArrowDn.gif" width="8" height="8" alt="" style="border: 0px; margin-right: 6px;" />hide help');
    }
    $('#help').slideToggle('400');
    return false;
	});
	
	// limit textarea maxlength
	$('textarea').maxlength();
	
});

// makes respond_to / format.js work correctly with jQuery
jQuery.ajaxSetup({ 
  'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} 
})


// jQuery UI button states
$(function(){
	//all hover and click logic for buttons
	$(".fg-button:not(.ui-state-disabled)")
	.hover(
		function(){ 
			$(this).addClass("ui-state-hover"); 
		},
		function(){ 
			$(this).removeClass("ui-state-hover"); 
		}
	)
	.mousedown(function(){
			$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
			if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
			else { $(this).addClass("ui-state-active"); }	
	})
	.mouseup(function(){
		if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
			$(this).removeClass("ui-state-active");
		}
	});
});