﻿$(document).ready(function(){
$('#checkbox').click(function() {
$.ajax({
   type: "POST",
   url: "index.php",
   data: "cfilter="+$('#checkbox').val(),
   success: function(msg){
      if($('#filtre').serialize() == 'cfilter=On'){
		   	   alert("Aile Filtresi Açılmıştır.");
	  }else{
	  	       alert('Aile Filtresi Kapanmıştır.');
	  }
   window.location.reload();
   }
 });
});

$('#cbutton').click(function(){
$('#load').show();
$.ajax({
   dataType: "json",
   type: "POST",
   url: "jsons/comment.php",
   data: $('#comment').serialize(),
   success: function(JSON){
   $('.cerr').empty();
   $('#commentwrap .content').css('height','300');
   $('#load').hide();
   if(JSON.errors != null){
$.each(JSON.errors, function(index, value) {
  $('#'+index).append(value);
});
   }else{
   $('#comment').hide();
   $('#success').empty();
   $('#success').append('Yorumunuz başarıyla gönderilmiştir.');
   $('#success').show();
   setTimeout('resetForm(\'comment\');new_captcha();$(\'#success\').hide();$(\'#comment\').show();',3000);
   }
   }
 });

});

$('#contactbtn').click(function(){
$('#load').show();
$.ajax({
   dataType: "json",
   type: "POST",
   url: "jsons/contact.php",
   data: $('#contact').serialize(),
   success: function(JSON){
   $('.cerr').empty();
   $('#load').hide();
   if(JSON.errors != null){
$.each(JSON.errors, function(index, value) {
  $('#'+index).append(value);
});
$('#conerrors').show();
   }else{
   $('#contact').hide();
$('#conerrors').hide().empty();
   $('#conerrors').empty();
   $('#conerrors').append('İletiniz başarıyla gönderilmiştir.');
   $('#conerrors').show();
   }
   }
 });

});


$('#rpbutton').click(function(){
$('#rpload').show();
$.ajax({
   dataType: "json",
   type: "POST",
   url: "jsons/report.php",
   data: $('#reportform').serialize(),
   success: function(JSON){
   $('.rpcerr').empty();
   $('#rpload').hide();
   if(JSON.errors != null){
$.each(JSON.errors, function(index, value) {
  $('#'+index).append(value);
});
   }else{
   $('#reportform').hide();
   $('#rpsuccess').empty();
   $('#rpsuccess').append('Şikayetiniz başarıyla gönderilmiştir.');
   $('#rpsuccess').show();
   setTimeout('$.fancybox.close();',2000);
   }
   }
 });

});
$('.rate_widget').each(function(i) {
            var widget = this;
            var out_data = {
                widget_id : $(widget).attr('id'),
                fetch: 1
            };
            $.post(
                'rate.php',
                out_data,
                function(INFO) {
                    $(widget).data( 'fsr', INFO );
                    set_votes(widget);
                },
                'json'
            );
        });


        $('.ratings_stars').hover(
            // Handles the mouseover
            function() {
                $(this).prevAll().andSelf().addClass('ratings_over');
                $(this).nextAll().removeClass('ratings_vote');
            },
            // Handles the mouseout
            function() {
                $(this).prevAll().andSelf().removeClass('ratings_over');
                // can't use 'this' because it wont contain the updated data
                set_votes($(this).parent());
            }
        );


        // This actually records the vote
        $('.ratings_stars').bind('click', function() {
            var star = this;
            var widget = $(this).parent();

            var clicked_data = {
                clicked_on : $(star).attr('class'),
                widget_id : $(star).parent().attr('id')
            };
            $.post(
                'rate.php',
                clicked_data,
                function(INFO) {
                    widget.data( 'fsr', INFO );
                    set_votes(widget);
                },
                'json'
            );
        });


});
function favadd(id,type){
$('#load').show();
$.ajax({
   dataType: "json",
   type: "get",
   url: "jsons/favorite.php",
   data: "favid="+id+"&type="+type,
   success: function(JSON){
   if(JSON.favadd == 1){
       alert('Bu videoyu başarıyla favori listenize ekledik.');
       $('#favdiv').empty();
       $('#favdiv').append('<a href="javascript:;" onclick="favadd('+id+', \'delete\');"><img src="images/bt-favorisil.jpg" alt="Favorilerden çıkar" width="107" height="24" /></a>');
   }
   if(JSON.favdel == 1){
       alert('Bu videoyu başarıyla favori listenizden çıkardık.');
       $('#favdiv').empty();
       $('#favdiv').append('<a href="javascript:;" onclick="favadd('+id+', \'null\');"><img src="images/bt-favoriekle.jpg" alt="Favorilere ekle" width="107" height="24" /></a>');
   }
   if(JSON.errors.fav == 3){
       alert('En fazla 40 tane videoyu favori listenize ekleyebilirsiniz.');
   }
   }
 });

};
function views(type){
$('#first, #manyview, #recommend').hide();
$('.mvideotab h3').removeClass('active');
$('#firstinfo, #manyviewinfo, #recommendinfo').hide();
$('#'+type).show();
$('#'+type+'h3').addClass('active');
$('#'+type+'info').show();
$('html,body').animate({scrollTop: $("#"+type+'h3').offset().top});
}
function listype(siteurl,catbase,catsef,currentpage){
var ltype = $('#listtype').val();
window.location= siteurl+catbase+'/'+catsef+'/'+currentpage+'/'+ltype;
}
function splistype(siteurl,catsef,currentpage){
var ltype = $('#listtype').val();
window.location= siteurl+catsef+'&listtype='+ltype;
}
function searchlistype(siteurl,query,pageid){
var ltype = $('#listtype').val();
window.location= siteurl+'search.php?query='+query+'&page='+pageid+'&type='+ltype;
}
function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}
function new_captcha()
{
var c_currentTime = new Date();
var c_miliseconds = c_currentTime.getTime();
$('#captchaimage').attr("src",'captcha.php?x='+c_miliseconds);
}
function set_votes(widget) {

        var avg = $(widget).data('fsr').whole_avg;
        var votes = $(widget).data('fsr').number_votes;
        var exact = $(widget).data('fsr').dec_avg;

        window.console && console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes);

        $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
        $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote');
        $(widget).find('.total_votes').text( votes + ' oy kullanıldı. (' + exact + ' puan)' );
    }
function faceshare(url,title){
window.open("http://www.facebook.com/sharer.php?u="+url+"&t="+title,"mywindow","menubar=1,resizable=1,width=650,height=350");
}

$(function(){
$('.more').live("click",function()
{
var ID = $(this).attr("id");
var lastcom = $('.lastcom').attr("id");
var sekmeyu = $('div#sekme1').height();
if(ID){
$("#more"+ID).html('<img src="images/loading.gif" />');
$.ajax({
type: "POST",
url: "jsons/ajax_more.php",
data: "lastmsg="+ID+"&lastcom="+lastcom,
cache: false,
success: function(html){
if(html != "Bitti."){
$('div.content').css('height', sekmeyu+170);
}

$("div#morecom").append(html);
$("#more"+ID).remove();
}
});
}
else{
$(".morebox").html('Bitti');
}

return false;
});
});
function gopart(id,part){
$('div.player').hide();
$('#partload').show();
$.ajax({
   dataType: "json",
   type: "POST",
   url: "jsons/gopart.php",
   data: "videoid="+id+"&part="+part,
   success: function(JSON){
   if(JSON.part != null){
$('div.parts ul li').removeClass('active');
$('div.parts ul li#part-'+part).addClass('active');
   $('div.player').empty();
  $('div.player').append(JSON.part);
$('#partload').hide();
$('div.player').show();
   }else{
$('div.player').show();
$('#partload').hide();
}
   }
 });

}

