jQuery.noConflict();

function stop(e) {
	if (!e) e = window.event;
	(e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true;
	(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	return false;
}

function prevDef(e) {
	if (!e) e = window.event;
	(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
	return false;
}    

jQuery(document).ready(function() {
	//Remove noJs bodyclass
	if (typeof Sitecore == 'undefined') {
		jQuery("body").removeClass("noJs").addClass("activeJs");
	}
	//add print button if needed
	if (jQuery('.print').length != 0) {jQuery('.print').printButton();}
	//init tabs
	if ((jQuery('#dl-tabs').length != 0) && (typeof Sitecore == 'undefined')) {inittabs(jQuery("#dl-tabs"), jQuery(".tabbedcontent"));}
	//init guideblock
	if (jQuery('#ctrGuides').length != 0) {initGuides();}
});
	

//#tabs

function inittabs(tabs,tabcontent) {
	
	//hide tab contents except active or first one
	
	var activetab = jQuery("li", jQuery(tabs)).index(jQuery('.on'));
	
	if (activetab > -1)
	{
		jQuery("li.tabcontent:not(:eq(" + activetab + "))", jQuery(tabcontent)).hide();
		jQuery("li.tabcontent:eq(" + activetab + ")", jQuery(tabcontent)).show();
	}
	else { //if no active tabs set, open with first one
		jQuery("li.tabcontent:not(:eq(0))",jQuery(tabcontent)).hide();
		jQuery("li:first",jQuery(tabs)).addClass("on");
	}
	
	//associate tabs with tabbed content
	jQuery("li a",jQuery(tabs)).each(function(intIndex){
		jQuery(this).attr('href', 'javascript:void(0)').click(function(){
			//hide all tab content
			jQuery("li.tabcontent",jQuery(tabcontent)).hide();
			//show content of clicked tab
			jQuery("li.tabcontent:eq("+intIndex+")",jQuery(tabcontent)).show();
			jQuery(this).parent().addClass("on").siblings().removeClass("on");
		});
	})
	
}	

function initGuides() {

	//var slideTime = 200;
    var waitTime = 3000;
    var slideTimer = null;
    //if(slideTime>=waitTime){slideTime=waitTime}
	
	function nextSlide(index) {
	
		var target = jQuery(".guide:eq("+index+")","#ctrGuides");		
		
		jQuery(target).switchClass('guidenormal','guideactive', 30);
		jQuery(target).siblings().switchClass('guideactive','guidenormal', 50);
					  
		//toggle the persona images!
		var theindex = jQuery('#ctrGuides li.guide').index(jQuery(target));
		jQuery("li:eq(" + theindex + ")","#ctrGuideImages").siblings().fadeOut(500).hide().end().fadeIn(500);			
		
	}
	
	function startSlider() {
		clearInterval(slideTimer);
		//disable images except the active one (initialy randomized by XSL rendering)
		var theindex = jQuery('#ctrGuides li.guide').index(jQuery('#ctrGuides li.guideactive'));
		jQuery("li:not(:eq(" + theindex + "))","#ctrGuideImages").hide();
		slideTimer = setInterval(function() { 
			nextSlide(theindex);
			theindex = (theindex<2? theindex = theindex+1 : theindex=0 ); 
		}, waitTime)
	}	
	//set behaviour when mouse is moved onto guide block
	jQuery(".guide","#ctrGuides").mouseenter(function(e){	
		clearInterval(slideTimer);
		var theindex = jQuery('#ctrGuides li.guide').index(this);
		nextSlide(theindex);
	})
	//set behaviour when mouse is moved away from guide block
	jQuery(".guide","#ctrGuides").mouseleave(function(e){	
		clearInterval(slideTimer);
		startSlider();
	})	
	
	startSlider();
};



