xnTimeOut = 0;
jQuery(document).ready(function(){
  
  $('a.change_lang2').each(
    function () {
      $(this).attr(
        'href',
        $(this).attr('href')+'?L=2'
      );
      
    }
  );
  
  if ( $('div.programme_overview_graph_event').length > 0 ) {
    $('div.programme_overview_graph_event a').each (
      function () {
        he = $(this).height();
        he1 = $(this).find('div.subtitle').height();
        he2 = $(this).find('div.title').height();
        pt = (he-he1-he2)/2;
        $(this).find('div.title').css({
          'top':pt+'px'
        });
        $(this).find('div.subtitle').css({
          'top':(pt+he2)+'px'
        });
      }
    );
    $('div.programme_overview_graph_event a').each (
      function() {
        url = "/"+$(this).attr('href');
        $(this).parents('div.programme_overview_graph_event').first().css({
          "cursor":"pointer"
        });
        
        $(this).parents('div.programme_overview_graph_event').first().click(
            function() {
              location.href(url);
            }
        )
      }
    );
  
  }
  
  
  
  
        if ( $('.image-gallery').length > 0 ) {
        	$('a.image-gallery-ele').each(
        		function() {
				var galARel = 'cboxGal';
                                /*var galTitle = $(this).parent('div.grid_12').find('h2').text();
                                if ( galTitle.length > 0 ) {
                                    galARel = galARel+'-'+galTitle;
                                }*/
        			$(this).colorbox({rel:galARel,maxHeight:'80%',opacity:'0.7'});
        		}
        	);    
        }
	
	$("a.zoom-image").colorbox({maxHeight:'80%',opacity:'0.7'});
	
	$(".lightbox1").colorbox({width:"800px", height:"80%", iframe:true});
	//$(".accordion").accordion({ active: false });
	$(".accordion").accordion({ active: false, collapsible: true, autoHeight: false });
	$(".button").button();
	$(".dialog").dialog();
  $(".tabs").tabs();
  var effect = 'slide';
  var options = {};
  var speedin = 300;
  var speedout = 50;
  xbproofAni = true;
  blink_state = 0;
  $('.blink').blink(500);
  $('.sidebar_blink a').blink(500);
  function fadeInSub1() {	
    if ( typeof(xoInterval) != 'undefined' ) {
      window.clearInterval(xoInterval);
    }
    if ( xbproofAni ) {
      // xoInterval = window.setInterval("clearMenu()",1000);
      xnTimeOut = 0;
      xbproofAni = false;
      /*
      $('div.sub:visible',$(this).prevAll()).hide(effect,options,speedout);
      $('div.sub:visible',$(this).nextAll()).hide(effect,options,speedout);
      $('div.subsub:visible',$(this).prevAll()).hide(effect,options,speedout);
      $('div.subsub:visible',$(this).nextAll()).hide(effect,options,speedout);
      */
      if ( $('div.sub:visible',$(this)).length > 0 ) {
        xbproofAni = true;
      }
      $('div.sub:hidden',$(this)).show(effect,options,speedin, 
        function() {
          xbproofAni = true;
        }
      );
      /*
      $('div.sub:visible',$(this).parent().prevAll()).hide(effect,options,speedout);
      $('div.sub:visible',$(this).parent().nextAll()).hide(effect,options,speedout);
      $('div.subsub:visible',$(this).parent().prevAll()).hide(effect,options,speedout);
      $('div.subsub:visible',$(this).parent().nextAll()).hide(effect,options,speedout);
      if ( $('div.sub:visible',$(this).parent()).length > 0 ) {
        xbproofAni = true;
      }
      $('div.sub:hidden',$(this).parent()).show(effect,options,speedin, 
        function() {
          xbproofAni = true;
        }
      );
      
      */
    }
   }
  $("#navigation ul li.sub1").mouseover( 
    fadeInSub1
  );
  $("#navigation ul li.sub1").mouseleave( 
  function() {
      $('div.sub:visible',$(this)).hide(effect,options,speedout);
      $('div.subsub:visible',$(this)).hide(effect,options,speedout);
    }
  );

  /*
  $("#navigation ul li.nosub a").mouseover(
    function() { 
      $('div.sub:visible',$(this).parent().prevAll()).hide(effect,options,speedout);
      $('div.sub:visible',$(this).parent().nextAll()).hide(effect,options,speedout);
      $('div.subsub:visible',$(this).parent().prevAll()).hide(effect,options,speedout);
      $('div.subsub:visible',$(this).parent().nextAll()).hide(effect,options,speedout);
    }
  );  
  */
  
  $("#navigation ul li.sub2 a").mouseover( 
    function() {
    if ( typeof(xoInterval) != 'undefined' ) {
      window.clearInterval(xoInterval);
    }
    /*
    xnTimeOut = 0;
    xoInterval = window.setInterval("clearMenu()",1000);
    */
    $('div.subsub:visible',$(this).parent().prevAll()).stop(true,true).hide(effect,options,speedout);
    $('div.subsub:visible',$(this).parent().nextAll()).stop(true,true).hide(effect,options,speedout);
    $('div.subsub:hidden',$(this).parent()).stop(true,true).show(effect,options,speedin);
    }
  );
  
  $("#navigation ul li.sub2asdfasdfasf").mouseleave( 
    function() {
      $('div.subsub:visible',$(this)).hide(effect,options,speedout);
    }
  );
  
  
});

(function($)
{
	$.fn.blink = function(options)
	{
		var defaults = { delay:500 };
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var obj = $(this);
			
			var defaultColor = "rgb(55,55,55)";
			if ( $(obj).css('color') ) {
				defaultColor = $(obj).css('color');	
			}
			
			setInterval(function()
			{
				if(blink_state == 0 )
				{
					$(obj).css('color',"rgb(255,0,0)");
					blink_state = 1;
				}
				else
				{
					//$(obj).css('color',"rgb(55,55,55)");
					$(obj).css('color',defaultColor);
					blink_state = 0;
				}
			}, options.delay);
		});
	}
        $.fn.blink_button = function(options)
	{
		var defaults = { delay:500 };
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var obj = $(this);
			setInterval(function()
			{
				if($(obj).css("color") == "#fff")
				{
					$(obj).css('color','#000');
				}
				else
				{
					$(obj).css('color','#fff');
				}
			}, options.delay);
		});
	}
}(jQuery))

function clearMenu () {
  var effect = 'slide';
  var options = {};
  var speedin = 500;
  var speedout = 50;
  xnTimeOut ++;
  if ( xnTimeOut >= 4 ) {
      $('div.sub:visible').hide(effect,options,speedout);
      $('div.subsub:visible').hide(effect,options,speedout);
      xnTimeOut = 0;
  } 
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  win = window.open(theURL,winName,features);
  win.focus();
}
