function limitChars(textid, limit, infodiv) {
  var text = $('#'+textid).val(); 
  var textlength = text.length;
  if(textlength > limit)
  {
  $('#' + infodiv).html('You cannot write more then '+limit+' characters!');
  $('#'+textid).val(text.substr(0,limit));
  return false;
  }
 else
 {
  $('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
 return true;
 }
 }
 
$(document).ready(function() {
	$('embed').each(function() {
			var b = $('<div></div>');
			$(this).attr('wmode','transparent');
			$(this).wrap(b);
	});

	if($('.print-header').attr('src')) {
		window.print();
	}
	$('.print-button').click(function() {
		window.open($(this).attr('href'),'print','width=700px,height=500px');
		return false;
	});
	
	
	// set external links
	$("a[href^=http]").each(
	    function(){
	      if(this.href.indexOf(location.hostname) == -1) {
		  	$(this).attr('target','_blank');
	      }
	    }
	);
	
		
	var optF = {
		overlayOpacity : 0.7
	};
	$(".gallery a").fancybox(optF);
	$('a[target="_fancybox"]').fancybox(optF);
	
	$('a[target="youtube"]').fancybox({
		frameWidth			:	560,
		frameHeight			:	340,
		hideOnContentClick   :  false,
		overlayOpacity : 0.7
	});
	// gallery
	$('.list .item').each(function() {
		$('a[rel="group"]',this).fancybox(optF);	
	});
	$('a[rel="startGal"]').click(function() {
		$('div[rel="'+$(this).attr('target')+'"] a:eq(0)').trigger('click');
		//$(this).parent().find('.imgs a:eq(0)').trigger('click');
		return false;
	});
	
	
	$('a[target="_fancyboxPop"]').fancybox({
		overlayOpacity : 0.7,
		frameWidth : 550,
		frameHeight : 650
	});
	$('a.media').media();

	$('li.lev1').hover(function() {
		$('ul',this).css('visibility','visible');
	},function() {
		$('ul',this).css('visibility','hidden');
	});

	$('.gb-pop input[name="name"]').maxlength({maxCharacters:50, statusDiv : "#nameStatus"});
	$('.gb-pop input[name="location"]').maxlength({maxCharacters:30, statusDiv : "#locationStatus"});
	$('.gb-pop textarea[name="msg"]').maxlength({maxCharacters:500, statusDiv : "#msgStatus"}); 
	$('.gb-pop form').submit(function() {
		var d = new Date();
		var date = d.getFullYear()+d.getMonth()+d.getDate();
		$('.gb-pop form').append('<input type="hidden" name="checkSum" value="'+date+'"/>');
	});
	$('.gb_page').change(function() {
		$(this).parent().submit();
	});
});