dojo.require("dijit.layout.ContentPane");
dojo.require("dojo.parser");
dojo.require("dijit.form.FilteringSelect");
dojo.require("dojo.data.ItemFileWriteStore");


var _p0vid, ytplaylisturl="/beta/t/ytstore/playlist.";
dojo.addOnLoad(function(){
	var stylesheet=dojo.doc.createElement("link"), cssrules;
	stylesheet.setAttribute("rel","stylesheet");
	stylesheet.setAttribute("href","/beta/t/css/video.css");
	dojo.doc.getElementsByTagName("head")[0].appendChild(stylesheet);
	stylesheet=dojo.doc.createElement("style");
	stylesheet.setAttribute("type","text/css");
	cssrules="#extVidP{\n\toverflow:hidden;\n}\n#p0player, #p0video{\n\twidth:355px;\n}\n#p0libContainer{\n\twidth:238px;\n}";
	if (stylesheet.styleSheet) stylesheet.styleSheet.cssText=cssrules;
	else stylesheet.appendChild(dojo.doc.createTextNode(cssrules));
	dojo.doc.getElementsByTagName("head")[0].appendChild(stylesheet);
	//dojo.parser.parse();
});

function VidInit(){
	try{
		_p0vid=new VidPanel();
	}catch(Err){console.log(Err);}
}

function unpackStoreItem(store,item,arrayValues,lvl){
	if (!store.isItem(item)) return;
        var     n, m, attrs=store.getAttributes(item),
                ui={}, tmp;
        if(typeof(lvl)=="undefined") lvl=0;
        else if(lvl>10) return ui;
        for(n=0;n<attrs.length;n++){
                if (arrayValues && attrs[n] in arrayValues){
                        tmp=store.getValues(item,attrs[n],null);
                        if (tmp){
                                for(m=0;m<tmp.length;m++){
                                        if (store.isItem(tmp[m]))
                                                tmp[m]=unpackStoreItem(store,tmp[m],arrayValues,lvl+1);
                                }
                        }
                        ui[attrs[n]]=tmp;
                        continue;
                }
                tmp=store.getValue(item,attrs[n],null);
                if (store.isItem(tmp)){
                        ui[attrs[n]]=unpackStoreItem(store,tmp,arrayValues,lvl+1);
                } else {
                        ui[attrs[n]]=tmp;
                }
        }
        return ui;
}

