
    $(document).ready(function(){

        $("#embedded_hires_link2, #embedded_lores_link2, #embedded_hires_link_pic2, #embedded_lores_link_pic2").live("click", function(){
            hide_embedded();
            var t = $(this);
            init_embedded_flash(t.attr("dID"), t.attr("db_path"), t.attr("path"), t.attr("hires"), t.attr("real_ip"), t.attr("_bgColor"), t.attr("_width"), t.attr("_height"));
        });
    });

    function hide_embedded(){
        $("#embedded_need_logged_on").slideUp("fast");
        $("#embedded_flash_div").slideUp("fast");
        $("#embedded_need_premium_on").slideUp("fast");
        $("#embedded_res_div").slideUp("fast");
        $("#embedded_flashcontent").html();
    }

    function show_embedded_flash(did, db_path, lo_path, hi_path, logged_in, is_prem, real_ip, prem_user, hires, vblock, prem_video, bgColor, _smallwidth, _smallheight, _width, _height){
        if( bgColor == undefined ) bgColor = "CAD08E";
        if( _smallwidth == undefined ) _smallwidth = -1;
        if( _smallheight == undefined ) _smallheight = -1;
        if( _width == undefined ) _width = -1;
        if( _height == undefined ) _height = -1;
        if (logged_in == 1){
            if ((prem_video == 1 && is_prem == 1) || (prem_video != 1)){
                    $("#embedded_hires_link2, #embedded_hires_link_pic2").attr("dID", did)
                        .attr("db_path", db_path)
                        .attr("path", hi_path)
                        .attr("logged_in", logged_in)
                        .attr("is_prem", is_prem)
                        .attr("real_ip", real_ip)
                        .attr("prem_user", prem_user)
                        .attr("hires", 1)
                        .attr("vblock", vblock)
                        .attr("prem_video", prem_video)
                        .attr("_width", _width)
                        .attr("_height", _height)
                        .attr("_bgColor", bgColor);

                    $("#embedded_lores_link2, #embedded_lores_link_pic2").attr("dID", did)
                        .attr("db_path", db_path)
                        .attr("path", lo_path)
                        .attr("logged_in", logged_in)
                        .attr("is_prem", is_prem)
                        .attr("real_ip", real_ip)
                        .attr("prem_user", prem_user)
                        .attr("hires", 0)
                        .attr("vblock", vblock)
                        .attr("prem_video", prem_video)
                        .attr("_width", _smallwidth)
                        .attr("_height", _smallheight)
                        .attr("_bgColor", bgColor);

                if (hires == 1){
                    hide_embedded();
                    $("#embedded_res_div").slideDown("fast");
                } else {
                    init_embedded_flash(did, db_path, lo_path, 0, real_ip, bgColor, _smallwidth, _smallheight);
                }
            } else {
                hide_embedded();
                show_embedded_premium();
            }
        } else {
            hide_embedded();
            show_embedded_loggedin();
        }
    }

    function show_embedded_premium(){
        hide_embedded();
        $("#embedded_need_premium_on").slideDown("fast");
    }

    function show_embedded_loggedin(){
        hide_embedded();
        $("#embedded_need_logged_on").slideDown("fast");
    }

    function init_embedded_flash(did, db_path, path, hires, real_ip, bgColor, _w, _h){
        hide_embedded();
        $("#embedded_flash_div").slideDown("fast");

        //if( bgColor === undefined )
            bgColor = 'CAD08E';

        var player_width = (hires == 0) ? "400" : "640";
        var player_height = (hires == 0) ? "390" : "570";

        if (_w > 0) player_width = _w;
        if (_h > 0) player_height = _h;


        $("#embedded_flashcontent").html('<iframe id="flash_container" allowtransparency="true" background="#' + bgColor + '" style="margin:0px; padding:0px;" src="/flvplayer/embedded_container.php?pfad='+path+'&hires='+hires+'&db_path='+db_path+'&bgColor='+ bgColor +'" width="'+player_width+'" height="'+player_height+'" frameborder="0" scrolling="no"></iframe>');


        $.get("/video_counter.php?&acache="+Math.round(Math.random()*100000), {"pfad": db_path, "did": did, "real_ip": real_ip});
    }
