/*
*
* Coded by Tolga ARICAN
* www.dxenia.com
*
*/


// gecis efekt suresi
var fader = 22;

// son acik anamenu
var openedMenu = "";

// dil tanimlamalari (bos: TR)
var lang = "";

// ideefixe kitap array.i
var ideefixe=new Array("-","RXBE186HSB5BYALX260F","N1F47FDD5Y5GJ0YTRZPM","EKI4ZU8T7Z0Z4M4RDGEB","YAVIAV873K3K4XLP2FJY","QYBDJLKSRG7G4EN04XYG");

function menuSwitch(mId) {
	
	if (openedMenu != mId) {
	
		var opened = false;
		var contentOpened = (document.getElementById("content") != null);
		
		if (contentOpened) {
			document.getElementById("content").innerHTML = "";
			document.getElementById("fotoContent").innerHTML = "";
			document.getElementById("content").className = "contentContainer noborder";
		}
		
		if (document.getElementById("top"+mId) != null)
			opened = (document.getElementById("top"+mId).style.display == "block");
			
		var faderWait = 0;
		
		// eski menu gizleme
		if ((openedMenu != "") && (document.getElementById("top"+openedMenu) != null)) {
						
			for (var i=10;i>-1;i--)
				setTimeout("setOpacity("+i+",'top"+openedMenu+"')",fader*(10-i));
				
			document.getElementById("m"+openedMenu).className = "";
			faderWait = fader * 20;
		}
		
		// yeni menu acma
		if ((!opened) && (document.getElementById("top"+mId) != null)) {
		
			for (var i=10;i>-1;i--)
				setTimeout("setOpacity("+i+",'top"+mId+"')",fader*i+faderWait);
				
		}
		openedMenu = mId;
		document.getElementById("m"+mId).className = "secili";		
		
	} else {
		
		if (document.getElementById("top"+mId) != null) {
			
			document.getElementById("top"+mId).style.display = "none";
			document.getElementById("m"+mId).className = "";
			openedMenu = "";
		}
	}
}

function menuSubSwitch(id) {

	var opened = false;
	if (document.getElementById("menu"+id+"Icon") != null)
	opened = (document.getElementById("menu"+id+"Icon").innerHTML == "-");
	
	if (!opened) {
	
		if(document.getElementById("menu"+id+"Icon") != null)
			document.getElementById("menu"+id+"Icon").innerHTML = "-";
		
		if(document.getElementById("menu"+id) != null)
			document.getElementById("menu"+id).style.display = "block";
			
		if(document.getElementById("menu"+id+"Btn") != null)	
			document.getElementById("menu"+id+"Btn").className = "secili";
	} else {
		
		document.getElementById("menu"+id+"Icon").innerHTML = "+";
		document.getElementById("menu"+id).style.display = "none";
		document.getElementById("menu"+id+"Btn").className = "";
	}
}

function menuClick(id) {
	
	if(document.getElementById("menu"+id+"Icon") != null)
		document.getElementById("menu"+id+"Icon").innerHTML = "-";
			
	if(document.getElementById("menu"+id+"Btn") != null)	
		document.getElementById("menu"+id+"Btn").className = "secili";
}

function setOpacity(value,div) {

	theDiv = document.getElementById(div);

	if (theDiv != null) {
		if(document.all) {
			theDiv.runtimeStyle.filter = "alpha(opacity=" + value*10 + ")";
		} else {
			theDiv.style.opacity = value/10;
		}
	}
	
	if (value==0)
		theDiv.style.display = "none";
	else
		theDiv.style.display = "block";
}

var mOld = "";
var mainContent = "";

function selectedMenu(mID,mID2,mID3,mID4,mFrom,mPic) {
	
	if ( mPic === undefined ) {
		mPic = '';
	}
	
	if ((mFrom != "") && (mOld != mFrom)) {
		
		document.getElementById('content').className = "contentContainer";
		
		menuClick(mFrom);
		
		if (mOld != "") {
			if(document.getElementById("menu"+mOld+"Icon") != null)
			document.getElementById("menu"+mOld+"Icon").innerHTML = "+";
			
			if(document.getElementById("menu"+mOld+"Btn") != null)
				document.getElementById("menu"+mOld+"Btn").className = "";
		}
		
		mOld = mFrom;
		
		document.getElementById('content').innerHTML == "İçerik Yükleniyor...";
		mainContent = mID;
		
		if ((mID == "1") && (mID3 != "4")) {
			document.getElementById('fotoContent').innerHTML = "<img src=\"content1/0"+mID2+"/kapak.jpg\">";
			
			if (lang == "_en")
				document.getElementById('fotoContent').innerHTML += "<br><a href=\"http://www.ideefixe.com/Kitap/tanim.asp?sid="+ideefixe[mID2]+"\" target=\"_blank\">buy</a>";
			else
				document.getElementById('fotoContent').innerHTML += "<br><a href=\"http://www.ideefixe.com/Kitap/tanim.asp?sid="+ideefixe[mID2]+"\" target=\"_blank\">satın al</a>";
		}
		else if (mPic != "")
			document.getElementById('fotoContent').innerHTML = "<img src=\"images/"+mPic+"\">";
		else
			document.getElementById('fotoContent').innerHTML = "";
			
		
		if ((mainContent == "1") || (mainContent == "2") || (mainContent == "3") || (mainContent == "5")) {
			document.getElementById('content').className = 'contentContainer';
			document.getElementById('content').style.padding = '';
		} else {
			document.getElementById('content').className = 'contentContainer noborder';
			document.getElementById('content').style.padding = '0px !important;';
		}
		
		if ((mID2 == "") && (mID3 == ""))
			loadXMLDoc('content'+mID+'/0'+mID4+'.html');
		else if ((mID2 != "") && (mID3 == ""))
			loadXMLDoc('content'+mID+'/0'+mID2+'/0'+mID4+'.html');
		else
			loadXMLDoc('content'+mID+'/0'+mID2+'/0'+mID3+'/0'+mID4+'.html');
			
	}
}

var xmlhttp;

function loadXMLDoc(url)
{
	
	if (xmlhttp != null) {
		xmlhttp.close;
		xmlhttp = null;
	}
	
	// mozilla
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
	}
	// ie
	else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function state_Change()
{

	if (!((window.xmlhttp === undefined) || (xmlhttp === undefined)))  {
		
		if (xmlhttp.readyState==4) {
		
			if (xmlhttp.status==200) {
			
				document.getElementById('content').innerHTML = xmlhttp.responseText;
				
				if ((mainContent == "1") || (mainContent == "2") ||(mainContent == "3")) { 
					document.getElementById('content').innerHTML += "<div class=\"tools\"><a href=\"javascript:printContent('content');\"><img src=\"images/print"+lang+".gif\"></a><a href=\"javascript:switchFont();\"><img src=\"images/fontsize.gif\"></a></div>";					
				}
				
				xmlhttp.close;
				xmlhttp = null;
			}
		}
	}

}

function switchFont() {
	
	var contentDiv = document.getElementById("content");
	
	if ((contentDiv.style.fontSize == "") || (contentDiv.style.fontSize == "15px"))
		contentDiv.style.fontSize = "17px";
	else
		contentDiv.style.fontSize = "15px";
}

function printContent(id) {
	
	str=document.getElementById(id).innerHTML;
	newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
	newwin.document.write('<HTML>\n<HEAD>\n')
	newwin.document.write('<TITLE>Print Page</TITLE>\n')
	newwin.document.write('<script>\n')
	newwin.document.write('function chkstate(){\n')
	newwin.document.write('if(document.readyState=="complete"){\n')
	newwin.document.write('window.close()\n')
	newwin.document.write('}\n')
	newwin.document.write('else{\n')
	newwin.document.write('setTimeout("chkstate()",2000)\n')
	newwin.document.write('}\n')
	newwin.document.write('}\n')
	newwin.document.write('function print_win(){\n')
	newwin.document.write('window.print();\n')
	newwin.document.write('chkstate();\n')
	newwin.document.write('}\n')
	newwin.document.write('<\/script>\n')
	newwin.document.write('</HEAD>\n')
	newwin.document.write('<BODY onload="print_win()">\n')
	newwin.document.write('<b>Hakan Bıçakcı - hakanbicakci.com</b><br><br>')
	newwin.document.write(str)
	newwin.document.write('</BODY>\n')
	newwin.document.write('</HTML>\n')
	newwin.document.close()
}