var $j = jQuery.noConflict();
var rotateCount = 1;
var timeout = 6000;
var timeoutActive = 12000;


$j(document).ready(function(){
	tabtimer=setTimeout("rotateTabs()", timeout);
	/* make tabs transparent*/
	//$j("#tabrotator-nav li").css({"opacity" : 1});
	//$j("#tabrotator-nav li.active").css({"opacity" : 1});
	
	/* init filled in tabs, hide the rest */
	/* IE6/7/8 calculate number of active (non-empty) tabs */
	var $listitems = $j("#tabrotator-nav li");
	listitems = $listitems.length;
	for (var i=1;i<=listitems;i++) {
		if( ($listitems.children().html()).indexOf("TemplateParagraphHeader") >= 0 )	$listitems.children().html("");
		$listitems = $listitems.nextAll();
	}
	/* END IE6/7/8 FIX */
	$j("#tabrotator-nav li a:not(:empty)").parent().css({"display" : "inline"});
	$j("#tabrotator-nav li a:empty").parent().remove();

	/* Make UL/LI take up full width */
	/*activeTabs = $j("#tabrotator ul li a:not(:empty)").length;
	tabWidth = Math.round(540/activeTabs+0.4);
	$j("#tabrotator ul li").css({"width" : tabWidth+"px"});*/

	/* attach click function to tabs */
	$j("#tabrotator-nav li a").click(function(e){
		/* check clicked tab and set rotateCount to start from there */
		var $kids = $j("#tabrotator-nav").children();
		children = $kids.length;
		target = $j(e.target).parent().attr("id");
		for (var i=1;i<=children;i++) {
			if(target == $kids.attr("id") ) rotateCount = i;
			var $kids = $kids.nextAll();
		}
		
		/* restart timer and set to "active" timeout time */
		clearTimeout(tabtimer);
		//$j("#tabrotator div.tab").hide();
		//$j("#" + $j(this).parent("li").attr("id") + "content").show();
		//$j("#tabrotator div.tab").toggleClass("activetab");
		//$j("#" + $j(this).parent("li").attr("id") + "content").toggleClass("activetab");
		$j("#tabrotator div.tab").css({'visibility' : 'hidden'});
		$j("#" + $j(this).parent("li").attr("id") + "content").css({'visibility' : 'visible'});
		
		$j("#tabrotator-nav li").removeClass("active");
		$j("#tabrotator-nav li#"+$j(this).parent("li").attr("id")).addClass("active");
		tabtimer=setTimeout("rotateTabs()", timeoutActive); 

                DoCatylistUpdate(target);
    });
	
	/* extra klikactie op <a> gedefinieerd met class="activateTab tabrotator-tab[nummer]" */
	$j("a.activateTab").click(function(e){
		/* check clicked link and set rotateCount to start from there */
		var $kids = $j("#tabrotator-nav").children();
		children = $kids.length;
		target = $j(this).children("img").attr("class");
		for (var i=1;i<=children;i++) {
			if(target == $kids.attr("id") ) rotateCount = i;
			var $kids = $kids.nextAll();
		}
		
		/* restart timer and set to "active" timeout time */
		clearTimeout(tabtimer);
		
		$j("#tabrotator div.tab").css({'visibility' : 'hidden'});
		$j("#" + target + "content").css({'visibility' : 'visible'});
		
		$j("#tabrotator-nav li").removeClass("active");
		$j("#tabrotator-nav li#" + target).addClass("active");
		tabtimer=setTimeout("rotateTabs()", timeoutActive); 
    });
})


/* rotate iterative function, using defauklt timeout time */
function rotateTabs(){
	activeTabs = $j("#tabrotator-nav li a:not(:empty)").length;

	if(rotateCount < activeTabs)	rotateNext = rotateCount + 1;
	else rotateNext = 1;
	$j('#tabrotator-tab'+rotateCount).toggleClass("active");
	$j('#tabrotator-tab'+rotateNext).toggleClass("active");
	/*$j('#tabrotator-tab'+rotateCount+'content').toggle(0, function(){
		$j('#tabrotator-tab'+rotateNext+'content').toggle(0);
	});*/
	$j('#tabrotator-tab'+rotateCount+'content').css({'visibility' : 'hidden'});
	$j('#tabrotator-tab'+rotateNext+'content').css({'visibility' : 'visible'});
	
	if(rotateCount < activeTabs)	rotateCount++;
	else rotateCount = 1;
	//$j("#tabrotator-nav li.active").css({"opacity" : 1});
	tabtimer=setTimeout("rotateTabs()", timeout);
}

function DoCatylistUpdate(target)
{
   var arr
   try
   {
      if (!target) return;
      if (target.length == 0) return;
      if (target.indexOf("-") == -1) return;

      arr = target.split("-");
      s.prop3 = arr[1];
      
      var s_code=s.t();
      
      if (s_code)
        document.write(s_code);
   }
   catch (e)
   {
      //alert(e.message);
   }
}
