var showLoginForm = false;

$(document).ready(function(){
	
	if(showLoginForm) {
		$.fn.colorbox({rel: 'nofollow', width:"400px", inline:true, href: "#showLoginFormDiv"});
	}

	$("a#runSlideshow").colorbox({inline: true, width: "450px"});
	
	$("a[rel='galleryPhotos']").colorbox({maxHeight: "90%", maxWidth: "90%", href:function(){
			return $(this).attr("rev");
	}});
	
	$("a, img, span, button").easyTooltip();
	
	$("a[rel='boxInline'], a[rel='boxCalendar']").colorbox({title: function(){
	    var title = $(this).attr('title');
	    return title;
	}, rel: 'nofollow', width:"400px", inline:true, href: function(){
	    var id = $(this).attr('id');
	    return "#" + id + "Div";
	}});
	
	$("a[rel='boxCalendar']").colorbox({rel: 'cal'});
	
	$('a.colorbox').colorbox();

	//$(".vzkaz .obsah a").colorbox({rel:'nofollow', width:"90%", height:"90%", iframe:true});

 $("a.menu_competition_link").click(function(){
  $(this).next("ul.competition_menu").slideToggle('slow');
  return false;
 });

 $("div.menuBox").hover(function(){
  $title = $(this).children('.title');
  $win = $title.children('.window-control');
  $pos = $title.children('.visibility-control');
  $win.show();
  $pos.show();
 }, function(){
  $win.hide();
  $pos.hide();
 });

 $(".ZForm form span.legend").click(function(){
	 $(this).toggleClass('legendOnly');
  $(this).parent().next('fieldset').toggle();
 });

 $(".ZForm form input, .ZForm form textarea").hover(function(){
  $(this).addClass('hover');
 }, function(){
  $(this).removeClass('hover');
 });

 $(".ZForm form input, .ZForm form textarea").focus(function(){
  $(this).addClass('focused');
 });

 $(".ZForm form input, .ZForm form textarea").blur(function(){
  $(this).removeClass('focused');
 });

 $("#right_column").sortable({
  handle: 'div.title',
  placeholder: 'menuBoxPlaceholder',
  forcePlaceholderSize: true,
  opacity: 0.7,
  revert: true,
  items : '.sortable',
  update : function (){
   var list = $('#right_column').sortable('serialize');
   $.post('/libraries/ajax/menuBoxPosition.php', list);
  }
 });

 $("a#hideMenu").click(function(){
  $("#right_column").toggle();
  $("#left_column").toggleClass('leftColumnExtended');
  $("span#menuOptions").toggle();
  return false;
 });

 $("a.hideMenuBox").click(function(){
  $control = $(this).parent('.window-control');   
  $title = $control.parent('.title');
  if($title.hasClass('title_rounded')) {
   $rounded = true;
  } else {
   $rounded = false;
  }
  if($rounded) {
    $title.removeClass('title_rounded')
  }
  $box = $title.parent('.menuBox');
  $content = $box.children('.content');
  $content.slideToggle('slow', function(){
   $.post('/libraries/ajax/menuBoxCollapse.php?id=' + $box.attr('id') + '&type=' + ($content.is(':visible') ? 'visible' : 'hidden'));
   if(!$rounded) {
    $title.addClass('title_rounded');
   }
  });
  $control.find('.hideBox').toggle();
  $control.find('.showBox').toggle();
  return false;
 });

 $("a.closeMenuBox").click(function(){
  $control = $(this).parent('.visibility-control');
  $box = $control.parent('.title').parent('.menuBox');
  $box.hide('slow', function(){
   $.post('/libraries/ajax/menuBoxHide.php?id=' + $box.attr('id') + '&type=' + ($box.is(':visible') ? 'visible' : 'hidden'));
  });
  return false;
 });

 $("a.menuBoxPosition").click(function(){
  return false;
 });

 $("a#menuBoxHideAll").click(function(){
  var list = $('#right_column').sortable('serialize');
  $(".menuBox .content").slideUp('slow', function(){
   $(".menuBox .title").addClass('title_rounded');
  });
  $(".menuBox .title a.hideMenuBox .hideBox").hide();
  $(".menuBox .title a.hideMenuBox .showBox").show();
  $.post('/libraries/ajax/menuBoxCollapse.php?id=all&type=hide', list);
  return false;
 });

 $("a#menuBoxShowAll").click(function(){
  var list = $('#right_column').sortable('serialize');
  $(".menuBox .content").slideDown();              
  $(".menuBox .title").removeClass('title_rounded');
  $(".menuBox .title a.hideMenuBox .hideBox").show();
  $(".menuBox .title a.hideMenuBox .showBox").hide();
  $.post('/libraries/ajax/menuBoxCollapse.php?id=all&type=show', list);
  return false;
 });

 $("select#cmp_choice").change(function(){
  $("div.cmp").hide();
  $("div#cmp_" + $("select#cmp_choice").val()).fadeIn('slow');
  return false;
 });

});