/*************************
 * - www.ucreation.nl    *
 *************************
 Dit document bevat JavaScript/jQuery codering. 
 */

// jQuery document ready
jQuery(document).ready(function()
{
  /*
  
  TYPO3 EXTENSION IRFAQ
    
  */
  if(jQuery('div.irfaq').is(':visible'))
  {
    // We need this class to know in CSS we talking about a user with Javascript support
    jQuery('div.irfaq').addClass('withjs');
    
    // FAQ question hide all
    jQuery('div.answer').hide();
    
    // Here we make some nu functions
    jQuery('<div></div>').addClass('options').insertBefore('div.question:first');
    jQuery('<p></p>').appendTo('div.options');
    jQuery('<a></a>').addClass('showall').attr({'href' : '' + window.location.pathname + '#'}).html('Toon alles').appendTo('div.options p');
    jQuery('<a></a>').addClass('hideall').attr({'href' : '' + window.location.pathname + '#'}).html('Verberg alles').appendTo('div.options p');
    
    var i = 1;
    // Here we give some numbers
    jQuery('div.question').each(function()
    {
      if(jQuery(this).has('p'))
      {
        //alert('dd');
      }
      jQuery(this).attr({'rel' : i, 'id' : 'question' + i + ''});
      jQuery(this).children('p').html(jQuery('<a></a>').attr({'class' : 'linkquestion', 'href' : '' + window.location.pathname + '#linkquestion' + i + '', 'rel' : i, 'id' : 'linkquestion' + i + '', 'title' : jQuery(this).children('p').html()}).html('' + jQuery(this).children('p').html() + ''));
      jQuery(this).children('span.image').clone().prependTo(jQuery(this).children('p').children('a'));
      jQuery(this).children('span.image').remove();
      i++;
    });
    var i = 1;
    jQuery('div.answer').each(function()
    {
      jQuery(this).attr({'rel' : i, 'id' : 'answer' + i + ''});
      i++;
    });
    // Catch the instructions
    jQuery('a.linkquestion').click(function()
    {
      // If the element is NOT visible
      if(!jQuery('#answer' + jQuery(this).attr('rel') + '').is(':visible'))
      {
        jQuery('#answer' + jQuery(this).attr('rel') + '').show();
        jQuery('#question' + jQuery(this).attr('rel') + '').addClass('open');
        jQuery('#question' + jQuery(this).attr('rel') + ' .image img').attr({'src' : 'typo3conf/ext/irfaq/res/minus.gif'});
      // If it is visible
      } else
      {
        jQuery('#answer' + jQuery(this).attr('rel') + '').hide();
        jQuery('#question' + jQuery(this).attr('rel') + '').removeClass('open');
        jQuery('#question' + jQuery(this).attr('rel') + ' .image img').attr({'src' : 'typo3conf/ext/irfaq/res/plus.gif'});
      }
    });
    // Show all
    jQuery('a.showall').click(function()
    {
      jQuery('div.answer').show();
      jQuery('div.question').addClass('open');
      jQuery('div.question .image img').attr({'src' : 'typo3conf/ext/irfaq/res/minus.gif'});
    });
    // Hide all
    jQuery('a.hideall').click(function()
    {
      jQuery('div.answer').hide();
      jQuery('div.question').removeClass('open');
      jQuery('div.question .image img').attr({'src' : 'typo3conf/ext/irfaq/res/plus.gif'});
    });
  }
  /*
  
  TYPO3 EXTENSION JQUERY FANCYBOX
    
  */
  if(jQuery('a[rel=lightbox]').is(':visible'))
  {
    jQuery('a[rel=lightbox]').fancybox({});
  }
  
  // Print
  if(jQuery('.buttons ul li.print').is('.print'))
  {
  	jQuery('.buttons ul li.print').addClass('activate');
	jQuery('.buttons ul li.print a').click(function()
	{
		print();
		return false;
	});
  }
});
