var Loading = '<span id="Loading"><img src="/gfx/www/loading.gif"></span>';
$.fn.colorbox.settings.close = "Zamknij";
// START JQ ----------------------------------------------------------------
$(document).ready(function(){
if (base_url == '/upload' || base_url == '/upload-www') {
$('input[name^=nazwa]').change(function(){
var t=$(this);
t.attr('value',t.attr('value').replace(/\./gi,' '));
});


}

if (base_url == '/') {
$("#premiery").jCarouselLite({
	vertical: true,
	hoverPause:true,
	visible: 3,
	auto:1000,
	speed:2000
});
}

// ACTIVE LINK ----------------------------------------------------------------
$("a").each(function(){
var current_href = 'http://torrentbay.pl'+$(this).attr("href");
if (document.location == current_href) {
  $(this).blur();
  $(this).addClass('active');
}
});
// FIX corner ----------------------------------------------------------------
if($.browser.webkit) 	$('.button, textarea, input, .rating').corner('3px');
if($.browser.mozilla)	$('.button, textarea, input, .rating').corner('3px');
if($.browser.opera) 	$('a.button, textarea, input, .rating').corner('3px');
if ($.browser.webkit || $.browser.mozilla || $.browser.opera) {
// CORNER ----------------------------------------------------------------
$('.pager, .center .off, .box_info.ok, .box_info.err, .box_info.att, .box_info.info').corner('6px');
$('#tort .th').corner('top 3px');
}
// COMMENT BG ODD/EVEN ----------------------------------------------------------------
$("div.komentarz:odd").css("background-color", "#EBEBEB");
$("div.komentarz:even").css("background-color", "#EFF1F1");
// JQ BLOCK ----------------------------------------------------------------
$('.blockUI').click(function() {
var url = $(this).attr('href');
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
if (params['width'])	var mwidth = params['width'];	else	var mwidth = 500;
if (params['height'])	var mheight = params['height'];	else	var mheight = 400;
if (params['iframe'])	var miframe = params['iframe'];	else	var miframe = true;

$(this).colorbox({ iframe: miframe, width: mwidth, height: mheight, href: $(this).attr('href') });

});
// TORTY JQ BLOCK ----------------------------------------------------------------
$('#tort .tr a[href*=".jpg"], #tort .tr a[href*=".png"]').click(function() {
$(this).colorbox({ href: $(this).attr('href') });
});
// CSS FIX FORM ----------------------------------------------------------------
$('input[name=add],input[name=remove]').addClass('advmultiselect_button');
$('input[type=radio]').addClass('radio');
$('input[type=checkbox]').addClass('checkbox');

//  ----------------------------------------------------------------
$("ul.subnav").parent().append("<span></span>");
//  ----------------------------------------------------------------
$("ul.topnav li span").click(function() { 
	$(this).parent().find("ul.subnav").slideDown('fast').show();

	$(this).parent().hover(function() {
	}, function(){	
		$(this).parent().find("ul.subnav").slideUp('slow'); 
	});
	}).hover(function() { 
		$(this).addClass("subhover");
	}, function(){
		$(this).removeClass("subhover");
});
// ANIMATE MENU ----------------------------------------------------------------
$(".menuLeft li a").hover(
	function () {
		$(this).stop().animate({ paddingLeft: "45px" }, 200);
	}, 
	function () {
		$(this).stop().animate({ paddingLeft: "30px" });
	}
);

// RANGI ----------------------------------------------------------------
$('.uzyskanie').click(function() {

if ($(this).is(':checked'))
$('.chowaj').show();
else
$('.chowaj').hide();
});

// NEWSY ----------------------------------------------------------------
/*
$('.newsy div').click(function() {
id = $(this).attr("class");
$('.opis').slideUp();
$('.'+id+' .opis').slideDown();
});
$('.newsy div').first().find('ol').slideDown();
*/
$('.newsy div').click(function() {
id = $(this).attr("class");
$('.opis').hide();
$('.'+id+' .opis').show();
});
$('.newsy div').first().find('ol').show();

// MSG ----------------------------------------------------------------
/*
$('div[id^=wiadomosc]').click(function() {
id = $(this).attr('class');
idw = $(this).attr('alt');
$('.opis').slideUp();
$('.'+id+' .nowa').load('/jquery/przeczytana?id='+idw,function() {
$('#js_wiadomosci .liczba').text( ($('#js_wiadomosci small').text()-1) );
$('.'+id+' .nowa').remove();
});
$('.'+id+' .opis').slideDown();
});
*/
$('div[id^=wiadomosc]').click(function() {
id = $(this).attr('class');
idw = $(this).attr('alt');
$('.opis').hide();
$('.'+id+' .nowa').load('/jquery/przeczytana?id='+idw,function() {
$('#js_wiadomosci .liczba').text( ($('#js_wiadomosci small').text()-1) );
$('.'+id+' .nowa').remove();
});
$('.'+id+' .opis').show();
});
// TIPSY ----------------------------------------------------------------
$('.tTip').tipsy({gravity: 'n', fade: true});
$('.tTip.e').tipsy({gravity: 'e', fade: true});
$('.tTip.s').tipsy({gravity: 's', fade: true});
$('.tTip.w').tipsy({gravity: 'w', fade: true});
$('input.tTip, textarea.tTip, select.tTip').tipsy({gravity: 'w', fade: true, trigger: 'focus'});
// MENU ZMIANA STRON ----------------------------------------------------------------
$('.menu_zmian_stron').click(function(){
if ($('div.content_l').attr('class') == 'content_l cll') {
$('div.content_l').removeClass('cll'); $('div.content_r').removeClass('cll'); $('div.content_l').addClass('clr'); $('div.content_r').addClass('clr');
$('.menu_zmian_stron').text('« Przenieś na lewo');
createCookie('menu', 'prawo', 365);
}
else {
$('div.content_l').removeClass('clr'); $('div.content_r').removeClass('clr'); $('div.content_l').addClass('cll'); $('div.content_r').addClass('cll');
$('.menu_zmian_stron').text('Przenieś na prawo »');
createCookie('menu', 'lewo', 365);
}
return false;
});
// MSG SEARCH ----------------------------------------------------------------
szukaj_usera();
// TRACKER STATUS ----------------------------------------------------------------


$('a.tracker_staty').click(function() {
url = $(this).attr('href');
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );
$.ajax({
type: "GET",
url: $(this).attr('href'),
dataType: "json",
data: {},
beforeSend: function(){
$('.peer'+params['poz']+' .seed b').html(Loading);
$('.peer'+params['poz']+' .leech b').html(Loading);
$('.peer'+params['poz']+' .finish b').html(Loading);
},
success: function(obj) {

if(typeof(obj.e) != "undefined") {

	if(obj.e != ""){
		$('.peer'+params['poz']+' .seed b').html('---');
		$('.peer'+params['poz']+' .leech b').html('---');
		$('.peer'+params['poz']+' .finish b').html('---');
		alert(obj.e);
	}
	else{
	//$('#Loading').remove();
	$('.peer'+params['poz']+' .seed b').html(obj.s);
	$('.peer'+params['poz']+' .leech b').html(obj.l);
	$('.peer'+params['poz']+' .finish b').html(obj.c);
	}
}

}
});

return false;
});
// END JQ ----------------------------------------------------------------
});
//  ----------------------------------------------------------------
function checkAll(item) {
			$( '.checkAll' ).live( 'change', function() {
				$( item ).attr( 'checked', $( this ).is( ':checked' ) ? 'checked' : '' );
				$( this ).next().text( $( this ).is( ':checked' ) ? 'Odznacz wszystko' : 'Zaznacz wszystko' );
			});
			$( '.invertSelection' ).live( 'click', function() {
				$( item ).each( function() {
					$( this ).attr( 'checked', $( this ).is( ':checked' ) ? '' : 'checked' );
				}).trigger( 'change' );
 
			});
			$( item ).live( 'change', function() {
				$( item ).length == $( item+':checked' ).length ? $( '.checkAll' ).attr( 'checked', 'checked' ).next().text( 'Odznacz wszystko' ) : $( '.checkAll' ).attr( 'checked', '' ).next().text( 'Zaznacz wszystko' );
 
			});
}
//  ----------------------------------------------------------------
function szukaj_usera() {
if ($('input[class^=js_szukaj_usera]'))
$("input[class^=js_szukaj_usera]").autocomplete('/jquery/szukaj_usera', {
	dataType: "json",
	selectFirst: false,
	width: 418,
	delay: 400,
	parse: function(data) {
		return $.map(data, function(row) {
			return {
				data: row,
				value: row.login,
				result: row.login
			}
		});
	},
	formatItem: function(item) {
		return format(item);
	}
});
}
//  ----------------------------------------------------------------
function format(row) {

	return '<span>' + row.login + ' - <i>grupa: ' + [row.grupa] + '</i></span>';
}
//  ----------------------------------------------------------------
function yt(x) {
$('.yt').colorbox({ href: '/jquery/yt/' + x });
}
//  ----------------------------------------------------------------
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//  ----------------------------------------------------------------
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//  ----------------------------------------------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//  ----------------------------------------------------------------
function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}
//  ----------------------------------------------------------------
function torrentMinShow(id){

if (!$(".t"+id).is(':visible')) {
$('.tortmin .content:visible').slideUp();
$(".t"+id).slideDown();
}
else
$(".t"+id).slideUp();

}
//  ----------------------------------------------------------------
function tracker_staty(url) {
var queryString = url.replace(/^[^\?]+\??/,'');
var params = tb_parseQuery( queryString );

$.ajax({
type: "GET",
url: url,
dataType: "json",
data: {},
beforeSend: function(){
$('#torrent'+params['poz']+' .peer .seed b').html(Loading);
$('#torrent'+params['poz']+' .peer .leech b').html(Loading);
$('#torrent'+params['poz']+' .peer .finish b').html(Loading);
},
success: function(obj) {

if(typeof(obj.e) != "undefined") {

	if(obj.e != ""){
		$('#torrent'+params['poz']+' .peer .seed b').html('---');
		$('#torrent'+params['poz']+' .peer .leech b').html('---');
		$('#torrent'+params['poz']+' .peer .finish b').html('---');
		$('#torrent'+params['poz']+' .box0').attr('css', 'tTip');
		$('#torrent'+params['poz']+' .box0').attr('title', obj.e);
	}
	else{
	//$('#Loading').remove();
	$('#torrent'+params['poz']+' .peer .seed b').html(obj.s);
	$('#torrent'+params['poz']+' .peer .leech b').html(obj.l);
	$('#torrent'+params['poz']+' .peer .finish b').html(obj.c);
	}
}

}
});

}
// END ----------------------------------------------------------------
