function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function handleExternals() {
    var a = document.getElementsByTagName('a');
    for (var i = 0; i < a.length; i++) {
        if (a[i].rel == 'external') {
            a[i].target = '_blank';
        }
    }
}

function isMSIE() {
	if(navigator.appName != 'Microsoft Internet Explorer') {
		return false;
	}
}

function isMSIE6() {
	if(!isMSIE()) {
		return false;
	}

	var ua = navigator.userAgent;
	var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if (re.exec(ua) == null) {
		return false;
	}

	return parseFloat(RegExp.$1) == 6;
}

function expandAd(slot, width, height) {
    var ad = document.getElementById('ad' + slot);
    ad.width = width;
    ad.height = height;
}

function createAdFrame(container, slot, width, height) {
    var obj = document.createElement("iframe");
    obj.setAttribute('id', 'ad' + slot);
    obj.setAttribute('width', 0);
    obj.setAttribute('height', 0);
    obj.setAttribute('frameborder', 0);
    obj.setAttribute('marginheight', 0);
    obj.setAttribute('marginwidth', 0);
    obj.setAttribute('scrolling', 'no');
    obj.setAttribute('border', '0');
    obj.setAttribute('allowTransparency', "true");
    obj.style.border = 'none';
    obj = document.getElementById(container).appendChild(obj);

    addLoadEvent(function() {
        obj.setAttribute('src', '/ad.jsp?slot=' + slot + '&width=' + width + '&height=' + height);
    });
}

function showAd(slot) {
    document.write('<scr' + 'ipt type="text/javascript">' +
        'GA_googleAddSlot("ca-pub-8488825407587998", "' + slot + '");' +
        'GA_googleFetchAds();' +
        '</sc' + 'ript>');
    document.write('<scr' + 'ipt type="text/javascript">' +
        'GA_googleFillSlot("' + slot + '");' +
        '</sc' + 'ript>');
}

function moveAd(container, locator) {
    var adContainer = document.getElementById(container);
    var adLocator = document.getElementById(locator);
    adContainer.appendChild(adLocator);
    adLocator.style.display='';
}

function TabView(id) {
    this.view = document.getElementById(id);
    this.tabs = this.view.getElementsByTagName('li');
    this.selectTimer = null;
    this.nextTimer = null;

    for (var i = 0; i < this.tabs.length; i++) {
        var tab = this.tabs[i];
        var links = tab.getElementsByTagName('a');
        for (var j = 0; j < links.length; j++) {
            this.initLink(tab, links[j]);
        }
    }

    // todo seçili olan olmalı 0 değil
    this.scheduleNext(this.tabs[0]);
}

TabView.prototype = {
    initLink:function(tab, link) {
        var instance = this;
        link.onmouseover = function() {
            instance.cancelSelect();
            this.selectTimer = setTimeout(function() {
                instance.select(tab);
            }, 100);
        };

        link.onmouseout = this.cancelSelect;
    },

    // todo this.tabs[i].getElementsByTagName('a')[0] 
    select:function(tab) {
        for (var i = 0; i < this.tabs.length; i++) {
            if (/selected/.test(this.tabs[i].className)) {
                this.tabs[i].className = this.tabs[i].className.replace(/selected/gi, '');
                document.getElementById(this.tabs[i].getElementsByTagName('a')[0].rel).style.display = 'none';
                break;
            }
        }

        tab.className += ' selected';
        document.getElementById(tab.getElementsByTagName('a')[0].rel).style.display = 'block';

        this.scheduleNext(tab);
    },

    cancelSelect:function() {
        if (this.selectTimer != null) {
            window.clearTimeout(this.selectTimer);
            this.selectTimer = null;
        }
    },

    scheduleNext:function(tab) {
        this.cancelNext();
        for (var i = 0; i < this.tabs.length; i++) {
            if (tab == this.tabs[i]) {
                tab = this.tabs[(i + 1) % this.tabs.length];
                break;
            }
        }

        var instance = this;
        this.nextTimer = setTimeout(function() {
            instance.select(tab);
        }, 7500);
    },

    cancelNext:function() {
        if (this.nextTimer != null) {
            window.clearTimeout(this.nextTimer);
            this.nextTimer = null;
        }
    }
};

handleExternals();