Array.prototype.indexOf = function(o, i) {
    for (var j = this.length,i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0; i < j && this[i] !== o; i++);
    return j <= i ? -1 : i;
};
$.fn.extend({flash:function(opt) {
    var has,cv,ie;

    function attr(a, b) {
        return' ' + a + '="' + b + '"';
    }

    function param(a, b) {
        return'<param name="' + a + '" value="' + b + '" />';
    }

    var p = navigator.plugins;
    if (p && p.length) {
        var f = p['Shockwave Flash'];
        if (f) {
            has = true;
            if (f.description)cv = f.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
        }
        if (p['Shockwave Flash 2.0']) {
            has = true;
            cv = '2.0.0.11';
        }
    } else {
        try {
            var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
        } catch(e) {
            try {
                var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
                cv = [6,0,21];
                has = true;
            } catch(e) {
            }
            ;
            try {
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
            } catch(e) {
            }
            ;
        }
        if (axo != null) {
            cv = axo.GetVariable("$version").split(" ")[1].split(",");
            has = true;
            ie = true;
        }
    }
    $(this).each(function() {
        if (has) {
            var e = $(this),s = $.extend({'id':e.attr('id'),'class':e.attr('class'),'width':e.width(),'height':e.height(),'src':e.attr('href'),'classid':'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000','pluginspace':'http://get.adobe.com/flashplayer','availattrs':['id','class','width','height','src'],'availparams':['src','bgcolor','quality','allowscriptaccess','allowfullscreen','flashvars','wmode'],'version':'9.0.24'}, opt),a = s.availattrs,b = s.availparams,rv = s.version.split('.'),o = '<object';
            if (!s.codebase) {
                s.codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + rv.join(',');
            }
            if (s.express) {
                for (var i in cv) {
                    if (parseInt(cv[i]) > parseInt(rv[i])) {
                        break;
                    }
                    if (parseInt(cv[i]) < parseInt(rv[i])) {
                        s.src = s.express;
                    }
                }
            }
            if (s.flashvars) {
                s.flashvars = unescape($.param(s.flashvars));
            }
            a = ie ? a.concat(['classid','codebase']) : a.concat(['pluginspage']);
            for (k in a) {
                var n = (k == a.indexOf('src')) ? 'data' : a[k];
                o += s[a[k]] ? attr(n, s[a[k]]) : '';
            }
            ;
            o += '>';
            for (k in b) {
                var n = (k == b.indexOf('src')) ? 'movie' : b[k];
                o += s[b[k]] ? param(n, s[b[k]]) : '';
            }
            ;
            o += '</object>';
            e.replaceWith(o);
        }
        return this;
    });
}});



    $('html').ajaxSend(function(event, xhr, settings) {
        function getCookie(name) {
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }

        if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
            // Only send the token to relative URLs i.e. locally.
            xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
        }
    });


    // foto_goster.htm icin sepet'e ekleme kolayligi
    $('.urunadet').focus(function(){this.value = this.value =='' ? 1 : this.value;})

//});


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


tt_padding = 30
tt_html = "<div id=ttdis style='display:none;position:absolute;z-index:100;padding:" + tt_padding + "px;'> <div id=ttic style='background-color:#fff; border:1px solid #f5f5f5'></div> </div>"

function ttip(e, icerik, gen, yuk) {
    if (typeof(gen) == 'undefined' && typeof(yuk) == 'undefined') {
        if ($('#ttic img')[0]) {
            gen = $('#ttic img')[0].width
            yuk = $('#ttic img')[0].height
        }
        else {
            gen = yuk = 200
        }
    }

    $('body').append(tt_html);
    $('#ttic').html(icerik);

//    alert(gen)
    //.css({width:genislik,height:yukseklik})
    $('#ttdis').offset({ top: (e.pageY - yuk), left: (e.pageX - gen) }).show('slow').hover(function() {
            }, function() {
                $(this).hide('slow', function() {
                    $(this).remove()
                })
            })
//    alert(e.pageX)

}


function urun_oniz(event, oniz_foto, urun_foto, top, left, gen, yuk) {
    top = tt_padding + top
    left = tt_padding + left
    gen = gen ? "width='" + gen + "' " : ' '
    yuk = yuk ? "height='" + yuk + "' " : ' '
    ttip(event, "<div><img onload=\"$('#oniz_urun_foto').show()\" src='" + oniz_foto + "'><img id='oniz_urun_foto' style='z-index:230px;display:none;position:absolute;top:" + top + "px;left:" + left + "px' " + gen + yuk + " src='" + urun_foto + "'></div> ")
}


paylas_title = "Fotoğraf şuanda paylaşılıyor, paylaşımdan kaldırmak için tıklayın"
paylasma_title = "Fotoğraf şuanda paylaşılmıyor, paylaşmak için tıklayın"
function payyap(n) {
    n = $(n)
    if (n.attr('src').indexOf('pasif') > -1)n.attr('title', paylasma_title)
    else n.attr('title', paylas_title)
}

$().ready(function() {


    $(".fpaylas").each(function() {
        payyap(this)
    });
//$('.flash').flash({
//    // As always; all settings are entirely optional.
//    id			: $(this).attr('id'), // ID
//    class		: $(this).attr('class'), // class
//    width		: parseInt($(this).attr('width')), // Width
//    height		: parseInt($(this).attr('height')), // Height
//    src			: $(this).attr('href'), // Path to swf
//    flashvars		: flashvars // JSON structured flashvars data
//
//});

    //dugme yapiyoruz
//         $("div.d").bind("mousedown mouseup mouseout", dugme);
//         $("div.d").each(function(){$(this).html('<div class="d1"></div><div class="d2">'+$(this).html()+'</div><div class="d3"></div>')} );
//
//         //arama inputu yapiyoruz
////         $("div.in").each(function(){$(this).html('<div class="in1"></div><div  class="in2"><div contentEditable="true" onKeyUp="ara(event)" onclick="$(this).html(\' \');" id="aradiv">'+$(this).html()+'</div></div><div class="in3"></div>')} );
//         $('#footer').bind("onresize", boyutlandir);
//         boyutlandir();
//      $('#menu').hover(
//      menuAc,
//      function(){$('#menu').addClass('kapanacak');setTimeout('menuKapat()',2000)}
//)
//       setTimeout('menuKapat()',2000)
//

});

/*
 jquery.flash v1.3.1 -  02/01/10
 (c)2009 Stephen Belanger - MIT/GPL.
 http://docs.jquery.com/License
 */


paylas = "/static/grafik/paylas_ikon.gif"
paylasma = "/static/grafik/paylas_ikon_pasif.gif"
function fotoPaylas(id) {
    n = $('#fp' + id)
    if (n.attr('src').indexOf(paylasma) > -1)genel = 1;
    else genel = 0
    $.post('/foto/foto_duzenle/' + id + '/', {genel:genel}, function(data) {
                if (data.indexOf('tamam') > -1) {
                    if (genel)n.attr('src', paylas)
                    else n.attr('src', paylasma)
                }
                payyap(n[0])
            })

}
function fotoAd(id, ad) {

    $.post('/foto/foto_duzenle/' + id + '/', {ad:ad}, function(data) {
//            if(data.indexOf('tamam')>-1)$('#f'+id).hide('slow');
            })

}

function tumFotoPaylas(id, genel) {
    n = $('#fp' + id)
    $.post('/foto/album_yayinla/' + id + '/', {genel:genel}, function(data) {
                if (data.indexOf('tamam') > -1) {
                    if (genel)$(".fpaylas").each(function() {
                        $(this).attr('src', paylas);
                        payyap(this);
                    });
                    else $(".fpaylas").each(function() {
                        $(this).attr('src', paylasma);
                        payyap(this);
                    });
                }
                payyap(n[0])
            })

}


var response = '';
function get_dims(file, instance_name) {
    // up_dims = [genislik, yukseklik]
    var uploader = document.jumpLoaderApplet.getUploader();
    var imageInfo = uploader.getImageInfo(file);
    var width = imageInfo.getImageWidth(0);
    var height = imageInfo.getImageHeight(0);
    foto_kenar = width + height;
    sinir_kenar = up_dims[0] + up_dims[1];
    if (sinir_kenar > foto_kenar) {
        sinirlar = '10000x10000';//toplam foto alani sinir icindeyse herhangi bir boyutlandirma yapmiyoruz.
    } else {
        sinir_duzgun = up_dims[0] / up_dims[1] >= 1; // duzgunden kasit genisligin yukseklikten fazla olmasi.
        foto_duzgun = width / height >= 1;
        sinirlar = sinir_duzgun == foto_duzgun ? up_dims[0] + 'x' + up_dims[1] : up_dims[1] + 'x' + up_dims[0];
    }
    return sinirlar;
}
function uploaderFilePartitionUploaded(uploader, file) {
    response = file.getResponseContent();
//    if (response.length>100) document.write(response)
}
function uploaderStatusChanged(uploader) {
    if (uploader.getStatus() == 0) {
        document.location.href = response;
    }
}

function init_drag(){
    $("#album_ul").dragsort({ dragSelector: "div", dragEnd: saveOrder, placeHolderTemplate: "<li class='placeHolder'><div></div></li>" });
    saveOrder();
    $(".pancheck").click(_pancheck);
}



function isEven(x) {
    return (x % 2) ? false : true
}

function _pancheck(){
    t = $(this);
    if(t.attr('checked')){
        idx = t.parents('.li').index()
        if (isEven(idx)){
            panIt(t,idx)
        }
    }
}


function saveOrder() {
    var data = $(".ogid").map(function() { return $(this).val(); }).get();
    $("input[name=siralama]").val(data.join("|"));
};

//

