var X;
var Y;

if (window.attachEvent)
{
    document.attachEvent("onmousemove",MouseMv);
}
else
{
    document.addEventListener("mousemove",MouseMv,false);
}

function MouseMv(e) {
if (!e) e = window.event;

if (typeof e.pageY == "number"){
	//firefox
  X = e.pageX;
  Y = e.pageY;
}
else{
  X = e.clientX;
  Y = e.clientY;
}

}

var t;
var x = 100;
var y = 100;
var q = 5;
var show = 0;


var maxleft;
var minleft;
var q2;
var l;

var maxtop;
var mintop;
var q3;
var l3;

function increaseWidth(){
 if(x==344){
    x=100;
    return;
 }

 q=40;

 x=x+q;
 if(x > 344)
	x = 344;

 l = l + q2;
 l3 = l3 + q3;
 if(l3 < maxtop) {
	if(document.getElementById('popup_turuncu_border').clientHeight > 400)
		l3 = maxtop - 70;
	else
		l3 = maxtop;
 }

 var e=document.getElementById('popup_turuncu_border');
 e.style.width = x + 'px';
 document.getElementById('popup_sag_golge').style.width = x + 2 + 'px';
 document.getElementById('popup_alt_golge').style.width = x + 2 + 'px';
 document.getElementById('popup_alt_golge').style.height = document.getElementById('popup_turuncu_border').clientHeight + 2 + 'px';
 document.getElementById('help_popup').style.left = l + 'px';
 document.getElementById('help_popup').style.top = l3 + 'px';
 t=setTimeout("increaseWidth();",0);
}

function decreaseWidth(){
 if(x<0){
    x=100;
	sakla();
    return;
 }
 q=10;
 x=x-q;
 var e=document.getElementById('help_popup');

 e.style.width = x + 'px';
 t=setTimeout("decreaseWidth();",0);
}

function show_help(faqId) {
	var url = '/getHelp';
	new Ajax.Request(url,
            {
               method:'post',
               parameters: {
                  faqId: faqId
               },
               onSuccess: function(transport) {
					document.getElementById('helpContent').innerHTML = transport.responseText;
					minleft = X;
					mintop = Y;
					var browse = document.getElementById('help_popup');
					maxleft = (document.body.offsetWidth<screen.width) ?
				((screen.width - 344) / 2) : ((document.body.offsetWidth - 344) / 2);
					
					if(BrowserDetect.browser == 'Explorer') {
						maxtop = 100 + document.documentElement.scrollTop;
						mintop = mintop + document.documentElement.scrollTop;
					}
					else
						maxtop = 100 + window.pageYOffset;
					
					q2 = (maxleft - minleft) / 6;
					q3 = (maxtop - mintop) / 6;
					browse.style.left = minleft + 'px';
					browse.style.top = mintop + 'px';
					l = minleft;
					l3 = mintop;
					browse.style.display = 'block';

					increaseWidth();
               },
               onFailure: function() {
               }
            });
}

function checkChars(ta, L) {
	var len = ta.value.length;
	if (len > L) {
		ta.value = ta.value.substring(0, L);
		return;
	}
}

function hide_help() {

	var browse = document.getElementById('help_popup');
	browse.style.display = 'none';
}

function showCourseSubtitle(div, name, index) {
	
	document.getElementById(div).className = "menu_sel";
	if (document.getElementById(div).childNodes.length > 5)	
		document.getElementById(div).childNodes[5].style.display = "";	
	else	
		document.getElementById(div).childNodes[2].style.display = "";

	document.getElementById(name + '_ust_' + index).style.display = 'block';
	document.getElementById(name + '_alt_' + index).style.display = 'block';

	document.getElementById(name + '_img_' + index).style.marginTop = '0px';
}

function hideCourseSubtitle(div, name, index) {
	document.getElementById(div).className = "menu_norm";
	if (document.getElementById(div).childNodes.length > 5)	
		document.getElementById(div).childNodes[5].style.display = "none";	
	else	
		document.getElementById(div).childNodes[2].style.display = "none";

	document.getElementById(name + '_ust_' + index).style.display = 'none';
	document.getElementById(name + '_alt_' + index).style.display = 'none';

	document.getElementById(name + '_img_' + index).style.marginTop = '8px';
}

function replaceAll(source, oldVal, newVal) {
   var intIndexOfMatch = source.indexOf(oldVal);

   while (intIndexOfMatch != -1){
      source = source.replace(oldVal,newVal);
      intIndexOfMatch = source.indexOf(oldVal);
   }

   return source;
}

var thread_id = 0;
var lastId = -1;

function activate(id){
	if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6) {
		document.getElementById('act' + id).style.zIndex = '10';
		document.getElementById('pas' + id).style.zIndex = '8';
		thread_id += 1;
		lastId = id;
	}
	else {
		menu('img' + id,'/images/172_playbutton.png');
	}
}

function passivate(id){
	if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version == 6) {
		setTimeout('passifet(' + thread_id + ', ' + id + ', ' + lastId + ')', 100);
	}
	else {
		menu('img' + id,'/images/172_playbutton_pasif.png');
	}
}

function passifet(thread, id, last) {
	if(thread_id == thread) {
		document.getElementById('act' + id).style.zIndex = '8';
		document.getElementById('pas' + id).style.zIndex = '10';
	}
	else if(lastId != last) {
		document.getElementById('act' + id).style.zIndex = '8';
		document.getElementById('pas' + id).style.zIndex = '10';
	}
}

function menu(id,resim){ 
	document.getElementById(id).src=resim; 
}

function ede(id,resim){ 
	document.getElementById(id).style.background="url("+resim+")";
}

var nav_tracker = 0;
function showNavPopup() {
	nav_tracker += 1;
	document.getElementById('nav_popup').style.display = 'block';
}

function hideNavPopup() {
	setTimeout("hideDiv(" + nav_tracker + ")", 1000);
}

function hideDiv(id) {
	if(id == nav_tracker)
		document.getElementById("nav_popup").style.display = 'none';
}

function getHttpRequest() {
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var progIds = ['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0']
		var success = false;
		for (var iterator = 0; (iterator < progIds.length) && ( ! success); iterator ++) {
			try {
				xmlHttp = new ActiveXObject(progIds[iterator]);
				success = true;
			} catch (e) {
			}
		}
		if (! success) {
			return null;
		}
	}
	return xmlHttp;
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version < 7) && (document.body.filters))
   {
	   
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG" || imgName.substring(imgName.length-3, imgName.length) == "png")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();
