var p=1;
var g=1;
var picsCount;
var currentPic;
var orating = 0;
var bookopen = false;
var was = 0;

function round_corner(id) {
        $('#'+id).corner('round 30px');
}

function enter(){
        if(document.getElementById('iagree').checked)document.location.href='main/';
        else alert('!אתה חייב להסכים לתנאי השימוש בשביל להכנס לאתר');
}

function nexts(ww){
        if(ww == 'scroll_height'){
                if(g < $('#'+ww+' .inothers').length && $('#'+ww+' .inothers:eq('+g+') .preview').length > 0){
                        $('#'+ww+' .inothers:eq('+(g-1)+')').hide();
                        g++;
                        $('#'+ww+' .inothers:eq('+(g-1)+')').show();
                }
        }else{
                $('#'+ww+' .middle:eq('+(p-1)+')').hide('slow',function(){
                        p++;
                        if(p>$('#'+ww+' .middle').length)p=1;
                        $('#'+ww+' .middle:eq('+(p-1)+')').show('slow');
                });
        }
}
function prevs(ww){
        if(ww == 'scroll_height'){
                if(g > 1){
                        $('#'+ww+' .inothers:eq('+(g-1)+')').hide();
                        g=g-1;
                        $('#'+ww+' .inothers:eq('+(g-1)+')').show();
                }
        }else{
                $('#'+ww+' .middle:eq('+(p-1)+')').hide('slow',function(){
                        p=p-1;
                        if(p<1)p=$('#'+ww+' .middle').length;
                        $('#'+ww+' .middle:eq('+(p-1)+')').show('slow');
                });
        }
}

function next() {

        $('#big_pic .img_' + currentPic).hide();
        currentPic = (currentPic +1 < picsCount)? (currentPic+1) : 0;
        $('#big_pic .img_' + currentPic).show();
}

function prev() {

        $('#big_pic .img_' + currentPic).hide();
        currentPic = (currentPic != 0 )? (currentPic-1) : (picsCount-1);
        $('#big_pic .img_' + currentPic).show();
}

function net(pid){
        window.open('<?=URL;?>/pictures/big_pics/<?=$gal->id;?>/?li=<?=LI;?>&p='+pid,'','fullscreen,scrollbars');
}

function change_big(file){

        $("#clip a img").attr({src: 'http://tarabin.net/public/photo/' + file});
}


function rate (how, item, item_id) {
	if (how > 0) {
		if (how <= 5) {
                        $.ajax({
                          url: url+'ajax/rate_'+item+'/'+item_id+'/'+how+'/',
                          data: {
                                  key: item_id,
                                  value: how
                          },
                          success: function(data) {
                                showrating (data);
                                orating = data;
                          }
//                          error: function(XMLHttpRequest, textStatus, errorThrown){
//                                alert(errorThrown);
//                          }
                        });
                      if (was == 0) {
				alert (newRate);
				was = 1;
			} else {
                                alert (changedRate);
                      }
		}
	}
}

var now = orating;

function showrating (how) {
        if (now != how) {
                $('#rating a').each( function (i) {
			if((i+1) <= how) {
                                $(this).html('<img src="'+url+'public/img/stars/y_star.png" />');
                        }
			else {
                                $(this).html('<img src="'+url+'public/img/stars/g_star.png" />');
                        }
		});
		now = how;
	}
}

function favorites (method, model_name, model_id) {

        $.ajax({
                
                url: url + 'ajax/' + method + '_favorites/',
                data: {
                        model: model_name,
                        id: model_id
                },
                success: function(data) {
                        alert(data);
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                             alert(errorThrown);
                }

        });

}
var comm_sent=0;

function comm_send(model, id){

        if(comm_sent==0){
                comm_sent=1;
                $('#forcomms').hide();

                $.ajax({
                        url: url+'ajax/'+model+'_comment/'+id+'/',
                        data: $('#commform').serialize(),

                        success: function(data) {
                                alert(data);
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown){
                             alert(errorThrown);
                        }
                });
        }
}