 /* make it work with other library's */

(function($) {

/* continue as normal */
$(document).ready(function(){

function NavWidth(elem) {

	var props = { position:"absolute", visibility: "hidden", display: "block" };
	var itemWidth = 0;

	$(elem).each(function(index, e) {
		$.swap($(this)[0], props, function() {
			itemWidth = $(this).width();
		});
		$(this).css('width', itemWidth);
		$(this).find('li').css('width', itemWidth);
		
	});
	
	//loop through ul and set left width based on parent width
	$('ul.nav-tabs ul').each(function() {
	
		var childUL = $(this).find('ul');
		var parentWidth = $(this).width();
		
		childUL.css('left', parentWidth);
		childUL.css('width','195px');
		childUL.find('li').css('width','195px');
				
	});
	
}

//opera fix.... width of items was calculated incorrectly,  so fixed width is set.
if ($.browser.opera) {
    //alert("this is opera!");
	$('ul.nav-tabs ul').each(function() {

		$(this).css('width','215px');
		$(this).find('li').css('width','215px');
		$(this).find('a').css('white-space','normal');
				
	});	
} else {
	NavWidth("ul.nav-tabs ul"); //set ul element to use
}

function NieuwsBox() {		
	//give unique class names to li items
	$(".tab-box li").each(function(index, e) {
		$(this).addClass('item-' + index);
	});

	//give unique class names to div items
	$(".nieuws-box .tab-content,").each(function(index, e) {
		$(this).addClass('item-' + index);
	});
	
	//hide all but the first tab content box
	$("div.tab-content:gt(0)").hide();
	
	//do something with the onlick, except the last-tab.
	$("ul.tab-box li:not('.last-tab')").click(function() {
		$(this).addClass('active-box').removeClass('next-box').siblings().removeClass('active-box');
		$(this).siblings().removeClass('next-box');
		
		var active_class = $("li.active-box").attr('class').match(/item-[0-9]/);			
		 
		$('li.active-box').next().addClass('next-box');	
		$(".nieuws-box div.tab-content." + active_class).show().siblings('div').hide();
	});	
}

function FixActiveLink() {

	$("ul.nav-tabs li").mouseover(function() {
		$(this).find(":first").css({'color':'#d7571a'});					 
	}).mouseout(function() {
		$(this).find(":first").css('color','');			
	});

}

function InnderFade() {
	//animation for the homepage
	$('ul#animated-panorama').animatedinnerfade({
		speed: 'normal',
		timeout: 5000,
		type: 'sequence',
		containerheight: '225px',
		containerwidth: '580px',
		animationSpeed: 5000,
		animationtype: 'fade',
		bgFrame: 'none',
		controlBox: 'show',
		controlBoxClass: 'mycontrolboxclass',
		controlButtonsPath: 'img',
		displayTitle: 'yes' 
	});
	
	$('ul#banner-list, ul#banner-list2').animatedinnerfade({
		speed: 'normal',
		timeout: 5000,
		type: 'sequence',
		containerheight: '113px',
		containerwidth: '247px',
		animationSpeed: 5000,
		animationtype: 'fade',
		bgFrame: 'none',
		controlBox: 'none',
		controlBoxClass: 'mycontrolboxclass',
		controlButtonsPath: 'img',
		displayTitle: 'no' 
	});
}


$('ul#banner-list .innerfade-title, ul#banner-list2 .innerfade-title').hide();
		


if($("ul.nav-tabs li ul").length > 0) {

	$("ul.nav-tabs li ul ul").parent('li').addClass('subnav-list');
		
	$("ul.nav-tabs > li").mouseenter(function() {
		$('ul.nav-tabs li.subnav-list ul').css('display','none');
	})

	$("ul.nav-tabs li.subnav-list").mouseover(function() {
		$("ul.nav-tabs li.subnav-list ul").css('display','');		 
	})
	
	$("li.subnav-list ul").mouseout(function() {
		$(this).css('display','none');				 
	})
	
	//fix link color
	$("ul.nav-tabs li ul ul").mouseover(function() {
		//$(this).parent('li').find('a:eq(0)').addClass('active-subtab');	
		$(this).parent('li').find('a:first').addClass('active-subtab');		
	}).mouseout(function() {
		//$(this).parent('li').find('a:eq(0)').removeClass('active-subtab');	
		$(this).parent('li').find('a:first').removeClass('active-subtab');			
	});
	
	//$("ul.nav-tabs > li").mouseover(function() {
	//	$('ul.nav-tabs ul ul').css('display','');
	//})

}

//check if element exists before running the function
if($('.tab-box').length > 0 ) {
	NieuwsBox();
}

//check if element exists before running the function
if($('ul#animated-panorama').length > 0 ) {
	InnderFade();
}

/* 
IE 6 only, fixes the main link from turning 
white if you hover over any of the subnav links 
*/
if ($.browser.msie && $.browser.version == 6) {	
	FixActiveLink();
}

});				
})(jQuery);



