$(document).ready(function(){
    Down();
	});
var down, cmin, csec, chr;
function Display(hr,min,sec) { 
	var disp='';
	if(hr<=9) disp+="0";
	disp+=hr+"hrs ";
	if(min<=9) disp+="0";
	disp+=min+"min ";
	if(sec<=9) disp+="0"+sec;
	else disp+=sec;
	disp+="sec";
	return(disp); }

function DownRepeat() {
        csec--;
	if(csec==-1) { csec=59; cmin--; }
	if(cmin==-1) { cmin=59; chr--; }
    //out 
	//window.status=Display(chr,cmin,csec);
        $('#timerShow').empty();
        $('#timerShow').append(Display(chr,cmin,csec));
	if((chr==0) && (cmin==0) && (csec==0)) {var s='';$('.next_update').empty();$('.next_update').append('<a href"/">check updates</a>');}
	else{down=setTimeout("DownRepeat()",1000); }}
/*
function show_pic(image,maxwidth) {
    var new_width='';
    $('#big').attr('id','big_old');
    $('#bigimg').attr('id','bigimg_old');
	$("#brl").after('<a href="'+image+'" id="big"><img src="'+image+'?'+Math.random()+'" border="0" id="bigimg"></a>');
	//$('#galbig').append('<a href="'+image+'" id="big"><img src="'+image+'?'+Math.random()+'" border="0"></a>');
	$('#bigimg').hide();
	$('#loading').show();
	$('#brl').show();
	$('#bigimg').load(function(){ 
	if(maxwidth > $('#bigimg').width()){new_width=$('#bigimg').width();}else{new_width=maxwidth;}
	$('#loading').hide();$('#brl').hide();
    $('#bigimg').attr('width',new_width);
	$('#bigimg_old').fadeOut('normal'); $('#big_old').remove(); $('#bigimg').fadeIn('normal');
	});
}
*/
function show_pic(image,maxwidth) {
    var new_width='';
	$('#big').remove();
	if($.browser.msie)
	  {
	  $("#brl").after('<a href="'+image+'" id="big"><img src="'+image+'?'+Math.random()+'" border="0" id="bigimg"></a>');
	  }
	else
	  {
	  $("#brl").after('<a href="'+image+'" id="big"><img src="'+image+'?'+Math.random()+'" border="0" id="bigimg"></a>');
	  }
	$('#bigimg').load(function(){ 
	if(maxwidth > $('#bigimg').width()){new_width=$('#bigimg').width();}else{new_width=maxwidth;}
    $('#bigimg').attr('width',new_width);
	});
}
function stars(d){if(!d.id||!d.callback||!d.width||!d.height)return false;this.$=function(v,o){return((typeof(o)=='object'?o:document).getElementById(v))};this.$S=function(o){return((typeof(o)=='object'?o:this.$(o)).style)};this.agent=function(v){return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0))};this.abPos=function(o){var o=(typeof(o)=='object'?o:this.$(o)),z={X:0,Y:0};while(o!=null){z.X+=o.offsetLeft;z.Y+=o.offsetTop;o=o.offsetParent};return(z)};this.XY=function(e,v){var o=this.agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY};return(v?o[v]:o)};this.mouse=function(e,o){if(this.stop||isNaN(this.stop)){this.stop=0;var c=this;document.onmousemove=function(e){if(!c.$('star'+d.id)||!c.$S('starCur'+d.id)||!c.$S('rating'+d.id))return false;var n=d.id;var p=c.abPos(c.$('star'+n)),x=c.XY(e),a=x.X-p.X,b=x.Y-p.Y;c.num=o.id;if(a<1||a>d.width||b<0||b>d.height){c.stop=1;c.revert()}else{c.$S('starCur'+n).width=a+'px';word_rate(Math.round(a/d.width*100));c.$('rating'+n).className=d.RatingOnClassName;c.$('rating'+n).innerHTML=Math.round(a/d.width*100)+'%'}}}};this.update=function(e,o){if(!this.$('rating'+d.id))return false;var n=d.id,v=parseInt(this.$('rating'+n).innerHTML);this.$('starCur'+n).title=v;if(d.actionURL){req=new XMLHttpRequest();req.open('GET',d.actionURL+(v/100),false);req.send(null)}else{if(d.callback)d.callback.returnMethod()(v)}};this.revert=function(){if(!this.$('starCur'+d.id))return false;var n=d.id,v=parseInt(this.$('starCur'+n).title);this.$S('starCur'+n).width=Math.round(v*d.width/100)+'px';word_rate(v>0?Math.round(v):0);this.$('rating'+n).innerHTML=(v>0?Math.round(v)+'%':0+'%');this.$('rating'+n).className=d.RatingOffClassName};String.prototype.returnMethod=function(){if(!/\W/.test(this.toString())){var a=eval(this.toString());if(typeof(a)==="function"){return a}else{return null}}}}
function word_rate(rating){
if(rating==0){var word='rate it';}
if(rating >0 && rating < 21){var word='poor';}
if(rating >20 && rating<41){var word='nothing special';}
if(rating >40 && rating<61){var word='worth watching';}
if(rating >60 && rating<81){var word='pretty cool';}
if(rating >80 && rating<101){var word='awesome!';}
$('#word_rate').text(word);
}

function send_abuse(){
  $('#good').hide();$('#error').hide();
var str='ajax=add_abuse&';
$('#abuseform input,select,textarea').each(function(n,element){
 if($(element).attr('id')){str=str + $(element).attr('id') +'='+encodeURIComponent($(element).val())+'&';}
 });
$.post('backend.php',str,onSuccess);
}
function onSuccess(data){
window.scroll(0,0);
var d = data.split('|');
if(d[0]=='ok' || d[0]=='login'){document.forms['abuses'].reset();$('#good').show();change_image();}
if(d[0]=='error')
  {
  $('#error').empty();
  $('#error').append(d[1]);
  $('#error').show();
  }
if(d[2] && d[0]=='ok'){setTimeout("document.location='"+d[2]+"';", 5000);}
if(d[2] && d[0]=='login'){document.location=d[2];}
}
function send_reg_data(){
$('#good').hide();$('#error').hide();
var str='ajax=add_user&';
$('#regform input,select,textarea').each(function(n,element){
 if($(element).attr('id')){str=str + $(element).attr('id') +'='+encodeURIComponent($(element).val())+'&';}
 });
$.post('backend.php',str,onSuccess);
}
function change_image(){var cont_img=$("#cap_img").attr('src');$("#cap_img").attr('src',cont_img+'&rand='+Math.random());}
function send_lost_email(){
$('#good').hide();$('#error').hide();
var str='ajax=sent_pass&';
$('#lostform input,select,textarea').each(function(n,element){
 if($(element).attr('id')){str=str + $(element).attr('id') +'='+encodeURIComponent($(element).val())+'&';}
 });
$.post('backend.php',str,onSuccess);
}
function login(){
$('#good').hide();$('#error').hide();
var str='ajax=login&';
$('#loginform input,select,textarea').each(function(n,element){
 if($(element).attr('id') && $(element).attr('id')!='set_cookie'){str=str + $(element).attr('id') +'='+encodeURIComponent($(element).val())+'&';}
 if($(element).attr('id')=='set_cookie' && $(element).attr('checked')==true){str=str + $(element).attr('id') +'='+encodeURIComponent($(element).val())+'&';}
 });
$.post('backend.php',str,onSuccess);
}
function add_favorite(gid){
var str='ajax=add_favorite&gid='+gid;
$.post('backend.php',str,onReload);
}
function onReload(data){if(data){document.location=data;}}
function checkall(){$('.checkclass').attr('checked',true);}
function uncheckall(){$('.checkclass').attr('checked',false);}
function deletechecked(){
var str='ajax=delete_favorites&';
$('body .checkclass').each(function(n,element){
 if($(element).attr('checked')==true){str=str + 'ids[]='+$(element).val()+'&';}
 });
$.post('backend.php',str,onReloadSelf);
}
function onReloadSelf(data){location.reload();}
function show_related(id){
for(var i=0;i<10;i++){if(i!=id){$("#related_"+i).hide();$("#but_"+i).removeAttr("class");}}
$("#related_"+id).show();$("#but_"+id).attr("class","active");
}
function sent_comment(){$('#warning').remove();if($("#comment").val()){$.post('backend.php','ajax=sent_comment&gid='+$("#gid").val()+'&comment='+encodeURIComponent($("#comment").val()),insertComment);}}
function insertComment(data){
$('#warning').remove();
var d = data.split('|');
if(d[0]=='error'){$("#comments_box").append(d[1]);setTimeout("$('#warning').remove();", 3000);}
if(d[0]=='stop'){$("#comments_box").append(d[1]);}
if(d[0]=='ok')
  {
  $("#comments_box").remove();$("#paging").remove();$(".addcomment").before(d[1]);
  var col=$("#comm_cnt").text();col++;
  $("#comm_cnt").text(col);
  $("#comment").val('');
  }
}
   
function show_page(id,page){$.post('backend.php','ajax=show_page&gid='+id+'&page='+page,insertPage);}
function insertPage(data){$("#comments_box").remove();$("#paging").remove();$(".addcomment").before(data);}
function sent_spam_report(cid){$.post('backend.php','ajax=sent_spam_report&cid='+cid,showReport);}
function showReport(data){$('#warning').remove();$("#comments_box").append(data);setTimeout("$('#warning').remove();", 3000);}
function sent_gallery_report(gid){$('#msg_report').hide();$('#msg_report').empty();$.post('backend.php','ajax=sent_gallery_report&gid='+gid+'&reason='+encodeURIComponent($("#reason").val())+'&details='+encodeURIComponent($("#details").val()),showReportGallery);}
function showReportGallery(data){
$('#details').val('');
var d = data.split('|');
if(d[0]=='error'){$('#msg_report').append('<b style="color:red">'+d[1]+'</b>');$('#msg_report').show();setTimeout("$('#msg_report').hide();", 5000);}
if(d[0]=='ok'){$('#msg_report').append('<b style="color:green">'+d[1]+'</b>');$('#msg_report').show();setTimeout("$('#msg_report').hide();", 5000);setTimeout("$('#reportform').hide();", 6000);}
}
