// jQuery document ready
jQuery(document).ready(function()
{
	jQuery('#navigation > ul > li').each(function()
	{
		jQuery(this).has('ul').addClass('hasul');
	});
	
	jQuery('#navigation ul li.hasul').each(function()
	{
		jQuery(this).children('a').attr('ajaxhref',jQuery(this).children('a').attr('href'));
		jQuery(this).children('a').removeAttr('href');
		if(jQuery(this).find('li.selected').is(':visible'))
		{
			jQuery(this).children('ul').addClass('opened');
		} else
		{
			jQuery(this).children('ul').hide();
		}
	});
	
	jQuery('#navigation ul li.hasul > a').click(function()
	{
		var thisObj = jQuery(this).parent();
			
		if(jQuery(thisObj).children('ul').hasClass('opened'))
		{
			jQuery(thisObj).children('ul').removeClass('opened');
			jQuery(thisObj).children('ul').slideUp(400);		
		} else
		{
			jQuery('#navigation ul li.hasul ul.opened').slideUp(400);
			jQuery('#navigation ul li.hasul ul.opened').removeClass('opened');
			
			jQuery(thisObj).children('ul').addClass('opened');
			jQuery(thisObj).children('ul').slideDown(400);
		}
		
		var ajaxrequest = jQuery(thisObj).children('a').attr('ajaxhref');
		var ajaxrequest = ajaxrequest.replace('conceptscompany.nl/','conceptscompany.nl/box/');
		var ajaxrequest_right = ajaxrequest.replace('conceptscompany.nl/box/','conceptscompany.nl/box/right/');
		
		jQuery('#navigation').find('li.selected').removeClass('selected');
		
		
		jQuery('#content .middle').fadeOut(1, function()
		{
			jQuery.ajax({
			url: ajaxrequest,
			success: function(data) {
					jQuery('#content .middle').html(data);
				}
			});
			jQuery('#content .middle').fadeIn(1, function()
			{
			});
			jQuery(thisObj).children('a').addClass('selected');
			jQuery(thisObj).addClass('selected');	
		});
		
	});
	
	jQuery('ul#bannerimages').innerfade({
                 speed: 950,
                 timeout: 3500,
                 type: 'sequence'
            });
						
	if(jQuery(':input').is(':visible')){
		jQuery(':input').autotab_magic();
	}
	
	
	if(jQuery('.maketarget').is(':visible')){
		jQuery('.maketarget').attr({'target' : '_blank'});
	}
	
	if(jQuery('#juitterContainer').is(':visible')){
		jQuery.Juitter.start({
			searchType:"fromUser", // needed, you can use "searchWord", "fromUser", "toUser"
			searchObject:"urgenda,NL_Klantgericht,EventBrancheNL", // needed, you can insert a username here or a word to be searched for, if you wish multiple search, separate the words by comma.
	
			// The values below will overwrite the ones on the Juitter default configuration. 
			// They are optional here.
			// I'm changing here as a example only
			lang:"nl", // restricts the search by the given language
			live:"live-15", // the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates.
			placeHolder:"juitterContainer", // Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
			loadMSG: "Laden...", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on 
			imgName: "loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
			total: 2, // number of tweets to be show - max 100
		});
	}
});
