
var sendeajaxsekmeayarlari={}
sendeajaxsekmeayarlari.bustcachevar=1  //bust potential caching of external pages after initial request? (1=yes, 0=no)
sendeajaxsekmeayarlari.loadstatustext="<br><br><br><center><img src='resimler/listeyukleniyor.gif'><font face='tahoma, arial, helvetica, sans-serif' size='2px'><b>&nbsp;&nbsp;Liste y&#252kleniyor...</b></font></center>" 



function sendeajaxsekmeler(sekmetipno, iceriktipno){
	this.sekmetipno=sekmetipno //ID of Tab Menu main container
	this.tabs=document.getElementById(sekmetipno).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.iceriktipno=iceriktipno
	this.gecerliHTML=""
	this.GecerliIframe='<iframe src="about:blank" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" class="tabcontentiframe" style="width:100%; height:auto; min-height: 100px"></iframe>'
	this.GecerliIframe=this.GecerliIframe.replace(/<iframe/i, '<iframe name="'+"_ddajaxtabsiframe-"+iceriktipno+'" ')
this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

sendeajaxsekmeler.connect=function(sayfalinki, sekmedurumu){
	var sayfadan_gelen = false
	var parametreduzelt=""
	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
		try {
		sayfadan_gelen = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e){
			try{
			sayfadan_gelen = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
		sayfadan_gelen = new XMLHttpRequest()
	else
		return false
	var ajaxlinkkontrolu=sayfalinki.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
	sayfadan_gelen.onreadystatechange=function(){sendeajaxsekmeler.loadpage(sayfadan_gelen, sayfalinki, sekmedurumu)}
	if (sendeajaxsekmeayarlari.bustcachevar) //if bust caching of external page
		parametreduzelt=(ajaxlinkkontrolu.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	sayfadan_gelen.open('GET', ajaxlinkkontrolu+parametreduzelt, true)
	sayfadan_gelen.send(null)
}

sendeajaxsekmeler.loadpage=function(sayfadan_gelen, sayfalinki, sekmedurumu){
	var divId=sekmedurumu.iceriktipno
	document.getElementById(divId).innerHTML=sendeajaxsekmeayarlari.loadstatustext //Display "fetching page message"
	if (sayfadan_gelen.readyState == 4 && (sayfadan_gelen.status==200 || window.location.href.indexOf("http")==-1)){
		document.getElementById(divId).innerHTML=sayfadan_gelen.responseText
		sendeajaxsekmeler.ajaxpageloadaction(sayfalinki, sekmedurumu)
	}
}

sendeajaxsekmeler.ajaxpageloadaction=function(sayfalinki, sekmedurumu){
	sekmedurumu.onajaxpageload(sayfalinki) //call user customized onajaxpageload() function when an ajax page is fetched/ loaded
}

sendeajaxsekmeler.getCookie=function(isim){ 
	var re=new RegExp(isim+"=[^;]+", "i"); //construct RE to search for target isim/deger pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its deger
	return ""
}

sendeajaxsekmeler.setCookie=function(isim, deger){
	document.cookie = isim+"="+deger+";path=/" //cookie deger is domain wide (path=/)
}

sendeajaxsekmeler.prototype={

	expandit:function(sekmeno_pozisyon){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.calistirma() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof sekmeno_pozisyon=="string" && document.getElementById(sekmeno_pozisyon).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(sekmeno_pozisyon)
			else if (parseInt(sekmeno_pozisyon)!=NaN && this.tabs[sekmeno_pozisyon].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[sekmeno_pozisyon]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, calistir){ //PUBLIC function to move foward or backwards through each hot tab (sekmedurumu.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof calistir=="undefined") //if cycleit() is being called by user, versus calistir() function
			this.calistirma() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	loadajaxpage:function(sayfalinki){ //PUBLIC function to fetch a page via Ajax and display it within the Tab Content instance's container
		sendeajaxsekmeler.connect(sayfalinki, this)
	},

	loadiframepage:function(sayfalinki){ //PUBLIC function to fetch a page and load it into the IFRAME of the Tab Content instance's container
		this.iframegosterim(sayfalinki, this.iceriktipno)
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	linkdegsecim:function(sekmetipno){
		var result=window.location.search.match(new RegExp(sekmetipno+"=(\\d+)", "i")) //check for "?sekmetipno=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	onajaxpageload:function(sayfalinki){ //PUBLIC Event handler that can invoke custom code whenever an Ajax page has been fetched and displayed
		//do nothing by default
	},

	expandtab:function(tabref){
		var relattrdegeri=tabref.getAttribute("rel")
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easy searching through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		if (relattrdegeri=="#default")
			document.getElementById(this.iceriktipno).innerHTML=this.gecerliHTML
		else if (relattrdegeri=="#iframe")
			this.iframegosterim(tabref.getAttribute("href"), this.iceriktipno)
		else
			sendeajaxsekmeler.connect(tabref.getAttribute("href"), this)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("href")==tabref.getAttribute("href"))? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			sendeajaxsekmeler.setCookie(this.sekmetipno, tabref.sekmepozisyonu)
		this.setcurrenttabindex(tabref.sekmepozisyonu) //remember position of selected tab within hottabspositions[] array
	},

	iframegosterim:function(sayfalinki, iceriktipno){
		if (typeof window.frames["_ddajaxtabsiframe-"+iceriktipno]!="undefined"){
			try{delete window.frames["_ddajaxtabsiframe-"+iceriktipno]} //delete iframe within Tab content container if it exists (due to bug in Firefox)
			catch(err){}
		}
		document.getElementById(iceriktipno).innerHTML=this.GecerliIframe
		window.frames["_ddajaxtabsiframe-"+iceriktipno].location.replace(sayfalinki) //load desired page into iframe
	},


	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(sekmepozisyonu){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (sekmepozisyonu==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	calistir:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	calistirma:function(){
		if (typeof this.calistirmazamani!="undefined")
			TemizlemeSuresi(this.calistirmazamani)
	},

	init:function(calistirmaperiyodu){
		var persistedtab=sendeajaxsekmeler.getCookie(this.sekmetipno) //get position of persisted tab (applicable if persistence is enabled)
		var secilisekme=-1 //Currently selected tab index (-1 meaning none)
		var linktensecilisekme=this.linkdegsecim(this.sekmetipno) //returns null or index from: tabcontent.htm?sekmetipno=index
		this.calistirmaperiyodu=calistirmaperiyodu || 0
		this.gecerliHTML=document.getElementById(this.iceriktipno).innerHTML
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].sekmepozisyonu=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var sekmedurumu=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.tabs[i].onclick=function(){
					sekmedurumu.expandtab(this)
					sekmedurumu.calistirma() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each deger within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (linktensecilisekme==i || this.enabletabpersistence && secilisekme==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && secilisekme==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					secilisekme=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (secilisekme!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[secilisekme]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.calistirmaperiyodu)>500 && this.hottabspositions.length>1){
			this.calistirmazamani=setInterval(function(){sekmedurumu.calistir()}, this.calistirmaperiyodu)
		}
	} //END int() function

} //END Prototype assignment