// JavaScript Document

function popup(url, w, h) 
{
	window.open(url, '', 'toolbar=0, scrollbars=0, location=0, statusbar=0, menubar=0, resizable=1, width='+ w +', height='+ h +', left=250, top=150');
}

function show_news(href, img, brief)
{	
	var div = document.getElementById("part_4"); 
	div.childNodes[0].href = href; // img href
	div.childNodes[0].childNodes[0].src = img; // img src 
	div.childNodes[1].childNodes[0].href = href; // brief href 
	div.childNodes[1].childNodes[0].innerHTML = brief; 
}

function show_writer(href, name, title, img, date)
{
	document.getElementById("name").innerHTML = name; 
	document.getElementById("img").childNodes[0].src = img; 
	document.getElementById("date").innerHTML = date; 
	document.getElementById("title").innerHTML = '<a href="'+ href +'" target="_blank">'+ title +'</a>'; 
}

/* http://webfx.eae.net */

// This function is used to define if the browser supports the needed
// features
function hasSupport() {

	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;
	
	var ie55 = /msie 5\.[56789]/i.test(navigator.userAgent);
	
	hasSupport.support = (typeof document.implementation != "undefined" &&
			document.implementation.hasFeature("html", "1.0") || ie55)
			
	// IE55 has a serious DOM1 bug... Patch it!
	if (ie55) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function (sTagName) {
			if (sTagName == "*")
				return document.all;
			else
				return document._getElementsByTagName(sTagName);
		};
	}

	return hasSupport.support;
}

// The constructor for tab panes
//
// el : HTMLElement		The html element used to represent the tab pane
// bUseCookie : Boolean	Optional. Default is true. Used to determine whether to us
//						persistance using cookies or not
//
function WebFXTabPane(el, bUseCookie) {
	if (!hasSupport() || el == null) return;
	
	this.element = el;
	this.element.tabPane = this;
	this.pages = [];
	this.selectedIndex = null;
	this.useCookie = bUseCookie != null ? bUseCookie : true;
	
	// add class name tag to class name
	this.element.className = this.classNameTag + " " + this.element.className;
	
	// add tab row
	this.tabRow = document.createElement("div");
	this.tabRow.className = "tab-row";
	el.insertBefore(this.tabRow, el.firstChild);

	var tabIndex = 0;
	if (this.useCookie) {
		tabIndex = Number(WebFXTabPane.getCookie("webfxtab_" + this.element.id));
		if (isNaN(tabIndex))
			tabIndex = 0;
	}
	this.selectedIndex = tabIndex;
	
	// loop through child nodes and add them
	var cs = el.childNodes;
	var n;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab-page") {
			this.addTabPage(cs[i]);
		}
	}
}

WebFXTabPane.prototype.classNameTag = "dynamic-tab-pane-control";

WebFXTabPane.prototype.setSelectedIndex = function (n) {
	if (this.selectedIndex != n) {
		if (this.selectedIndex != null && this.pages[ this.selectedIndex ] != null)
			this.pages[ this.selectedIndex ].hide();
		this.selectedIndex = n;
		this.pages[ this.selectedIndex ].show();
		
		if (this.useCookie)
			WebFXTabPane.setCookie("webfxtab_" + this.element.id, n);	// session cookie
	}
};
	
WebFXTabPane.prototype.getSelectedIndex = function () {
	return this.selectedIndex;
};
	
WebFXTabPane.prototype.addTabPage = function (oElement) {
	if (!hasSupport()) return;
	
	if (oElement.tabPage == this)	// already added
		return oElement.tabPage;

	var n = this.pages.length;
	var tp = this.pages[n] = new WebFXTabPage(oElement, this, n);
	tp.tabPane = this;
	
	// move the tab out of the box
	this.tabRow.appendChild(tp.tab);
			
	if (n == this.selectedIndex)
		tp.show();
	else
		tp.hide();
		
	return tp;
};
	
WebFXTabPane.prototype.dispose = function () {
	this.element.tabPane = null;
	this.element = null;		
	this.tabRow = null;
	
	for (var i = 0; i < this.pages.length; i++) {
		this.pages[i].dispose();
		this.pages[i] = null;
	}
	this.pages = null;
};

// Cookie handling
WebFXTabPane.setCookie = function (sName, sValue, nDays) {
	var expires = "";
	if (nDays) {
		var d = new Date();
		d.setTime(d.getTime() + nDays * 24 * 60 * 60 * 1000);
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};

WebFXTabPane.getCookie = function (sName) {
	var re = new RegExp("(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)");
	var res = re.exec(document.cookie);
	return res != null ? res[3] : null;
};

WebFXTabPane.removeCookie = function (name) {
	setCookie(name, "", -1);
};

// The constructor for tab pages. This one should not be used.
// Use WebFXTabPage.addTabPage instead
//
// el : HTMLElement			The html element used to represent the tab pane
// tabPane : WebFXTabPane	The parent tab pane
// nindex :	Number			The index of the page in the parent pane page array
//
function WebFXTabPage(el, tabPane, nIndex) {
	if (!hasSupport() || el == null) return;
	
	this.element = el;
	this.element.tabPage = this;
	this.index = nIndex;
	
	var cs = el.childNodes;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1) {
			this.tab = cs[i];
			break;
		}
	}
	
	// insert a tag around content to support keyboard navigation
	
	var a = document.createElement("A");
	this.aElement = a;
	a.href = "#";
	a.onclick = function () { return false; };
	while (this.tab.hasChildNodes())
		a.appendChild(this.tab.firstChild);
	this.tab.appendChild(a);
	
	// hook up events, using DOM0
	var oThis = this;
	this.tab.onclick = function () { oThis.select(); };
	this.tab.onmouseover = function () { WebFXTabPage.tabOver(oThis); };
	this.tab.onmouseout = function () { WebFXTabPage.tabOut(oThis); };
}

WebFXTabPage.prototype.show = function () {
	var el = this.tab;
	var s = el.className + " selected";
	s = s.replace(/ +/g, " ");
	el.className = s;
	
	this.element.style.display = "block";
};

WebFXTabPage.prototype.hide = function () {
	var el = this.tab;
	var s = el.className;
	s = s.replace(/ selected/g, "");
	el.className = s;

	this.element.style.display = "none";
};
	
WebFXTabPage.prototype.select = function () {
	this.tabPane.setSelectedIndex(this.index);
};
	
WebFXTabPage.prototype.dispose = function () {
	this.aElement.onclick = null;
	this.aElement = null;
	this.element.tabPage = null;
	this.tab.onclick = null;
	this.tab.onmouseover = null;
	this.tab.onmouseout = null;
	this.tab = null;
	this.tabPane = null;
	this.element = null;
};

WebFXTabPage.tabOver = function (tabpage) {
	var el = tabpage.tab;
	var s = el.className + " hover";
	s = s.replace(/ +/g, " ");
	el.className = s;
};

WebFXTabPage.tabOut = function (tabpage) {
	var el = tabpage.tab;
	var s = el.className;
	s = s.replace(/ hover/g, "");
	el.className = s;
};

// This function initializes all uninitialized tab panes and tab pages
function setupAllTabs() {
	if (!hasSupport()) return;

	var all = document.getElementsByTagName("*");
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var tabPageRe = /tab\-page/;
	var cn, el;
	var parentTabPane;
	
	for (var i = 0; i < l; i++) {
		el = all[i]
		cn = el.className;

		// no className
		if (cn == "") continue;
		
		// uninitiated tab pane
		if (tabPaneRe.test(cn) && !el.tabPane)
			new WebFXTabPane(el);
	
		// unitiated tab page wit a valid tab pane parent
		else if (tabPageRe.test(cn) && !el.tabPage &&
					tabPaneRe.test(el.parentNode.className)) {
			el.parentNode.tabPane.addTabPage(el);			
		}
	}
}

function disposeAllTabs() {
	if (!hasSupport()) return;
	
	var all = document.getElementsByTagName("*");
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var cn, el;
	var tabPanes = [];
	
	for (var i = 0; i < l; i++) {
		el = all[i]
		cn = el.className;

		// no className
		if (cn == "") continue;
		
		// tab pane
		if (tabPaneRe.test(cn) && el.tabPane)
			tabPanes[tabPanes.length] = el.tabPane;
	}
	
	for (var i = tabPanes.length - 1; i >= 0; i--) {
		tabPanes[i].dispose();
		tabPanes[i] = null;
	}
}
/*
// initialization hook up
// DOM2
if (typeof window.addEventListener != "undefined")
	window.addEventListener("load", setupAllTabs, false);
// IE 
else if (typeof window.attachEvent != "undefined") {
	window.attachEvent("onload", setupAllTabs);
	window.attachEvent("onunload", disposeAllTabs);
}
else {
	if (window.onload != null) {
		var oldOnload = window.onload;
		window.onload = function (e) {
			oldOnload(e);
			setupAllTabs();
		};
	}
	else 
		window.onload = setupAllTabs;
}
*/

 http://www.realmedya.com

function CM_galeri_slider(cmz_no)
{	
	this.recordCount = 0;	
	this.elm = null;
	this.current = 0;
	this.direction = -1;
	this.itemWidth = 0;
	this.visibleCount = 0;
	this.firstSlide = true;
	this.stepTime = 60;
	this.stepCount = 10;
	this.stepAmount = 0;
	this.stepIndex = 0;
	this.totalWidth = 0;
	this.lastestLeft = 0;
	this._automaticStepTime = 5000;
	this._automaticTimer = null;
	this.timerIndex = null;
	this._start = _start;
	this._action = _action;
	this._clear = _clear;
	this._go = _go;
	this.go = go;
	this._automatic = _automatic;
	this._clearAutomaticTimer = _clearAutomaticTimer;
	this._checkStatus = _checkStatus;
	
	function _start()
	{
		if(!this.elm)
			return false;
		
		tmp = this.elm.getElementsByTagName('div');

		for(i = 0; i<tmp.length; i++) {
			if(tmp[i].className == (cmz_no + '_slider_item')) {
				this.recordCount += 1;
				this.itemWidth = tmp[i].offsetWidth; // alert(this.itemWidth);
			}
		}
		
		this.visibleCount = parseInt(this.elm.offsetWidth / this.itemWidth) * 1;
		this.totalWidth = this.itemWidth * this.recordCount;
		this.stepAmount = parseInt(this.itemWidth / this.stepCount);
		this.lastestLeft = document.getElementById(cmz_no + "_item_" + (this.recordCount - 1)).offsetLeft;
	}
	
	function _action()
	{
		if(!this.recordCount)
			return false;
		else if(this.visibleCount >= this.recordCount)
			return false;
		
		this._automatic();
	//	this._go();
	}
	
	function _go()
	{
		this.stepIndex++;
		
		if(this.stepIndex == this.stepCount) {
			_step = this.itemWidth - (this.stepCount * this.stepAmount) + this.stepAmount;
		//	alert(_step);
		//	alert(this.itemWidth + ' - (' + this.stepCount + ' * ' + this.stepAmount + ') + ' + this.stepAmount);
		}
		else {
			_step = this.stepAmount;
		}
		
		for(i = 0; i < this.recordCount; i++) {
			tmp = document.getElementById(cmz_no + "_item_" + i).offsetLeft + _step * this.direction;
			if(tmp > this.lastestLeft)
				tmp = _step - this.itemWidth;
			document.getElementById(cmz_no + "_item_" + i).style.left = tmp + "px";
		}
		
		if(this.stepIndex == this.stepCount) {
			this._clear();
		}
		else {
			this.timerIndex = setTimeout(cmz_no + "._go();", this.stepTime);
		}
	}
	
	function go(direction,automatic) 
	{
		if(!automatic)
			this._clearAutomaticTimer(); // Kaydirma islemini durdur
		
		if(this.current + direction > 0)
			return false;
		
		if((this.recordCount - this.visibleCount) < Math.abs(this.current + direction))
			return false;

		this.direction = direction;
		this.current += direction;
		this._go();		
	}
	
	function _clear()
	{
		this.stepIndex = 0;
		
		if(this.timerIndex != null)
			clearTimeout(this.timerIndex);
		this.timerIndex = null;
	}
	
	function _clearAutomaticTimer()
	{
		if (this._automaticTimer != null)
			clearTimeout(this._automaticTimer);
		this._automaticTimer = null;		
	}
	
	function _automatic() 
	{
		if(this.firstSlide) {
			var temp = setTimeout("this.go(this.direction,1)", this._automaticStepTime);
			clearTimeout(temp);
			this.firstSlide = false;
		}
		else {
			this._checkStatus();
			this.go(this.direction, 1);
		}
		this._automaticTimer = setTimeout(cmz_no + "._automatic();", this._automaticStepTime);
	}
	
	function _checkStatus()
	{
		var index = this.recordCount - this.visibleCount;
		
		if(this.current == -(index))
			this.direction = 1;
		else if(this.current == 0)
			this.direction = -1;	
	}
}
