$(document).ready(function(){

yb=$.cookie('yazitipi_boyutu');
if (yb)$(".ozelboyutlu").css('font-size',yb);
$('#cokokunanlar > ul').tabs({ fx: { opacity: 'toggle' } });
$('#trating > ul').tabs({ fx: { opacity: 'toggle' } });
sbanner();
$('#date-view1').datePicker({inline:true,startDate: '2008/12/14',endDate: (new Date()).asString()}).bind('dateSelected',function(e, selectedDate, $td){document.location='/arsiv/'+selectedDate.asString();});







$('.btn').each(function(){
// find the DOM element we're processing
var b = $(this);
// find the current text or value of the currently processed .btn element
var tt = b.text() || b.val();
// find the href value - only for normal buttons
var href = $(this).attr('href') || '';
// make a note of the parent form
var parentForm = $(this).parents('form');
// work out what type of element we're processing.
var type = $(this).attr('type');
if(type == 'submit' || type == 'reset') {
// just hide the button, so the form still submits when enter key is pressed on a field
$(this).hide();
// insert the replacement button after the existing hidden element
b = $('' + tt + '').insertAfter(this);
// add a click listener to the button
b.click(function() {
if(type == 'submit') {
parentForm.submit();
} else if(type == 'reset') {
parentForm.reset();
}
return false;
});
// allows for the enter button to submit form contents cross-browser
parentForm.keyup(function(e) {
if(e.keyCode == 13) {
parentForm.submit();
return false;
}
});
} else {
// normal Anchor Tag, just replace the contents of the element with the button formatting
b = $(this).html('' + tt + '');
}
});

});




function setlang(){
    ln=$("#language").val();
    pt=document.location.pathname;
    if (pt.search(/en/) >0 || pt.search(/ar/) >0) {
        if (ln=='en')eski='ar';
        else eski='en';
        pt=pt.replace('/'+eski+'/','/'+ln+'/');
        $("#next").val(pt);
        }
    $('#langform').submit();
}





search_cache='';
function search_set(focus,obj,def){
    if(focus==1){
        search_cache=obj.value;
        obj.value='';
        $("#query").val('');
        }
    else{
        if (obj.value==''){
            if (search_cache!='')obj.value=search_cache;
            else obj.value=def;
        }
    }
}


function add2cart(id){
    $("#bookid").val(id);
    $("#bookform").submit();
    }
function removeFromCart(id){
    $("#removeitem").val(id);
    $("#maincart").submit();
    }





function getCities(id){
    country=$("#"+id);
    var index=country.attr('id').replace("id_address_set-","").replace("-country","");
    selectedcounty=country.val();
    selectedcity=$("#city_"+index).val();

    if (selectedcounty)$.get("/l10n/cities/",{ countryid:selectedcounty,selected:selectedcity},function(data){$("#id_address_set-"+index+"-city").html(data);});
    }

function getCities41(val){
    $.get("/l10n/cities/",{ countryid:val},function(data){$("#id_city").html(data);});
    }


function findPos(obj) {

	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function sbanner(){
    pos=findPos($('#duba')[0]);
    m=$("#sidebanner");
    if($.browser.msie && $.browser.version=='6.0')m.css('position','absolute');
    m.css('left',pos[0]+85);
    //m.css('top',pos[1]+20);
    m.fadeTo(1,0.1).show().fadeTo(1000,1).css('z-index',1000);

    }

function gzlSptMsj(){
    m=$("#msjbox");
    m.fadeTo(2000,0.0).hide('slow');
    setTimeout("m.css('z-index',-2)",2000);
    }

function mbox(msj,nsn,hideafter){
    pos=false;
    if(typeof(nsn)=='undefined' || !nsn ){
        mouseX = mouseY = 0;
        $().mousemove(function(e) { mouseX = e.pageX; mouseY = e.pageY; });
        pos=[mouseX,mouseY];
        }
    else if(typeof(nsn)=='string'){
            nsn=$('#'+nsn)[0]
        }
    if(!pos && nsn)pos=findPos(nsn);
    if (!$("#msjbox")[0])$("body").append("<div id='msjbox'></div>");
    m=$("#msjbox");

    m.hide();
    m.html(msj);
    m.css('left',pos[0]);
    m.css('top',pos[1]+20);
    m.fadeTo(1,0.3).show().fadeTo(400,0.7).css('z-index',1000);
    setTimeout('gzlSptMsj()',8000);
    if(hideafter)$("#"+hideafter).hide('slow');
    }


function getBookCommentForm(){
    $.get("/yorum_ekle/",{},function(data){$("#xcontainer").html(data).show('slow');});
    }

function getBookComments(page){
    $.get("/yorumlar/"+$("#bid").val(),{'page':page},function(data){$("#comments").html(data).show('slow');});
    }


function reviewBook(nsn){
    e=$("#id_email").val();
    s=$("#id_title").val();
    n=$("#id_name").val();
    t=$("#id_comment").val();
    $.post("/yorum_gir/"+idd+'/',{'name':n,'email':e,'title':s,'comment':t,'id':idd},function(data){
            $('#add_book_comment' ).html("<h3 style='text-align:center;'>"+data+"</h3>");
                }
        );
    }

function yaziBoyutu(b){
    $(".ozelboyutlu").css('font-size',b);
    $.cookie('yazitipi_boyutu',b,{path:'/',expires: 360 });
    }

sinir=750;
function yorumSay(){
    ic=$("#id_comment");
    say=sinir-ic.val().length;
    $("#sayac").html(say);
    if (say<1){ic.val(ic.val().substring(0,sinir));}
    }


function yorumGoster(id,sayfa){
    $.get("/yorum_goster/"+id+"/",{page:sayfa},function(data){$("#yorumkutu").html(data);});
    }
