jQuery(document).ready( function() {	
	
	Cufon.replace('#menuContainer a, #flashTitles div, #mainTabsNavigation div, .neotech' , { fontFamily: 'neotech', hover: true } );
	
	//jQuery("#listMenuRoot > li:last").remove();
	
	jQuery(".flashTitles").each( function() {
		
		jQuery(this).unwrap().unwrap();
		
	});
	
	jQuery(jQuery(".flashTitles")[0]).unwrap().unwrap();
	
	var mainFlashContainer = jQuery("#flashContainer");
	var mainFlashContent = jQuery("#flashContent");
	var mainFlashContentItem = jQuery(".flashContent");
	var mainFlashNav = jQuery("#flashNavigation");
	var mainFlashContentItemTitle = jQuery("#flashTitles").children("div");
	var mainFlashCount = 0;
	var mainFlashIndex = -1;
	var didyouknowtimeout;
	
	mainFlashContentItem.each( function(i,selected) {
		
		mainFlashNav.append("<div />");
		
	});
	
	mainFlashNav.children("div").mouseenter( function() {
		
		mainFlashCount = mainFlashIndex;
		
		mainFlashIndex = mainFlashNav.children("div").index(jQuery(this));
		
		if ( mainFlashCount != mainFlashIndex )
		{
			mainFlashNav.children("div").removeClass("active");
			jQuery(this).addClass("active");
			
			mainFlashContentItem.fadeOut("slow");
			mainFlashContentItemTitle.fadeOut("slow");
			jQuery(mainFlashContentItem[mainFlashIndex]).fadeIn("slow");
			jQuery(mainFlashContentItemTitle[mainFlashIndex]).fadeIn("slow");
		}
		
		clearTimeout(didyouknowtimeout);
		
	});
	
	mainFlashNav.children("div").mouseleave( function() {
		
		mainFlashNavAuto();
		
	});
	
	jQuery(mainFlashNav.children("div")[0]).mouseenter();
	jQuery(mainFlashNav.children("div")[0]).mouseleave();
	
	function mainFlashNavAuto() {
	
		didyouknowtimeout = setTimeout( function() {
			var mainFlashNavActive = mainFlashNav.children("div").index(mainFlashNav.children(".active"))
			mainFlashNavActive++;
			if ( mainFlashNavActive == mainFlashNav.children("div").size() )
			{
				mainFlashNavActive = 0
			}
			jQuery(mainFlashNav.children("div")[mainFlashNavActive]).mouseenter();

		},8000);
	
	}
	
	var mainTabsNavigation = jQuery("#mainTabsNavigation").children("div");
	var mainTabsContent = jQuery("#mainTabsContent").children("div");
	var mainTabsIndex = -1;
	var mainTabsCount = 0;
	
	
	mainTabsNavigation.click( function() {

		mainTabsCount = mainTabsIndex;

		mainTabsIndex = mainTabsNavigation.index(jQuery(this));
		
		if ( mainTabsCount != mainTabsIndex )
		{
			mainTabsNavigation.removeClass("active");
			jQuery(this).addClass("active");
			
			mainTabsContent.fadeOut("slow");
			jQuery(mainTabsContent[mainTabsIndex]).fadeIn("slow");
		}
		
		Cufon.refresh();
		
	});
	
	jQuery(mainTabsNavigation[0]).click();
	
	var newsSliderContent = jQuery(".newsSliderContent");
	var newsSliderIndex = 0;
	var newsSliderNavigationLeft = jQuery("#newsSliderNavigationLeft");
	var newsSliderNavigationRight = jQuery("#newsSliderNavigationRight");
	var newsSliderTimeout;
	
	newsSliderContent.each( function(i,selected) {
		
		jQuery("#newsSliderNavigationNumbers").append("<div><span>" + ( i + 1 ) + "</span></div>")
		
	});
	
	var newsSliderNavigationNumbers = jQuery("#newsSliderNavigationNumbers").children("div");
	
	newsSliderNavigationNumbers.click( function() {
		
		newsSliderIndex = newsSliderNavigationNumbers.index(jQuery(this));
		newsSliderContent.css("display","none");
		jQuery(newsSliderContent[newsSliderIndex]).css("display","block");
		
		newsSliderNavigationNumbers.removeClass("active");
		jQuery(this).addClass("active");
		
	});
	
	newsSliderNavigationRight.click( function() {
		
		newsSliderIndex++;
		
		if ( newsSliderIndex > (newsSliderNavigationNumbers.size() - 1) )
		{
			newsSliderIndex = 0;
		}
		
		jQuery(newsSliderNavigationNumbers[newsSliderIndex]).click();
		
	});
	
	newsSliderNavigationLeft.click( function() {
		
		newsSliderIndex--;
		
		if ( newsSliderIndex < 0 )
		{
			newsSliderIndex = newsSliderNavigationNumbers.size() - 1;
		}
		
		jQuery(newsSliderNavigationNumbers[newsSliderIndex]).click();
		
	});
	
	function newsSliderAuto()
	{
	
		newsSliderTimeout = setTimeout( function() {
		
			newsSliderNavigationRight.click();
			newsSliderAuto();
			
		},12000);
	
	}
	
	jQuery(newsSliderNavigationNumbers[newsSliderIndex]).click();
	newsSliderAuto();
	
	var faceBookGroupsNavLeft = jQuery("#faceBookGroupsNavLeft");
	var faceBookGroupsNavRight = jQuery("#faceBookGroupsNavRight");
	var faceBookGroupsContent = jQuery("#faceBookGroupsContent");
	var faceBookGroupsContentHeight = parseInt(faceBookGroupsContent.parent().height());
	var faceBookGroupsCount = 0;
	var faceBookGroupsShowSize = 7;
	var faceBookGroupsContentSize;
	
	if ( (jQuery("#faceBookGroupsContent").children().size() % faceBookGroupsShowSize) != 0 )
	{
		faceBookGroupsContentSize = parseInt(jQuery("#faceBookGroupsContent").children().size() / faceBookGroupsShowSize);
	}
	else
	{
		faceBookGroupsContentSize = parseInt(jQuery("#faceBookGroupsContent").children().size() / faceBookGroupsShowSize) - 1;
	}
	
	faceBookGroupsNavLeft.click( function() {
		
		faceBookGroupsCount--;
		
		if ( faceBookGroupsCount < 0 )
		{
			faceBookGroupsCount = faceBookGroupsContentSize;
		}
		
		faceBookGroupsContent.animate({ marginTop: ( 0 - (faceBookGroupsContentHeight * faceBookGroupsCount) ) })
		
	});
	
	faceBookGroupsNavRight.click( function() {
		
		faceBookGroupsCount++;
		
		if ( faceBookGroupsCount > faceBookGroupsContentSize )
		{
			faceBookGroupsCount = 0;
		}
		
		faceBookGroupsContent.animate({ marginTop: ( 0 - (faceBookGroupsContentHeight * faceBookGroupsCount) ) })
		
	});
	
});

function PopupPic(sPicURL) {
	window.open( "../popup.htm?"+sPicURL, "", "resizable=0,HEIGHT=400,WIDTH=400");
}
