$.ajaxSetup({async:true, cache:true});


// change message border 

$.blockUI.defaults.css.border = '1px solid #efefef';
$.blockUI.defaults.css.padding = '5px';
$.blockUI.defaults.message = '<h1><img src="gfx/28-1.gif" /> Proszę czekać ...</h1>';

var Loading = '<div id="Loading"><img src="gfx/28-1.gif"></div>';

function createCookie(name,value) {
	var date = new Date();
	date.setTime(date.getTime()+(365*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function Scale(image) {
	if (image.width > 500) {
		image.height = Math.round(((500)/image.width)*image.height);
		image.width = 500;
		image.title = "Preview";
		image.setAttribute("onclick", "Preview(this);");
	}
}


function oPopup(link,width,height)
{

var Wide = screen.width;
var High = screen.height;
dw = parseInt((Wide-width)/2);
dh = parseInt((High-height)/2);
popup = window.open(link,"mywindow","menubar=1,resizable=1,scrollbars=yes,width="+width+",height="+height+",left="+dw+",top="+dh);
popup.resizeTo(width,height);
popup.focus();

}

function newsShow(id){

if (!$(".c"+id).is(':visible')) {
$('.list .content:visible').slideUp();
$(".c"+id).slideDown();
}
else
$(".c"+id).slideUp();

}

function torrentMinShow(id){

if (!$(".t"+id).is(':visible')) {
$('.boxTorrentyMin .content:visible').slideUp();
$(".t"+id).slideDown();
}
else
$(".t"+id).slideUp();

}

function report(type,id,link) {

if(!$('textarea[@name=report]').val()) {

var html  = '';
html += '<div class="caption">Wpisz powód raportowania</div><br/>';
html += '<textarea name="report" style="width:330px;"></textarea>';
html += '<a href="javascript:;" onclick="report(\''+type+'\',\''+id+'\',\''+link+'\');" id="close" class="btn">Wyslij</a>';	   
html += '<a href="javascript:;" onclick="$.unblockUI();" id="close" class="btn">Reset</a>';	   
html += '<a href="javascript:;" onclick="$.unblockUI();" id="close" class="btn">Anuluj</a>';	   

$.blockUI({ message: html });

}
else {

if ($('textarea[@name=report]').val().length == 0) {
alert('Wpisz powód raportowania');
return false;
}

var data = {};
data['act'] = 'raporty';
data['type'] = type;
data['id'] = id;
data['descr'] = $('textarea[@name=report]').val();
data['link'] = link;

$.ajax({
type: "POST",
url: "/ajax.html",
data: data,
beforeSend: function(){
$.blockUI();
},
success: function(obj) {
$.unblockUI();
$(".jsReport"+id).css('color','red');
$(".jsReport"+id).html('Raportowany');
}
});

}

}



function yt(id) {

	   var html  = '';
	   html += '<div id="youtubecontent" >';
	   
/* 	   html += '<object>';
	   html += '<param name="movie" value="http://www.youtube.com/v/'+id+'&hl=pl&fs=1"></param>';
	   html += '<param name="allowFullScreen" value="true"></param>';
	   html += '<param name="allowscriptaccess" value="always"></param>';
	   html += '<param name="autoplay" value="1"></param>';
	   html += '<param name="wmode" value="transparent"></param>';
	   html += '<embed src="http://www.youtube.com/v/'+id+'&autoplay=1&hl=pl&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" wmode="transparent" width="425" height="349"></embed>';
	   html += '</object>'; */
	   
	   html += '<object width="640" height="385">';
	   html += '<param name="movie" value="http://www.youtube.com/v/'+id+'&hl=pl&fs=1"></param>';
	   html += '<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>';
	   html += '<embed src="http://www.youtube.com/v/'+id+'&hl=pl&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed>';
	   html += '</object>';
	   
	   html += '<a href="javascript:;" onclick="$.unblockUI();" id="close" class="btn">Przerwij oglądanie</a>';	   
	   html += '</div>';


if(jQuery.browser.mozilla)
$.blockUI({ css: { top:  (jQuery(window).height() - 425) /3 + 'px', left: (jQuery(window).width() - 625) /2 + 'px', width: '640px'}, message: html });
else if (jQuery.browser.opera)
$.blockUI({ css: { top: 150  + 'px', width: '640px'}, message: html });
else
$.blockUI({ css: { top:  (jQuery(window).height() - 425) /3 + 'px', width: '640px'}, message: html });

}


function getPeer(announce,infohash,id) {

var data = {};
data['announce'] = announce;
data['infohash'] = infohash;

$.ajax({
type: "POST",
url: "/check.php",
dataType: "json",
data: data,
beforeSend: function(){
$('.getPeer'+id).hide();
$('.torrent'+id+' .peer').hide();
$('.torrent'+id+' .peer').after(Loading);
},
success: function(obj,status) {

if(typeof(obj.error) != "undefined") {
	
	if(obj.error != ""){
		$('#Loading').remove();	
		$('.torrent'+id+' .peer').show();
		$('.getPeer'+id).show();
		alert(obj.error);
	}
	else{
	$('#Loading').remove();
	$('.torrent'+id+' .s').html(obj.s);
	$('.torrent'+id+' .l').html(obj.l);
	$('.torrent'+id+' .f').html(obj.c);
	$('.torrent'+id+' .peer').show();
	}
}

}
});

}

tt = null;
 
document.onmousemove = updateTT;
 
function updateTT(e) {
  var scrTop = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
  var scrLeft = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
  x = (document.all) ? window.event.x + scrLeft : e.pageX;
  y = (document.all) ? window.event.y + scrTop : e.pageY;
  if (tt != null) {
	tt.css('left',((x * 1) + 20) + "px");
	tt.css('top',((y * 1) + 20) + "px");
  }
}

 
function showTT(id) {

      tt = $('#'+id);
	  tt.show();

      if (tt != null) {
        tt.css('left',((x * 1) + 20) + "px");
        tt.css('top',((y * 1) + 20) + "px");
      }

}
 
function hideTT() {
    tt.hide();
}

$().ready(function() {


$("a[@href^='#js_check']").click(function(){
var id = $(this).attr('id');

var data = {};
data['ajax'] = '1';
data['act'] = 'edit';


advAJAX.post({
url: "test.php",
parameters: data,
onLoading : function(msg) {
$("#loading_"+id).html('<img src="images/28-1.gif">');
},
onSuccess : function(msg) {
$("#loading_"+id).html('');
alert(msg.responseText);
},
onError : function(obj) { alert("Error: " + obj.status); }
});



return false;
}); 

});