﻿$(document).ready(function() { 
	$('#navigation ul.superfish').superfish({ 
		hoverClass:   'sfHover' 
		,delay:        1000
		,animation:    {opacity:'show',height:'show'}
		,speed:        'normal'
		,autoArrows:   false
		,dropShadows:  false
		,onShow:       function(){ $(this).parent('li').children('a').addClass('sfHover'); }
                ,onHide:       function(){ $(this).parent('li').children('a').removeClass('sfHover'); }
	});
		
	$('#accordion').accordion({ 
		active: false 
		,header: 'dt'
		,navigation: false
		,event: 'mouseover'
		,fillSpace: false
		,collapsible: false
		,autoHeight: true
	});
	
	$('.lightbox a').click(function(event) {
		
		event.preventDefault();
		
		if ($(this).attr("class").indexOf("close") == -1) {
			
			window.top.location = $(this).attr('href');		
		}
	});

	$('#lightbox-container .close').click(function() {
		self.parent.tb_remove();
	});
	
	function limitCaracters(textJqueryObject, limit) {
	
		var text = textJqueryObject.val(); 
		var textlength = text.length;
	
		if(textlength > limit) {
	
			textJqueryObject.next().html('You have '+ limit +' characters left.');
			textJqueryObject.val(text.substr(0,limit));
	
			return false;
		}
		  else {
	
			textJqueryObject.next().html('You have '+ (limit - textlength) +' characters left.');
			return true;
		}
	}
	
	$('#content textarea').each(function(i) {
										 
		var textarea = $(this);
		var limit = 275;
		
		textarea.after('<span class="remaining">You have ' + limit.toString() + ' characters left.</span>');
	
		textarea.keyup(function() {
		
			limitCaracters(textarea, limit);
		});
	});	
}); 

