jQuery.noConflict();

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};

jQuery(document).ready(function(){ 	

	jQuery("ul#ticker01").liScroll({travelocity: .05});


    jQuery('#mycarousel').jcarousel({
        vertical: true,
        scroll: 1
    });

//    jQuery('#mycarousel').jcarousel({
//        vertical: true,
//		scroll: 1,
//		auto: true,
//        wrap: 'last',
//		animation:'slow',
//        initCallback: mycarousel_initCallback
//    });



		
		jQuery(".youTubeVideo").fancybox({'type':'iframe','titlePosition':'inside','title':'&nbsp;','overlayOpacity':'0.8','overlayColor':'#000'});

		if (jQuery("#mygoalsmenu").size()>0) {
			jQuery("#mygoalsmenu").load("/adactus/AdactusLoginMenu.aspx", function(){
				//jQuery("#mygoalsmenu .newRHSMenu .newRHSMenuTop").addClass("newRHSMenuTopBg");
				
				jQuery("#mygoalsmenu .newRHSMenu .newRHSMenuTop").addClass("newRHSMenuTopBgDown");
				jQuery("#mygoalsmenu .newRHSMenu .newRHSMenuContent").show();
				
				jQuery("#mygoalsmenu .newRHSMenu .newRHSMenuTop").click(function(){
					if(jQuery(this).hasClass("newRHSMenuTopBg"))
					{
						jQuery(this).removeClass("newRHSMenuTopBg");
						jQuery(this).addClass("newRHSMenuTopBgDown");
						//jQuery(this).next(".newRHSMenuContent").show();
						jQuery(this).next(".newRHSMenuContent").slideDown("slow");
					}
					else 
					{
						jQuery(this).removeClass("newRHSMenuTopBgDown");
						jQuery(this).addClass("newRHSMenuTopBg");
						//jQuery(this).next(".newRHSMenuContent").hide();
						jQuery(this).next(".newRHSMenuContent").slideUp("slow");
					}
				});
				
				
				
			});
		}
		
		var branchID = '';
		var branchQS = '';
		if(querySt("BranchId")!=undefined){
			branchID = querySt("BranchId");
			branchQS = "?BranchId="+branchID;
		}
	
		
		if(querySt("test") == "y"){
			alert(branchQS);	
		}
		
        jQuery("#LoginControlContainer").load("/adactus/AdactusLogin.aspx"+branchQS);
        jQuery("#locationSelectForm").load("/adactus/AdactusChangeSite.aspx"+branchQS);
        jQuery("#contentHeader_container").load("/adactus/AdactusBranchHeader.aspx"+branchQS);
		jQuery("#selectCentre").load("/adactus/AdactusChangeSite.aspx"+branchQS);
		
		
		
		//jQuery(".newRHSMenuTop").addClass("newRHSMenuTopBg");

		jQuery(".newRHSMenuTop:eq(0)").addClass("newRHSMenuTopBgDown");
		jQuery(".newRHSMenuTop:gt(0)").addClass("newRHSMenuTopBg");
		jQuery(".newRHSMenuContent:first").show();
		
		
		
		
		jQuery(".newRHSMenuTop").click(function(){
			
			if(jQuery(this).hasClass("newRHSMenuTopBg"))
			{
				jQuery(this).removeClass("newRHSMenuTopBg");
				jQuery(this).addClass("newRHSMenuTopBgDown");
				//jQuery(this).next(".newRHSMenuContent").show();
				jQuery(this).next(".newRHSMenuContent").slideDown("slow");
			}
			else 
			{
				jQuery(this).removeClass("newRHSMenuTopBgDown");
				jQuery(this).addClass("newRHSMenuTopBg");
				//jQuery(this).next(".newRHSMenuContent").hide();
				jQuery(this).next(".newRHSMenuContent").slideUp("slow");
			}
		});

		

		var newsPage = 3;
		
		var totalnewsPage = Math.ceil(jQuery(".newHomepageNews .newsArticleT").length/3)*3;
		//jQuery("#pageNum").html(newsPage + "of " + totalnewsPage);
		
		jQuery(".newHomepageNews .newsArticleT:lt("+newsPage+")").show();
		
		jQuery("#newHomepageNewsDown").click(function(){
			
			if(newsPage < totalnewsPage)
			{
				jQuery(this).removeClass("inactive");
				newsPage = newsPage +3;
				jQuery(".newHomepageNews .newsArticleT").css({"display":"none"});
				
				jQuery(".newHomepageNews .newsArticleT:eq("+(newsPage-1)+")").css({"display":"table"});
				jQuery(".newHomepageNews .newsArticleT:eq("+(newsPage-2)+")").css({"display":"table"});
				jQuery(".newHomepageNews .newsArticleT:eq("+(newsPage-3)+")").css({"display":"table"});


				//jQuery(".newHomepageNews .newsArticleT:gt("+(newsPage-2)+"):lt("+(newsPage)+")").css({"display":"table"});
				//alert(newsPage);
				
			}
			else
			{
				jQuery(this).addClass("inactive");
			}
			
			if(newsPage > 3)
			{
				jQuery("#newHomepageNewsUp").removeClass("inactive");	
			}
			if (newsPage == totalnewsPage)
			{
				jQuery("#newHomepageNewsDown").addClass("inactive");
			}
			
			//jQuery("#pageNum").html(newsPage + "of " + totalnewsPage);
			
		});
		

		
		jQuery("#newHomepageNewsUp").click(function(){
			
			if(newsPage > 3)
			{
				
				jQuery(this).removeClass("inactive");
				
				newsPage = newsPage - 3;
				jQuery(".newHomepageNews .newsArticleT").css({"display":"none"});
				
				jQuery(".newHomepageNews .newsArticleT:eq("+(newsPage-1)+")").css({"display":"table"});
				jQuery(".newHomepageNews .newsArticleT:eq("+(newsPage-2)+")").css({"display":"table"});
				jQuery(".newHomepageNews .newsArticleT:eq("+(newsPage-3)+")").css({"display":"table"});
				
			}
			else
			{
				jQuery(this).addClass("inactive");
			}
			
			if (newsPage < totalnewsPage)
			{
				jQuery("#newHomepageNewsDown").removeClass("inactive");
			}
			if (newsPage == 3)
			{
				jQuery("#newHomepageNewsUp").addClass("inactive");
			}
			
			//jQuery("#pageNum").html(newsPage + "of " + totalnewsPage);
			
		});
		

	

    });

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

if(navigator.userAgent.indexOf('Mac') != -1)
{document.write ('<style type="text/css">#row2 ul li a{font-size:11px!important;}</style>');}

