﻿$(function(){

	$('a.colorbox').colorbox();
	
	$('#menuBar .navigation a').each(function(){
		if($(this).attr('href') == '/Sayfalar/TeskilatSemasi.html'){
			$(this).colorbox({iframe: true, height: '600px', width:'800px'});
		}
	});	
		   
	Cufon.replace('h2.title');	
	Cufon.replace('.shortCuts .box');
	//Cufon.replace('#menuBar .navigation > li > a',{textShadow: '1px 1px 0 #484848'});
	//Cufon.replace('h1', {textShadow:'1px 1px 0px #f5f5f5'});
	//Cufon.replace('h3.pageTitle');
	//Cufon.replace('#searchBar b',{textShadow: '1px 1px 0px #fff'});
	
	/* Breadcrumbs Replace */
	if($('.SolidBreadCrumbCurrent').text() == 'Detay')
	{
		$('.SolidBreadCrumbCurrent').text($('h3.pageTitle').text());
	}
	
	$('#s4-ribbonrow #RibbonContainer-TabRowLeft #siteactiontd .ms-siteactionsmenuinner').length ? $('#s4-ribbonrow').show() : $('#s4-ribbonrow').hide();
	
	/* English Page Control */
	var substrURL = window.location.pathname.split('/');
	var sc = substrURL.length;		
	for(i=0;i<=sc-1;i++){
		if(substrURL[i] == "Eng"){
			$('#wrapper').addClass('eng');			
			$('#footerContent span').html('Republic of Turkey Ministry of Finance Strategy Development Unit © 2011');
			$('#searchBar .left').html('» All documents search can be performed in SGB Portal');
			$('#searchBar .right b').html('» SGB SEARCH');
			$('#footerContent ul.navigation a').each(function(){
				var txt = $(this).html();
				if(txt == 'Ana Sayfa'){$(this).html('Main Page');}
				if(txt == 'İletişim'){$(this).html('Contact');}
				if(txt == 'Site Haritası'){$(this).html('Site Map');}
				if(txt == 'Görüş ve Önerileriniz'){$(this).html('Comments and Suggestions');}
			});			
		}
		if(substrURL[i] == "Forms"){
			if($('#userMenu .s4-signInLink').length){
				$('#s4-ribbonrow').hide();
			}
		}			
	}
	
	
	
	
	$("#menuBar .navigation li").dropdown();
	$("#footer .shortCuts div:last").css('margin','0px');
	
	
	/* Units */
	var unitName = $("#menuBar .navigation > li:first > a").html();
	if(	unitName == 'Destek Hizmetleri' || unitName == 'İç Kontrol' || unitName == 'Ekonomik Analiz' || unitName == 'Stratejik Yönetim' || unitName == 'YBS' ){$("#menuBar .navigation > li:first > a").addClass('unit');}
	
	/* Scheme Switch */
	/*
	$('#colorScheme a').each(function(){
		$(this).bind('click',function(){			
			var color = $(this).attr('class');
			if(color == 'blue'){$('#sgbStyle').attr('href','style/sgb_main.css');}
			else if(color == 'red'){$('#sgbStyle').attr('href','style/sgb_main_red.css');}
		});
	});
	*/
	
	/* Flash News */
	$('.flashTexts li:first').addClass('current');
	$('.flashTexts li:last').addClass('last');

	
	$('.flashTexts ul a').each(function(){
		$(this).bind('mouseenter',function(){
			var indexNo = $('.flashTexts ul a').index(this);
			$('.flashTexts ul a').removeAttr('class');
			$(this).addClass('current');
			$('.flashPhotos a').hide();
			$('.flashPhotos a:eq('+indexNo+')').show();
		});	
	});
	
	$('.flashNews').hover(
		function(){clearInterval(slide);},
		function(){clearInterval(slide);slide = setInterval("slideSwitch()",5000);}
	);
	
	slide = setInterval( "slideSwitch()", 5000 );
	
	
	$('.shortCuts a:last').css('margin-right','0px');
	
	/* Accordion Content */
	$('.accordionContent .birim').each(function(){		
		$('> p',this).bind('click',function(){	
			$(this).next().slideToggle();		
		});	
	});
	
	
	/* CAROUSEL */
	$('.carousel-contents img').removeAttr('style');	
 	var contentCount = $('.carousel-contents > div').size();
	var newWidth = contentCount * 142;
	var newXPos  = 0;
	var position = 0; /* $('.carousel-contents').position().left */
	$('.carousel-contents').css('width',newWidth);
	if(contentCount <= 1){
		$('.carousel .left a').addClass('passive');
		$('.carousel .right a').addClass('passive');
	}
	else
	{
		$('.carousel .left a').addClass('passive');		
	}
	
	$('.carousel-nav a').bind('click',function(){
		var direction = $(this).attr('rel');

		if(direction == 'right')
		{
			if(newXPos != -(newWidth - 142))
			{
				newXPos = newXPos - 142;
				$('.carousel-contents').animate({left:''+newXPos+'px'},500);	
				$('.carousel .left a').removeAttr('class');
				if(newXPos == -(newWidth - 142))
				{
					$(this).addClass('passive');
					return false;				
				}
			}
		}
		else
		{
			if(newXPos != 0)
			{
				newXPos = newXPos + 142;
				$('.carousel-contents').animate({left:''+newXPos+'px'},500);
				$('.carousel .right a').removeAttr('class');
				if(newXPos == 0)
				{
					$(this).addClass('passive');
					return false;				
				}
			}
		}
		return false;
	});
	
	
});

function slideSwitch(){
	var currentNo = $('.flashTexts li a.current').parent().prevAll().length;
	currentNo++;
	if(currentNo == 5){currentNo = 0;}	
	$('.flashTexts li a').removeAttr('class');
	$('.flashTexts li a:eq('+currentNo+')').addClass('current');
	$('.flashPhotos a').hide();
	$('.flashPhotos a:eq('+currentNo+')').show();
	
}

$.fn.dropdown = function() {
	$(this).hover(function(){
		$(this).addClass("hover");
		$('> .dir',this).addClass("open");
		$('ul:first',this).css('visibility', 'visible');
		
	},function(){
		$(this).removeClass("hover");
		$('.open',this).removeClass("open");
		$('ul:first',this).css('visibility', 'hidden');
	});

}

	


