var currentRoot = '';
var currentRootTitle = '';
var currentSubTitle = '';

function init_Home()
{
	print_menu();
	print_frames();
	print_footerMenu();
	print_actual();
	var aArray = Array( makeRequest( '/ftp/aciklamaAnaSayfa.html' , 'news' ) , makeRequest( '/ftp/gunlukAnaSayfa.html' , 'agenda_row' ) );
	//var aArray = Array( makeRequest( '/aciklamaAnaSayfa.html' , 'news' ) , makeRequest( '/gunlukAnaSayfa.html' , 'agenda_row' ) );

	$( 'header' ).innerHTML = '<table width="100%"><tr><td><div id="viForm" align="left"><a href="/pages/">English</a></div></td><td align="right"><div id="viForm" align="right"><form action="http://www.tccb.gov.tr/basin/arama/aramaListe.aspx"><input type="text" name="key"/><input type="submit" value="Ara"></form></div></td></tr></table>'; /*ingilizce satırı bu alandan açılır*/
	//$( 'header' ).innerHTML = '<div><p><a href="/pages/">English</a></p></div>'; /*ingilizce satırı bu alandan açılır*/
	//$( 'header' ).innerHTML = '<div><p><a href="/pages/guests/detail/?d=haber15">English</a></p></div>'; /*ingilizce satırı bu alandan açılır*/
}

function init_Sub()
{
	print_menu();
	print_frames();
	print_SUBBmenu();
	print_footerMenu();
	print_html_title();
	$( 'header' ).innerHTML = '<table width="100%"><tr><td><div id="viForm" align="left"><a href="/pages/">English</a></div></td><td align="right"><div id="viForm" align="right"><form action="http://www.tccb.gov.tr/basin/arama/aramaListe.aspx"><input type="text" name="key"/><input type="submit" value="Ara"></form></div></td></tr></table>'; /*ingilizce satırı bu alandan açılır*/
	//$( 'header' ).innerHTML = '<div><p><a href="/pages/">English</a></p></div>';
	//$( 'header' ).innerHTML = '<div><p><a href="/pages/guests/detail/?d=haber15">English</a></p></div>';
}

//menuyü yazan alan başladı
function print_menu()
{
	var currentL = location.pathname;
	var strMenu = '<ul>';

	if( currentL != "/" )
	{
		strMenu+= '<li><a href="/">Ana Sayfa</a></li>';//eski hali : strMenu+= '<li><a href="/">Ana Sayfa</a></li><li>&nbsp;</li>';
	}
	for( var strTitle in menu )
	{
		if( !menu[ strTitle ][ 'hide' ] )
		{
			var sUrl = menu[ strTitle ][ 'link' ];
			var sTarget = '';
			if( menu[ strTitle ][ 'target' ] )
			{
				sTarget = 'target="_blank" ';
			}
			if( ( currentL == sUrl ) || ( currentL.indexOf( sUrl ) >= 0 ) )
			{
				strMenu+= '<li><span>' + strTitle + '</span></li>';
				currentRoot = sUrl;
				currentRootTitle = strTitle;
			}
			else
			{
				strMenu+= '<li><a ' + sTarget + 'href="' + sUrl + '">' + strTitle + '</a></li>';			
			}
		}
	}

	strMenu+= '</ul>';
	$( 'menu' ).innerHTML = strMenu;
	$( 'divATO' ).innerHTML = '<p><a href="/sayfa/ata_ozel/biyografi/"><img src="/layout/banners/ata-ozel-Y.gif" alt="Atatürk Özel" /></a></p> '; 
	//$( 'divATO' ).innerHTML += '<p><a href="http://www.kureselfotograf.com/cankaya/"><img src="/layout/buttons/sanal-tur-y.jpg" alt="Sanal Tur" /></a></p> '; 
}
//menuyü yazan alan bitti


function print_frames()
{
	var sOut = '';
	
	for( var sAlt in framesMenu )
	{
		var sUrl = 'http://' + framesMenu[ sAlt ][ 'link' ];
		var sSrc = '/layout/links/' + framesMenu[ sAlt ][ 'img' ];
		sOut+= '<p><a target="_parent" href="' + sUrl + '"><img src="' + sSrc + '" alt="' + sAlt + '"/></a></p>[DEL]';
	}
	sOut = sOut.substr( 0 , ( sOut.length - 5 ) );
	var regPattern = /\[DEL\]/gi;
	$( 'frames_html' ).innerHTML = sOut.replace( regPattern , '<p><img src="/layout/backgrounds/framedelimiter.gif" alt="#" /></p>' );
}

function print_footerMenu()
{
	var sOut = '';
	for( var strTitle in menu )
	{
		var regSPACE = / /g;
		var sUrl = menu[ strTitle ][ 'link' ];
		var sTarget = '';
		if( menu[ strTitle ][ 'target' ] )
		{
			sTarget = 'target="_blank" ';
		}
		sOut+= '<span><a ' + sTarget + 'href="' + sUrl + '">' + strTitle.replace( regSPACE , '&nbsp;' ) + '</a></span>[DEL]';
	}
	sOut = sOut.substr( 0 , ( sOut.length - 5 ) );
	var regPattern = /\[DEL\]/gi;
	sOut = sOut.replace( regPattern , ' <span class="d">|</span> ' );
	$( 'footer_html' ).innerHTML = sOut;
}


//ana sayfa resimli alt alta sıralı haber başladı
function print_actual()
{
	var strOut = '<h1>' + newsItems[ newsFlash ][ 'title' ] + '</h1>';

	switch( newsItems[ newsFlash ][ 'media' ][ 'type' ] )
	{
		case "image" :
			strOut+= '<p><img src="' + newsItems[ newsFlash ][ 'media' ][ 'link' ] + '" alt="' + newsItems[ newsFlash ][ 'media' ][ 'alt' ] + '"/></p>';
		break;

		case "video" :
			strOut+= '<div id="vid"><object type="application/x-shockwave-flash" data="/mediaplayer.swf" width="400" height="320"><param name="movie" value="/mediaplayer.swf"/><param name="allowfullscreen" value="true"/><param name="quality" value="best"/><param name="flashvars" value="file=' + newsItems[ newsFlash ][ 'media' ][ 'link' ] + '&amp;autostart=false&amp;repeat=false&amp;width=400&amp;height=320&amp;image=' + newsItems[ newsFlash ][ 'media' ][ 'poster' ] + '\"/></object></div>'
		// autostart= ( true | false )  repeat=true&amp;
		break;
	}
	
	//strOut+= '<div id="actual_description">' + newsItems[ newsFlash ][ 'description' ] + '<p>'; 'eski hali
	strOut+= '<a href="/sayfa/haber/detay/?d=' + newsFlash + '"><div id="actual_description">' + newsItems[ newsFlash ][ 'description' ] + '</a>';

	if( newsItems[ newsFlash ][ 'full' ] )	
	{
		//strOut+= '<a href="/sayfa/haber/detay/?d=' + newsFlash + '">Ayrıntı<\/a>' ;
		//strOut+= '<a href="/sayfa/haber/detay/?d=' + newsFlash + '">Ayrıntı<\/a>' ; ' eski hali
	}	

	strOut+= '</div>';	
	//strOut+= '<p id="actual_date">' + newsItems[ newsFlash ][ 'date' ] + '</p>'; 'ana sayfada açıklama altında yer alan ayrıntı ifadesinin altında yer alan tarih

	strOut+= '<hr noshade="noshade" size="1"/>';	
	strOut+= '<p id="actual_others">';	

	var c = 0;
	for( var newsIndex in newsItems )
	{
		var thImg = newsItems[ newsIndex ][ 'thumb' ];
		var thAlt = newsItems[ newsIndex ][ 'media' ][ 'alt' ];
		var clsStr = ( newsIndex == newsFlash ) ? 'class="selected" ' : '';
		strOut+= '<img ' + clsStr + 'src="' + thImg + '" alt="' + thAlt + '" title="' + thAlt + '" onclick="setFlashNews( \'' + newsIndex + '\' );"/>';
		c++;
		if( c == 4 )
		{
			break;
		}
	}
	strOut+= '</p>';
	$( 'actual' ).innerHTML = strOut;
	
	var oldNews = '';
	var c = 0;
	for( var newsIndex in newsItems )
	{
		if( c > 3 )
		{
			if( c > 8 ) // ana sayfada listelenen haberlerin sayısını belirler
			{
				break;
			}

			var thTitle = newsItems[ newsIndex ][ 'title' ];
			var thDesc = newsItems[ newsIndex ][ 'description' ];
			var thDate = newsItems[ newsIndex ][ 'date' ];
			var thIMGSTR = '<dt>&nbsp;</dt>';			
			if( newsItems[ newsIndex ][ 'thumb' ] )
			{
				thIMGSTR = '<dt><a href="/sayfa/haber/detay/?d=' + newsIndex + '"><img src="' + newsItems[ newsIndex ][ 'thumb' ] + '" alt="' + newsItems[ newsIndex ][ 'media' ][ 'alt' ] + '" align="top"/></a></dt>';
			}
			
			oldNews+= ''
				+ '<dl>'
				+ thIMGSTR
				+ '<dd><p><a href="/sayfa/haber/detay/?d=' + newsIndex + '">' + thTitle + '</a></p><p><big>' + thDate + '</big></p></dd>'
				+ '</dl>'
				+ '';
		}
		c++;
	}
	if( oldNews.length > 0 )
	{
		$( 'ex_actual' ).innerHTML = oldNews;
	}
}
//ana sayfa resimli alt alta sıralı haber bitti


function setFlashNews( nID )
{
	newsFlash = nID;
	print_actual();
}

function init_SubPrograms()
{
	var htmlOut = '';
	for( var i = 0; i < agendaTodayItems.length; i++ )
	{
		htmlOut+= '<dl class="programs_row">'
			+ '<dt>' + agendaTodayItems[ i ][ 0 ] + '</dt><dd>' + agendaTodayItems[ i ][ 1 ] + '</dd>'
			+ '</dl>';
	}
	$( 'html_programs' ).innerHTML = htmlOut;
}

function print_SUBBmenu()
{
	if( $( 'dynamic_SUB' ) )
	{
		//window.alert( "currentRoot=" + currentRoot );
		//window.alert( location.pathname );

		if( currentRoot.length == 0 )
		{
			switch( location.pathname )
			{	
				// Hanımefendi Etkinlikler
				case "/sayfa/hanimefendi/etkinlikler/" :
					currentRoot = "/sayfa/hanimefendi/";
				break;

				case "/sayfa/hanimefendi/etkinlikler/yurt_disi/" :
					currentRoot = "/sayfa/hanimefendi/";
				break;

				case "/sayfa/hanimefendi/etkinlikler/konuk/" :
					currentRoot = "/sayfa/hanimefendi/";
				break;

				case "/sayfa/hanimefendi/etkinlikler/diger/" :
					currentRoot = "/sayfa/hanimefendi/";
				break;

				
				// Foto Galeri
				case "/sayfa/galeri/" :
					currentRoot = "/sayfa/galeri/";
				break;

				case "/sayfa/galeri/ilkbahar/" :
					currentRoot = "/sayfa/galeri/";
				break;			
				
				case "/sayfa/galeri/yaz/" :
					currentRoot = "/sayfa/galeri/";
				break;	

				case "/sayfa/galeri/sonbahar/" :
					currentRoot = "/sayfa/galeri/";
				break;				

				case "/sayfa/galeri/kis/" :
					currentRoot = "/sayfa/galeri/";
				break;				

				case "/sayfa/galeri/tarabya/" :
					currentRoot = "/sayfa/galeri/";
				break;
				
				case "/sayfa/galeri/cumhurbaskani/" :
					currentRoot = "/sayfa/galeri/";
				break;				


				// Ata Özel
				case "/sayfa/ata_ozel/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/biyografi/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/muzik/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/biyografi/arsiv/02/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/biyografi/arsiv/03/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/biyografi/arsiv/04/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/kitaplik/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/fotograf/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				case "/sayfa/ata_ozel/video/" :
					currentRoot = "/sayfa/ata_ozel/";
				break;

				
				// Afrika
				case "/sayfa/afrika/" :
					currentRoot = "/sayfa/afrika/";
				break;

				case "/sayfa/afrika/tanzanya/" :
					currentRoot = "/sayfa/afrika/";
				break;

				case "/sayfa/afrika/kenya/" :
					currentRoot = "/sayfa/afrika/";
				break;


				// Konuşan Kitap
				case "/sayfa/konusankitap/" :
					currentRoot = "/sayfa/konusankitap/";
				break;

				case "/sayfa/konusankitap/istanbul/" :
					currentRoot = "/sayfa/konusankitap/";
				break;

				case "/sayfa/konusankitap/sanliurfa/" :
					currentRoot = "/sayfa/konusankitap/";
				break;


				// Mimar Sinan
				case "/sayfa/mimarsinan/" :
					currentRoot = "/sayfa/mimarsinan/";
				break;
				
				case "/sayfa/mimarsinan/sofya/" :
					currentRoot = "/sayfa/mimarsinan/";
				break;
				
				case "/sayfa/mimarsinan/saraybosna/" :
					currentRoot = "/sayfa/mimarsinan/";
				break;

				case "/sayfa/mimarsinan/suriye/" :
					currentRoot = "/sayfa/mimarsinan/";
				break;

				case "/sayfa/mimarsinan/esadpasakonagi/" :
					currentRoot = "/sayfa/mimarsinan/";
				break;


				// Eğitim Her Engeli Aşar
				case "/sayfa/egitimherengeliasar/" :
					currentRoot = "/sayfa/egitimherengeliasar/";
				break;

				case "/sayfa/egitimherengeliasar/2009/" :
					currentRoot = "/sayfa/egitimherengeliasar/";
				break;

				case "/sayfa/egitimherengeliasar/2010/" :
					currentRoot = "/sayfa/egitimherengeliasar/";
				break;

				
				// Zirve
				case "/sayfa/zirve/" :
					currentRoot = "/sayfa/zirve/";
				break;

				case "/sayfa/zirve/istanbul/" :
					currentRoot = "/sayfa/zirve/";
				break;

				
				// 81 İlden 81 Yıldız
				case "/sayfa/81ilden81yildiz/" :
					currentRoot = "/sayfa/81ilden81yildiz/";
				break;

				case "/sayfa/81ilden81yildiz/2009/" :
					currentRoot = "/sayfa/81ilden81yildiz/";
				break;
			}
		}


		var strHTML = '';
		for( var strSubMenuTitle in subb_menu[ currentRoot ] )
		{
			var strURL = subb_menu[ currentRoot ][ strSubMenuTitle ];
			strHTML+= '<li>';
			
			//window.alert( location.pathname + ' = ' + strURL );
			
			if( ( location.pathname == strURL ) || ( subb_menu3[ strURL ] && subb_menu3[ strURL ][ location.pathname ] ) )
			{
				strHTML+= '<span>' + strSubMenuTitle + '</span>';
				currentSubTitle = ' > ' + strSubMenuTitle;
			}
			else
			{
				var xTarget = '';
				if( strURL.substr( 0 , 4 ) == 'http' )
				{
					xTarget = ' target="_blank"';
				}
				strHTML+= '<a href="' + strURL + '"' + xTarget + '>' + strSubMenuTitle + '</a>'; 
				//strHTML+= '<a href="' + strURL + '">' + strSubMenuTitle + '</a>';
			}
			strHTML+= '</li>';
		}
		if( strHTML.length > 0 )
		{
			strHTML = '<ul>' + strHTML + '</ul>';
			$( 'dynamic_SUB' ).innerHTML = strHTML;
		}
	}
}

function print_html_title()
{
	if( currentRootTitle.length > 0 )
	{
		var strPageTitle = 'T.C. CUMHURBAŞKANLIĞI : ' + currentRootTitle + currentSubTitle;
		top.document.title = strPageTitle;
	}
}

function $( strID )
{
	return document.getElementById( strID );
}
// -------------------------------------------------------------------------------------------------------------------
function makeRequest( url , xid )
{
	var httpRequest;
	var xid;
	if( window.XMLHttpRequest )
	{
		httpRequest = new XMLHttpRequest();
		if( httpRequest.overrideMimeType )
		{
			httpRequest.overrideMimeType( 'text/xml' );
		}
	} 
	else if( window.ActiveXObject )
	{
		try
		{
			httpRequest = new ActiveXObject( "Msxml2.XMLHTTP" );
		} 
		catch( e )
		{
			try
			{
				httpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} 
			catch( e ){}
		}
	}
	if( !httpRequest )
	{
		//window.alert( 'Giving up :( Cannot create an XMLHTTP instance' );
		return false;
	}
	httpRequest.onreadystatechange = function()
	{
		alertContents( httpRequest , xid );
	}
	httpRequest.open( 'GET' , url , true );
	httpRequest.setRequestHeader( 'Pragma' , "no-cache" );
	httpRequest.setRequestHeader( 'Cache-Control' , "no-cache" );
	httpRequest.send( null );
}

function alertContents( httpRequest , xid ) {
	if( httpRequest.readyState == 4 )
	{
		if( httpRequest.status == 200 )
		{
			//window.alert( httpRequest.responseText );
			//window.alert( xid );
			document.getElementById( xid ).innerHTML = httpRequest.responseText;
		}
		else
		{
			//window.alert( 'There was a problem with the request.' );
		}
	}
}
// -------------------------------------------------------------------------------------------------------------------

function init_Visits( viso )
{
	var htmlo = '';
	var c = 0;
	for( var fIndex in viso )
	{
		htmlo+= ''
			+ '<div class="iRow">'
			+ '<div class="iDate"><h1>' + viso[ fIndex ][ 'day' ] + '</h1><h2>' + viso[ fIndex ][ 'month' ] + '</h2><h3>' + viso[ fIndex ][ 'year' ] + '</h3></div>'
			+ '<div class="iDesc">'
			+ '<h4>' + viso[ fIndex ][ 'title' ] + '</h4>' + viso[ fIndex ][ 'description' ]
			+ '';
		if( viso[ fIndex ][ 'photos' ] )
		{
			htmlo+= '<div class="iThumbs">';
			for( var strPhotAlt in viso[ fIndex ][ 'photos' ] )
			{
				htmlo+= '<p><a rel="lightbox[grp' + c + ']" title="' + strPhotAlt + '" href="' + viso[ fIndex ][ 'photos' ][ strPhotAlt ][ 'big' ] + '"><img src="' + viso[ fIndex ][ 'photos' ][ strPhotAlt ][ 'thumb' ] + '" alt="' + strPhotAlt + '"/></a></p>';
			}
			htmlo+= '</div>';
		}
		htmlo+= '</div></div>';
		c++;
	}
	
	$( 'internalsHtml' ).innerHTML = htmlo;
}


//foto galeri başladı
function kickGall( endNum , filePath )
{
	var xHtmlOut = '<div>';
	var c = 0;
	for( var i = 1; i < ( endNum + 1 ); i++ )
	{
		fixedNUM = set_digits( i , 5 )
		xHtmlOut+= '<p><a rel="lightbox[grp]" href="/common/gallery/' + filePath + '/photo_' + fixedNUM + '.jpg"><img src="/common/gallery/' + filePath + '/thumbs/photo_' + fixedNUM + '.jpg" alt="#"/></a></p>';
		c++;
		if( c == 4 )
		{
			c = 0;
			xHtmlOut+= '</div>';
			if( i < endNum )
			{
				xHtmlOut+= '<div>';
			}
		}
	}
	
	xHtmlOut+= '</div>';
	
	$( 'fgallery_Area' ).innerHTML = xHtmlOut;
}
//foto galeri bitti


function set_digits( number_val , digits ){
	var to_str = new String( number_val );
	if( !arguments[1] ){ digits = 2; }
	if( to_str.length == digits ){ return number_val; }
	var str_addition = "";
	for( var iqq = to_str.length; iqq < digits; iqq++ ){ str_addition+= "0"; }
	return str_addition + number_val;
}

function showHide( strID )
{
	var disVal = $( strID ).style.display;
	if( disVal.length == 0 || disVal == 'none' )
	{
		$( strID ).style.display = 'block';
	}
	else
	{
		$( strID ).style.display = 'none';
	}
}