function overTable(obj){
	$(obj+' td').mouseover(function(){
		if($(this).parent().index() == 0){return false}
		$(this).parent().addClass('over');
		if($(this).index() > 1){
			var ni = $(this).index()+1;
			$('.rw td:nth-child('+ni+')').addClass('over');
		}
	});
	$(obj+' td').mouseout(function(){
		$(this).parent().removeClass('over');
		var ni = $(this).index()+1;
		$('.rw td:nth-child('+ni+')').removeClass('over');
	});
}

function tabControl(obj){
	var thisObj = this;
	this.tabLength = $(obj+' .tabNavigation li').length;
	this.oldTab = 0;
	
	$(obj+' .tabNavigation li a').click(function(){
		var id = $(this).parent().index();
		$(obj+' .tabNavigation li:eq('+thisObj.oldTab+')').removeClass('selected');
		$(obj+' .tabNavigation li:eq('+id+')').addClass('selected');
		$(obj+' .tabContent:eq('+thisObj.oldTab+')').removeClass('selectedTabContent');
		$(obj+' .tabContent:eq('+id+')').addClass('selectedTabContent');
		thisObj.oldTab = id;
		console.log(obj)
	});
	
}

function tableTab(obj){
	var thisObj = this;
	this.tabLength = $(obj+' .tabs li').length;
	this.oldTab = 0;
	$(obj).find('.tabs li a').click(function(){
		var id = $(this).parent().index();
		$(obj+' .tabs li:eq('+thisObj.oldTab+')').removeClass('selected');
		$(obj+' .tabs li:eq('+id+')').addClass('selected');
		
		$.get('/uygulama/lig/puanlar/' + id, function (result) {
			$(obj+' .contentBox').html(result);
			var mainOverTable = new overTable('.ptsTable');
		});
		
		thisObj.oldTab = id;
	});
}


function fiksTab(obj){
	var thisObj = this;
	this.tabLength = $(obj+' .tabs li').length;
	this.oldTab = 0;
	
	$(obj).find('.tabs li a').click(function(){
		var id = $(this).parent().index();
		$(obj+' .tabs li:eq('+thisObj.oldTab+')').removeClass('selected');
		$(obj+' .tabs li:eq('+id+')').addClass('selected');
		
		$.get('/uygulama/lig/fikstur/' + id, function (result) {
			$(obj+' .contentBox').html(result);
			var fixNav = new fixtureNav('.fixtureContainer');
		});
		
		thisObj.oldTab = id;
	});
}


function newsContentTools(){
	var thisObj = this
	this.defaultSize = 100;
	this.size = this.defaultSize;
	this.textArea = $('.newsText p, .newsText h1, .newsText h2, .newsText h3, .newsText h4, .newsText h5, .newsText h6, .newsText li');
	$('.textTools .up').click(function(){
		thisObj.size = thisObj.size+20;
		if(thisObj.size > 160)
		{
			thisObj.size = 160;
		}
		$(thisObj.textArea).css('font-size',thisObj.size+'%')
	});
	$('.textTools .down').click(function(){
		thisObj.size = thisObj.size-20;
		if(thisObj.size < 60)
		{
			thisObj.size = 60;
		}
		$(thisObj.textArea).css('font-size',thisObj.size+'%')
	});
	$('.textTools .normal').click(function(){
		thisObj.size = 100;
		$(thisObj.textArea).css('font-size',thisObj.size+'%')
	});
	$('.textTools .print').click(function(){
		window.print();
	});
	
}




function fixtureNav(obj){
	var thisObj = this;
	this.length = $(obj).find('.item').length;
	this.oldItem = 0;
	
	$(obj).find('.nav .forward').click(function(){
			if(thisObj.oldItem<thisObj.length-1){
				$(obj).find('.item:eq('+(thisObj.oldItem)+')').removeClass('selected');
				$(obj).find('.item:eq('+(thisObj.oldItem+1)+')').addClass('selected');
				thisObj.oldItem++;
			}
	});
	$(obj).find('.nav .backward').click(function(){
			if(thisObj.oldItem > 0){
				$(obj).find('.item:eq('+(thisObj.oldItem)+')').removeClass('selected');
				$(obj).find('.item:eq('+(thisObj.oldItem-1)+')').addClass('selected');
				thisObj.oldItem--;
			}
	});
	
}






$('document').ready(function(){
    
    var fixNav = new fixtureNav('.fixtureContainer');
	
	var nct = new newsContentTools();
	
	var tabWin1 = new tabControl('#tabWin1')
	var tabWin2 = new tabControl('#tabWin2')
	
	var ptsTableNav = new tableTab('#puanDurumu');
	var fixTabs = new fiksTab('#fixturTabs');
	
			var mainOverTable = new overTable('.ptsTable');
   function newsComments(obj) {
        var thisObj = this;
        this.expandObj = $('.news-comments .newComment .expand');
        this.textAreaObj = $('.news-comments .'+obj+' .textArea textarea');
        this.cancelNewCommentObj = $('.news-comments .newComment .expand .cancel');
		this.cancelReplyCommentObj = $('.news-comments .replyComment .expand .cancel');
        this.toolsObjs = $('.news-comments .commentItems li .tools');
        this.commentItemObj = $('.news-comments .commentItems li');
        this.charstatusObj = $('.news-comments .'+obj+' .charStatus span');
		

        this.defaultText = this.textAreaObj.html();

        this.toolsObjs.css('opacity', '0.35');
		if(obj == 'newComment'){
        	this.expandObj.css("display", "none");
		}
		if(obj == 'replyComment')
		{
			$('.'+obj).css('display','none');
		}
		


        $('.news-comments .newComment .textArea textarea').click(function () {
           	thisObj.expandObj.slideDown('fast');
			if(thisObj.textAreaObj.val() == thisObj.defaultText){
				thisObj.textAreaObj.val('');
			}
            
            thisObj.updateStatus();
        });

        this.cancelNewCommentObj.click(function () {
            thisObj.expandObj.slideUp('fast');
            thisObj.textAreaObj.val(thisObj.defaultText);
        });
		this.cancelReplyCommentObj.click(function () {
            $('#replyObj').slideUp('fast');
        });

        this.commentItemObj.mouseover(function () {
            $(this).find('.tools:first').stop().fadeTo('fast', 1);
            return false;
        });
        this.commentItemObj.mouseout(function () {

            $(this).find('.tools:first').stop().fadeTo('fast', 0.35);
            return false;
        });

        this.textAreaObj.keyup(function () {
            thisObj.updateStatus();
        });
        this.updateStatus = function () {
            // var remainChar = 500 - thisObj.textAreaObj.val().length;
             var remainChar = 500;            
            if (remainChar <= 0) {
                thisObj.charstatusObj.addClass('red');
            } else {
                thisObj.charstatusObj.removeClass('red');
            }
            thisObj.charstatusObj.html(remainChar);
        }
		
		
		this.initReplyButton = function()
		{
			$('.news-comments .commentItems li .reply a').each(function (index, value) {
				$(value).click(function () {
					var commentObj = $(this).parent().parent().parent();
					$('#replyObj').insertAfter($(commentObj));
					$('#replyObj').css('display','none');
					$('#replyObj').slideDown('fast');
				})
			});
		}

}
    
var newComment = new newsComments('newComment');
var replyComment = new newsComments('replyComment');
//site timer close
replyComment.initReplyButton();

});
function oyver()
{   
    formgonder($('form[name=anket]').serialize(), 'oyver', 'anket_sonuc');
}
function formgonder(seri, deger, yer)
{
	 $('#'+yer).html('<img src="/uygulama/tasarim/images/load.gif" />');
	 $.ajax({
	   type: 'POST',
	   url: '/rot/anket/'+deger+'/',
	   data: seri,
	   success: function(sonuc) {
		$('#'+yer).html(sonuc).show('slow');
	   }
	  });
	  return false;
}
function arama(yer)
{
    var deger = $('.'+yer).val();
    window.location = '/ara/?q='+deger;
}
function yeniPencere(URL, width, height) {
    width  = width  > 1 ? width : 500;
	height = height > 1 ? height: 275;
	aWindow=window.open(URL,"","toolbar=no,width="+width+",height="+height+",status=no,scrollbars=yes,resize=no,menubars=no");
}
function anasayfaYap() {
	if (document.all)  {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.oyunskor.com/');
	} else if (window.sidebar) {
		if(window.netscape) {
			try {  
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}  
			catch(e) {  
				alert("tarayıcı desteklemiyor..");  
			}
		} 
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage','http://www.oyunskor.com/');
	}
}
/*
function sonuclar(){$.ajax({type: 'GET',url: '/canlisonuclar/sonuclar',data: '',success: function(sonuc) {$('#canlisonuclar').html(sonuc).show('slow');}}); setTimeout("sonuclar()", 60000); return false; }
function bitenler(){$('#canlisonuclar').html('<img src="/uygulama/tasarim/images/load.gif" />'); $.ajax({type: 'GET',url: '/canlisonuclar/bitti',data: '',success: function(sonuc) {$('#canlisonuclar').html(sonuc).show('slow');}}); setTimeout("bitenler()", 60000); return false; }
*/
function sikKullanilan() {
    title   = document.title;
    url     = location.href;
    
    if (window.sidebar) { 
        // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"");
    } else if( window.external ) {  // IE Favorite
        window.external.AddFavorite( url, title);
    }
    else if(window.opera && window.print) {  // Opera Hotlist
        return true; 
    }
}

var simdi = 0;
var git = 0;
function mac_ileri()
{
	if(simdi == 8)
	{
		git = 1;
	} else {
		git = simdi + 1;
	}
	
	$('.maclar').hide();
	$('.mac'+git).fadeIn(400);
	
	simdi = git;
}

function mac_geri()
{
	if(simdi == 0)
	{
		git = 8;
	} else {
		git = simdi - 1;
	}
	
	$('.maclar').hide();
	$('.mac'+git).fadeIn(400);
	
	simdi = git;
}
function canliSonuclar(tarih)
{
	if(tarih == "")
	{
		$.get('/uygulama/macsonuclari.php', {}, function(cevap){$('#MacSonuclari').html(cevap)});
	} else 
	{
		$.get('/uygulama/macsonuclari.php', {tarih:tarih}, function(cevap){$('#MacSonuclari').html(cevap)});
	}
}
function macbilgi(ID)
{
	$.getJSON('/uygulama/macbilgi.php?mID='+ID, function(veri){
	var eh = '';
	var dp = '';
	var dk = '';
	var cikti= '';
	var bilgiler = veri;
	   $.each(bilgiler, function(i, bilgi){
			if(bilgi.yer == 1)
			{ eh = eh + bilgi.isim +'<br>'; dp = dp + '-<br>'; } else { dp = dp + bilgi.isim+'<br>'; eh = eh + '-<br>'; }
			dk = dk + bilgi.dk + '<br>';
	  });
	  $('#macBilgiDk'+ID).html(dk);
	  $('#macBilgiEs'+ID).html(eh);
	  $('#macBilgiDp'+ID).html(dp);
	  $('#macBilgi'+ID).toggle();
	});
}
//setInterval("mac_ileri()", 4000); 

