jQuery(document).ready( function() {	
	
	// Süreler
	
	tabTime = 11000; // Anasayfa sol tab otomatik degisme süresi
	newsTime = 9000; // Anasayfa sag haber alani otomatik degisme süresi
	flashTime = 10000; // Flash otomatik degisme süresi
	
	
	Cufon.replace('h1, h2, .takvimBaslikic' , { fontFamily: 'DINEngsbek', hover: true } );
	Cufon.replace('#tabs_area h1' , { fontFamily: 'DINBEK Bold TR', hover: true } );
	
	var tabContentHeight = parseInt(jQuery("#tabContentWrapper").height());
	var tabContent = jQuery("#tabContent");
	var tabNav = jQuery("#tabNav div");
	var tabNavIndex = 0;
	
	var tabNavLeft = jQuery("#tabNavLeft");
	var tabNavRight = jQuery("#tabNavRight");
	var tabTimeout;
	
	tabNav.click( function() {
		
		tabNavIndex = tabNav.index(jQuery(this));
		tabber();
		
	});
	
	tabNavLeft.click( function() {
		
		tabNavIndex--;
		
		if ( tabNavIndex < 0 )
		{
			tabNavIndex = tabNav.size() - 1;
		}
		
		tabber();
		
	});
	
	tabNavRight.click( function() {
		
		tabNavIndex++;
		
		if ( tabNavIndex > tabNav.size() - 1 )
		{
			tabNavIndex = 0;
		}
		
		tabber();
		
	});
	
	jQuery(tabNav[0]).click();

	function tabber()
	{
		clearTimeout(tabTimeout);
		
		tabNav.removeClass("active");
		jQuery(tabNav[tabNavIndex]).addClass("active");
		
		tabContent.animate({
			
			marginTop: 0 - ( tabNavIndex * tabContentHeight )
			
		},500);
		
		autotabber();
		
	}
	
	function autotabber()
	{
		tabTimeout = setTimeout( function() {
		
			tabNavIndex++;
			if ( tabNavIndex > tabNav.size() - 1 )
			{
				tabNavIndex = 0;
			}
			tabber();
			
		},tabTime);	
	}
	
	var newsContentHeight = parseInt(jQuery("#newsContentContainer").height());
	var newsContent = jQuery("#newsContent");
	var newsTimeout;
	
	jQuery(".newsContent").each( function(i,selected) {
											   
		jQuery("#newsNav").append("<div class='newsNav' />");
		
	});
	
	var newsNav = jQuery("#newsNav .newsNav");
	var newsNavIndex = 0;
	
	newsNav.click( function() {
		
		newsNavIndex = newsNav.index(jQuery(this));
		newsMaker();
		
	});
	
	jQuery(newsNav[0]).click();

	function newsMaker()
	{
		clearTimeout(newsTimeout);
		
		newsNav.removeClass("active");
		jQuery(newsNav[newsNavIndex]).addClass("active");
		
		newsContent.animate({
			
			marginTop: 0 - ( newsNavIndex * newsContentHeight )
			
		},500);	
		
		jQuery("#newsDetail").children("a").attr("href",jQuery(jQuery(".newsContent")[newsNavIndex]).children(".newsContentImage").children("a").attr("href"));
		
		autonewsMaker();
		
	}
	
	function autonewsMaker()
	{
		newsTimeout = setTimeout( function() {
		
			newsNavIndex++;
			if ( newsNavIndex > newsNav.size() - 1 )
			{
				newsNavIndex = 0;
			}
			newsMaker();
			
		},newsTime);	
	}
	
	jQuery(".flashContent").each(function() {
								
		jQuery(this).unwrap().unwrap();
	
	});
	
	jQuery(".flashContent:first").unwrap().unwrap();
	
	var flashTimeout;
	var flashNav = jQuery(".flashNav");
	var flashNavContainer = jQuery("#flashNav");
	var flashContent = jQuery(".flashContent");
	var flashIndex = 0;
	
	flashNav.click( function() {
		
		flashIndex = flashNav.index(jQuery(this));
		
		flashNav.removeClass("active");
		jQuery(this).removeClass("active");
		
		flashMaker();
		
	});
	
	jQuery(flashNav[0]).click();
	
	function flashMaker() 
	{
		clearTimeout(flashTimeout);
		
		flashContent.css("display","none");
		jQuery(flashContent[flashIndex]).css("display","block");
		
		flashNavContainer.removeClass();
		flashNavContainer.addClass("active" + (flashIndex + 1));
		
		autoFlashMaker();
	}
	
	function autoFlashMaker()
	{
		flashTimeout = setTimeout( function() {
		
			flashIndex++;
			if ( flashIndex > flashNav.size() - 1 )
			{
				flashIndex = 0;
			}
			flashMaker()
			
		},flashTime);	
	}
	
});
